././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1644246191.615767 unity-settings-daemon-15.04.1+21.10.20220207/0000775000175000017500000000000000000000000017036 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/AUTHORS0000664000175000017500000000011000000000000020076 0ustar00jeremyjeremyJonathan Blandford William Jon McCann ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/COPYING0000664000175000017500000004312200000000000020073 0ustar00jeremyjeremy GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 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. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) 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 this service 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 make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. 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. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. 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 Program or any portion of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, 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 Program, 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 Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) 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; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, 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 executable. However, as a special exception, the source code 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. If distribution of executable or 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 counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program 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. 5. 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 Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program 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 to this License. 7. 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 Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program 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 Program. 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. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program 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. 9. The Free Software Foundation may publish revised and/or new versions of the 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 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 Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, 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 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. 12. 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 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. 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 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. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision 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, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This 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 Library General Public License instead of this License. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/COPYING.LIB0000664000175000017500000006350400000000000020506 0ustar00jeremyjeremy 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. Copyright (C) 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. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/ChangeLog0000664000175000017500000042501300000000000020615 0ustar00jeremyjeremy2008-08-03 C de-Avillez * plugins/mouse/gsd-mouse-manager.c: add '-k' to syndaemon call, in order to ignore modifier keys when monitoring keyboard. Thanks to Dag Asheim for spotting this, and proposing a patch. 2008-07-01 Sergey Udaltsov * configure.ac, plugins/keyboard/gsd-keyboard-xkb.c: depend on libxklavier 4.0, updated API 2009-06-01 Jens Granseuer * plugins/housekeeping/gsd-disk-space.c: include config.h so the notifications stuff can actually be built (bug #584217) 2009-05-06 Federico Mena Quintero * plugins/xrandr/gsd-xrandr-manager.c (make_menu_item_for_output_title): Make the menu item label explicitly black. We don't want to follow the theme's colors, as the label is always shown against a light pastel background --- using the theme's colors makes the label hard to read on "inverse" themes. Fixes the gnome-settings-daemon part of bug #556050. 2009-04-15 Thomas H.P. Andersen * plugins/xrandr/gsd-xrandr-manager.c: (status_icon_start): * configure.ac: Replace deprecated gtk symbol gtk_status_icon_set_tooltip. Bump required gtk to 2.16. (bug #578480) 2009-04-14 Jens Granseuer * plugins/xrandr/gsd-xrandr-manager.c: (print_countdown_text): use ngettext for the reset dialog (bug #575409) ==================== 2.26.1 ==================== 2009-04-14 Jens Granseuer * NEWS: * configure.ac: release 2.26.1 2009-04-11 Jens Granseuer * plugins/keybindings/gsd-keybindings-manager.c: (gsd_keybindings_manager_start): move the lookup of allowed keys after the directory has been cached in callback registration to avoid GConf roundtrip (bug #578539) 2009-04-11 Jens Granseuer * plugins/keyboard/gsd-keyboard-manager.c: (start_keyboard_idle_cb): preload GConf keyboard directory recursively to avoid roundtrips (bug #578542) 2009-04-08 Federico Mena Quintero * plugins/xrandr/gsd-xrandr-manager.c (user_says_things_are_ok): Use 30 seconds for the confirmation timeout, so that monitors can settle down and the user will have a chance to read the message. 2009-04-03 Jens Granseuer Patch by: * plugins/media-keys/Makefile.am: don't install the plugin descriptor if the plugin isn't installed (bug #577815) 2009-04-02 Jens Granseuer * plugins/keyboard/gsd-keyboard-manager.c: (numlock_gconf_state_key): use info level instead of warning for the "NumLock remembering disabled" message (bug #577578) 2009-03-28 Jens Granseuer * plugins/xrandr/gsd-xrandr-manager.c: (sanitize), (generate_fn_f7_configs): if the sanitized array ends up having no members at all return a NULL configuration since the following code assumes it has at least one valid setup if it's not NULL. Fixes a crash when closing the lid on some laptops (bug #576875) 2009-03-27 Jens Granseuer * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (on_notification_closed), (on_slow_keys_action), (on_sticky_keys_action), (ax_slowkeys_warning_post_bubble), (ax_stickykeys_warning_post_bubble), (gsd_a11y_keyboard_manager_stop): fix crash when closing the a11y notification bubble caused by incompatible changes in libnotify API (bug #576535). Also remove workarounds for bugs in libnotify < 0.4.5 2009-03-27 Jens Granseuer * plugins/xrandr/gsd-xrandr-manager.c: (restore_backup_configuration), (try_to_apply_intended_configuration): remove unused variables 2009-03-26 Federico Mena Quintero * plugins/xrandr/gsd-xrandr-manager.c (ensure_current_configuration_is_saved): New helper function. Ensures that a monitors.xml exists with the current/unchanged configuration, so that a latter gnome_rr_config_save() will create a backup file out of *that* original configuration. This lets the "revert" function from gnome-display-properties work properly on an initial login, even when there is no monitors.xml already present. 2009-03-25 Federico Mena Quintero * plugins/xrandr/gsd-xrandr-manager.c (restore_backup_configuration): Handle the case where no backup file was created for monitors.xml, because *that* file didn't exist (such as on a first-time login). 2009-03-25 Federico Mena Quintero Centralize the handling of GNOME_RR_ERROR_NO_MATCHING_CONFIG, as that is not really an error. * plugins/xrandr/gsd-xrandr-manager.c (apply_configuration_from_filename): New helper function; centralizes the handling of gnome_rr_config_apply_from_filename() and ignores GNOME_RR_ERROR_NO_MATCHING_CONFIG. That is not actually an error; it just means that the user probably changed his monitors and the stored set of configurations doesn't have a config that is usable for the new monitors. (restore_backup_configuration): Use apply_configuration_from_filename(). (try_to_apply_intended_configuration): Likewise. (apply_intended_configuration): Likewise. (apply_stored_configuration_at_startup): Likewise. 2009-03-19 Federico Mena Quintero http://bugzilla.gnome.org/show_bug.cgi?id=576006 - The confirmation dialog from the RANDR plugin can appear behind the window from gnome-display-properties. This also depends on a change to gnome-control-center. * plugins/xrandr/gsd-xrandr-manager.xml: Add an org.gnome.SettingsDaemon.XRANDR_2 interface in addition to the old XRANDR one, with an ApplyConfiguration method that also takes a parent window ID and a timestamp. * plugins/xrandr/gsd-xrandr-manager.c (gsd_xrandr_manager_2_apply_configuration): Implement the new DBus method with the parent window and timestamp. (user_says_things_are_ok): Use the parent window. 2009-03-19 Federico Mena Quintero * plugins/xrandr/gsd-xrandr-manager.c (user_says_things_are_ok): Revert the use of g_timeout_add_seconds(), since we actually care that the user sees real second ticks in the dialog. This isn't a neverending timeout anyway. 2009-03-18 Jens Granseuer * gnome-settings-daemon/Makefile.am: * plugins/a11y-keyboard/Makefile.am: * plugins/background/Makefile.am: * plugins/clipboard/Makefile.am: * plugins/dummy/Makefile.am: * plugins/font/Makefile.am: * plugins/housekeeping/Makefile.am: * plugins/keybindings/Makefile.am: * plugins/keyboard/Makefile.am: * plugins/media-keys/Makefile.am: * plugins/mouse/Makefile.am: * plugins/screensaver/Makefile.am: * plugins/sound/Makefile.am: * plugins/typing-break/Makefile.am: * plugins/xrandr/Makefile.am: * plugins/xrdb/Makefile.am: * plugins/xsettings/Makefile.am: revert build patch from r763 ==================== 2.26.0 ==================== 2009-03-16 Rodrigo Moya * NEWS: * configure.ac: release 2.26.0 2009-03-07 Jens Granseuer Based on patch by: Christopher Taylor * gnome-settings-daemon/Makefile.am: * plugins/a11y-keyboard/Makefile.am: * plugins/background/Makefile.am: * plugins/clipboard/Makefile.am: * plugins/dummy/Makefile.am: * plugins/font/Makefile.am: * plugins/housekeeping/Makefile.am: * plugins/keybindings/Makefile.am: * plugins/keyboard/Makefile.am: * plugins/media-keys/Makefile.am: * plugins/mouse/Makefile.am: * plugins/screensaver/Makefile.am: * plugins/sound/Makefile.am: * plugins/typing-break/Makefile.am: * plugins/xrandr/Makefile.am: * plugins/xrdb/Makefile.am: * plugins/xsettings/Makefile.am: make build work with -Wl,-z,defs linker options (bug #574452) ==================== 2.25.92 ==================== 2009-03-02 Jens Granseuer * NEWS: * configure.ac: release 2.25.92 2009-03-02 Jens Granseuer * gnome-settings-daemon/Makefile.am: also install the plugin header file because it is needed for custom plugins (bug #573610) 2009-02-23 Jens Granseuer * data/gnome-settings-daemon.schemas.in: add missing keys for a11y shortcut names (bug #572807) 2009-02-22 Jens Granseuer * plugins/xrandr/gsd-xrandr-manager.c: (user_says_things_are_ok): use g_timeout_add_seconds instead of g_timeout_add 2009-02-21 Jens Granseuer * plugins/xrandr/gsd-xrandr-manager.c: (timeout_response_cb): revert the screen resolution change if the user closes the window or hits escape (bug #571492) 2009-02-21 Jens Granseuer Fix compiler warnings. * plugins/housekeeping/gsd-disk-space.c: add missing include * plugins/housekeeping/gsd-housekeeping-manager.c: ditto * plugins/housekeeping/gsd-disk-space.h: don't declare public functions static 2009-02-20 Jens Granseuer * plugins/keybindings/gsd-keybindings-manager.c: (parse_binding), (bindings_get_entry): don't output a warning for disabled shortcuts 2009-02-15 Jens Granseuer Patch by: Leo Iannacone * plugins/media-keys/gsd-media-keys-window.c: (on_expose_event): fix alignment of the composited media window (bug #567249) 2009-02-15 Luca Ferretti reviewed by: Jens Granseuer * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (ax_slowkeys_warning_post_dialog), (ax_stickykeys_warning_post_dialog): * plugins/mouse/gsd-mouse-manager.c: (set_mousetweaks_daemon): Don't use legacy icons for keyboard and mouse (bug #571823) 2009-02-15 Luca Ferretti reviewed by: Jens Granseuer * plugins/xrandr/gsd-xrandr-manager.c: (user_says_things_are_ok): HIG fix for button labels (bug #571819) 2009-02-15 Luca Ferretti reviewed by: Jens Granseuer * plugins/keyboard/modmap-dialog.glade: Fix label for "Don't show this message again" checkbox, isn't a `string change` due to reusing a yet available label (bug #571821) 2009-02-11 Jens Granseuer * plugins/common/eggaccelerators.c: (egg_accelerator_parse_virtual): don't return TRUE if we can't parse the accelerator at all; fixes crash with invalid keyboard shortuts (bug #571329) 2009-02-11 Matthias Clasen Bug 570590 – a11y plugin warning * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: Avoid warnings due to notifications on nonexisting statusicons. 2009-02-08 Jens Granseuer Patch by: Nirbheek Chauhan * configure.ac: add --without-libnotify to disable notifications (bug #570885) 2009-02-06 Matthias Clasen Bug 570743 – restart on crash * data/gnome-settings-daemon.desktop.in.in: Have gnome-session restart g-s-d if it crashes (heaven forbid!). 2009-02-04 Vincent Untz * configure.in: post-release bump to 2.25.91 ==================== 2.25.90 ==================== 2009-02-04 Vincent Untz * NEWS: * configure.in: version 2.25.90 2009-02-04 Vincent Untz * data/Makefile.am: fix distcheck 2009-02-03 Federico Mena Quintero * plugins/xrandr/gsd-xrandr-manager.c (restore_backup_configuration): Use gnome_rr_config_apply_from_filename(), as that's the new, non-deprecated API. (try_to_apply_intended_configuration): Likewise. (apply_intended_configuration): Likewise. (apply_stored_configuration_at_startup): Likewise. 2009-02-01 Frederic Peters * plugins/housekeeping/Makefile.am: * plugins/housekeeping/gsd-disk-space.c: add low diskspace checker files to housekeeping plug-in Makefile.am; and make its clean and setup methods available are made available. (bug #570132) 2009-01-31 Theppitak Karoonboonyanan * plugins/media-keys/Makefile.am: Fix include paths for non-source-dir builds. (bug #569955) 2009-01-28 Jens Granseuer * configure.ac: require gnome-desktop 2.25.6 due to recent changes 2009-01-27 Federico Mena Quintero http://bugzilla.gnome.org/show_bug.cgi?id=545115 - Ask for confirmation, with a timeout, after changing the RANDR configuration for if we leave the user with an unusable display. This also handles the case where the machine may crash after changing the configuration; the old/known-good configuration will be restored when the user restarts his session. Refactor: * plugins/xrandr/gsd-xrandr-manager.c (apply_stored_configuration_at_startup): Factor out the logic to apply the stored configuration at startup. (gsd_xrandr_manager_start): Use the function above. During startup, restore the backup configuration if it existed, to recover from the case when the machine crashes while applying an intended configuration. * plugins/xrandr/gsd-xrandr-manager.c (apply_stored_configuration_at_startup): First see if we have a backup configuration; if so, it means the machine or g-s-d crashed while changing the RANDR parameters. If there is no backup configuration, then we have a known-good configuration which we can use. (apply_intended_configuration): New function, used to load the intended configuration (i.e. the non-backup one). (restore_backup_configuration): Utility function to overwrite the known-bad configuration with the known-good backup one. Use a timeout-confirmation dialog after changing the display configuration: * plugins/xrandr/gsd-xrandr-manager.c (try_to_apply_intended_configuration): New function; applies the intended configuration, restores the backup configuration if that fails, or asks the user to confirm if the intended configuration is usable. (gsd_xrandr_manager_apply_configuration): Use try_to_apply_intended_configuration() in the implementation of the D-Bus method to apply RANDR configurations. This way all apps which use this D-Bus method will get confirmation for free. (output_rotation_item_activate_cb): Use try_to_apply_intended_configuration() so that the RANDR tray-icon also uses the confirmation/backup logic. (restore_backup_configuration): Restore the screen configuration itself in addition to restoring the file on disk from the backup. (user_says_things_are_ok): New utility function to handle a timeout-confirmation dialog. Fix error reporting at startup: * plugins/xrandr/gsd-xrandr-manager.c (error_message): Handle the case where the status_icon is not created yet; this happens during startup or when the status_icon is disabled by the user. Handle the case where there is no matching configuration at startup; this is not an error: * plugins/xrandr/gsd-xrandr-manager.c (apply_intended_configuration): "no matching configuration" is not an error when looking for a suitable configuration in monitors.xml; it simply means that the user has a different set of monitors than the ones that are available in that file. 2009-01-24 Jens Granseuer Patch by: Andres Freund Fix possible crash when pressing Fn-F7 (bug #568713) * plugins/xrandr/gsd-xrandr-manager.c: (handle_fn_f7): only try to dereference the error when it was actually set 2009-01-27 Federico Mena Quintero http://bugzilla.gnome.org/show_bug.cgi?id=545115 - Ask for confirmation, with a timeout, after changing the RANDR configuration for if we leave the user with an unusable display. This also handles the case where the machine may crash after changing the configuration; the old/known-good configuration will be restored when the user restarts his session. Refactor: * plugins/xrandr/gsd-xrandr-manager.c (apply_stored_configuration_at_startup): Factor out the logic to apply the stored configuration at startup. (gsd_xrandr_manager_start): Use the function above. 2009-01-26 Ray Strode Delay drawing the background until SessionRunning. * plugins/background/gsd-background-manager.c: (queue_draw_background): Cancel queued draw if nautilus is now running. (on_bus_message), (draw_background_after_session_loads), (gsd_background_manager_start): wait for SessionRunning and then queue background draw (gsd_background_manager_stop): remove message filter 2009-01-24 Jens Granseuer Patch by: Andres Freund Fix possible crash when pressing Fn-F7 (bug #568713) * plugins/xrandr/gsd-xrandr-manager.c: (handle_fn_f7): only try to dereference the error when it was actually set 2009-01-22 Bastien Nocera * data/apps_gnome_settings_daemon_keybindings.schemas.in: KEY_FILE maps to XF86Explorer, so use that to launch the file manager in the user's home directory 2009-01-19 Ray Strode Add crossfade transition when switching bgs (bug 552857) * plugins/background/gsd-background-manager.c (draw_background): Add use_crossfade argument that initiates the fade if TRUE. (on_bg_changed): call draw_background with crossfade. (on_bg_transitioned): new function that calls draw_background without crossfade during slide show transitioning. (setup_bg): set up transitioned signal handler. (queue_draw_background): draw_background without crossfade after 8 second timeout waiting for nautilus. 2009-01-19 Ray Strode * plugins/background/gsd-background-manager.c (gsd_background_manager_start): Don't draw_background immediately when nautilus is disabled. gnome_bg_load_from_preferences forces a "changed" signal to get emitted which will queue a draw anyway 2009-01-18 Jens Granseuer * plugins/media-keys/Makefile.am: fix automake warning 2009-01-18 Jens Granseuer * configure.ac: fix build with PulseAudio, too (bug #568179) 2009-01-17 Jens Granseuer * plugins/media-keys/Makefile.am: fix build without PulseAudio (bug #568015) 2009-01-15 Bastien Nocera * plugins/media-keys/cut-n-paste/*: Cut'n'paste code from the PulseAudio enabled code in gnome-media's gnome-volume-control * plugins/media-keys/actions/acme-volume-*.[ch]: Remove the old AcmeVolume code * plugins/media-keys/actions/acme.glade: * plugins/media-keys/actions/acme.h: Move to plugins/media-keys/ * configure.ac: Tell config.h when PulseAudio support is disabled * plugins/media-keys/gsd-media-keys-manager.c (update_dialog), (on_stream_event_notify), (do_sound_action), (update_default_sink), (on_control_ready), (on_control_default_sink_changed), (do_action), (gsd_media_keys_manager_start), (gsd_media_keys_manager_stop): Use PulseAudio directly to change the volume. It will automatically change the volume of the default audio output for the machine (Closes: #567177) * plugins/media-keys/Makefile.am: * plugins/media-keys/actions/Makefile.am: Changes for the above 2009-01-15 Jens Granseuer * plugins/keybindings/gsd-keybindings-manager.c: (binding_unregister_keys), (gsd_keybindings_manager_stop): also ungrab keys when this module is disabled 2009-01-15 Jens Granseuer * plugins/media-keys/gsd-media-keys-manager.c: (gsd_media_keys_manager_stop): ungrab shortcut keys when the plugin is disabled (bug #567867) 2009-01-14 Federico Mena Quintero * plugins/xrandr/gsd-xrandr-manager.c (gsd_xrandr_manager_start): If there was no file with a stored configuration, don't pop up an error message --- this is not an error when the daemon starts up. Fixes https://bugzilla.novell.com/show_bug.cgi?id=465968 2009-01-10 William Jon McCann * plugins/sound/gsd-sound-manager.c (register_config_callback): Fix typo. 2009-01-08 Jens Granseuer Based on a patch by: Lennart Poettering * configure.ac: * data/gnome-settings-daemon.schemas.in: * plugins/Makefile.am: * plugins/sound/Makefile.am: * plugins/sound/gsd-sound-manager.c: * plugins/sound/gsd-sound-plugin.h: * plugins/sound/sound.gnome-settings-plugin.in: Add a new sound plugin that tells PulseAudio to drop its sample cache when the sound theme changes (bug #545386). 2009-01-08 Jens Granseuer * plugins/media-keys/gsd-media-keys-manager.c: (gsd_media_keys_manager_grab_media_player_keys), (gsd_media_keys_manager_release_media_player_keys): add a little debugging output when de/registering media players (bug #564433) 2009-01-05 Bastien Nocera * plugins/xrdb/gsd-xrdb-manager.c (apply_settings): Quiet xrdb when there are duplicate rules in the .ad files (Closes: #566610) 2008-12-30 Matthias Clasen Bug 565310 – support hotkeys for a11y tools * configure.ac: Set GNOME_KEYBINDINGS_KEYSDIR. * data/gnome-settings-daemon.schemas.in: Add missing schemas for the keys in /destkop/gnome/applications/at, and also add new schemas for keys in /desktop/gnome/keybindings that define global keybindings for turning ATs on and off. Todo: There are no default key combinations in the schema yet. * data/50-accessibility.xml.in: Keybinding file to group the new keybindings in an "Accessibility" section in the keybinding capplet. * data/Makefile.am: Install the keybinding file in the proper location. * po/POTFILES.in: Add 50-accessibility.xml.in. 2008-12-31 Rodrigo Moya Patch by Vincent Untz from openSUSE package (bug #557647) * configure.ac: require giounix for diskspace checker * Makefile.am: * plugins/housekeeping/gsd-disk-space.[ch]: add low diskspace checker to housekeeping plugin. * plugins/housekeeping/gsd-housekeeping-manager.c (gsd_housekeeping_manager_start, gsd_housekeeping_manager_stop): start/stop the low diskspace checker. * plugins/housekeeping/housekeeping.gnome-settings-plugin.in: add new plugin capability to description * po/POTFILES.in: add new files 2008-12-28 Jens Granseuer * plugins/screensaver/gsd-screensaver-manager.c: (start_screensaver_cb), (gsd_screensaver_manager_start): spawn screensaver after a 30 second timeout instead of when idle so that it doesn't compete with other processes when the session starts (bug #564059). Also plug a few small leaks. 2008-12-28 Jens Granseuer Based on patch by: Jasper Lievisse Adriaanse * plugins/media-keys/gsd-media-keys-manager.c: (do_eject_action), (do_action): better support for Eject and Sleep actions on OpenBSD and FreeBSD (bug #565472) 2008-12-28 Jens Granseuer Patch by: Jasper Lievisse Adriaanse * plugins/typing-break/gsd-typing-break-manager.c: include signal.h to fix build on OpenBSD (bug #565470) 2008-12-28 Jens Granseuer Patch by: Frederic Peters * gnome-settings-daemon/main.c: (main): initialize thread system since ORBit no longer does it for us (#565515) ==================== 2.25.3 ==================== 2008-12-18 Bastien Nocera * NEWS: upd * configure.ac: 2.25.3 update gnome-desktop requirements for the new GnomeRR API * plugins/xrandr/Makefile.am: Fix distcheck 2008-12-07 Ray Strode Restore AccessX bits to original values on exit * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c (struct GsdA11yKeyboardManagerPrivate): add new field to cache original AccessX bits. (start_a11y_keyboard_idle_cb): save bits. (restore_server_xkb_config), (gsd_a11y_keyboard_manager_stop): restore bits when stopping. 2008-12-07 Ray Strode Shutdown properly when bus goes away. Previously we were just letting libdbus call exit(1) for us. * gnome-settings-daemon/main.c (get_session_bus): Set up a filter function to catch disconection events. (bus_message_handler): quit event loop when disconnected from bus. 2008-12-07 Ray Strode Shutdown properly when killed. * gnome-settings-daemon/main.c (on_term_signal): top half of signal handling code. close a pipe when getting SIGTERM. (on_term_signal_pipe_closed), (watch_for_term_signal), (set_session_over_handler): bottom half. Quit event loop when term pipe gets closed. 2008-12-07 Ray Strode * gnome-settings-daemon/main.c: Rename pipefds to daemon_pipe_fds. This fits the naming style of the surrounding code better. Also, we're going to need another pipe, so better to use a specific name here. 2008-12-09 Jens Granseuer Patch by: Pedro Fragoso * plugins/a11y-keyboard/gsd-a11y-preferences-dialog.h: * plugins/common/eggaccelerators.c: * plugins/common/eggaccelerators.h: * plugins/mouse/gsd-locate-pointer.h: only use top-level headers for glib and GTK+ (bug #563796) 2008-12-08 Jens Granseuer * plugins/xrandr/gsd-xrandr-manager.c: (error_message): make libnotify optional again (bug #563226) (handle_fn_f7): fix memory leak, use g_debug instead of g_print 2008-12-07 Behdad Esfahbod * gnome-settings-daemon/main.c (daemon_detach): Don't call umask (bug #563543) 2008-12-04 Jens Granseuer * plugins/mouse/gsd-mouse-manager.c: (set_devicepresence_handler): fix crash with X servers that don't provide XInput (bug #562977) 2008-12-02 Federico Mena Quintero Use a DBus interface to tell the XRANDR manager to apply the stored configuration, instead of an X client message, so that we can pass errors back to the caller. * plugins/xrandr/gsd-xrandr-manager.xml: Trivial DBus interface to tell the XRANDR manager to apply the stored configuration. * plugins/xrandr/gsd-xrandr-manager.c (gsd_xrandr_manager_apply_configuration): Moved from on_client_message(). Now we are a DBus-Glib method, so that we can pass back errors to the remote caller. * plugins/xrandr/Makefile.am: Add the machinery to generate DBus glue. 2008-12-02 Federico Mena Quintero * plugins/xrandr/gsd-xrandr-manager.c (error_message): Renamed from error_dialog(); use libnotify instead of ugly dialogs for error messages. (gsd_xrandr_manager_start): Proxy the error from gnome_rr_screen_new() to our caller. (gsd_xrandr_manager_start): Display an error if we cannot apply the initially-loaded configuration. (generate_fn_f7_configs, get_allowed_rotations_for_output): Pass GError arguments to the gnome_rr_*() functions. (handle_fn_f7): Display an error if we cannot refresh the screen configuration or apply the new one. (output_rotation_item_activate_cb): Display an error if the rotation cannot be applied. Tue Dec 2 15:37:21 2008 Søren Sandmann * plugins/xrandr/gsd-xrandr-manager.c: Add support for fn-F7 type keys. ==================== 2.25.2 ==================== 2008-12-01 Rodrigo Moya * NEWS: * configure.ac: prepare for 2.25.2 release. 2008-11-29 Jens Granseuer * plugins/keyboard/gsd-keyboard-xkb.c: (gsd_keyboard_xkb_init): fix check for xklavier device discovery 2008-11-29 Jens Granseuer * configure.ac: fix checks for various X11 libraries (bug #562661) * plugins/mouse/gsd-mouse-manager.c: (set_left_handed), (gsd_mouse_manager_idle_cb), (gsd_mouse_manager_stop): * plugins/xrandr/gsd-xrandr-manager.c: adapt ifdefs accordingly 2008-11-27 Sergey Udaltsov * configure.ac, plugins/keyboard/gsd-keyboard-xkb.c: introduce dependency on libxklavier 3.8. Use "new device" notification to reload XKB configuration when new keyboard is plugged in 2008-11-24 Behdad Esfahbod * gnome-settings-daemon/main.c (parse_args), (main): Fix --no-daemon (bug #562175) 2008-11-24 Jens Granseuer When multiple keys (keycodes) were mapped to the same keysym, g-s-d would only accept the first of those keycodes in the keymap as a valid shortcut. To fix this, instead of checking against a single keycode, we need to grab all keycodes that match the respective keysym (bug #561275). With thanks to Mario Limonciello * plugins/common/eggaccelerators.c: (egg_accelerator_parse_virtual): * plugins/common/eggaccelerators.h: possibly return multiple keycodes * plugins/common/gsd-keygrab.c: (grab_key_unsafe), (key_uses_keycode), (match_key): grab all matching keys * plugins/common/gsd-keygrab.h: * plugins/keybindings/gsd-keybindings-manager.c: (parse_binding), (bindings_get_entry), (same_keycode), (same_key), (key_already_used), (binding_register_keys), (gsd_keybindings_manager_stop): * plugins/media-keys/gsd-media-keys-manager.c: (update_kbd_cb), (init_kbd), (gsd_media_keys_manager_stop): update to handle changes in data structures 2008-11-23 Jens Granseuer Patch by: * configure.ac: add bundle_loader linker flag to fix compilation on MacOS X (bug #522673) 2008-11-20 Jens Granseuer * plugins/media-keys/gsd-media-keys-manager.c: (find_by_time), (gsd_media_keys_manager_grab_media_player_keys): fix handling of time = GDK_CURRENT_TIME. Previously, apps that registered with GDK_CURRENT_TIME would be trumped by any app that registered with time != 0 (bug #559797) 2008-11-20 Jens Granseuer * plugins/mouse/gsd-mouse-manager.c: (set_devicepresence_handler): trap X errors so we don't crash on X servers that don't support DevicePresence (bug #560618) 2008-11-13 Jens Granseuer * data/desktop_gnome_keybindings.schemas.in: fix typo 2008-11-11 Matthias Clasen Bug 553434 – lockdown in the keybinding plugin * data/Makefile.am: Install the new schema file. * data/desktop_gnome_keybindings.schemas.in: Add schema for /desktop/gnome/keybindings/allowed_keys. * plugins/keybindings/gsd-keybinding-manager.c: Support locking down keybindings with a list of allowed keys. 2008-11-10 Behdad Esfahbod * gnome-settings-daemon/main.c (daemon_start): Check return value of pipe(). 2008-11-10 Behdad Esfahbod * gnome-settings-daemon/main.c (daemon_start), (daemon_detach), (daemon_terminate_parent), (main): Fork before gtk_init (bug #559695) 2008-11-09 Jens Granseuer * plugins/media-keys/gsd-media-keys-manager.c: (do_sound_action): add debugging output for volume_step 2008-11-08 Jens Granseuer Patch by: William Grant * plugins/mouse/gsd-mouse-manager.c: (devicepresence_filter): listen for DeviceEnabled instead of DeviceAdded so we can be sure it has been initialized (bug #559827) 2008-11-06 Behdad Esfahbod * plugins/background/gsd-background-manager.c (setup_bg), (queue_draw_background), (gsd_background_manager_start): Delay constructing the GnomeBg object until we need it. This avoids unneeded change triggers caused by a bug in gnome-screensaver (fixed in trunk it seems). (bug #559639) 2008-11-06 Behdad Esfahbod * data/gnome-settings-daemon.schemas.in: Reshuffle plugin priorities a bit. Now that we do many of the plugins in idle callback, those can be put at the end. 2008-11-06 Behdad Esfahbod * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c (maybe_show_status_icon), (ax_slowkeys_warning_post_bubble), (ax_stickykeys_warning_post_bubble), (gsd_a11y_keyboard_manager_stop), (gsd_a11y_keyboard_manager_ensure_status_icon), (gsd_a11y_keyboard_manager_init): Init status icon only when needed (bug #559558) 2008-11-06 Behdad Esfahbod * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c (start_a11y_keyboard_idle_cb), (gsd_a11y_keyboard_manager_start): Start manager in idle callback (bug #559564) * plugins/media-keys/gsd-media-keys-manager.c (start_media_keys_idle_cb), (gsd_media_keys_manager_start): Start manager in idle callback (bug #559564). Leave the acme initialization in the main start function to force gstreamer cache up to date check before we let other applications start. 2008-11-06 Behdad Esfahbod * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c (get_xkb_desc_rec): * plugins/common/gsd-keygrab.c (have_xkb): Remove more unnecessary X error traps and synchs (bug #559562) 2008-11-06 Jens Granseuer * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (xkb_enabled), (gsd_a11y_keyboard_manager_start): remove unnecessary X error traps (bug #559562) 2008-11-05 Behdad Esfahbod * plugins/xsettings/fontconfig-monitor.c (fontconfig_cache_init): * plugins/xsettings/fontconfig-monitor.h: * plugins/xsettings/gsd-xsettings-manager.c (start_fontconfig_monitor): Only initialize fontconfig when starting up. A cache update is redundant there. (bug #559550) 2008-11-05 Behdad Esfahbod * plugins/keyboard/gsd-keyboard-manager.c (start_keyboard_idle_cb), (gsd_keyboard_manager_start): Start manager in idle callback (bug #559482) 2008-11-05 Behdad Esfahbod * plugins/keyboard/gsd-keyboard-xkb.c (gsd_keyboard_xkb_init): Add some performance logging annotations around libxklavier calls. 2008-11-05 Jens Granseuer * plugins/keyboard/gsd-keyboard-manager.c: (numlock_xkb_init): XkbQueryExtension and friends shouldn't cause errors, so no need to try and trap them (bug #559346) ==================== 2.25.1 ==================== 2008-11-04 Rodrigo Moya * NEWS: * configure.ac: prepare for 2.25.1 release 2008-11-04 Behdad Esfahbod * gnome-settings-daemon/main.c (daemonize), (main): Use a pipe to communicate between child and parent process instead of a signal. Signals are not queued, so if the child tried to signal the parent before the parent got a chance to wait for it, the signal would be lost and parent wait indefinitely for a signal that would never arrive. 2008-11-04 Behdad Esfahbod * gnome-settings-daemon/main.c (daemonize): Don't close stderr. Otherwise we just lose all our warnings that will not end up in ~/.xsession-errors. Also fix indentation. 2008-11-03 Jens Granseuer * plugins/keyboard/gsd-keyboard-xkb.c: add missing include 2008-11-03 Behdad Esfahbod * gnome-settings-daemon/main.c (daemonize), (main): Make parent wait for initialization in children to finish before returning. This makes gnome-session to wait for initialization to be done before spawning other processes. This way, apps start up with the right xsettings and other settings, and don't have to handle change signals right after starting up. (bug #559168) 2008-11-03 Behdad Esfahbod * gnome-settings-daemon/gnome-settings-manager.c (_load_file), (gnome_settings_manager_start), (gnome_settings_manager_stop): * gnome-settings-daemon/gnome-settings-plugin-info.c (gnome_settings_plugin_info_set_enabled_key_name): * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c (register_config_callback): * plugins/keybindings/gsd-keybindings-manager.c (register_config_callback), (gsd_keybindings_manager_start): * plugins/keyboard/gsd-keyboard-manager.c (gsd_keyboard_manager_start): * plugins/keyboard/gsd-keyboard-xkb.c (register_config_callback): * plugins/mouse/gsd-mouse-manager.c (register_config_callback): * plugins/typing-break/gsd-typing-break-manager.c (gsd_typing_break_manager_start): * plugins/xrandr/gsd-xrandr-manager.c (gsd_xrandr_manager_start): * plugins/xsettings/gsd-xsettings-manager.c (register_config_callback), (gnome_xsettings_manager_start): Preload gconf dirs when feasible (bug #559167) 2008-11-03 Behdad Esfahbod * plugins/clipboard/gsd-clipboard-manager.c (start_clipboard_idle_cb), (gsd_clipboard_manager_start): Start manager in idle callback (bug #559166) * plugins/mouse/gsd-mouse-manager.c (gsd_mouse_manager_idle_cb), (gsd_mouse_manager_start): Start manager in idle callback (bug #559166) * plugins/xsettings/fontconfig-monitor.c (fontconfig_cache_update), (update): * plugins/xsettings/fontconfig-monitor.h: * plugins/xsettings/gsd-xsettings-manager.c (start_fontconfig_monitor_idle_cb), (start_fontconfig_monitor), (stop_fontconfig_monitor): Start fontconfig monitors in idle callback. However, make sure fontconfig caches are up to date during initialization (bug #559166) 2008-11-03 Behdad Esfahbod * plugins/mouse/gsd-mouse-manager.c (set_mousetweaks_daemon): Don't run "mousetweaks -s" at startup time (#559165) All "mousetweaks -s" does is shutdown the already-running daemon. When g-s-d starts, there is no daemon running. So, remember that and do not try to shut the non-existing daemon down. 2008-11-03 Behdad Esfahbod * plugins/common/gsd-keygrab.c (setup_modifiers), (grab_key_real), (grab_key_unsafe): * plugins/common/gsd-keygrab.h: * plugins/keybindings/gsd-keybindings-manager.c (binding_register_keys): * plugins/media-keys/gsd-media-keys-manager.c (update_kbd_cb), (init_kbd): Don't trap errors around grab_key (bug #559164) Such that we can do a single gdk_flush for multiple keys. The only downside is that we cannot write out in the warning which key is being accessed by another app. Not that we really care. 2008-11-03 Behdad Esfahbod * plugins/font/gsd-font-manager.c (setup_dir), (empty_check_dir), (setup_font_dir), (setup_cursor_dir), (load_font_paths), (gsd_font_manager_start): Cleanup font module (bug #559163) The old code had several flaws: - It tried to create directories in user's home even if we didn't have any use for them. - It called mkfontdir and XSync even if there was no fonts installed. The new code does the following: - Only call mkfontdir and XSync if there's actually any fonts in the relevant dirs. - Remove the ~/.gnome2/share/fonts and/or ~/.gnome2/share/cursor-fonts if they are empty and no cursor font is set. 2008-11-03 Behdad Esfahbod * gnome-settings-daemon/gnome-settings-manager.c (_load_file): * gnome-settings-daemon/gnome-settings-plugin-info.c (gnome_settings_plugin_info_fill_from_file), (load_plugin_module): * plugins/font/gsd-font-manager.c (child_watch_cb), (spawn_with_input): * plugins/keyboard/gsd-keyboard-xkb.c (gsd_keyboard_xkb_init): * plugins/xrandr/gsd-xrandr-manager.c (gsd_xrandr_manager_start): * plugins/xsettings/gsd-xsettings-manager.c (child_watch_cb), (spawn_with_input), (start_fontconfig_monitor), (stop_fontconfig_monitor), (gnome_xsettings_manager_start), (gnome_xsettings_manager_stop): Improve performance logging annotations (bug #559162) 2008-11-03 Behdad Esfahbod * data/gnome-settings-daemon.schemas.in: Disable xrdb plugin by default (#bug #557807) 2008-11-02 Jens Granseuer * configure.ac: remove AM_MAINTAINER_MODE because it is deprecated and supposedly unsafe (bug #558503) 2008-11-01 Jens Granseuer Patch by: William Grant * plugins/mouse/gsd-mouse-manager.c: (devicepresence_filter), (set_devicepresence_handler), (set_mouse_settings), (gsd_mouse_manager_start), (gsd_mouse_manager_stop): listen for X device changes, and reconfigure the mouse if necessary so that the settings aren't ignored when hotplugging (bug #549267) 2008-10-29 Jens Granseuer Get rid of libgnome (bug #557808). * configure.ac: bump required gtk+ version to 2.13.1 * gnome-settings-daemon/main.c: (main): don't use g_program_init * plugins/a11y-keyboard/Makefile.am: * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (ax_response_callback), (ax_stickykeys_response), (ax_slowkeys_response), (on_slow_keys_action), (on_sticky_keys_action): replace gnome_help_display_desktop with gtk_show_uri 2008-10-29 Jens Granseuer * plugins/screensaver/gsd-screensaver-manager.c: (gsd_screensaver_manager_start): fix plugin activation, too 2008-10-29 Jens Granseuer * plugins/screensaver/gsd-screensaver-manager.c: (start_screensaver_idle_cb), (gsd_screensaver_manager_start): fix broken changes to screensaver plugin 2008-10-29 Jens Granseuer Remove ESD-based sound plugin (bug #557806). This means that g-s-d will no longer start a sound server (esd or PulseAudio) at session startup. This should be handled using the autostart mechanism of gnome-session instead. * configure.ac: * plugins/Makefile.am: * plugins/sound/Makefile.am: * plugins/sound/gsd-sound-manager.c: * plugins/sound/gsd-sound-manager.h: * plugins/sound/gsd-sound-plugin.c: * plugins/sound/gsd-sound-plugin.h: * plugins/sound/sound.gnome-settings-plugin.in: remove sound plugin 2008-10-29 Rodrigo Moya * plugins/screensaver/gsd-screensaver-manager.c (gsd_screensaver_manager_start): spawn screensaver process in idle callback as it was before. 2008-10-23 Jens Granseuer Based on a patch by: Bogdan Butnaru * plugins/media-keys/gsd-media-keys-window.c: (draw_waves), (draw_cross), (draw_action_volume): make the composited volume images more clear: draw waves matching current volume and show a cross when muted (bug #557307) 2008-10-23 Jens Granseuer * plugins/media-keys/actions/acme-volume-gstreamer.c: (acme_volume_gstreamer_finalize), (acme_volume_gstreamer_close_real), (acme_volume_gstreamer_open), (acme_volume_gstreamer_close), (acme_volume_gstreamer_init), (acme_volume_gstreamer_class_init): * plugins/media-keys/actions/acme-volume-gstreamer.h: clean up Volume initialization so that we don't get non-functional volume keys when the plugin starts up with an invalid configuration initially, even if the configuration is fixed afterwards (bug #552383) 2008-10-19 Matthias Clasen Bug 556797 – support the Gtk/ButtonImages XSetting * plugins/xsettings/gsd-xsettings-manager.c: Support the Gtk/ButtonImages xsetting. 2008-10-15 Matthias Clasen Bug 556307 – show the shutdown dialog when the power button is pressed * plugins/media-keys/gsd-media-keys-manager.c (do_exit_action): Show the shutdown dialog when the power button is pressed, not the logout dialog. 2008-10-12 Christian Persch Bug 555553 – format not a string literal and no format arguments * gnome-settings-daemon/gnome-settings-manager.c * gnome-settings-daemon/gnome-settings-module.c * gnome-settings-daemon/main.c * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c * plugins/xrdb/gsd-xrdb-manager.c: Use printf safely. 2008-10-06 Matthias Clasen Bug 555873 – fix gdm keyboard layout handling even more * plugins/keyboard/gsd-keyboard-xkb.c (apply_xkb_settings): Try harder to handle initial-login situations correctly, while not overwriting any user configuration. 2008-10-06 Matthias Clasen Bug 554525 – fix the picking up of the gdm layout * plugins/keyboard/gsd-keyboard-xkb.c (apply_xkb_settings): Active a specific group only after activating the right keyboard configuration. Because the other way around doesn't work. 2008-10-05 Jens Granseuer * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (set_server_from_gconf): don't make togglekeys_enable depend on global AccessX state (bug #555009) 2008-10-04 Jens Granseuer Patch by: Eric Piel * plugins/xrandr/gsd-xrandr-manager.c: (output_rotation_item_activate_cb): ignore the "activate" signal for deselected items so that the rotation setting doesn't reset when the systray menu is opened (bug #554951) ==================== 2.24.0 ==================== 2008-09-23 Rodrigo Moya * NEWS: * configure.ac: prepare for 2.24.0 release. 2008-09-22 Michael J. Chudobiak * plugins/housekeeping/gsd-housekeeping-manager.c: Made the housekeeping plugin less aggressive by default (bug #552680). Code freeze break approved by release team. 2008-09-16 Matthias Clasen * plugins/keyboard/gsd-keyboard-xkb.c: Remove an accidentally added debug printf. 2008-09-12 Jens Granseuer Also allow linking the module state to other boolean keys by using a string value that is the name of the key to use. Note that in this case the state won't be updated at runtime due to GConf limitations. * plugins/xsettings/gsd-xsettings-manager.c: (get_gtk_modules): enable linking to other keys 2008-09-12 Jens Granseuer Specify GTK modules to load in a GConf directory instead of the single /desktop/gnome/gtk-modules key. Apps can now easily install additional modules by dropping a key with the name of the module and a boolean value (enabled/disabled) into /apps/gnome_settings_daemon/gtk-modules/ (bug #539840). * plugins/xsettings/gsd-xsettings-manager.c: (get_gtk_modules), (gtk_modules_callback), (gnome_xsettings_manager_start), (gnome_xsettings_manager_stop): remove the old gtk-modules key in favor of a GConf directory 2008-09-12 Jens Granseuer * COPYING: add GPLv2 copyright notice explicitly so that newer versions of autotools don't declare us GPLv3 (bug #551956) 2008-09-11 Jens Granseuer Make the volume popup not crash when invoking it on any screen but the first when using a compositing manager (bug #551677) * plugins/media-keys/gsd-media-keys-window.c: (gsd_media_keys_window_real_realize), (gsd_media_keys_window_init): do not set the window colormap at init time where we'll only use the colormap of the default screen. Instead, whenever the window is realized, update the colormap to match the current screen. 2008-09-10 Jens Granseuer Patch by: Simon Zheng * gnome-settings-daemon/main.c: (main): fix the fix for read-only home directories from bug #530975 ==================== 2.23.92 ==================== 2008-09-08 Rodrigo Moya * NEWS: prepare for 2.23.92 release. 2008-09-06 Matthias Clasen Bug 551062 – try harder to use the keyboard layout passed by gdm * plugins/keyboard/gsd-keyboard-xkb.c: Be tolerant of variants when trying to match the gdm-provided keyboard layout to the existing keyboard configuration. ==================== 2.23.91 ==================== 2008-09-01 Rodrigo Moya * NEWS: * configure.ac: prepare for 2.23.91 release. 2008-08-28 William Jon McCann * configure.ac: Belated post release version bump 2008-08-27 Jens Granseuer * plugins/xsettings/gsd-xsettings-manager.c: (setup_xsettings_managers): use g_warning instead of g_error when setup fails so we don't abort (bug #549483) 2008-08-26 William Jon McCann * plugins/a11y-keyboard/Makefile.am: * plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c (dpi_from_pixels_and_mm), (get_dpi_from_x_server), (config_get_large_print), (config_set_large_print): * plugins/a11y-keyboard/test-a11y-preferences-dialog.c (test_window), (main): Use a scale factor instead of a fixed DPI. Add a test program. 2008-08-22 William Jon McCann * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c (on_notification_closed): Oops. Missing comma. 2008-08-22 William Jon McCann * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c (on_notification_closed): Fix a crash due to an incorrect signal handler definition. 2008-08-21 Jens Granseuer * plugins/keyboard/gsd-keyboard-xkb.c: (apply_xkb_settings): fix a constness warning 2008-08-19 Claude Paroz * plugins/a11y-keyboard/gsd-a11y-preferences-dialog.glade: Removed the translatable property on stock gtk-close. ==================== 2.23.90 ==================== 2008-08-18 Rodrigo Moya * NEWS: * configure.ac: prepare for 2.23.90 release. 2008-08-14 William Jon McCann * plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c (get_dpi_from_x_server): Use gdk api to get dpi. 2008-08-13 Federico Mena Quintero * plugins/xrandr/gsd-xrandr-manager.c (status_icon_popup_menu): Create the RANDR configuration and labeler before the menu items. 2008-08-13 Federico Mena Quintero * plugins/xrandr/gsd-xrandr-manager.c (status_icon_popup_menu): Add a separator to the menu before "Configure display settings". 2008-08-13 Federico Mena Quintero * plugins/xrandr/gsd-xrandr-manager.c (status_icon_popup_menu): When the menu comes up, create a GnomeRRLabeler so that the user can identify which physical monitors we are talking about. This will actually be visible in the popup menu once we implement the rotation commands. (status_icon_popup_menu_selection_done_cb): Hide and destroy the GnomeRRLabeler. (struct GsdXrandrManagerPrivate): New field "labeler". 2008-08-12 Federico Mena Quintero * configure.ac: For LIBSOUNDS, check for libgnomeui, not just libgnome. 2008-08-12 Jens Granseuer Even if we can't properly remove a client message handler at least make sure everything works as expected when enabling/disabling the plugin at runtime * plugins/xrandr/gsd-xrandr-manager.c: (on_client_message), (gsd_xrandr_manager_start): pass the manager as user data instead of the screen because the manager will remain stable during the lifetime of the daemon; also, don't filter messages when the plugin is disabled 2008-08-12 Jens Granseuer * plugins/xrandr/gsd-xrandr-manager.c: (status_icon_start): remove obsolete comment 2008-08-11 Jens Granseuer * configure.ac: require gnome-desktop 2.23.90 * plugins/xrandr/gsd-xrandr-manager.c: (gsd_xrandr_manager_start), (gsd_xrandr_manager_stop), (gsd_xrandr_manager_init): try harder to clean up in _stop so we can enable/disable the plugin on the fly; not quite there, yet 2008-08-10 Jens Granseuer Patch by: Matthias Clasen * plugins/xrandr/gsd-xrandr-manager.c: (gsd_xrandr_manager_start): fail on start if we couldn't set up xrandr (bug #546446) 2008-08-08 Jens Granseuer * plugins/xrandr/gsd-xrandr-manager.c: (gsd_xrandr_manager_init): pass the manager as callback data so we don't crash with a NULL pointer in on_randr_event 2008-08-08 Jens Granseuer * plugins/xrandr/gsd-xrandr-manager.c: (gsd_xrandr_manager_start): remove warning that isn't 2008-08-05 Jens Granseuer * configure.ac: require glib >= 2.17.3 * plugins/xsettings/fontconfig-monitor.c: (monitor_files): use g_file_monitor instead of g_file_monitor_file/directory (bug #546372) 2008-08-05 Jens Granseuer * plugins/font/gsd-font-manager.c: (gsd_font_manager_class_init), (gsd_font_manager_init): remove some unneccessary boilerplate 2008-08-05 Jens Granseuer * plugins/a11y-keyboard/Makefile.am: put the glade file where all the others are 2008-08-05 Jens Granseuer * configure.ac: simplify libnotify check, fix fontconfig result output 2008-08-05 William Jon McCann * configure.ac: * plugins/a11y-keyboard/Makefile.am: * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c (get_int), (set_clear), (maybe_show_status_icon), (on_notification_closed), (on_slow_keys_action), (on_sticky_keys_action), (ax_slowkeys_warning_post_bubble), (ax_slowkeys_warning_post_dialog), (ax_slowkeys_warning_post), (ax_stickykeys_warning_post_bubble), (ax_stickykeys_warning_post_dialog), (ax_stickykeys_warning_post), (set_gconf_from_server), (keyboard_callback), (gsd_a11y_keyboard_manager_start), (gsd_a11y_keyboard_manager_stop), (on_preferences_dialog_response), (on_status_icon_activate), (gsd_a11y_keyboard_manager_init): * plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c (gsd_a11y_preferences_dialog_set_property), (gsd_a11y_preferences_dialog_get_property), (gsd_a11y_preferences_dialog_constructor), (gsd_a11y_preferences_dialog_dispose), (gsd_a11y_preferences_dialog_class_init), (on_response), (config_get_string), (config_get_bool), (dpi_from_pixels_and_mm), (get_dpi_from_x_server), (config_get_large_print), (config_set_large_print), (config_get_high_contrast), (config_set_high_contrast), (config_get_sticky_keys), (config_set_sticky_keys), (config_get_bounce_keys), (config_set_bounce_keys), (config_get_slow_keys), (config_set_slow_keys), (config_have_at_gconf_condition), (config_get_at_screen_reader), (config_get_at_screen_keyboard), (config_get_at_screen_magnifier), (config_set_at_screen_reader), (config_set_at_screen_keyboard), (config_set_at_screen_magnifier), (on_sticky_keys_checkbutton_toggled), (on_bounce_keys_checkbutton_toggled), (on_slow_keys_checkbutton_toggled), (on_high_contrast_checkbutton_toggled), (on_at_screen_reader_checkbutton_toggled), (on_at_screen_keyboard_checkbutton_toggled), (on_at_screen_magnifier_checkbutton_toggled), (on_large_print_checkbutton_toggled), (ui_set_sticky_keys), (ui_set_bounce_keys), (ui_set_slow_keys), (ui_set_high_contrast), (ui_set_at_screen_reader), (ui_set_at_screen_keyboard), (ui_set_at_screen_magnifier), (ui_set_large_print), (key_changed_cb), (setup_dialog), (gsd_a11y_preferences_dialog_init), (gsd_a11y_preferences_dialog_finalize), (gsd_a11y_preferences_dialog_new): * plugins/a11y-keyboard/gsd-a11y-preferences-dialog.glade: * plugins/a11y-keyboard/gsd-a11y-preferences-dialog.h: Add status icon when a11y hotkeys are enabled. Display Universal Access Preferences when it is clicked. Fixes #526070 2008-08-04 Jens Granseuer * configure.ac: fix PulseAudio check to not output "no" twice ==================== 2.23.6 ==================== 2008-08-04 Rodrigo Moya * NEWS: * configure.ac: prepare for 2.23.6 release. 2008-08-03 Jens Granseuer * plugins/common/gsd-keygrab.c: (setup_modifiers), (grab_key), (match_key): resolve NumLock dynamically and make sure we ignore it so using e.g. the media keys works even when NumLock is on (still bug #165343) Tue Jul 29 01:09:46 2008 Søren Sandmann * plugins/xrandr/gsd-xrandr-manager.c (start_or_stop_icon): Make the display notification icon configurable. 2008-07-26 Matthias Clasen Bug 544733 – use standard icon names in the volume OSD, initially * plugins/media-keys/actions/acme.glade: Use standard icon names for the OSD. 2008-07-26 Wouter Bolsterlee * configure.ac: Bump glib dependency to 2.15. Fixes bug #544737. 2008-07-25 Rob Bradford * configure.ac: libsounds needs to use gtk+-2.0 now libgnomeui is removed. 2008-07-24 James Sharpe * configure.ac: * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: * plugins/sound/gsd-sound-manager.c: Remove libgnomeui. (bug #544347) ==================== 2.23.5 ==================== Thu Jul 24 14:48:04 2008 Søren Sandmann * Downgrade intltool requirement to 0.37.1. This bug http://bugzilla.gnome.org/show_bug.cgi?id=537352 says that's what I'm supposed to do. * Bump version number to 2.23.5 * NEWS: Update this file. 2008-07-22 Lennart Poettering Fixes #539786 * plugins/xsettings/gsd-xsettings-manager.c: add three new xsettings for event sounds. 2008-07-16 Jens Granseuer Patch by: Damien Carbery * data/gnome-settings-daemon-uninstalled.pc.in: fix include path for building against the uninstalled package (bug #543289) 2008-07-15 Gerd Kohlberger * plugins/mouse/gsd-mouse-manager.c: (set_mousetweaks_daemon): Remove 'daemon' from the warning message (see bug #543095). 2008-07-15 Jens Granseuer * plugins/common/gsd-keygrab.c: (match_key): always remove Shift from the consumed modifiers if we're matching the lowercase symbol to make more shortcuts with Shift work (bug #542275) Wed Jul 9 11:48:02 2008 Søren Sandmann * plugins/xrandr/gsd-xrandr-manager.c: Call the new gnome_rr functions instead of the old ones. 2008-06-28 Jens Granseuer * plugins/common/gsd-keygrab.c: don't ignore any ModX modifiers. This should finally make g-s-d recognize keybindings with Super and Meta although we still don't handle the corresponding virtual modifiers (bug #165343) 2008-06-20 Jens Granseuer * plugins/common/gsd-keygrab.c: (match_key): fix accel check so that we don't match e.g. XF86RaiseVolume if + XF86RaiseVolume was pressed (bug #538699). Also fix build without XKB 2008-06-18 Jens Granseuer * Makefile.am: * configure.ac: require intltool >= 0.40 2008-06-18 Jens Granseuer * configure.ac: bump gnome-desktop requirement to 2.23.5 Tue Jun 17 19:41:55 2008 Søren Sandmann * Merge randr-12 branch into trunk Mon Jun 16 14:50:53 2008 Søren Sandmann * Port to new gnome-desktop API Mon Jun 16 14:30:13 2008 Søren Sandmann * Merge from trunk. 2008-06-17 Colin Walters http://bugzilla.gnome.org/show_bug.cgi?id=533198 * configure.ac: Detect PulseAudio at build time; if available, default to always starting it (ignore the legacy esd GConf key /desktop/gnome/sound/enable_esd). If you're a system administrator or OS builder and want to disable PulseAudio, you should preferably figure out what the problem you have with it is; but failing that, just remove it from the install image. * plugins/sound/gsd-sound-manager.c: If we're not compiled with legacy sound pref, always start sound. ==================== 2.23.4 ==================== 2008-06-17 Rodrigo Moya * configure.ac: * NEWS: update for 2.23.4 release. 2008-06-14 Jens Granseuer Based on a patch by: Brian Cameron * configure.ac: * plugins/sound/Makefile.am: * plugins/sound/gsd-sound-manager.c: (start_gnome_sound): if available use the esd_serverdir variable to locate the esd daemon so it can be started even if it's not in the PATH (bug #531868) 2008-06-13 Jens Granseuer Based on a patch by: Bastien Nocera * plugins/common/gsd-keygrab.c: (match_key): properly match keybindings that need Shift for resolving the keysym (bug #536581) 2008-06-07 Behdad Esfahbod (Commit this again) * configure.ac: Check for fontconfig instead of xft2. * plugins/xsettings/Makefile.am: * plugins/xsettings/gsd-xsettings-manager.c (fontconfig_callback), (gnome_xsettings_manager_start), (gnome_xsettings_manager_stop): Send a Fontconfig/Timestamp xsettings notification whenever fontconfig configurations change. (bug #490374) * plugins/xsettings/fontconfig-monitor.c: * plugins/xsettings/fontconfig-monitor.h: Monitor fontconfig configuration files using gio. ==================== 2.23.3 ====================== 2008-06-03 Jens Granseuer * configure.ac: use correct release number 2008-06-03 Jens Granseuer * NEWS: Update for 2.23.3 release. 2008-06-02 Behdad Esfahbod * configure.ac: * plugins/xsettings/Makefile.am: * plugins/xsettings/fontconfig-monitor.c: * plugins/xsettings/fontconfig-monitor.h: * plugins/xsettings/gsd-xsettings-manager.c (gnome_xsettings_manager_start), (gnome_xsettings_manager_stop): Revert previous change. Working on a slightly different design. (bug #490374) 2008-06-02 Behdad Esfahbod * configure.ac: Check for fontconfig instead of xft2. * plugins/xsettings/Makefile.am: * plugins/xsettings/gsd-xsettings-manager.c (fontconfig_callback), (gnome_xsettings_manager_start), (gnome_xsettings_manager_stop): Send a Fontconfig/Timestamp xsettings notification whenever fontconfig configurations change. (bug #490374) * plugins/xsettings/fontconfig-monitor.c: * plugins/xsettings/fontconfig-monitor.h: Monitor fontconfig configuration files using gio. 2008-06-02 Jens Granseuer * configure.ac: do not add stuff to GST_LIBS when gstreamer is disabled. Fixes build without gstreamer (bug #536177) 2008-06-02 Gerd Kohlberger * plugins/mouse/gsd-locate-pointer.c: (timeline_frame_cb): Keep animation centered below pointer. Bug #531665 2008-05-30 Jens Granseuer * plugins/font/gsd-font-manager.c: (load_xcursor_theme): fix a few leaks 2008-05-27 Jens Granseuer * gnome-settings-daemon/gnome-settings-manager.c: (_unload_plugin), (_unload_all): stop all plugins on shutdown 2008-05-27 Lucas Rocha * gnome-settings-daemon/main.c (set_session_over_handler, on_session_over, main): listen to "SessionOver" D-Bus signal from Session Manager to know when to shutdown. Bug #522017. 2008-05-14 William Jon McCann * plugins/mouse/gsd-mouse-manager.c (filter): Bummer. Revert part of last commit. 2008-05-14 William Jon McCann * plugins/mouse/gsd-mouse-manager.c (filter): Don't eat keypresses for multimedia key events Patch by Bastien Nocera 2008-05-13 Jens Granseuer * plugins/background/gsd-background-manager.c: (gsd_background_manager_start): reuse the GConf client we already have 2008-05-13 William Jon McCann * configure.ac: * plugins/background/Makefile.am: * plugins/background/gsd-background-manager.c (draw_background), (queue_draw_background), (on_bg_changed), (gconf_changed_callback), (watch_bg_preferences), (gsd_background_manager_start), (gsd_background_manager_stop): Use new gnome-desktop background preference loading api. Drop use of libbackground. 2008-05-08 Carlos Garnacho * plugins/media-keys/gsd-media-keys-window.c (gsd_media_keys_window_real_realize): New function, sets a fully transparent input shape, so that clicks go through the media keys windows. Bug #531862. (gsd_media_keys_window_class_init): The usual glue. 2008-05-08 Carlos Garnacho * plugins/mouse/gsd-locate-pointer.c (set_transparent_shape): new function, sets a fully transparent shape to the whole window. (timeline_finished_cb) (gsd_locate_pointer): set the window transparent once the animation is finished, and before it's shown for the first time. The shape will be changed afterwards while running the animation. This fixes some artifacts shown when showing/moving the window, bug #531861. (locate_pointer_expose): Plug a leak. 2008-05-02 Jens Granseuer Patch by: Brian Cameron * gnome-settings-daemon/main.c: (main): don't die when the user's home directory is read-only (bug #530975) 2008-05-02 Jens Granseuer Based on a patch by: Matthias Clasen * plugins/keyboard/gsd-keyboard-xkb.c: (apply_xkb_settings), (gsd_keyboard_xkb_init): if the user set a keyboard layout from the login screen, try to keep that setting (bug #531589) 2008-05-02 Jens Granseuer * plugins/background/gsd-background-manager.c: (gsd_background_manager_start): add a comment explaining why we are applying the prefs regardless of nautilus 2008-05-02 Jens Granseuer Patch by: Matthias Clasen * plugins/background/gsd-background-manager.c: (gsd_background_manager_start): eventually apply the settings even if nautilus is supposed to be handling the background to make people running without nautilus happy (bug #531487) 2008-04-29 Bastien Nocera * plugins/common/gsd-keygrab.c (have_xkb), (match_key): When checking whether a key matches our key event, check the keysym from the key event, to avoid triggering another keybindings with the same keycode, but different keysym, Fixes Eject being triggered when pressing the Stop key with the default inet keymap (Closes: #530356) 2008-04-23 Vincent Untz * configure.ac: post release version bump. ==================== 2.23.1.1 ==================== 2008-04-23 Vincent Untz * configure.in: * NEWS: Update for 2.23.1.1 release. 2008-04-21 Lucas Rocha Install .desktop for gnome-settings-daemon in a standard autostart directory as required by new gnome-session (bug #526984). * configure.ac: expand $libexecdir to be used on .desktop file. * acinclude.m4: added new m4 macro (AS_AC_EXPAND) for expanding variables. * data/Makefile.am, data/gnome-settings-daemon.desktop.in.in: install g-s-d .desktop file. 2008-04-21 Rodrigo Moya * configure.ac: post release version bump. ==== 2.23.1 ==== 2008-04-21 Rodrigo Moya * configure.in: * NEWS: Update for release. 2008-04-20 Jens Granseuer * plugins/media-keys/actions/acme-volume-alsa.c: (acme_volume_alsa_finalize), (acme_volume_alsa_class_init): * plugins/media-keys/actions/acme-volume-dummy.c: (acme_volume_dummy_finalize), (acme_volume_dummy_class_init): * plugins/media-keys/actions/acme-volume-gstreamer.c: (acme_volume_gstreamer_finalize), (acme_volume_gstreamer_class_init): * plugins/media-keys/actions/acme-volume-oss.c: (acme_volume_oss_finalize), (acme_volume_oss_class_init): * plugins/media-keys/actions/acme-volume.c: (acme_volume_class_init): drop redundant GType stuff 2008-04-19 Jens Granseuer * plugins/keybindings/gsd-keybindings-manager.c: (bindings_get_entry): remove some code (and translatable strings) for error that can never happen 2008-04-18 Jens Granseuer * plugins/mouse/gsd-mouse-manager.c: (set_mousetweaks_daemon): when we can't launch the daemon reset the GConf keys before showing the error dialog. If we wait until after the dialog is closed, the user can still toggle the settings while it's open 2008-04-13 Jens Granseuer Extract some functionality used by several plugins into a separate shared helper library (bug #525426). * configure.ac: * plugins/Makefile.am: * plugins/common/Makefile.am: * plugins/common/gsd-keygrab.c: * plugins/common/gsd-keygrab.h: * plugins/common/eggaccelerators.c: * plugins/common/eggaccelerators.h: new shared components * plugins/keybindings/Makefile.am: * plugins/keybindings/eggaccelerators.c: * plugins/keybindings/eggaccelerators.h: * plugins/keybindings/gsd-keybindings-manager.c: (binding_register_keys), (keybindings_filter): * plugins/media-keys/Makefile.am: * plugins/media-keys/actions/Makefile.am: * plugins/media-keys/actions/acme.h: * plugins/media-keys/eggaccelerators.c: * plugins/media-keys/eggaccelerators.h: * plugins/media-keys/gsd-media-keys-manager.c: (update_kbd_cb), (init_kbd), (acme_filter_events): make keybindings and media-keys plugins use the shared components 2008-04-13 Sergey Udaltsov * plugins/keyboard/gsd-keyboard-xkb.c: dropped gconf backup 2008-04-12 Jens Granseuer * plugins/keybindings/gsd-keybindings-manager.c: (do_grab): * plugins/media-keys/gsd-media-keys-manager.c: (grab_key): make some tiny optimizations and add some more comments on what's happening 2008-04-12 Jens Granseuer * gnome-settings-daemon/main.c: * plugins/media-keys/gsd-media-keys-manager.c: DBus API has been stable for a while; don't define DBUS_API_SUBJECT_TO_CHANGE anymore 2008-04-12 Jens Granseuer * gnome-settings-daemon/main.c: (acquire_name_on_proxy), (bus_register), (main): fix a few small leaks 2008-04-12 Jens Granseuer * plugins/media-keys/gsd-media-keys-manager.c: (init_screens): drop redundant code 2008-04-11 Jens Granseuer * gnome-settings-daemon/main.c: turn into a daemon by default and make --no-daemon work 2008-04-11 Jens Granseuer * plugins/sound/gsd-sound-plugin.c: (impl_deactivate): fix typo 2008-04-11 Jens Granseuer Make xrandr, xrdb, and xsettings plugin deactivation work * plugins/xrandr/gsd-xrandr-manager.c: (apply_settings): cleanup * plugins/xrandr/gsd-xrandr-plugin.c: (impl_deactivate): * plugins/xrdb/gsd-xrdb-plugin.c: (impl_deactivate): * plugins/xsettings/gsd-xsettings-plugin.c: (impl_deactivate): stop manager on deactivation * plugins/xrdb/gsd-xrdb-manager.c: (gsd_xrdb_manager_start), (gsd_xrdb_manager_stop): * plugins/xsettings/gsd-xsettings-manager.c: (gsd_xsettings_error_quark), (find_translation_entry), (xsettings_callback), (register_config_callback), (terminate_cb), (setup_xsettings_managers), (gnome_xsettings_manager_start), (gnome_xsettings_manager_stop), (gnome_xsettings_manager_init): clean up properly on stop 2008-04-11 Jens Granseuer Make typing-break plugin deactivation work * plugins/typing-break/gsd-typing-break-manager.c: (register_config_callback), (gsd_typing_break_manager_start), (gsd_typing_break_manager_stop): clean up properly on stop * plugins/typing-break/gsd-typing-break-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-11 Jens Granseuer Make screensaver and sound plugin deactivation work (sort of). The screensaver is currently not reaped when deactivating the plugin, but since the plugin should go away anyway, it doesn't seem worth adding that right now. For the sound plugin, esd is currently not reaped when HAVE_ESD is set. Maybe we want to get rid of the esd API altogether? * plugins/sound/gsd-sound-manager.c: (apply_settings), (register_config_callback), (gsd_sound_manager_start), (gsd_sound_manager_stop): clean up a bit more on stop * plugins/screensaver/gsd-screensaver-plugin.c: (impl_deactivate): * plugins/sound/gsd-sound-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-11 Jens Granseuer Make mouse plugin deactivation work * plugins/mouse/gsd-mouse-manager.c: (register_config_callback), (gsd_mouse_manager_init), (gsd_mouse_manager_start), (gsd_mouse_manager_stop): clean up properly on stop * plugins/mouse/gsd-mouse-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-11 Jens Granseuer * plugins/keyboard/gsd-keyboard-xkb.c: (gsd_keyboard_xkb_shutdown): clear the user callback data even if initialiation failed * plugins/keyboard/gsd-xmodmap.c: (gsd_load_modmap_files): properly NULL-terminate g_build_filename 2008-04-11 Jens Granseuer Make media-keys plugin deactivation work * plugins/media-keys/gsd-media-keys-manager.c: (acme_error), (dialog_init), (init_kbd), (gsd_media_keys_manager_stop), (register_manager): clean up properly on stop * plugins/media-keys/gsd-media-keys-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-11 Jens Granseuer * plugins/keyboard/gsd-xmodmap.c: (check_button_callback), (gsd_load_modmap_files), (response_callback), (remove_string_from_list), (remove_button_clicked_callback), (load_button_clicked_callback), (gsd_modmap_dialog_call): fix memory leaks 2008-04-10 Jens Granseuer Make keyboard plugin deactivation work * plugins/keyboard/gsd-keyboard-manager.c: (register_config_callback), (gsd_keyboard_manager_start), (gsd_keyboard_manager_stop): * plugins/keyboard/gsd-keyboard-xkb.c: (register_config_callback), (gsd_keyboard_xkb_init), (gsd_keyboard_xkb_shutdown): * plugins/keyboard/gsd-keyboard-xkb.h: clean up properly on stop * plugins/keyboard/gsd-keyboard-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-10 Jens Granseuer Make keybinding plugin deactivation work * plugins/keybindings/gsd-keybindings-manager.c: (register_config_callback), (gsd_keybindings_manager_start), (gsd_keybindings_manager_stop): clean up properly on stop * plugins/keybindings/gsd-keybindings-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-10 Jens Granseuer * plugins/font/gsd-font-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-10 Jens Granseuer * plugins/dummy/gsd-dummy-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-10 Jens Granseuer * plugins/clipboard/gsd-clipboard-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-10 Jens Granseuer Make background plugin deactivation work * plugins/background/gsd-background-manager.c: (gsd_background_manager_start), (gsd_background_manager_stop): clean up properly on stop * plugins/background/gsd-background-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-10 Jens Granseuer * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (gsd_a11y_keyboard_manager_stop): also remove GConf watch directory 2008-04-10 Jens Granseuer Make housekeeping plugin deactivation work * plugins/housekeeping/gsd-housekeeping-manager.c: (register_config_callback), (gsd_housekeeping_manager_start), (gsd_housekeeping_manager_stop), (gsd_housekeeping_manager_init): clean up properly on stop * plugins/housekeeping/gsd-housekeeping-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-10 Jens Granseuer Make a11y-keyboard plugin deactivation work * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (register_config_callback), (gsd_a11y_keyboard_manager_start), (gsd_a11y_keyboard_manager_stop): properly clean up on _stop * plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c: (impl_deactivate): stop manager on deactivation 2008-04-10 Jens Granseuer * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (get_xkb_desc_rec), (set_server_from_gconf), (ax_slowkeys_warning_dialog_post), (ax_stickykeys_warning_dialog_post), (set_gconf_from_server), (cb_xkb_event_filter), (gsd_a11y_keyboard_manager_init): more cleanup 2008-04-10 Jens Granseuer * plugins/media-keys/gsd-media-keys-manager.c: (grab_key_real): remove excessive key grab logging 2008-04-09 Jens Granseuer * plugins/keyboard/gsd-keyboard-manager.c: (numlock_xkb_init), (numlock_set_xkb_state), (numlock_gconf_state_key), (numlock_xkb_callback), (numlock_install_xkb_callback), (apply_settings), (gsd_keyboard_manager_start): split XKB initialization and calbback installation which allows us to get rid of some more special-casing and yet another static variable 2008-04-09 Jens Granseuer * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (xkb_enabled), (get_xkb_desc_rec), (gsd_a11y_keyboard_manager_start): don't install any listeners or callbacks when XKB is not available 2008-04-09 Michael J. Chudobiak * plugins/housekeeping/gsd-housekeeping-manager.c: (gsd_housekeeping_manager_stop): Purge thumbnail cache on shutdown if and only if the max size or max age parameters have been set to zero (for paranoid people) (bug #526999). 2008-04-07 Jens Granseuer Currently, the percentage by which to lower or raise the volume when hitting the multimedia keys is taken from GConf, with 6 being the default. We don't have any settings dialogs to actually change it, though. If the user now selects a mixer that supports fewer volume levels than the GConf setting implies (100/6) it becomes impossible to change the volume (without fiddling with the GConf setting). This patch adds a "threshold" property to the AcmeVolume class that denotes the minimum percentage required to actually affect the volume. The plugin now uses the step size read from GConf or the mixer threshold, depending on which one is bigger. (bug #441910) * plugins/media-keys/actions/acme-volume-alsa.c: (acme_volume_alsa_get_threshold), (acme_volume_alsa_class_init): * plugins/media-keys/actions/acme-volume-dummy.c: (acme_volume_dummy_get_threshold), (acme_volume_dummy_class_init): * plugins/media-keys/actions/acme-volume-gstreamer.c: (acme_volume_gstreamer_get_threshold), (acme_volume_gstreamer_class_init): * plugins/media-keys/actions/acme-volume-oss.c: (acme_volume_oss_get_threshold), (acme_volume_oss_class_init), (acme_volume_oss_mixer_check): * plugins/media-keys/actions/acme-volume.c: (acme_volume_get_threshold): * plugins/media-keys/actions/acme-volume.h: add get_threshold method * plugins/media-keys/gsd-media-keys-manager.c: (do_sound_action): use gconf value or threshold, depending on what's bigger 2008-04-07 Jens Granseuer * plugins/media-keys/gsd-media-keys-manager.c: (do_sound_action): only use the built-in default for volume_step if we get an error from GConf, not just when the value is 0 which might be what the user wants (see the discussion on the Thinkpad driver again) 2008-04-07 Jens Granseuer Remove the Thinkpad driver again. See bug #524425 for some discussion. * configure.ac: * plugins/media-keys/actions/Makefile.am: * plugins/media-keys/actions/acme-volume-thinkpad.c: * plugins/media-keys/actions/acme-volume-thinkpad.h: * plugins/media-keys/actions/acme-volume.c: (acme_volume_new): remove extra Thinkpad support 2008-04-06 Jens Granseuer * plugins/keyboard/gsd-keyboard-manager.c: (gsd_keyboard_get_hostname_key), (numlock_set_xkb_state), (numlock_gconf_state_key), (numlock_get_gconf_state), (numlock_set_gconf_state), (numlock_xkb_callback), (numlock_install_xkb_callback), (apply_settings), (gsd_keyboard_manager_start), (gsd_keyboard_manager_init): * plugins/keyboard/gsd-keyboard-xkb.c: (gsd_keyboard_xkb_init): * plugins/keyboard/gsd-keyboard-xkb.h: continued attempt at making XKB setup and error handling a bit less arcane and crufty 2008-04-06 Jens Granseuer * plugins/keyboard/gsd-keyboard-xkb.c: * plugins/keyboard/gsd-keyboard-xkb.h: initialize inited_ok or behaviour is undefined when xkb setup fails; don't export XklEngine 2008-04-06 Jens Granseuer * plugins/media-keys/gsd-media-keys-manager.c: (do_action): make "Home" keybinding work again 2008-04-05 Jens Granseuer * configure.ac: * plugins/media-keys/actions/Makefile.am: hook up the Thinkpad support 2008-04-05 Jens Granseuer Patch by: Lorne Applebaum <4lorne@gmail.com> * plugins/media-keys/actions/acme-volume-thinkpad.c: * plugins/media-keys/actions/acme-volume-thinkpad.h: * plugins/media-keys/actions/acme-volume.c: (acme_volume_new): add a special volume subclass for better support of IBM Thinkpad hardware volume buttons (bug #524425) 2008-04-05 Jens Granseuer Patch by: Lorne Applebaum <4lorne@gmail.com> * plugins/media-keys/actions/acme-volume-dummy.h: fix TYPE macro and remove an unimplemented prototype 2008-04-01 Jens Granseuer * plugins/keyboard/gsd-keyboard-manager.c: (gsd_keyboard_manager_start): apply keyboard settings on startup, too (bug #525440) 2008-03-31 Jens Granseuer * plugins/keybindings/gsd-keybindings-manager.c: (bindings_get_entry): fix various leaks and other memory management issues 2008-03-31 Jens Granseuer * plugins/keybindings/gsd-keybindings-manager.c: (bindings_get_entry), (binding_register_keys): remove trailing newlines from messages since g_warning already takes care of those 2008-03-31 Jens Granseuer * plugins/keybindings/gsd-keybindings-manager.c: (do_grab): * plugins/media-keys/gsd-media-keys-manager.c: (grab_key): don't try to add grabs with invalid modifiers 2008-03-30 Gerd Kohlberger * plugins/mouse/gsd-mouse-manager.c: (set_mousetweaks_daemon): Set gconf keys back to false, if mousetweaks isn't installed. Bug #525042. 2008-03-30 Jens Granseuer * plugins/xsettings/gsd-xsettings-manager.c: add mapping for Gtk/Modules xsetting using GConf path /desktop/gnome/gtk-modules (bug #507386) 2008-03-30 Jens Granseuer * plugins/housekeeping/gsd-housekeeping-manager.c: change data types to match glib; avoid using time_t 2008-03-30 Jens Granseuer * plugins/media-keys/actions/acme-volume-dummy.c: (acme_volume_dummy_init), (acme_volume_dummy_class_init): change to use G_DEFINE_TYPE instead of open-coding it 2008-03-29 Jens Granseuer * configure.ac: fix profiling to be off by default 2008-03-29 Jens Granseuer * gnome-settings-daemon/main.c: mark string for translation 2008-03-29 Jens Granseuer * plugins/keybindings/eggaccelerators.c: (egg_accelerator_parse_virtual): * plugins/media-keys/eggaccelerators.c: (egg_accelerator_parse_virtual): readd a chunk that got lost in the last commit. *sigh*. Why do we have several differing copies of those files? 2008-03-29 Jens Granseuer * plugins/keybindings/eggaccelerators.c: (egg_accelerator_parse_virtual), (egg_virtual_accelerator_name), (egg_virtual_accelerator_label), (egg_keymap_resolve_virtual_modifiers), (egg_keymap_virtualize_modifiers), (reload_modmap), (egg_keymap_get_modmap): * plugins/keybindings/eggaccelerators.h: fix mismatched modifier mapping between egg and GTK (so that e.g. works) and replace some custom functionality with stock GTK 2008-03-29 Jens Granseuer * plugins/media-keys/eggaccelerators.c: (egg_accelerator_parse_virtual), (egg_virtual_accelerator_name), (egg_virtual_accelerator_label), (egg_keymap_resolve_virtual_modifiers), (egg_keymap_virtualize_modifiers), (reload_modmap), (egg_keymap_get_modmap): * plugins/media-keys/eggaccelerators.h: fix mismatched modifier mapping between egg and GTK (so that e.g. works) and replace some custom functionality with stock GTK 2008-03-29 Jens Granseuer * plugins/housekeeping/gsd-housekeeping-manager.c: (get_gconf_int_with_default): rename to better reflect what it does, and also use the default passed in if we don't get an int from GConf, or we'll end up with a value of 0 which is certainly not what we want (purge_thumbnail_cache): update callers 2008-03-28 Michael J. Chudobiak * configure.ac: * data/gnome-settings-daemon.schemas.in: * plugins/Makefile.am: * plugins/housekeeping/Makefile.am: * plugins/housekeeping/gsd-housekeeping-manager.c: (thumb_data_free), (read_dir_for_purge), (purge_old_thumbnails), (sort_file_mtime), (get_gconf_int_with_nonzero_default), (purge_thumbnail_cache), (do_cleanup), (do_cleanup_once), (do_cleanup_soon), (bindings_callback), (register_config_callback), (gsd_housekeeping_manager_start), (gsd_housekeeping_manager_stop), (gsd_housekeeping_manager_class_init), (gsd_housekeeping_manager_init), (gsd_housekeeping_manager_new): * plugins/housekeeping/gsd-housekeeping-manager.h: * plugins/housekeeping/gsd-housekeeping-plugin.c: (gsd_housekeeping_plugin_init), (gsd_housekeeping_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_housekeeping_plugin_class_init): * plugins/housekeeping/gsd-housekeeping-plugin.h: * plugins/housekeeping/housekeeping.gnome-settings-plugin.in: Added a new "housekeeping" plugin to set limits on the size and age of the thumbnail cache (bug #523159). 2008-03-25 Jens Granseuer Patch by: Matthias Clasen * plugins/mouse/gsd-mouse-manager.c: (filter): don't eat key events; other plugins might need them as well (bug #523676) 2008-03-24 William Jon McCann * configure.ac: Add some stuff to the configuration summary. * plugins/media-keys/gsd-media-keys-manager.c: (gsd_media_keys_manager_start): Add a few more profiling points. 2008-03-24 William Jon McCann * gnome-settings-daemon/Makefile.am: * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (set_server_from_gconf), (gsd_a11y_keyboard_manager_start): * plugins/background/Makefile.am: * plugins/background/gsd-background-manager.c: (apply_prefs), (gsd_background_manager_start): * plugins/clipboard/gsd-clipboard-manager.c: (gsd_clipboard_manager_start): * plugins/dummy/gsd-dummy-manager.c: (gsd_dummy_manager_start): * plugins/font/gsd-font-manager.c: (load_xcursor_theme), (load_cursor), (gsd_font_manager_start): * plugins/keybindings/gsd-keybindings-manager.c: (gsd_keybindings_manager_start): * plugins/keyboard/gsd-keyboard-manager.c: (gsd_keyboard_manager_start): * plugins/media-keys/Makefile.am: * plugins/media-keys/gsd-media-keys-manager.c: (init_kbd), (gsd_media_keys_manager_start): * plugins/mouse/gsd-mouse-manager.c: (gsd_mouse_manager_start): * plugins/screensaver/gsd-screensaver-manager.c: (gsd_screensaver_manager_start): * plugins/sound/gsd-sound-manager.c: (start_gnome_sound), (reload_foreach_cb), (apply_settings), (gsd_sound_manager_start): * plugins/typing-break/gsd-typing-break-manager.c: (setup_typing_break), (gsd_typing_break_manager_start): * plugins/xrandr/gsd-xrandr-manager.c: (apply_settings): * plugins/xrdb/gsd-xrdb-manager.c: (apply_settings), (gsd_xrdb_manager_start): * plugins/xsettings/gsd-xsettings-manager.c: (xft_settings_set_xsettings), (xft_settings_set_xresources), (update_xft_settings), (gnome_xsettings_manager_start): Add profiling points to plugins. 2008-03-24 William Jon McCann * gnome-settings-daemon/gnome-settings-manager.c: (compare_location), (_load_file), (_load_dir): * gnome-settings-daemon/gnome-settings-plugin-info.c: (debug_info), (gnome_settings_plugin_info_fill_from_file), (gnome_settings_plugin_info_deactivate), (load_plugin_module), (gnome_settings_plugin_info_activate), (gnome_settings_plugin_info_is_active), (gnome_settings_plugin_info_get_enabled), (gnome_settings_plugin_info_is_available), (gnome_settings_plugin_info_get_name), (gnome_settings_plugin_info_get_description), (gnome_settings_plugin_info_get_authors), (gnome_settings_plugin_info_get_website), (gnome_settings_plugin_info_get_copyright), (gnome_settings_plugin_info_get_location), (gnome_settings_plugin_info_get_priority), (gnome_settings_plugin_info_set_priority): Fix a refcounting bug. Add a few more checks. Fix up a leak. Fixes #524183 2008-03-24 William Jon McCann * plugins/media-keys/gsd-media-keys-manager.c: (acme_filter_events): * plugins/sound/gsd-sound-manager.c: (start_gnome_sound): Fix two compiler warnings. 2008-03-24 William Jon McCann * gnome-settings-daemon/gnome-settings-manager.c: (gnome_settings_manager_start): * gnome-settings-daemon/gnome-settings-profile.c: (_gnome_settings_profile_log): * gnome-settings-daemon/gnome-settings-profile.h: * gnome-settings-daemon/main.c: (main): Add missing files. Add some more profiling points. 2008-03-24 William Jon McCann * configure.ac: * gnome-settings-daemon/Makefile.am: * gnome-settings-daemon/gnome-settings-manager.c: (_load_file), (_load_dir), (_load_all), (gnome_settings_manager_start): * gnome-settings-daemon/gnome-settings-plugin-info.c: (gnome_settings_plugin_info_fill_from_file), (load_plugin_module), (_activate_plugin): * gnome-settings-daemon/main.c: (bus_register), (main): Add some profiling code. Must specify --enable-profiling to configure. Can now be profiled like so: strace -ttt -f -o /tmp/logfile.strace gnome-settings-daemon python plot-timeline.py -o prettygraph.png /tmp/logfile.strace See: http://www.gnome.org/~federico/news-2006-03.html#09 2008-03-24 Jens Granseuer Patch by: Alexey Shabalin * plugins/sound/gsd-sound-manager.c: (apply_settings): now that "starting esd" can mean either esd or PulseAudio, check the GConf setting for starting the sound server even when esd is disabled (bug #523743) 2008-03-24 Jens Granseuer * plugins/dummy/Makefile.am: remove NULL definition so authors using this as the base for their own plugins don't get strange ideas 2008-03-20 William Jon McCann * plugins/media-keys/Makefile.am: * plugins/media-keys/gsd-media-keys-manager.c: (grab_key_real), (init_kbd), (acme_filter_events), (gsd_media_keys_manager_start): * plugins/media-keys/test-media-keys.c: (main): Add a tool to test media keys. 2008-03-16 William Jon McCann * plugins/sound/gsd-sound-manager.c: (reset_esd_pid), (start_gnome_sound), (wait_on_child), (stop_child), (stop_gnome_sound), (apply_settings), (gsd_sound_manager_dispose): Fix handling of child process. 2008-03-14 Jens Granseuer * plugins/media-keys/gsd-media-keys-window.c: (remove_hide_timeout): reset opacity when removing the timeout so that the fadeout is restarted when media keys are pressed while the popup is already fading out (bug #522499) 2008-03-13 Jens Granseuer * plugins/media-keys/actions/acme.glade: remove unused properties (and, in particular, an unused translated string) 2008-03-13 Jens Granseuer Patch by: Danny Baumann * plugins/media-keys/gsd-media-keys-window.c: (gsd_media_keys_window_new): set window type hint on the volume popup (bug #522232) 2008-03-11 Jens Granseuer * plugins/typing-break/gsd-typing-break-manager.c: (setup_typing_break): pass data to the timeout so shutting down the typing monitor works instead of segfaulting (bug #521786) (gsd_typing_break_manager_start): use g_timeout_add_seconds instead of g_timeout_add 2008-03-10 Rodrigo Moya * configure.ac: Post release version bump ==== 2.22.0 ==== 2008-03-10 Rodrigo Moya * NEWS: Update for release. 2008-03-08 Jens Granseuer * data/Makefile.am: * data/apps_gnome_settings_daemon_default_editor.schemas.in: * data/gnome-settings-daemon.schemas.in: remove obsolete settings for the removed default editor plugin 2008-03-01 Jens Granseuer * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (ax_response_callback): don't pass the GError argument if we're not going to use it. Also remove some unnecessary casting 2008-02-29 William Jon McCann * gnome-settings-daemon/main.c: Disable debug by default again. 2008-02-29 Jens Granseuer * configure.ac: * plugins/mouse/Makefile.am: when building with XInput support, actually link against libXi, or we'll fail to load the plugin due to unresolved symbols (bug #519488) 2008-02-29 William Jon McCann * configure.ac: Post release version bump ==== 2.21.92 ==== 2008-02-29 William Jon McCann * NEWS: Update for release. 2008-02-29 William Jon McCann * configure.ac: Remove Werror. 2008-02-29 Jens Granseuer * gnome-settings-daemon/gnome-settings-manager.c: (register_manager), (gnome_settings_manager_start): minor clean-up 2008-02-28 William Jon McCann * gnome-settings-daemon/gnome-settings-manager.c: (gnome_settings_manager_error_quark), (_load_file), (gnome_settings_manager_awake), (gnome_settings_manager_start), (gnome_settings_manager_start_with_settings_prefix), (_set_settings_prefix), (gnome_settings_manager_set_property), (gnome_settings_manager_get_property), (gnome_settings_manager_class_init), (gnome_settings_manager_finalize), (gnome_settings_manager_new): * gnome-settings-daemon/gnome-settings-manager.h: * gnome-settings-daemon/gnome-settings-manager.xml: * gnome-settings-daemon/main.c: (main): When dbus activated only load the plugins when requested instead of at startup. Add a new method to start and set plugin settings prefix. This allows gdm to use dbus activation. It also fixes cases where g-s-d is activated and plugins are loaded unintentionally. 2008-02-29 Wouter Bolsterlee * plugins/sound/gsd-sound-manager.c (apply_settings): Add braces to fix amgiguous else. Avoids compiler warnings. 2008-02-28 Bastien Nocera * plugins/sound/gsd-sound-manager.c (reset_esd_pid), (start_gnome_sound), (stop_gnome_sound), (apply_settings), (gsd_sound_manager_stop): Start the sound server ourselves, as we need it to cache samples. If esd (or the PulseAudio esd compat bits) isn't available, just print an error, and don't try to cache the samples If you use PulseAudio instead of esound in your distribution, build with --disable-esd passed to configure (Closes: #518075) 2008-02-25 William Jon McCann * gnome-settings-daemon/main.c: (gsd_log_default_handler), (main): Add --debug command line option. Only print DEBUG level messages if --debug is used. 2008-02-25 William Jon McCann * gnome-settings-daemon/gnome-settings-plugin-info.c: (gnome_settings_plugin_info_fill_from_file): Don't warn on missing priority since we don't recommend that it be used. 2008-02-22 William Jon McCann * data/gnome-settings-daemon.schemas.in: Take a stab at defining the default load priorities. Fixes #518155 2008-02-22 William Jon McCann * data/gnome-settings-daemon.schemas.in: * gnome-settings-daemon/gnome-settings-manager.c: (_load_file): * gnome-settings-daemon/gnome-settings-plugin-info.c: (gnome_settings_plugin_info_set_priority): * gnome-settings-daemon/gnome-settings-plugin-info.h: Allow gconf to override priorities. Set sound plugin priority to 1 (highest). Fixes #515340 2008-02-22 William Jon McCann * gnome-settings-daemon/Makefile.am: * gnome-settings-daemon/gnome-settings-manager.c: (_load_info), (maybe_activate_plugin), (compare_location), (compare_priority), (on_plugin_activated), (on_plugin_deactivated), (_load_file), (_load_dir), (_load_all), (_unload_all), (gnome_settings_manager_start), (gnome_settings_manager_stop), (gnome_settings_manager_constructor), (gnome_settings_manager_class_init), (gnome_settings_manager_finalize): * gnome-settings-daemon/gnome-settings-manager.h: * gnome-settings-daemon/gnome-settings-manager.xml: * gnome-settings-daemon/gnome-settings-plugin-info.c: (gnome_settings_plugin_info_class_init), (gnome_settings_plugin_info_set_enabled_key_name), (_deactivate_plugin), (_activate_plugin): * gnome-settings-daemon/gnome-settings-plugin-info.h: * gnome-settings-daemon/gnome-settings-plugins-engine.c: * gnome-settings-daemon/gnome-settings-plugins-engine.h: Merge PluginsEngine functionality into Manager. Emit signals when plugins are activated or deactivated. Fixes #515341 2008-02-22 William Jon McCann * gnome-settings-daemon/Makefile.am: * gnome-settings-daemon/gnome-settings-manager.c: (gnome_settings_manager_start), (gnome_settings_manager_stop), (gnome_settings_manager_constructor), (gnome_settings_manager_finalize): * gnome-settings-daemon/gnome-settings-plugin-info.c: (gnome_settings_plugin_info_finalize), (gnome_settings_plugin_info_class_init), (gnome_settings_plugin_info_init), (gnome_settings_plugin_info_fill_from_file), (plugin_enabled_cb), (gnome_settings_plugin_info_set_enabled_key_name), (gnome_settings_plugin_info_new_from_file), (_deactivate_plugin), (gnome_settings_plugin_info_deactivate), (load_plugin_module), (_activate_plugin), (gnome_settings_plugin_info_activate), (gnome_settings_plugin_info_is_active), (gnome_settings_plugin_info_get_enabled), (gnome_settings_plugin_info_is_available), (gnome_settings_plugin_info_get_name), (gnome_settings_plugin_info_get_description), (gnome_settings_plugin_info_get_authors), (gnome_settings_plugin_info_get_website), (gnome_settings_plugin_info_get_copyright), (gnome_settings_plugin_info_get_location), (gnome_settings_plugin_info_get_priority): * gnome-settings-daemon/gnome-settings-plugin-info.h: * gnome-settings-daemon/gnome-settings-plugins-engine.c: (gnome_settings_plugins_engine_load), (maybe_activate_plugin), (compare_location), (compare_priority), (gnome_settings_plugins_engine_load_file), (gnome_settings_plugins_engine_load_dir), (gnome_settings_plugins_engine_load_all), (gnome_settings_plugins_engine_unload_all), (gnome_settings_plugins_engine_start), (gnome_settings_plugins_engine_garbage_collect), (gnome_settings_plugins_engine_stop), (gnome_settings_plugins_engine_get_plugins_list), (_set_gconf_prefix), (gnome_settings_plugins_engine_set_property), (gnome_settings_plugins_engine_get_property), (gnome_settings_plugins_engine_class_init), (gnome_settings_plugins_engine_init), (gnome_settings_plugins_engine_finalize), (gnome_settings_plugins_engine_new): * gnome-settings-daemon/gnome-settings-plugins-engine.h: Refactor the PluginInfo structure into a class. This will facilitate fixing bug #515341 2008-02-22 Bastien Nocera * configure.ac: Only enable ALSA and OSS support if we don't have GStreamer support, as the media-keys code doesn't have any fallbacks if GStreamer fails to load (see acme-volume.c's _new ()) 2008-02-19 Vincent Untz * plugins/keyboard/gsd-keyboard-manager.c: (gsd_keyboard_get_hostname_key): escape the hostname before using it in a gconf path since it might contain invalid characters. Fix bug #517259. 2008-02-19 Jens Granseuer * configure.ac: remove some unused stuff * plugins/sound/Makefile.am: add missing ESD_CFLAGS/LIBS 2008-02-19 Jens Granseuer * configure.ac: * plugins/xrandr/Makefile.am: * plugins/xrandr/gsd-xrandr-manager.c: (gsd_xrandr_manager_class_init), (gsd_xrandr_manager_init), (gsd_xrandr_manager_finalize): build with XRandR if available, makes setting screen geometry at login time work again (bug #517418) 2008-02-16 Jens Granseuer * gnome-settings-daemon/main.c: mark string as translatable 2008-02-14 Jens Granseuer * plugins/background/gsd-background-manager.c: (gsd_background_manager_start): at startup, don't apply background prefs twice and don't check for nautilus running since we're usually started first 2008-02-12 Kjartan Maraas * configure.ac: Fix for 515956. Build with Gio. ==== 2.21.91 ==== 2008-02-11 Rodrigo Moya * configure.ac: * NEWS: prepare for 2.21.91. 2008-02-11 Rodrigo Moya Fixes bug #513990 * plugins/background/gsd-background-manager.c: use GIO instead of gnome-vfs. * plugins/configure.ac: * plugins/Makefile.am: * plugins/default-editor/*: removed useless default editor plugin. 2008-02-11 Rodrigo Moya Patch by Wouter Bolsterlee * gnome-settings-daemon/gnome-settings-plugins-engine.c (gnome_settings_plugins_engine_load_all): assign return value from g_slist_sort to the plugins list variable. (bug #515340) 2008-02-10 Jens Granseuer * gnome-settings-daemon/main.c: update the default GConf prefix to match the changes from r112 or bug #514411 2008-02-09 Jens Granseuer Support for defining plugin start order got lost in the split from gnome-control-center, but it is essential for some plugins to work correctly. With this change the "Priority" keyword can be used in the ".gnome-settings-plugin" file to set plugin priorities. Priority can take values from 1 upwards, with 1 being maximum priority and 100 being the default if nothing is specified by the plugin. For multiple plugins with identical priority start order is undefined. (bug #515340) * gnome-settings-daemon/gnome-settings-plugins-engine.c: (gnome_settings_plugins_engine_load), (activate_plugin), (compare_location), (compare_priority), (gnome_settings_plugins_engine_load_file), (gnome_settings_plugins_engine_load_all), (gnome_settings_plugins_engine_init), (gnome_settings_plugins_engine_shutdown), (gnome_settings_plugins_engine_get_plugins_list), (gnome_settings_plugins_engine_get_plugin_copyright), (gnome_settings_plugins_engine_get_plugin_priority): * gnome-settings-daemon/gnome-settings-plugins-engine.h: add back support for defining plugin start order 2008-02-09 Jens Granseuer * plugins/media-keys/gsd-media-keys-manager.c: (gsd_media_keys_manager_stop): declare variables at the beginning of a block to make older compilers happy 2008-02-09 Jens Granseuer * plugins/clipboard/gsd-clipboard-manager.c: (gsd_clipboard_error_quark): fix copy'n'paste error (bug #515426) 2008-02-08 Sebastien Bacher * configure.ac: check for xinput (bug #514942) 2008-02-08 Jens Granseuer * plugins/background/gsd-background-manager.c: (gsd_background_manager_start), (gsd_background_manager_stop): * plugins/keybindings/gsd-keybindings-manager.c: (gsd_keybindings_manager_start): * plugins/media-keys/gsd-media-keys-manager.c: (gsd_media_keys_manager_stop): fix leaks * plugins/default-editor/gsd-default-editor-manager.c: (gsd_default_editor_manager_start): fix leak and pass the correct data to the mime type callback * plugins/xsettings/gsd-xsettings-manager.c: (gnome_xsettings_manager_start): unref the GConfClient only after we're done with it 2008-02-08 Jens Granseuer * plugins/clipboard/gsd-clipboard-manager.c: (gsd_kbd_a11y_error_quark), (gsd_clipboard_manager_start): make sure we return a GError if initialization fails 2008-02-08 Matthias Clasen * plugins/keyboard/gsd-keyboard-manager.c (gsd_keyboard_manager_start): Load the XKB settings initially. Fixes bug #511771. 2008-02-07 Jens Granseuer * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: (gsd_kbd_a11y_error_quark), (gsd_a11y_keyboard_manager_start): make sure we return a GError if initialization fails (bug #514926) 2008-02-06 Jens Granseuer * plugins/media-keys/gsd-media-keys-window.c: (volume_controls_set_visible), (window_set_icon_name), (window_set_icon_file), (volume_level_changed), (gsd_media_keys_window_class_init), (gsd_media_keys_window_init): release the glade XML file as soon as possible and keep track of the two widgets we need. This way we can also get rid of the custom finalize method 2008-02-06 Jens Granseuer * data/gnome-settings-daemon.schemas.in: use gnome_settings_daemon for the GConf path. This is what the other g-s-d settings use as well, and there is no good reason to use two separate paths (bug #514411) 2008-02-06 Jens Granseuer * configure.ac: add separate checks for libbackground * plugins/background/libbackground/*: delete files and use the external copy from gnome-control-center to avoid duplication 2008-02-05 Jens Granseuer Based on a patch by: Damien Carberry * configure.ac: * data/gnome-settings-daemon-uninstalled.pc.in: add uninstalled.pc file for building against an uninstalled copy of g-s-d (bug #511820) 2008-02-05 Jens Granseuer Based on a patch by: Damien Carberry * Makefile.am: * autogen.sh: * configure.ac: * plugins/a11y-keyboard/Makefile.am: * plugins/background/Makefile.am: * plugins/clipboard/Makefile.am: * plugins/default-editor/Makefile.am: * plugins/dummy/Makefile.am: * plugins/font/Makefile.am: * plugins/keybindings/Makefile.am: * plugins/keyboard/Makefile.am: * plugins/media-keys/Makefile.am: * plugins/media-keys/actions/Makefile.am: * plugins/mouse/Makefile.am: * plugins/screensaver/Makefile.am: * plugins/sound/Makefile.am: * plugins/typing-break/Makefile.am: * plugins/xrandr/Makefile.am: * plugins/xrdb/Makefile.am: * plugins/xsettings/Makefile.am: * src: rename the src folder to gnome-settings-daemon. This is needed so we can supply an uninstalled.pc file for g-s-d (see discussion in bug #511820) 2008-02-04 Jens Granseuer * plugins/screensaver/gsd-screensaver-manager.c: (gsd_screensaver_manager_start): don't crash when running the screensaver fails. The plugin relies on the GError it passes always being filled in if we couldn't start the module, so set it up properly in those cases (bug #514385) 2008-02-04 Luca Ferretti reviewed by: Jens Granseuer * data/apps_gnome_settings_daemon_default_editor.schemas.in: * data/apps_gnome_settings_daemon_keybindings.schemas.in: * data/apps_gnome_settings_daemon_screensaver.schemas.in: * data/desktop_gnome_font_rendering.schemas.in: * data/gnome-settings-daemon.schemas.in: Review short and long descriptions for GConf keys, bug #514047. 2008-02-02 Jens Granseuer * src/Makefile.am: remove duplicate CFLAGS (and NULL) 2008-02-01 Christian Persch * configure.ac: Install the settings plugin to $(libdir)/gnome-settings-daemon-2.0. Fixes install with libdir == libexecdir, bug #504203. 2008-02-01 Christian Persch Bug #513246. * acinclude.m4: * configure.ac: * plugins/a11y-keyboard/Makefile.am: * plugins/background/Makefile.am: * plugins/clipboard/Makefile.am: * plugins/default-editor/Makefile.am: * plugins/dummy/Makefile.am: * plugins/font/Makefile.am: * plugins/keybindings/Makefile.am: * plugins/keyboard/Makefile.am: * plugins/media-keys/Makefile.am: * plugins/media-keys/actions/Makefile.am: * plugins/mouse/Makefile.am: * plugins/screensaver/Makefile.am: * plugins/sound/Makefile.am: * plugins/typing-break/Makefile.am: * plugins/xrandr/Makefile.am: * plugins/xrdb/Makefile.am: * plugins/xsettings/Makefile.am: Use a flat directory instead of a directory hierarchy to install the plugins into. Install data files under $(pkgdatadir), not under $(libdir). * src/Makefile.am: * src/gnome-settings-plugins-engine.c: (gnome_settings_plugin_info_free), (gnome_settings_plugins_engine_load), (gnome_settings_plugins_engine_load_file), (gnome_settings_plugins_engine_load_dir): Don't scan the plugins directory recursively. Use GSlice for the plugin info struct. ==== 2.21.90.2 ==== 2008-01-30 Rodrigo Moya * NEWS: * configure.ac: prepare for 2.21.90.2. 2008-01-30 Gabor Kelemen * data/apps_gnome_settings_daemon_keybindings.schemas.in: Change E-mail schema's descriptions to be more verbose and sensible. Fix #512766. 2008-01-30 Christian Persch * configure.ac: * plugins/a11y-keyboard/Makefile.am: * plugins/a11y-keyboard/a11y-keyboard.gnome-settings-plugin.desktop .in: * plugins/background/Makefile.am: * plugins/background/background.gnome-settings-plugin.desktop.in: * plugins/clipboard/Makefile.am: * plugins/clipboard/clipboard.gnome-settings-plugin.desktop.in: * plugins/default-editor/Makefile.am: * plugins/default-editor/default-editor.gnome-settings-plugin.deskt op.in: * plugins/dummy/Makefile.am: * plugins/dummy/dummy.gnome-settings-plugin.desktop.in: * plugins/font/Makefile.am: * plugins/font/font.gnome-settings-plugin.desktop.in: * plugins/keybindings/Makefile.am: * plugins/keybindings/keybindings.gnome-settings-plugin.desktop.in: * plugins/keyboard/Makefile.am: * plugins/keyboard/keyboard.gnome-settings-plugin.desktop.in: * plugins/media-keys/Makefile.am: * plugins/media-keys/media-keys.gnome-settings-plugin.desktop.in: * plugins/mouse/Makefile.am: * plugins/mouse/mouse.gnome-settings-plugin.desktop.in: * plugins/screensaver/Makefile.am: * plugins/screensaver/screensaver.gnome-settings-plugin.desktop.in: * plugins/sound/Makefile.am: * plugins/sound/libsounds/Makefile.am: * plugins/sound/sound.gnome-settings-plugin.desktop.in: * plugins/typing-break/Makefile.am: * plugins/typing-break/typing-break.gnome-settings-plugin.desktop.in: * plugins/xrandr/Makefile.am: * plugins/xrandr/xrandr.gnome-settings-plugin.desktop.in: * plugins/xrdb/Makefile.am: * plugins/xrdb/xrdb.gnome-settings-plugin.desktop.in: * plugins/xsettings/Makefile.am: * plugins/xsettings/xsettings.gnome-settings-plugin.desktop.in: * po/POTFILES.in: No need to use weird naming of .gnome-settings-daemon.in files. Bug #512048. 2008-01-29 Rodrigo Moya * data/org.gnome.SettingsDaemon.service.in: use correct binary path. ==== 2.21.90.1 ==== 2008-01-29 Rodrigo Moya * NEWS: * configure.ac: prepare for 2.21.90.1. 2008-01-29 Rodrigo Moya * src/Makefile.am: use plain $libexecdir for g-s-d binary. ==== 2.21.90 ==== 2008-01-28 Rodrigo Moya * configure.ac: * NEWS: prepare for 2.21.90. 2008-01-28 Wouter Bolsterlee * data/Makefile.am: Suppress verbose GConf schema installation output. 2008-01-28 Wouter Bolsterlee * src/Makefile.am: Don't use weird autofu stuff to install gnome-settings-daemon into another directory, but define gsddir and gsd_PROGRAMS instead. Fixes bug #504203. 2008-01-28 Wouter Bolsterlee * data/org.gnome.SettingsDaemon.service.in: * src/Makefile.am: Hopefully allow $(libdir) to be the same directory as $(libexecdir) by installing the gnome-settings-daemon binary into a subdirectory of $(libexecdir), i.e. $(libexecdir)/gnome-settings-daemon/gnome-settings-daemon. Fixes bug #504203. 2008-01-28 Wouter Bolsterlee * src/main.c: (main): Don't leak the GnomeProgram instance. 2008-01-28 Wouter Bolsterlee * configure.ac: * src/main.c: (main): Initialize GnomeProgram to avoid critical warnings from libgnome. Fixes bug #509770. 2008-01-26 Jens Granseuer * data/gnome-settings-daemon.pc.in: DBus API has been frozen for a while now. No longer define DBUS_API_SUBJECT_TO_CHANGE 2008-01-25 Soren Sandmann * plugins/background/gsd-background-manager.c (GNOME_DESKTOP_USE_UNSTABLE_API): Define this macro before including gnome-bg.h 2008-01-25 Jens Granseuer * plugins/xsettings/gsd-xsettings-manager.c: (xft_settings_set_xresources): don't try to reference a non-existing variable (left-over cruft from the patch for bug #505470) 2008-01-25 Jens Granseuer * data/gnome-settings-daemon.schemas.in: fix typo in typing break key. Bug #510429. 2008-01-25 Jens Granseuer Patch by: * configure.ac: readd check for XFT2 that got lost in the g-s-d split. Bug #510925. 2008-01-25 Christian Persch * plugins/xsettings/gsd-xsettings-manager.c: (xft_settings_set_xresources): Use g_ascii_dtostr instead of setlocale. Bug #505470. 2008-01-25 Christian Persch * plugins/media-keys/Makefile.am: Fix build with builddir != srcdir. BUg #509142. 2008-01-24 Jens Granseuer * configure.ac: quote function names in AC_DEFUN to fix "underquoted definition" autoconf warning 2008-01-23 Kjartan Maraas * plugins/mouse/gsd-locate-pointer.c: (timeline_frame_cb), (timeline_finished_cb): Fix a couple typos that broke the build. 2008-01-22 Carlos Garnacho * plugins/mouse/gsd-locate-pointer.c: Reworked, add a more appealing animation if there's a composite manager present, also use a similar animation for the non-composite case, so most of the code is shared. * plugins/mouse/gsd-timeline.[ch]: New files, object to control the "locate pointer" animation. * plugins/mouse/Makefile.am: Added these files to build. ==== 2.21.5.2 ==== 2008-01-15 Rodrigo Moya * configure.ac: * NEWS: prepare for 2.21.5.2. 2008-01-15 Rodrigo Moya * plugins/sound/Makefile.am: * plugins/sound/libsounds/Makefile.am: use a libtool library for x86_64 warnings. * configure.ac: automake fixes for allowing long file names in tar.gz. ==== 2.21.5.1 ==== 2008-01-15 Rodrigo Moya * configure.ac: * NEWS: prepare for 2.21.5.1. ==== 2.21.5 ==== 2008-01-15 Rodrigo Moya * NEWS: prepare for 2.21.5. 2008-01-14 Rodrigo Moya * data/gnome-settings-daemon.pc.in: reverted last patch. 2008-01-14 Rodrigo Moya * data/gnome-settings-daemon.pc.in: added dbusapidir variable, for the gnome-control-center module to access the .xml DBus interfaces file. 2008-01-14 Denis Washington * plugins/xrandr/Makefile.in: This was probably commited by accident, remove it. 2008-01-14 Denis Washington * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c: Only consider /desktop/gnome/accessibility/keyboard/enable as option for enabling keyboard a11y features from the keyboard, not as global switch to turn all a11y features on/off. 2008-01-14 Denis Washington Patch from Gerd Kohlberger (bug #503547) * plugins/mouse/gsd-mouse-manager.c: Mousetweaks support. 2008-01-14 Rodrigo Moya * plugins/media-keys/gsd-media-keys-manager.c: reverted patch from bug #165343. 2007-12-24 Christian Persch * plugins/xsettings/gsd-xsettings-manager.c: Add Gtk/IMModule XSetting. Bug #504182, patch by Akira TAGOH. 2007-12-22 William Jon McCann * plugins/xsettings/gsd-xsettings-manager.c: use new setting from libgnome to make toolbar icon size setting work (bug #401030) Merge from gnome-control-center. 2007-12-22 William Jon McCann * plugins/xsettings/Makefile.am: * plugins/xsettings/gnome-xsettings-manager.c: * plugins/xsettings/gnome-xsettings-manager.h: * plugins/xsettings/gnome-xsettings-plugin.c: * plugins/xsettings/gnome-xsettings-plugin.h: * plugins/xsettings/gsd-xsettings-manager.c: * plugins/xsettings/gsd-xsettings-plugin.c: Rename files to be consistent with other plugins. 2007-12-21 William Jon McCann * plugins/background/Makefile.am: * plugins/background/background.gnome-settings-plugin.desktop.in: * plugins/background/gsd-background-manager.c: (gsd_background_manager_init): * plugins/background/test-background.c: (idle), (main): Init gnome-vfs and use the correct name in the desktop file. 2007-12-21 William Jon McCann * configure.ac: * plugins/background/gsd-background-manager.c: (nautilus_is_running), (apply_prefs), (queue_apply), (background_callback), (on_bg_changed), (gsd_background_manager_start): Merge g-c-c patch for animated backgrounds. Require gnome-desktop 2.21.4. Patch from: Soeren Sandmann 2007-12-18 William Jon McCann * configure.ac: Post release version bump ==== 2.21.4 ==== 2007-12-18 William Jon McCann * NEWS: Update for release. 2007-12-18 William Jon McCann * configure.ac: Update version number. 2007-12-18 William Jon McCann * src/gnome-settings-manager.c: (gnome_settings_manager_awake): * src/main.c: Turn off daemonizing for now since it confused D-Bus service activation. 2007-12-18 William Jon McCann * src/Makefile.am: * src/gnome-settings-manager.c: (gnome_settings_manager_awake), (register_manager), (gnome_settings_manager_class_init), (gnome_settings_manager_new): * src/gnome-settings-manager.h: * src/gnome-settings-manager.xml: Provide the awake method and install the dbus api header. 2007-12-17 William Jon McCann * plugins/background/Makefile.am: * plugins/sound/Makefile.am: Fix distcheck. 2007-12-17 William Jon McCann * plugins/Makefile.am: * plugins/a11y-keyboard/a11y-keyboard.gnome-settings-plugin.desktop .in: * plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h: * plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c: (gsd_a11y_keyboard_plugin_init), (gsd_a11y_keyboard_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_a11y_keyboard_plugin_class_init): * plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.h: Add a11y keyboard plugin. 2007-12-17 William Jon McCann * configure.ac: * plugins/Makefile.am: * plugins/typing-break/Makefile.am: * plugins/typing-break/gsd-typing-break-manager.c: (register_config_callback), (typing_break_timeout), (child_watch), (setup_typing_break), (typing_break_callback), (really_setup_typing_break), (gsd_typing_break_manager_start), (gsd_typing_break_manager_stop), (gsd_typing_break_manager_set_property), (gsd_typing_break_manager_get_property), (gsd_typing_break_manager_constructor), (gsd_typing_break_manager_dispose), (gsd_typing_break_manager_class_init), (gsd_typing_break_manager_init), (gsd_typing_break_manager_finalize), (gsd_typing_break_manager_new): * plugins/typing-break/gsd-typing-break-manager.h: * plugins/typing-break/gsd-typing-break-plugin.c: (gsd_typing_break_plugin_init), (gsd_typing_break_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_typing_break_plugin_class_init): * plugins/typing-break/gsd-typing-break-plugin.h: * plugins/typing-break/typing-break.gnome-settings-plugin.desktop.in: Add typing break plugin. 2007-12-17 William Jon McCann * configure.ac: * data/gnome-settings-daemon.schemas.in: * plugins/Makefile.am: * plugins/sound/Makefile.am: * plugins/sound/gsd-sound-manager.c: (start_gnome_sound), (stop_gnome_sound), (reload_foreach_cb), (apply_settings), (register_config_callback), (sound_callback), (gsd_sound_manager_start), (gsd_sound_manager_stop), (gsd_sound_manager_set_property), (gsd_sound_manager_get_property), (gsd_sound_manager_constructor), (gsd_sound_manager_dispose), (gsd_sound_manager_class_init), (gsd_sound_manager_init), (gsd_sound_manager_finalize), (gsd_sound_manager_new): * plugins/sound/gsd-sound-manager.h: * plugins/sound/gsd-sound-plugin.c: (gsd_sound_plugin_init), (gsd_sound_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_sound_plugin_class_init): * plugins/sound/gsd-sound-plugin.h: * plugins/sound/sound.gnome-settings-plugin.desktop.in: * plugins/xrandr/Makefile.in: Add sound plugin 2007-12-17 William Jon McCann * data/gnome-settings-daemon.schemas.in: Add schemas for media keys. 2007-12-17 William Jon McCann * configure.ac: * plugins/Makefile.am: * plugins/dummy/gsd-dummy-manager.c: * plugins/media-keys/Makefile.am: * plugins/media-keys/actions/Makefile.am: * plugins/media-keys/actions/acme-volume-alsa.c: (acme_volume_alsa_finalize), (acme_volume_alsa_set_mute), (acme_volume_alsa_get_mute), (acme_volume_alsa_get_volume), (acme_volume_alsa_set_volume), (acme_volume_alsa_close_real), (acme_volume_alsa_open), (acme_volume_alsa_close), (acme_volume_alsa_init), (acme_volume_alsa_class_init): * plugins/media-keys/actions/acme-volume-alsa.h: * plugins/media-keys/actions/acme-volume-dummy.c: (acme_volume_dummy_finalize), (acme_volume_dummy_set_mute), (acme_volume_dummy_get_mute), (acme_volume_dummy_get_volume), (acme_volume_dummy_set_volume), (acme_volume_dummy_init), (acme_volume_dummy_class_init), (acme_volume_dummy_get_type): * plugins/media-keys/actions/acme-volume-dummy.h: * plugins/media-keys/actions/acme-volume-gstreamer.c: (acme_volume_gstreamer_finalize), (acme_volume_gstreamer_set_mute), (update_state), (acme_volume_gstreamer_get_mute), (acme_volume_gstreamer_get_volume), (acme_volume_gstreamer_set_volume), (acme_volume_gstreamer_close_real), (_acme_set_mixer), (acme_volume_gstreamer_open), (acme_volume_gstreamer_close), (acme_volume_gstreamer_init), (acme_volume_gstreamer_class_init): * plugins/media-keys/actions/acme-volume-gstreamer.h: * plugins/media-keys/actions/acme-volume-oss.c: (acme_volume_oss_finalize), (acme_volume_oss_vol_check), (acme_volume_oss_set_mute), (acme_volume_oss_get_mute), (acme_volume_oss_get_volume), (acme_volume_oss_set_volume), (acme_volume_oss_init), (acme_volume_oss_class_init), (acme_volume_oss_mixer_check): * plugins/media-keys/actions/acme-volume-oss.h: * plugins/media-keys/actions/acme-volume.c: (acme_volume_class_init), (acme_volume_init), (acme_volume_get_volume), (acme_volume_set_volume), (acme_volume_get_mute), (acme_volume_set_mute), (acme_volume_mute_toggle), (acme_volume_new): * plugins/media-keys/actions/acme-volume.h: * plugins/media-keys/actions/acme.glade: * plugins/media-keys/actions/acme.h: * plugins/media-keys/eggaccelerators.c: (is_alt), (is_ctl), (is_modx), (is_ctrl), (is_shft), (is_shift), (is_control), (is_release), (is_meta), (is_super), (is_hyper), (is_keycode), (egg_accelerator_parse_virtual), (egg_virtual_accelerator_name), (egg_keymap_resolve_virtual_modifiers), (egg_keymap_virtualize_modifiers), (reload_modmap), (egg_keymap_get_modmap): * plugins/media-keys/eggaccelerators.h: * plugins/media-keys/gsd-marshal.list: * plugins/media-keys/gsd-media-keys-manager.c: (init_screens), (acme_error), (get_term_command), (execute), (do_sleep_action), (dialog_init), (grab_key_real), (grab_key), (is_valid_shortcut), (update_kbd_cb), (init_kbd), (dialog_show), (do_unknown_action), (do_help_action), (do_mail_action), (do_media_action), (do_www_action), (do_exit_action), (do_eject_action), (do_sound_action), (find_by_application), (find_by_time), (gsd_media_keys_manager_grab_media_player_keys), (gsd_media_keys_manager_release_media_player_keys), (gsd_media_player_key_pressed), (do_multimedia_player_action), (do_action), (acme_get_screen_from_event), (acme_filter_events), (gsd_media_keys_manager_start), (gsd_media_keys_manager_stop), (gsd_media_keys_manager_set_property), (gsd_media_keys_manager_get_property), (gsd_media_keys_manager_constructor), (gsd_media_keys_manager_dispose), (gsd_media_keys_manager_class_init), (gsd_media_keys_manager_init), (gsd_media_keys_manager_finalize), (register_manager), (gsd_media_keys_manager_new): * plugins/media-keys/gsd-media-keys-manager.h: * plugins/media-keys/gsd-media-keys-manager.xml: * plugins/media-keys/gsd-media-keys-plugin.c: (gsd_media_keys_plugin_init), (gsd_media_keys_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_media_keys_plugin_class_init): * plugins/media-keys/gsd-media-keys-plugin.h: * plugins/media-keys/gsd-media-keys-window.c: (fade_timeout), (hide_timeout), (remove_hide_timeout), (add_hide_timeout), (update_window), (volume_controls_set_visible), (window_set_icon_name), (window_set_icon_file), (action_changed), (volume_level_changed), (volume_muted_changed), (gsd_media_keys_window_set_action), (gsd_media_keys_window_set_volume_muted), (gsd_media_keys_window_set_volume_level), (curved_rectangle), (load_pixbuf), (render_eject), (draw_eject), (draw_action_eject), (draw_waves), (draw_speaker), (render_speaker), (draw_volume_boxes), (draw_action_volume), (draw_action), (on_expose_event), (gsd_media_keys_window_real_show), (gsd_media_keys_window_real_hide), (gsd_media_keys_window_class_init), (gsd_media_keys_window_is_valid), (initialize_alpha_mode), (gsd_media_keys_window_init), (gsd_media_keys_window_finalize), (gsd_media_keys_window_new): * plugins/media-keys/gsd-media-keys-window.h: * plugins/media-keys/media-keys.gnome-settings-plugin.desktop.in: * plugins/media-keys/test-media-window.c: (update_state), (test_window), (main): * plugins/xrandr/Makefile.in: Add media keys plugin. 2007-12-17 William Jon McCann * configure.ac: * data/Makefile.am: * data/apps_gnome_settings_daemon_default_editor.schemas.in: * data/apps_gnome_settings_daemon_keybindings.schemas.in: * data/apps_gnome_settings_daemon_screensaver.schemas.in: * data/desktop_gnome_font_rendering.schemas.in: * plugins/default-editor/Makefile.am: * plugins/default-editor/gsd-default-editor-manager.c: (gsd_default_editor_manager_init): * plugins/keyboard/Makefile.am: * plugins/keyboard/gsd-keyboard-manager.c: * plugins/mouse/gsd-mouse-manager.c: * plugins/screensaver/gsd-screensaver-manager.c: (gsd_screensaver_manager_start): * plugins/xrandr/Makefile.in: * plugins/xrandr/gsd-xrandr-manager.c: * plugins/xrdb/Makefile.am: Add other schemas. Fix some zero length private data. Fix some install dirs. Add libgnomekbd deps. 2007-12-17 William Jon McCann * configure.ac: * data/gnome-settings-daemon.schemas.in: * plugins/Makefile.am: * plugins/screensaver/Makefile.am: * plugins/screensaver/gsd-screensaver-manager.c: (key_toggled_cb), (gsd_screensaver_manager_start), (gsd_screensaver_manager_stop), (gsd_screensaver_manager_set_property), (gsd_screensaver_manager_get_property), (gsd_screensaver_manager_constructor), (gsd_screensaver_manager_dispose), (gsd_screensaver_manager_class_init), (gsd_screensaver_manager_init), (gsd_screensaver_manager_finalize), (gsd_screensaver_manager_new): * plugins/screensaver/gsd-screensaver-manager.h: * plugins/screensaver/gsd-screensaver-plugin.c: (gsd_screensaver_plugin_init), (gsd_screensaver_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_screensaver_plugin_class_init): * plugins/screensaver/gsd-screensaver-plugin.h: * plugins/screensaver/screensaver.gnome-settings-plugin.desktop.in: Add screensaver plugin. 2007-12-17 William Jon McCann * plugins/background/Makefile.am: * plugins/clipboard/Makefile.am: * plugins/default-editor/Makefile.am: * plugins/dummy/Makefile.am: * plugins/font/Makefile.am: * plugins/keybindings/Makefile.am: * plugins/mouse/Makefile.am: * plugins/xrandr/Makefile.am: * plugins/xrandr/Makefile.in: * plugins/xrdb/Makefile.am: * plugins/xsettings/Makefile.am: Install in subdirectories 2007-12-17 William Jon McCann * plugins/keyboard/Makefile.am: * plugins/keyboard/modmap-dialog.glade: Add missing glade file. 2007-12-17 William Jon McCann * plugins/font/gsd-font-manager.c: * src/gnome-settings-plugins-engine.c: (gnome_settings_plugins_engine_load_file), (gnome_settings_plugins_engine_activate_plugin), (gnome_settings_plugins_engine_deactivate_plugin): Fix an extraneous / in gconf path. Add a dummy var to pad out private data. 2007-12-16 William Jon McCann * configure.ac: * data/gnome-settings-daemon.schemas.in: * plugins/Makefile.am: * plugins/background/Makefile.am: * plugins/background/background.gnome-settings-plugin.desktop.in: * plugins/background/gsd-background-manager.c: (applier_idle), (background_callback), (gsd_background_manager_start), (gsd_background_manager_stop), (gsd_background_manager_set_property), (gsd_background_manager_get_property), (gsd_background_manager_constructor), (gsd_background_manager_dispose), (gsd_background_manager_class_init), (gsd_background_manager_init), (gsd_background_manager_finalize), (gsd_background_manager_new): * plugins/background/gsd-background-manager.h: * plugins/background/gsd-background-plugin.c: (gsd_background_plugin_init), (gsd_background_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_background_plugin_class_init): * plugins/background/gsd-background-plugin.h: Add background plugin. 2007-12-16 William Jon McCann * configure.ac: * data/gnome-settings-daemon.schemas.in: * plugins/Makefile.am: * plugins/default-editor/default-editor.gnome-settings-plugin.deskt op.in: * plugins/keybindings/Makefile.am: * plugins/keybindings/eggaccelerators.c: (is_alt), (is_ctl), (is_modx), (is_ctrl), (is_shft), (is_shift), (is_control), (is_release), (is_meta), (is_super), (is_hyper), (is_keycode), (egg_accelerator_parse_virtual), (egg_virtual_accelerator_name), (egg_keymap_resolve_virtual_modifiers), (egg_keymap_virtualize_modifiers), (reload_modmap), (egg_keymap_get_modmap): * plugins/keybindings/eggaccelerators.h: * plugins/keybindings/gsd-keybindings-manager.c: (get_screens_list), (entry_get_string), (parse_binding), (compare_bindings), (bindings_get_entry), (key_already_used), (grab_key), (do_grab), (binding_register_keys), (screen_exec_display_string), (get_exec_environment), (keybindings_filter), (bindings_callback), (register_config_callback), (gsd_keybindings_manager_start), (gsd_keybindings_manager_stop), (gsd_keybindings_manager_set_property), (gsd_keybindings_manager_get_property), (gsd_keybindings_manager_constructor), (gsd_keybindings_manager_dispose), (gsd_keybindings_manager_class_init), (gsd_keybindings_manager_init), (gsd_keybindings_manager_finalize), (gsd_keybindings_manager_new): * plugins/keybindings/gsd-keybindings-manager.h: * plugins/keybindings/gsd-keybindings-plugin.c: (gsd_keybindings_plugin_init), (gsd_keybindings_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_keybindings_plugin_class_init): * plugins/keybindings/gsd-keybindings-plugin.h: * plugins/keybindings/keybindings.gnome-settings-plugin.desktop.in: * plugins/keyboard/keyboard.gnome-settings-plugin.desktop.in: * plugins/mouse/mouse.gnome-settings-plugin.desktop.in: Add keybindings plugin. 2007-12-16 William Jon McCann * configure.ac: * data/gnome-settings-daemon.schemas.in: * plugins/Makefile.am: * plugins/mouse/Makefile.am: * plugins/mouse/gsd-locate-pointer.c: (locate_pointer_expose), (setup_window), (create_window), (locate_pointer_timeout), (gsd_locate_pointer): * plugins/mouse/gsd-locate-pointer.h: * plugins/mouse/gsd-mouse-manager.c: (gsd_mouse_manager_stop), (gsd_mouse_manager_set_property), (gsd_mouse_manager_get_property), (gsd_mouse_manager_constructor), (gsd_mouse_manager_dispose), (gsd_mouse_manager_class_init), (supports_xinput_devices), (configure_button_layout), (xinput_device_has_buttons), (set_xinput_devices_left_handed), (set_left_handed), (set_motion_acceleration), (set_motion_threshold), (filter), (set_locate_pointer), (mouse_callback), (register_config_callback), (gsd_mouse_manager_init), (gsd_mouse_manager_start), (gsd_mouse_manager_finalize), (gsd_mouse_manager_new): * plugins/mouse/gsd-mouse-manager.h: * plugins/mouse/gsd-mouse-plugin.c: (gsd_mouse_plugin_init), (gsd_mouse_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_mouse_plugin_class_init): * plugins/mouse/gsd-mouse-plugin.h: * plugins/mouse/mouse.gnome-settings-plugin.desktop.in: Add mouse plugin. 2007-12-16 William Jon McCann * configure.ac: * data/gnome-settings-daemon.schemas.in: * plugins/Makefile.am: * plugins/keyboard/Makefile.am: * plugins/keyboard/delayed-dialog.c: (gsd_delayed_show_dialog), (delayed_show_timeout), (message_filter): * plugins/keyboard/delayed-dialog.h: * plugins/keyboard/gsd-keyboard-manager.c: (xfree86_set_keyboard_autorepeat_rate), (xkb_set_keyboard_autorepeat_rate), (gsd_keyboard_get_hostname_key), (numlock_NumLock_modifier_mask), (numlock_set_xkb_state), (numlock_gconf_state_key), (numlock_get_gconf_state), (numlock_set_gconf_state), (numlock_xkb_callback), (numlock_install_xkb_callback), (apply_settings), (register_config_callback), (gsd_keyboard_manager_start), (gsd_keyboard_manager_stop), (gsd_keyboard_manager_set_property), (gsd_keyboard_manager_get_property), (gsd_keyboard_manager_constructor), (gsd_keyboard_manager_dispose), (gsd_keyboard_manager_class_init), (gsd_keyboard_manager_init), (gsd_keyboard_manager_finalize), (gsd_keyboard_manager_new): * plugins/keyboard/gsd-keyboard-manager.h: * plugins/keyboard/gsd-keyboard-plugin.c: (gsd_keyboard_plugin_init), (gsd_keyboard_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_keyboard_plugin_class_init): * plugins/keyboard/gsd-keyboard-plugin.h: * plugins/keyboard/gsd-keyboard-xkb.c: (gsd_keyboard_log_appender), (activation_error), (apply_settings), (apply_xkb_settings), (gsd_keyboard_xkb_analyze_sysconfig), (gsd_chk_file_list), (gsd_keyboard_xkb_chk_lcl_xmm), (gsd_keyboard_xkb_set_post_activation_callback), (gsd_keyboard_xkb_evt_filter), (register_config_callback), (gsd_keyboard_xkb_init), (gsd_keyboard_xkb_load): * plugins/keyboard/gsd-keyboard-xkb.h: * plugins/keyboard/gsd-xmodmap.c: (check_button_callback), (gsd_load_modmap_files), (response_callback), (get_selected_files_func), (remove_string_from_list), (remove_button_clicked_callback), (load_button_clicked_callback), (gsd_modmap_dialog_call): * plugins/keyboard/gsd-xmodmap.h: * plugins/keyboard/keyboard.gnome-settings-plugin.desktop.in: * plugins/xrandr/Makefile.in: Add the keyboard plugin. 2007-12-16 William Jon McCann * configure.ac: * data/gnome-settings-daemon.schemas.in: * plugins/Makefile.am: * plugins/default-editor/Makefile.am: * plugins/default-editor/default-editor.gnome-settings-plugin.deskt op.in: * plugins/default-editor/gsd-default-editor-manager.c: (sync_changes_cb), (register_config_callback), (vfs_change_cb), (gsd_default_editor_manager_start), (gsd_default_editor_manager_stop), (gsd_default_editor_manager_set_property), (gsd_default_editor_manager_get_property), (gsd_default_editor_manager_constructor), (gsd_default_editor_manager_dispose), (gsd_default_editor_manager_class_init), (gsd_default_editor_manager_init), (gsd_default_editor_manager_finalize), (gsd_default_editor_manager_new): * plugins/default-editor/gsd-default-editor-manager.h: * plugins/default-editor/gsd-default-editor-plugin.c: (gsd_default_editor_plugin_init), (gsd_default_editor_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_default_editor_plugin_class_init): * plugins/default-editor/gsd-default-editor-plugin.h: * plugins/font/Makefile: * plugins/font/Makefile.in: Add default editor plugin 2007-12-16 William Jon McCann * configure.ac: * data/gnome-settings-daemon.schemas.in: * plugins/Makefile.am: * plugins/font/Makefile: * plugins/font/Makefile.am: * plugins/font/Makefile.in: * plugins/font/delayed-dialog.c: (gnome_settings_delayed_show_dialog), (delayed_show_timeout), (message_filter): * plugins/font/delayed-dialog.h: * plugins/font/font.gnome-settings-plugin.desktop.in: * plugins/font/gsd-font-manager.c: (write_all), (child_watch_cb), (spawn_with_input), (load_xcursor_theme), (load_cursor), (gsd_font_manager_start), (gsd_font_manager_stop), (gsd_font_manager_set_property), (gsd_font_manager_get_property), (gsd_font_manager_constructor), (gsd_font_manager_dispose), (gsd_font_manager_class_init), (gsd_font_manager_init), (gsd_font_manager_finalize), (gsd_font_manager_new): * plugins/font/gsd-font-manager.h: * plugins/font/gsd-font-plugin.c: (gsd_font_plugin_init), (gsd_font_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_font_plugin_class_init): * plugins/font/gsd-font-plugin.h: Add font plugin 2007-12-14 William Jon McCann * data/gnome-settings-daemon.schemas.in: Add schemas for clipboard and xrandr. 2007-12-14 William Jon McCann * configure.ac: * plugins/Makefile.am: * plugins/clipboard/Makefile.am: * plugins/clipboard/clipboard.gnome-settings-plugin.desktop.in: * plugins/clipboard/gsd-clipboard-manager.c: (target_data_ref), (target_data_unref), (conversion_free), (send_selection_notify), (finish_selection_request), (clipboard_bytes_per_item), (save_targets), (find_content_target), (find_content_type), (find_conversion_requestor), (get_property), (receive_incrementally), (send_incrementally), (convert_clipboard_manager), (convert_clipboard_target), (collect_incremental), (convert_clipboard), (clipboard_manager_process_event), (clipboard_manager_event_filter), (clipboard_manager_watch_cb), (gsd_clipboard_manager_start), (gsd_clipboard_manager_stop), (gsd_clipboard_manager_set_property), (gsd_clipboard_manager_get_property), (gsd_clipboard_manager_constructor), (gsd_clipboard_manager_dispose), (gsd_clipboard_manager_class_init), (gsd_clipboard_manager_init), (gsd_clipboard_manager_finalize), (gsd_clipboard_manager_new): * plugins/clipboard/gsd-clipboard-manager.h: * plugins/clipboard/gsd-clipboard-plugin.c: (gsd_clipboard_plugin_init), (gsd_clipboard_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_clipboard_plugin_class_init): * plugins/clipboard/gsd-clipboard-plugin.h: * plugins/clipboard/list.c: (list_foreach), (list_prepend), (list_free), (list_find), (list_remove), (list_length), (list_copy): * plugins/clipboard/list.h: * plugins/clipboard/xutils.c: (init_atoms), (timestamp_predicate), (get_server_time): * plugins/clipboard/xutils.h: Port over the clipboard module. 2007-12-14 William Jon McCann * configure.ac: * plugins/xrdb/Makefile.am: * plugins/xrdb/data/Editres.ad: * plugins/xrdb/data/Emacs.ad: * plugins/xrdb/data/General.ad: * plugins/xrdb/data/Makefile.am: * plugins/xrdb/data/Motif.ad: * plugins/xrdb/data/Tk.ad: * plugins/xrdb/data/Xaw.ad: Add the .ad files. 2007-12-14 William Jon McCann * configure.ac: * plugins/Makefile.am: * plugins/xrandr/Makefile.am: * plugins/xrandr/Makefile.in: * plugins/xrandr/gsd-xrandr-manager.c: (get_rotation), (get_resolution), (get_rate), (find_closest_size), (apply_settings), (gsd_xrandr_manager_start), (gsd_xrandr_manager_stop), (gsd_xrandr_manager_set_property), (gsd_xrandr_manager_get_property), (gsd_xrandr_manager_constructor), (gsd_xrandr_manager_dispose), (gsd_xrandr_manager_class_init), (gsd_xrandr_manager_init), (gsd_xrandr_manager_finalize), (gsd_xrandr_manager_new): * plugins/xrandr/gsd-xrandr-manager.h: * plugins/xrandr/gsd-xrandr-plugin.c: (gsd_xrandr_plugin_init), (gsd_xrandr_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_xrandr_plugin_class_init): * plugins/xrandr/gsd-xrandr-plugin.h: * plugins/xrandr/xrandr.gnome-settings-plugin.desktop.in: Add xrandr plugin. 2007-12-14 William Jon McCann * configure.ac: * plugins/Makefile.am: * plugins/dummy/Makefile.am: * plugins/dummy/gsd-dummy-manager.c: (gsd_dummy_manager_start), (gsd_dummy_manager_stop), (gsd_dummy_manager_set_property), (gsd_dummy_manager_get_property), (gsd_dummy_manager_constructor), (gsd_dummy_manager_dispose), (gsd_dummy_manager_class_init), (gsd_dummy_manager_init), (gsd_dummy_manager_finalize), (gsd_dummy_manager_new): * plugins/dummy/gsd-dummy-manager.h: * plugins/dummy/gsd-dummy-plugin.c: (impl_activate), (impl_deactivate), (gsd_dummy_plugin_class_init): * plugins/dummy/gsd-dummy-plugin.h: Build the dummy. 2007-12-14 William Jon McCann * configure.ac: * data/gnome-settings-daemon.schemas.in: * plugins/Makefile.am: * plugins/dummy/Makefile.am: * plugins/dummy/dummy.gnome-settings-plugin.desktop.in: * plugins/dummy/gsd-dummy-manager.c: (gsd_xrdb_manager_start), (gsd_xrdb_manager_stop), (gsd_xrdb_manager_set_property), (gsd_xrdb_manager_get_property), (gsd_xrdb_manager_constructor), (gsd_xrdb_manager_dispose), (gsd_xrdb_manager_class_init), (gsd_xrdb_manager_init), (gsd_xrdb_manager_finalize), (gsd_xrdb_manager_new): * plugins/dummy/gsd-dummy-manager.h: * plugins/dummy/gsd-dummy-plugin.c: (gsd_dummy_plugin_init), (gsd_dummy_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_dummy_plugin_class_init): * plugins/dummy/gsd-dummy-plugin.h: * plugins/xrdb/Makefile.am: * plugins/xrdb/gsd-xrdb-manager.c: (append_color_define), (color_shade), (append_theme_colors), (scan_ad_directory), (compare_basenames), (scan_for_files), (append_file), (append_xresource_file), (write_all), (child_watch_cb), (spawn_with_input), (apply_settings), (theme_changed), (gsd_xrdb_manager_start), (gsd_xrdb_manager_stop), (gsd_xrdb_manager_set_property), (gsd_xrdb_manager_get_property), (gsd_xrdb_manager_constructor), (gsd_xrdb_manager_dispose), (gsd_xrdb_manager_class_init), (gsd_xrdb_manager_init), (gsd_xrdb_manager_finalize), (gsd_xrdb_manager_new): * plugins/xrdb/gsd-xrdb-manager.h: * plugins/xrdb/gsd-xrdb-plugin.c: (gsd_xrdb_plugin_init), (gsd_xrdb_plugin_finalize), (impl_activate), (impl_deactivate), (gsd_xrdb_plugin_class_init): * plugins/xrdb/gsd-xrdb-plugin.h: * plugins/xrdb/xrdb.gnome-settings-plugin.desktop.in: * plugins/xsettings/gnome-xsettings-manager.h: Port over the xrdb module. Also add a skeleton plugin dir. 2007-12-14 William Jon McCann * MAINTAINERS: * configure.ac: * src/main.c: (get_bus_proxy), (acquire_name_on_proxy), (get_session_bus), (bus_register), (main): Grab a name on the session bus. 2007-12-14 William Jon McCann * configure.ac, etc: Initial checkin. Previously lived in gdm module. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/MAINTAINERS0000664000175000017500000000054000000000000020532 0ustar00jeremyjeremyRodrigo Moya E-mail: rodrigo at gnome-db.org Userid: rodrigo Sebastien Bacher Email: seb128 at debian.org Userid: sbacher Thomas Wood Email: thos at gnome.org Userid: thos Jens Granseuer Email: jensgr at gmx.net Userid: jensg William Jon McCann Email: mccann at jhu.edu Userid: mccann Bastien Nocera Email: hadess at hadess dot net Userid: hadess ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/Makefile.am0000664000175000017500000000044300000000000021073 0ustar00jeremyjeremyNULL = SUBDIRS = \ gnome-settings-daemon \ plugins \ data \ po \ tests \ $(NULL) if ENABLE_MAN SUBDIRS += man endif # Honor aclocal flags ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} EXTRA_DIST = \ MAINTAINERS \ ChangeLog \ README \ $(NULL) DISTCLEANFILES = \ $(NULL) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/NEWS0000664000175000017500000030146200000000000017543 0ustar00jeremyjeremy=============== Version 3.8.6.1 =============== - New release for build failures ============= Version 3.8.6 ============= Housekeeping: - Optimise for "do nothing" when cleaning thumbnails Keyboard: - Don't set the XKB group switching option when not needed Mouse: - Fix critical warnings with touchpad settings Wacom: - Make OSD work again with newer librsvg Power: - Stop X from turning our screen off XRandR: - Prevent guint32 overflow ============= Version 3.8.5 ============= Housekeeping: - Fixed a bug that would prevent files in the Trash from being purged Mouse: - Enable edge scrolling if two-finger scroll is unavailable Power: - Fix a crash when hibernating on low power Printers: - Translate printer warnings - Code cleanup - Do more things asynchronously - Poll remote CUPS servers for notifications Screensaver: - Support KDE variant of interface - Fix a crash Updates: - Fix a crash ============= Version 3.8.4 ============= - Fix possible crasher on startup - Fix battery warning notifications not going away after plugging the laptop - Make gnome-shell's monitoring of user-added applications faster by creating the directory for them - Fix possible crash in XRandR with overlapping screens ============= Version 3.8.3 ============= Media-keys: - Fix potential crash if gnome-shell crashes while coming up - Show shell search for search button Keyboard: - Remove the input source switcher helper - Introduce a SetInputSource DBus method Updates: - Fix potential crash ============= Version 3.8.2 ============= Media-keys: - Don't show a label for "analog-output" ports Color: - Remove warning for some laptop docks - Don't try to parse temporary files we generate Power: - Fix brightness not being restored on resume on some systems - Make "Turn off screen when inactive" switch work ============= Version 3.8.1 ============= Power: - Don't change the active state when running in a VM - Fix compilation on non-Linux platforms Cursor: - Fix possible crashes on older versions of X.org Media-keys: - Fix race condition with gnome-shell on startup - Fix broken startup notifications - Fix possible crash when changing the volume - Fix crash when the shell vanishes and reappears Keyboard: - Cancel outstanding D-Bus operations when stopping - Enforce the XKB group when changing layouts - Make sure to add the XKB US layout in GDM on empty configurations Mouse: - Enable two-finger scrolling by default Printers: - Fix deprecation compile-time warnings ============= Version 3.8.0 ============= Color: - Set the default profile locale to be en_US, not EN_us Power: - Fix state problems if gnome-shell crashes or is killed within the screensaver Cursor: - Fix crash with X.org prior to 1.14, requires a matching gnome-desktop release as well - Updated translations ============== Version 3.7.92 ============== Media keys: - Remove obsolete check for XInput2 - Use the shell's D-Bus interface to show OSDs - Fix warnings on startup trying to call gnome-shell Keyboard: - Fix extra layouts being forgotten on GDM's second launch - Fix dead keys and similar features being broken in legacy applications - Avoid delay switch to IBus input source the first time around Font: - Remove reference to font schema Updates: - Fix possible crashers on exit - Updated translations ============== Version 3.7.91 ============== Media keys: - Key grabbing is now done in gnome-shell, which fixes problems with keybindings not working in certain conditions Sound: - Fix possible crashes when starting in a clean home directory Cursor: - Disable code to make it popup the On-Screen Keyboard on touchscreens ============== Version 3.7.90 ============== - Set locale and IBus envvars on startup for our children - Remove background plugin, as background handling is now done in gnome-shell A11y settings: - Import GIO instead of GTK+/GDK - Do enable toolkit accessibility, even if we don't need it, for the benefit of third-party/legacy toolkits and apps Media keys: - Add other bindings to the whitelist Cursor: - Enable the on-screen keyboard when touch is used Keyboard: - Adapt to gnome-xkb-info API change Power: - Make blanking timeouts match - Show notifications when about to suspend from idle - Wake up the display when about to logout - Adapt to new GnomeIdleMonitor API - Don't change the brightness on inactive sessions Remote Display: - Disable animations on Xvnc as well - Re-enable animations if Vino is gone Sound: - Avoid polling non-existent directories Updates: - Fix crasher when firmware updates is disabled XSettings: - propagate the remember-recent-files GSetting to XSettings Wacom: - Bump req for GDK_FULLSCREEN_ON_ALL_MONITORS =============== Version 3.7.5.1 =============== Fix keyboard shortcut handling with XI 2.3 ============= Version 3.7.5 ============= A11Y Keyboard: - Disable everything on exit if no settings changed - Remove GTK+ fallback dialogues Color: - Set the correct metadata on the auto-created EDID profile - Switching to a new account shouldn't warn Daemon: - Also apply LC_PAPER Media Keys: - Use D-Bus API to lock the screen - Use F20 for the temporary mic mute key Power: - Add way to disable the backlight helper - Avoid dead-locking with gnome-shell on startup - Avoid possible crash when shutting down quickly or at startup - Drop explicit screen locking on suspend - Fix incorrect backlight level on restore - Handle dim idle the same way as other idles - Lots of test additions - Wake up the display when unplugging the AC too Remote DIsplay: - Detect SPICE sessions as well - Monitor Vino's Connected status Screenshot: - Save to GtkRecentManager on success - Lots of test additions. Updates: - Allow the shell time to initialize before checking for offline update failures Wacom: - Use regular fullscreen window for OSD And updated translations ============= Version 3.7.4 ============= Updates: - Support notification filtering Media-keys: - Save screenshots without using gnome-screenshot - Updated design for the on-screen OSD - Show output device when changing the volume - Add OSD support for the "Battery" key on certain laptops - Add support for the microphone mute key on certain keyboards - Move sound initialisation out of the critical startup path Color: - Addition to implement new mockups in gnome-control-center Housekeeping: - Fix purging not working Keyboard: - Don't migrate ibus xkb engines Power: - Add test suite - Fix Power settings panel not picking up the updated brightness - Fix dimming of the screen not working, and don't dim when inhibited - Fix timeouts being longer than configured in some cases - Aggressively blank the screen when the shield is down - Update idle configuration when plugging or unplugging the mains - Really turn off the screen on suspend for MacBook laptops - Allow overriding VM detection with the gnome.is_vm=[01] kernel command-line parameter Wacom: - Fix problems resetting touch buttons on 64-bit systems - Allow switching modes while OSD is active XRandR: - use default-monitors-setup for autoconfiguration even after boot ============= Version 3.7.3 ============= - Add implementation for Freedesktop.org ScreenSaver inhibition API - Disable animations on slow links (VNC for example) - Remove fallback mode handling code - Disable the smartcard plugin for now Daemon: - Many plugins ordering bug fixes - Use gnome-session properties instead of libsystemd-login - Allow whitelisting plugins, to make it easier for gdm to catch up - Install all the schemas, even the ones for which the plugins aren't installed - Add a way to replace the daemon - exit gracefully if the session name is already taken Power: - Remove unused settings keys - Do not attempt to suspend, dim or blank if running inside a VM - Port to GnomeIdleMonitor from gnome-desktop - Adjust sleep timer to blank timer in some cases - Check if action is available before taking action - Hide critical battery warning when power is plugged - Fix possible race with gnome-shell on startup Sound: - Fix sound plugin never working properly Media-keys: - Use the shared libgnome-volume-control code - Support launching gnome-calculator instead of gcalctool - Add default shortcuts for the magnifier - Add repeat to the brightness keys Keyboard: - Fix build without IBus - Fix potential infinite loop due to num-lock handling - Don't print warnings when calls are cancelled - Handle keyboard shortcuts with Caps Lock for switching inputs Mouse: - Fix natural horizontal scroll XRandR: - Add new follow-lid behavior and tie gsd-power lid-close to XRandR - Avoid crasher if XRandR calls fail on startup - Fix the "rotate" button not working - Swap axes for some (non-Wacom) tablets as well Wacom: - Avoid infinite recursion with a non-Wacom display - Fix handling of Cintiq 24HD mode-switch buttons - Mode switch LED fixes for some tablets - Add OSD help window (see gnome-control-center for how to launch it) Cursor: - Only show the cursor when the mouse gets used Housekeeping: - Implement automatic purging of trash, along with a D-Bus interface for it Print-notifications: - Don't show strange notifications when printing Updates: - Fix warning on startup with PackageKit < 0.8.1 ============= Version 3.7.1 ============= Daemon: - Provide a singleton SessionManager proxy object - Ensure session registration happens before other idles - Use logind for suspending and rebooting the system - Require logind for session tracking Input: - Clarify hotplug command exit value handling - Add trackball detection Keyboard: - Add default ibus engine for Indic locales - Don't apply global settings for every keyboard Mouse: - Re-enable touchpad when mouse isn't present Power: - Fix "no devices" error path in gsd-backlight-helper - Add a watchdog to keep X's builtin screen saver disabled - Fix a number of possible crashers Wacom: - Add support for touchstrips and touchrings without a modeswitch XSettings: - Optimise xsettings changes ============= Version 3.6.1 ============= Keyboard: - Allow grabbing the Menu key - Apply XKB variants and options for each IBus engine - Don't setup legacy toolkits if IBus is missing - Add default setup for some particular languages - Convert old libgnomekbd and IBus configurations - Add support for more modifiers only combinations - Fix input switching eating the modifiers keys in some cases Mouse: - Fix "Locate Pointer" eating the Ctrl key - Fix "Locate Pointer" animation showing when the Ctrl key has been used Updates: - Never show the user a message about cancelled transactions Wacom: - Fix LEDs switching for some tablet models Housekeeping: - Fix possible crashers on exit Color: - Fix possible crashers on exit ============= Version 3.6.0 ============= Keyboard: - Create sources from the X layouts if the configuration is empty - Always do that in GDM, so system-wide layouts work - Add modifiers-only shortcuts to switch input sources ============== Version 3.5.92 ============== Keyboard: - Don't block getting the IBus global engine - Don't touch the XKB layout if no input sources were configured - Fix gtk+ IM module getting set to IBus for XKB sources Media keys: - Make "toggle brightness" work Color: - Don't warn about non-existent DMI file Power: - Fix some instances where an external screen would turn off Wacom: - Require wacom 0.6 to fix bugs with some tablets ============== Version 3.5.91 ============== Mouse: - Fix natural-scroll not working until switched off and on again Keyboard: - Don't handle IBus for fallback, it will use the same UI it always did - Hook IBus support for legacy applications Power: - Do not attempt to change the brightness of an output that was disabled - Fix idle blank and sleep timeout ============== Version 3.5.90 ============== Power: - Fix D-Bus path of the screensaver Mouse: - Add support for natural scroll for touchpads Keyboard: - Apply XKB options Wacom: - Implement the "switch monitor" combination And updated translations ============= Version 3.5.6 ============= Build: - Add optional man page - List plugin schemas as children of the main schema Updates: - Remove unused code - Avoid compilation warnings due to PackageKit API changes Mouse: - If one device was ignored, we would ignore all the devices Smartcard: - Don't try to use smartcard drivers that didn't load Keyboard: - Require ibus 1.4.99 for ibus support Wacom: - Avoid a warning at login ============= Version 3.5.5 ============= * Add test applications for a number of plugins Color: - Fix notification-related memory leaks Keyboard: - Add support for switching to IBus input methods Wacom: - Fix crasher related to screen tablets - Do not rotate "pad" devices - Apply display rotation to device that's mapped to it - Make shortcuts that require Shift work as expected - Re-apply calibration and aspect-ratio when the screen changes but don't apply it to touch devices Housekeeping: - Fix notification-related memory leaks Updates: - Remove unused settings - Remove a number of unused notifications - Don't ever live-update packages in the session - Fix a number of memory leaks - Prevent crash if a device that requires a firmware is removed before the firmware search completes ============= Version 3.5.4 ============= Wacom: - Fix crasher related to screen matching (Olivier Fourdan) Printers: - Don't block the session with unreachable printers ============= Version 3.5.3 ============= Keyboard A11y: - Don't crash when changing large print in fallback mode - Link to an existing help page Housekeeping: - Support new XDG thumbnail directory locations Keyboard: - Don't crash if LANG is empty Media-keys: - Make keyboard shortcuts work again - Use systemd to shutdown or suspend if available Mouse: - Only inhibits mouse clicks and scrolls with syndaemon Power: - End the lid-close safety timer when the lid gets opened - Update fallback status icon on icon state change - Don't leak notifications - Avoid duplicate translations - Use systemd to shutdown or suspend if available - Don't enable backlight helper if GUdev is not available Updates: - Adapt to new upstream property name - Add a notification for offline updates Wacom: - Update display mapping on monitor changes - Flag unknown devices created from fallback - Add keep aspect ratio option - Use GnomeRROutput instead of GnomeRROutputInfo - Match built-in monitor XRandr: - Explicitly set clone state variable when generating monitor configs ============= Version 3.5.2 ============= - Remove ability to D-Bus activate (Ray Strode) Media-keys: - Get proper gnome-keyring environment (Bastien Nocera) - Simplify the OSD code (Bastien) - Add keybindings to switch input sources (Rui Matos) Mouse: - Fix applying settings to newly added touchpads (Owen Taylor) - Reduce default touchpad deactivation to 1s (Nicolas Dufresne) Housekeeping: - Split out 'ingnore unix mount' code (Bastien) Keyboard: - Always apply xmodmap (Sergey V. Udaltsov) - Lots of cleanups (Bastien) - Apply XKB layouts ourselfs and stop relying on libgnomekbd (Rui Matos) Power: - Disconnect from upower signals when needed (Richard Hughes) - Add org.gnome.settings-daemon.plugins.power.lid-close-suspend-with-extrnal-monitors key to allow forcing suspend on lid close (Paolo Bonzini) Print: - Fix setting of default media size (Marek Kasik) - Don't create an unused proxy object (Matthias Clasen) - Speed up initialization (Matthias) Updates: - Automatically download updates rather than installing them (Richard) Wacom: - Disable wacom support on s390 (Dan Horák) - Disable wacom support on non-linux (Antoine Jacoutot) - Don't put touchscreens in relative mode (Timo Aaltonen) - Make tablet configuration per-machine (Bastien) Color: - Be quiet about unloadable profiles (Richard) Translations: - Catalan - Crimean Tatar - Dutch - Galician - German - Hebrew - Italian - Kannada - Norwegian bokmål - Slovenian - Swedish ============= Version 3.4.0 ============= Wacom: - Check if the "last-stylus" property has been set (Olivier Fourdan) Translations: - Simplified Chinese (zh_CN) (YunQiang Su) - Hindi (Chandan Kumar) - Belarusian (Ihar Hrachyshka) - Brazilian Portuguese (Jonh Wendell) - French (Bruno Brouard) - Hebrew (Yaron Shahrabani) - Lithuanian (Žygimantas Beručka) - Portuguese (Duarte Loreto) - Telugu (Sasi Bhushan) - Traditional Chinese (Chao-Hsiung Liao) - Vietnamese (Nguyễn Thái Ngọc Duy) - Ukranian (Daniel Korostil) ============== Version 3.3.92 ============== Color: - Apply the color profile even if the device has an invalid EDID (Richard Hughes) - Create a color device even if the device has an invalid EDID (Richard Hughes) - Don't use the username in the profile ID, it's optional and not-required (Richard Hughes) Common: - Add hint on how to set the script path (Bastien Nocera) - Fix library linkage on Mageia (Jani Välimaa) - Support explicitly setting G_MESSAGES_DEBUG (Martin Pitt) Media Keys: - Avoid hard-coded shortcuts not working (Bastien Nocera) - Call Shutdown for the logout action (Bastien Nocera) Mouse: - Stop syndaemon when settings-daemon dies (Martin Pitt) Power: - Do not emit DBus interface change signals when doing the idle dim (Richard Hughes) - Don't print a message when no backlights are detected (Richard Hughes) - Failing to clear DPMS timeouts should not be fatal (Alexandre Rostovtsev) - Fix broken abs_to_percentage() logic (Cosimo Cecchi) - Lazily connect to gnome-screensaver (Martin Pitt) - Lock the screensaver if the lid is closed and lock is enabled (Richard Hughes) - Make the idle dim time 90 seconds to match OSX (Richard Hughes) Print Notifications: - Add test tool (Lars Uebernickel) - Don't unref floating GVariant (Marek Kasik) Wacom: - Add README about configuration storage (Bastien Nocera) XRandR: - Fix the rotate display button not working (Sjoerd Simons) - List external display only before internal only (Bastien Nocera) XSettings: - Add README.xsettings about overrides (Ryan Lortie) - Add test-xsettings program (Ryan Lortie) - Add xsettings_setting_get() accessor (Ryan Lortie) - Add XSETTINGS_VARIANT_TYPE_COLOR macro (Ryan Lortie) - Always call xsettings_setting_set() (Ryan Lortie) - Don't return XSettingsResult codes (Ryan Lortie) - Introduce 'tiers' of XSettings (Ryan Lortie) - Load overrides on startup (Ryan Lortie) - Remove global 'settings' list (Ryan Lortie) - Switch manager to GLib memory functions (Ryan Lortie) - Switch to GVariant for value storage (Ryan Lortie) - Use GHashTable in the xsettings manager (Ryan Lortie) - Wire overrides into GSettings (Ryan Lortie) Translations: - Belarusian (Ihar Hrachyshka, Kasia Bondarava) - British English (Bruce Cowan) - Bulgarian (Alexander Shopov) - Catalan (Joan Duran) - Catalan (Valencian) (Carles Ferrando) - Czech (Adam Matoušek, Marek Černocký) - Finnish (Timo Jyrinki) - Galician (Fran Diéguez) - Gujarati (Sweta Kothari) - Hungarian (Gabor Kelemen) - Korean (Changwoo Ryu) - Latvian (Anita Reitere) - Norwegian bokmål (Kjartan Maraas) - Russian (Yuri Myasoedov) - Serbian (Мирослав Николић) - Slovenian (Matej Urbančič) - Traditional Chinese (Cheng-Chia Tseng) - Vietnamese (Nguyễn Thái Ngọc Duy) - Punjabi (A S Alam) - Ukranian (Daniel Korostil) ============== Version 3.3.91 ============== Color: - Fix warning with non-present devices - Make displays without EDID data use the correct device ID - Create the correct device ID for EDIDs with no text data - Fix EDID checksum generation Power: - Emit a Changed() signal when the backlight changes - Don't overflow when pressing the keyboard brightness button Media-keys: - Make Alt+Print appear as Alt+Print not Alt+SysRq Wacom: - Add support for mode switch buttons, touchrings, touchstrips, and light up the LEDs appropriately - Add support for current tool ID from Wacom driver - Fix possible crasher setting pressure curve or display area - Force touchpads to use relative mode and ignore mode changes - Fix double-event generation - Fix installation problems with libexecdir == libdir - Make monitor == -1 reset the display configuration ================ Version 3.3.90.1 ================ Build: - Fix build with --enable-systemd ============== Version 3.3.90 ============== Build: - Remove last requirement for dbus-glib - Remove use of deprecated g_thread_init() - Fix linking with -Bsymbolic Wacom: - Add tablet button listing and settings - Add display mapping Keyboard: - Fix blinking num-lock in some circumstances Color: - Set _ICC_PROFILE correctly when there is no primary device specified Power: - Fix possible crasher in backlight helper on error ============= Version 3.3.5 ============= Build: - Remove unused date & time mechanism. gnome-control-center uses a different API, provided by systemd on some systems. A11y keyboard: - Reduce the number of settings updates on startup Power: - Require a newer upower - Optionally use systemd to shutdown when power is low - Use GDBusProxy-compatible PropertiesChanged signal - Fix "
" appearing in notification popups Wacom: - Add a way to get/set the screen associated with a tablet - Don't crash when using a generic tablet - Add support for the puck and touch device types - Add support for enumerating tablet buttons Printers: - Also notify for unknown error reasons - Unify printer name usage Color: - Set the brightness of the display if it was saved as metadata in the color profile Media keys, XSettings, Updates: - Fix possible crashes on exit Housekeeping, Wacom, XSettings: - Fix memory leaks Media keys: - Add screenshot keyboard shortcuts Keyboard: - Don't save num-lock state when caps-lock changes Automounter: - Optionally use systemd to check for active seat ============= Version 3.3.4 ============= Build: - Fix distribution of a pre-processed desktop file Daemon: - Fix --debug not working - Remove gnome_settings_session_get_screen() and gnome_settings_session_get_upower_client(), as the underlying functions return singletons Color: - Fix some screen setups not being color corrected XRandR: - Better handling of docking stations and plugging of external monitors (for suspend, and turning off monitors to work as designed) Wacom: - Fix loading of the plugin - Fix GSettings read/write for per-tablet/per-styli configs - Export more tablet and stylus metadata =============== Version 3.3.3.1 =============== Wacom: - Fix referenced module name (Frederic Peters) ============= Version 3.3.3 ============= Build: - Require GTK+ 3.3.4 (for key accel parsing) - Require XI2 (for wacom support) Common: - Remove unused X key event code (Bastien) Wacom: - Lots of infrastructure buildup that I can't really summarize here (Bastien Nocera) - Rename plugin to avoid name clash with libwacom (Bastien) - Use libwacom to get tablet metadata (Bastien) - Implement per-device and per-stylus settings (Bastien) Power: - Add the vendor name to the battery recall warning (Dominique Leuenberger) (#664418) - Add automatic dimming of keyboard backlight (Alex Murray) Print: - Prevent crashes when cups sends malformed D-Bus signals (Lars Uebernickel) (#665689) XSettings: - Set GtkShellShowsAppMenu xsetting when the shell is running (Colin Walters) Translations: Hebrew Norwegian bokmål Romanian Spanish ============= Version 3.3.2 ============= Common: - Remove left-over debug (Bastien Nocera) (#660073) - Fix handling of (Bastien Nocera) - Update required gnome-desktop version (Bastien Nocera) - Return opcode when detecting XInput2 (Bastien Nocera) - Add helper to get the input device node (Bastien Nocera) - Use XInput2 to capture and match keys (Bastien Nocera) - Use GTK+ functions instead of own impl (Bastien Nocera) (#663343) - Fix small memleak (Bastien Nocera) - Allow to grab 'Print' without modifiers (Florian Müllner) (#663623) - Require gsettings-desktop-schemas 3.3.0 (Bastien Nocera) A11y keyboard: - Port to GSettings (Bastien Nocera) (#631502) Automount: - Call bind_textdomain_codeset() (Bastien Nocera) Color: - Do not load all the color devices twice at startup (Richard Hughes) - Don't assign the same device more than once at startup (Richard Hughes) - Fix a crash if ~/.local is deleted at runtime (Richard Hughes) (#660664) - Simplify gcm_profile_store_mkdir_with_parents() (Bastien Nocera) - Cancel any in-progress directory searching on plugin unload (Richard Hughes) - Do not check for directory presence sync (Richard Hughes) - Fix critical warning if the user disables the internal LCD screen (Richard Hughes) - Reset the gamma tables when the screen configuration changes (Richard Hughes) (#660164) - Unbreak loading profiles at startup (Cosimo Cecchi) (#660790) - Do not prefix the EDID profile title with 'Default' (Richard Hughes) - Set model and vendor to 'unknown' if not specified or unavailable (Richard Hughes) Daemon: - Create a reference to a GnomePnpIds object to speed up loading (Richard Hughes) Datetime: - Fix build requirements (Bastien Nocera) Media keys: - Use a GCancellable for g_bus_get calls so that they can be cancelled (Rodrigo Moya) - Don't assert if the user sets the 'button-power' action to 'shutdown' (Richard Hughes) - Don't assert if the user sets the 'button-power' action to 'nothing' (Richard Hughes) - Only ever send signals to specific apps (Bastien Nocera) - Document the MediaPlayerKeyPressed signal (Bastien Nocera) - Add some D-Bus API documentation (Bastien Nocera) - Fix OSD touchpad icon names (Bastien Nocera) (#661179) - Fix suspend button not locking the screen (Bastien Nocera) (#660267) - Fix the suspend key not working (Bastien Nocera) (#660267) - Remove unused allowed-keys entry (Bastien Nocera) - Cache the volume change event sound (Bastien Nocera) - Update for GVC API (Bastien Nocera) - Print warning for real errors (Bastien Nocera) - Apply volume on the device the key came from (Bastien Nocera) (#340720) - Add custom shortcut type (Bastien Nocera) - Implement GConf keyboard shortcuts (Bastien Nocera) (#625228) - Redraw volume OSD when not composited (Marien Zwart) (#660990) - Update for gsd-keygrab API change (Bastien Nocera) (#663343) - Move some metacity shortcuts into g-s-d (Florian Müllner) (#663623) - Port custom keybindings to GSettings (Florian Müllner) (#631502) Power: - Use a GCancellable for g_bus_get calls so that they can be cancelled (Rodrigo Moya) - Do not revert to the pre-idle brightness if idle dimming is disabled (Richard Hughes) (#660434) - Remove some unused schema for enabling the sleep-inactive actions (Richard Hughes) (#660395) - Clarify what a value of 0 is for sleep-inactive-x-timeout (Richard Hughes) - Do not sleep-on-idle by default (Richard Hughes) - Simplify hiding/showing the status icon (Bastien Nocera) - Ensure the DPMS state is 'on' at startup (Richard Hughes) (#660482) - Close low-battery notification when plugged in (Florian Müllner) (#660942) - Remove the window filter when the plugin is unloaded (Richard Hughes) - Don't crash when setting the dim timeout when using NX (Richard Hughes) (#661000) - Call XSyncInitialize() in case GTK+ wasn't compiled with XSync support (Richard Hughes) - Emit 'Changed' signal to all listeners (Gary Ching-Pang Lin) - Fix "undefined symbol: WEXITSTATUS" error (Richard Hughes) (#662020) - Make non-urgent notifications transient (Florian Müllner) (#662711) Printers: - Fix build on systems without LC_PAPER (Bastien Nocera) (#660626) - Call setlocale() (Bastien Nocera) (#660632) - Exit gsd-printer when session ends (Marek Kasik) (#660158) - Correct signature when calling PrinterAddOptionDefault (Marek Kasik) - Don't show "Not connected?" when not needed (Marek Kasik) - Unown name on the system bus when session goes idle (Marek Kasik) (#660158) - Set requesting-user-name when getting job info (Marek Kasik) - Show printer-state-reasons only when printing my jobs (Marek Kasik) - Don't allow "/" in printer name (Marek Kasik) (#661774) - Make notifications resident (Marek Kasik) - Fix a leak (Marek Kasik) Smartcard: - Remove unnecessary translations (Bastien Nocera) Xrandr: - Use a GCancellable for g_bus_get calls so that they can be cancelled (Rodrigo Moya) Xsettings: - Remove workaround to deal with g-s-d not exiting correctly (Rodrigo Moya) - Plug mem leaks (Christian Persch) (#663239) Wacom: - Fix possible crasher (Bastien Nocera) (#661170) - Set cursor devices to be in relative mode by default (Jason Gerecke) (#662977) - Add classes to manage settings and properties (Bastien Nocera) Translations: - ast (Xandru Armesto) - de (Mario Blättermann) - eo (Kristjan SCHMIDT) - es (Daniel Mustieles, Jorge González) - gl (Fran Dieguez) - lt (Algimantas Margevičius) - nb (Kjartan Maraas) - nl (Redmar, Wouter Bolsterlee) - or (Manoj Kumar Giri) - sl (Matej Urbančič) - sv (Daniel Nylander) - te (krishnababu k) - uk (Daniel Korostil) - vi (Nguyễn Thái Ngọc Duy) ============= Version 3.2.0 ============= Power: - Correctly put the screen and computer to sleep when idle (Richard Hughes) (#659066) Translations: - ca (Joan Duran, Gil Forcada) - ca@valencia (Carles Ferrando) - da (Flemming Christensen) - eu (Inaki Larranaga Murgoitio) - hu (Gabor Kelemen) - ja (OKANO Takayoshi) - ko (Changwoo Ryu) - or (Manoj Kumar Giri) - ru (Alexandre Prokoudine, Yuri Myasoedov) ============== Version 3.1.92 ============== A11Y keyboard: - Show the a11y dialogue on right-click (Bastien Nocera) (#564171) Color: - Be less chatty when creating duplicate profiles (Richard Hughes) - Do not segfault when doing fast-user-switching into a new account (Richard Hughes) (#736846) - Use a username suffix on the profile ID (Richard Hughes) (#736846) - Do not show a warning when switching to a new user account (Richard Hughes) - Use the correct profiles when fast user switching (Richard Hughes) - Fix linking (Matthias Clasen) (#659086) Common: - Add helper to list disabled devices (Bastien Nocera) - Clean up X11 library dependencies (Bastien Nocera) (#657178) - Bump colord dependency (Rodrigo Moya) Datetime: - Allow chrony to be used on Fedora (Tomas Bzatek) (#655119) - Add NTP support for SUSE variants (Vincent Untz) (#654970) GConf: - Plug some memory leaks (Rodrigo Moya) - Disconnect callbacks when cleaning up (Rodrigo Moya) Keyboard: - Remember and apply NumLock status (Bastien Nocera) (#631989) Media keys: - Don't show a level when muted (Bastien Nocera) (#644537) - Fix keyboard brightness (Alex Murray) (#658689) - Use the same "Music" mime-type as g-c-c (Bastien Nocera) - There's no Beagle anymore (Bastien Nocera) - Use gtk_show_uri() to launch nautilus (Bastien Nocera) - Clean up app launching (Bastien Nocera) (#141379) - Clean up upower req (Bastien Nocera) - Remove unused empty LIBS linkage (Bastien Nocera) - Fix compile-time warning (Bastien Nocera) - Move keyboard brightness icon here (Bastien Nocera) - Remove OSD icons (Bastien Nocera) Mouse: - Add more debug for "touchpad disabled" (Bastien Nocera) - Try harder to re-enable devices (Bastien Nocera) (#656397) Power: - Make ABS_TO_PERCENTAGE warn on invalid input (Bastien Nocera) (#657364) - Correctly check for helper exit status (Bastien Nocera) - Avoid warnings without backlights (Bastien Nocera) - Do not connect to signals if we failed to connect (Richard Hughes) - Don't crash if we try to calculate the idle state before connected to gnome-session (Richard Hughes) (#657917) - Be less chatty when optional hardware is not attached (Richard Hughes) (#658613) - Fix a critical warning when getting the session inhibit state (Richard Hughes) - Do not handle the idle state transaction when the session is not active (Richard Hughes) (#658568) - Don't fall through the switch statement when shutting down (Richard Hughes) (#659202) - Do not leak the icon when getting device status (Richard Hughes) (#659213) - Protect against a potential SIGFE (Richard Hughes) (#659205) - Do not emit multiple 'Changed' signals when recalculating (Richard Hughes) (#659204) - Do not use G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES when we want to read properties (Richard Hughes) (#659066) - Fix compilation without libcanberra-gtk (Bastien Nocera) Printers: - Use the best PPD for new printer (Marek Kasik) (#658544) - Style fixes (Bastien Nocera) Updates: - Ignore virtual mountpoints when looking for external media (Richard Hughes) (#658282) - Use the correct icons in the notifications (Richard Hughes) Translations: - de (Mario Blättermann) - en_GB (Bruce Cowan) - es (Jorge González, Daniel Mustieles) - fi (Timo Jyrinki) - fr (Bruno Brouard) - he (Yaron Shahrabani) - it (Luca Ferretti) - ja (Jiro Matsuzawa) - lt (Aurimas Černius) - lv (Rudolfs Mazurs) - pl (Piotr Drąg) - pt (Duarte Loreto) - sl (Matej Urbančič) - sr (Мирослав Николић) ============== Version 3.1.91 ============== Common: - Don't list XINPUT_LIBS twice, move X11_LIBS from LDFLAGS to LIBADD (Stefan Sauer) Color: - Ensure the 'Recalibration required' notification has a custom app name (Richard Hughes) - Fix a critical warning on startup (Richard Hughes) - Do not notify to recalibrate on every startup (Richard Hughes) Daemon: - Fix possible double-free outside gnome-session (Bastien Nocera) Gconf: - Double check stuff we add to the hash table (Rodrigo Moya) (#658055) Housekeeping: - NULL-terminate the ignore-paths array (Bastien Nocera) (#657849) Power: - Do not exit gnome-settings-daemon if upower fails to load (Richard Hughes) - Fix impossible to hit error paths (Bastien Nocera) (#657364) - Fix BRIGHTESS_STEP_AMOUNT calculation macro (Kamal Mostafa) - Do most of the work in _start () (Bastien Nocera) (#657924) - Never idle-dim the display to a higher brightness level (Richard Hughes) (#658144) Printers: - Remove redundant code (Marek Kasik) Xsettings: - Handle rgba-order key (Bastien Nocera) (#657525) - Don't poke at an empty hashtable (Bastien Nocera) (#657464) - Fix a stray brace (Owen Taylor) Translations: - be (Ihar Hrachyshka) - cz (Marek Černocký) - pt_BR (Og B. Maciel) - ta (Dr.T.Vasudevan) ============== Version 3.1.90 ============== A11Y-keyboard: - Use GIO's DBus API instead of dbus-glib's (Rodrigo Moya) Color: - Don't use uninitialized GErrors (Matthias Clasen) - Do not set an age for display and printer profiles (Richard Hughes) - Remove the ability to disable notifications (Richard Hughes) - Do not search user-icc directories if they do not exist (Richard Hughes) (#657484) Daemon: - Add Unity to OnlyShowIn value for autostart desktop file (Michael Terry) (#654919) Media keys: - Don't go up to 11 (Bastien Nocera) (#649411) Mouse: - Be more careful to avoid segfaults (Matthias Clasen) (#657462) Power: - Ensure the critical battery beep is stopped when the AC is inserted (Richard Hughes) - Ensure we lock the screen before suspending on lid close (Richard Hughes) (#655924) - Add mention of bug 652183 (Bastien Nocera) Smartcard: - Use GIO's DBus API instead of dbus-glib's (Rodrigo Moya) Updates: - Do not log a warning if the firmware-missing file does not exist (Richard Hughes) - Do not log a warning at startup if getting the upgrade list is not supported (Richard Hughes) (#657483) Translations: - bg (Alexander Shopov) - id (Andika Triwidada) - pa (A S Alam) - ta (Dr.T.Vasudevan) - zh_CN (Aron Xu) ============= Version 3.1.5 ============= A11y-keyboard: - Enable plugin by default (Rodrigo Moya) (#656287) Automount: - Link against the private profiler library (Cosimo Cecchi) - Add some missing includes (Cosimo Cecchi) - Don't ship the .in file, just the .in.in one (Bastien Nocera) - Silence two trivial -Wformat-security warnings (Richard Hughes) Color: - Do not show multiple warnings if colord is not available at runtime (Richard Hughes) - Fix a potential crash when unloading the color plugin (Richard Hughes) - Fix a potential crash if creating the per-user ICC directory fails (Richard Hughes) - Make lcms2 a hard dependency (Richard Hughes) Housekeeping: - Use new g_format_size() instead of g_format_size_for_display() (Javier Jardón) Media keys: - Don't preserve the path after filling (Cosimo Cecchi) - Remove the half pixel offset from the progressbar fill (Cosimo Cecchi) - Always round the render coordinates for media icons (Cosimo Cecchi) Power: - Add the idle actions (Richard Hughes) - Show a status icon when in fallback mode (Richard Hughes) - Respect the idle-dim-ac and idle-dim-battery configuration keys (Richard Hughes) - Add a backlight helper, as xbacklight isn't always present (Richard Hughes) - Fall back to the backlight helper if xbacklight is not available (Richard Hughes) - Fix a potential crash when unloading the power plugin (Richard Hughes) - Ensure we return the new percentage when changing the brightness (Richard Hughes) Updates: - Do not use deprecated PackageKit #defines (Richard Hughes) Wacom: - Invert TPCButton setting (Peter Hutterer) (#656372) Translations: - es (Daniel Mustieles) - fa (Arash Mousavi) - gl (Fran Dieguez) - he (Yaron Shahrabani) - ru (Yuri Kozlov) - sl (Andrej Žnidaršič) - sv (Daniel Nylander) - zh_HK (Chao-Hsiung Liao) - zh_TW (Chao-Hsiung Liao) ============= Version 3.1.4 ============= A11y-keyboard: - Do proper cleanup when the plugin is stopped (Rodrigo Moya) Automount: - Turn the automount plugin in a separate binary (Cosimo Cecchi) (#653521) - Fix distcheck of .desktop.in.in file (Rodrigo Moya) Common: - Fix grabbing of multimedia keys (Chris Coulson) Daemon: - Set locale environment on gnome-session as early as possible (Rodrigo Moya) (#654182) - Plug memory leak (Rodrigo Moya) Datetime: - Use friendlier wording for date & time policykit prompt (Michael Terry) (#645951) Media keys: - Add button handling code from gnome-power-manager (Richard Hughes) Power: - Add power plugin to replace g-p-m (Richard Hughes) Translations: - be (Ihar Hrachyshka) - cz (Marek Černocký) - de (Mario Blättermann) - es (Daniel Mustieles, Jorge González, Sebi Kul, Francisco Molinero) - gl (Fran Dieguez) - he (Yaron Shahrabani) - lt (Aurimas Černius) - lv (Rudolfs Mazurs) - nb (Kjartan Maraas) - pa (A S Alam) - tr (Muhammet Kara) ============= Version 3.1.3 ============= Common: - Use defines instead of variables for ranges (Bastien Nocera) - Fix function keys not being grabbed (Bastien Nocera) (#649222) - Allow the "Pause" key to be used (Bastien Nocera) (#653524) Clipboard: - Fix incremental sending from the clipboard manager (Cosimo Cecchi) (#652609) Color: - Fix a potential buffer-overflow when converting to wide text (Richard Hughes) Keyboard: - Use the same kbd layout menu labels as Gnome Shell (Jeremy Bicha) (#652836) - Add missing "Settings" to the string (Bastien Nocera) - Fix menu items actions (Bastien Nocera) Media keys: - Use constant for icon size in OSD (Bastien Nocera) - Remove progress bar borders (Bastien Nocera) (#652321) Mouse: - Check device is a touchpad before enabling/disabling it (Rodrigo Moya) Translations: - be (Ihar Hrachyshka) - es (Jorge González) - gl (Fran Diéguez) - he (Yaron Shahrabani) - nb (Kjartan Maraas) - sl (Matej Urbančič) - sr (Мирослав Николић) ============= Version 3.1.2 ============= Common: - Don't try to convert show-keyboard-leds-indicator in gnome-settings-daemon.convert (Chris Coulson) - Add touchscreen detection (Bastien Nocera) - Add X property setting helper (Bastien Nocera) - Add code to detect accelerometers (Bastien Nocera) - Add better error reporting for egg key parsing (Bastien Nocera) - Add code to allow disabling input devices (Bastien Nocera) Color: - Add new color plugin (Richard Hughes) Cursor: - Hide cursor on tablets with only a touchscreen (Bastien Nocera) (#650604) - Show the cursor again on exit (Bastien Nocera) - Fix XFixes version checking (Bastien Nocera) - Ignore PS/2 mice as well (Bastien Nocera) - Fix checking for extension pointer (Bastien Nocera) Datetime: - Fix ntp logic on Debian to include ntpdate as well as ntpd (Michael Terry) (#644821) GConf: - Add missing schema for org.gnome.settings-daemon.plugins.gconf (Rodrigo Moya) (#652200) Keybindings: - Complete update to egg key parsing change (Florian Müllner) Media keys: - Only start D-Bus when _start() is called (Bastien Nocera) - Simplify touchpad OSD (Bastien Nocera) - Hardcode the "toggle touchpad" button (Bastien Nocera) - Remove old-style OSD (Bastien Nocera) - Always use the primary monitor for display (Bastien Nocera) (#650159) - Make sound changes quiet with Alt (Bastien Nocera) (#651704) Mouse: - Use new disable/enable device code (Bastien Nocera) Orientation: - Add orientation plugin (Bastien Nocera) Updates: - Fix a string that is hard to translate (Richard Hughes) (#645749) Wacom: - Enable wacom touch key by default (Peter Hutterer) - Use property settings helper in common/ (Bastien Nocera) - Typedef the Wacom device types (Bastien Nocera) Xrandr: - Switch touchscreen rotation as wel (Bastien Nocera) - Fix small memory leak on shutdown (Bastien Nocera) - Remove the functionality to call gcm-apply when outputs change (Richard Hughes) - Remove rotation handling for wacom tablets (Bastien Nocera) Translations: - bg (Alexander Shopov) - ca@valencia (Carles Ferrando) - cz (Marek Černocký) - de (Mario Blättermann) - es (Jorge González, Daniel Mustieles) - fa (Arash Mousavi) - gl (Fran Diéguez) - he (Yaron Shahrabani) - nb (Kjartan Maraas) - pl (Piotr Drąg) - sl (Matej Urbančič) ============= Version 3.1.1 ============= Common: - Add input-helper test application (Bastien Nocera) - Fix syndaemon never getting started (Edward Sheldrake) (#648885) - Add meaningful app names to notifications from plugins (Matthias Clasen) (#648911) Datetime: - Simplify NTP handling for distros (Bastien Nocera) - Fix setting NTP on Fedora 15 (Bastien Nocera) Media keys: - Show a popup when no media player is running (Bastien Nocera) - Use symbolic icon for Eject action (Bastien Nocera) (#649523) Mouse: - Clean up error handling (Bastien Nocera) - Don't crash if mouse has no FeedbackStates (Bastien Nocera) (#649539) Updates: - Fix the interface name (Richard Hughes) - Deal with absence of gnome-session gracefully (Matthias Clasen) Xrandr: - Never use a notification for errors (Bastien Nocera) (#648303) Translations: - es (Daniel Mustieles) - he (Yaron Shahrabani) - ug (Abduxukur Abdurixit) ============= Version 3.0.3 ============= Common: - Use defines instead of variables for ranges (Bastien Nocera) - Fix function keys not being grabbed (Bastien Nocera) (#649222) - Allow the "Pause" key to be used (Bastien Nocera) (#653524) - Fix grabbing of multimedia keys (Rodrigo Moya) Wacom: - Enable wacom touch key by default (Peter Hutterer) (#651020) Translations: - bg (Alexander Shopov) - ca (Gil Forcada) - ca@valencia (Carles Ferrando) - cz (Marek Černocký) - de (Mario Blättermann) - es (Daniel Mustieles) - gl (Fran Diéguez) - pl (Piotr Drąg) - sl (Matej Urbančič) - sr (Мирослав Николић) - sv (Daniel Nylander) ============= Version 3.0.2 ============= Common: - Fix syndaemon never getting started (Edward Sheldrake) (#648885) - Fix example input device script (Bastien Nocera) - Don't try to convert show-keyboard-leds-indicator in gnome-settings-daemon.convert (Chris Coulson) Date & Time: - Fix setting NTP on Fedora 15 (Bastien Nocera) (#648556) Media keys: - Use symbolic icon for Eject action (Bastien Nocera) (#649523) Mouse: - Don't pass NULL to device_is_touchpad (Matthias Clasen) (#649214) - Clean up error handling (Bastien Nocera) - Don't crash if mouse has no FeedbackStates (Bastien Nocera) (#649539) XRandr: - Never use a notification for errors (Bastien Nocera) (#648303) Translations: - fa (Arash Mousavi) - ug (Abduxukur Abdurixit) ============= Version 3.0.1 ============= Updates: Fix firmware auto-installation Media-keys: Fix possible crash when sound device is removed Updated translations =============== Version 3.0.0.1 =============== Keyboard: Fix crash showing the keyboard layout in fallback mode Updated translations ============= Version 3.0.0 ============= Common: - Change default inactive sleep on battery to suspend (William Jon McCann) Keyboard: - Clarify actual units used for repeat rate (Bastien Nocera) (#646241) Printers: - Cancel CUPS' subscription policy (Marek Kasik) - Make CUPS' subscriptions expirable (Marek Kasik) - Remove old subscriptions (Marek Kasik) XSettings: - Try a few times to start the xsettings manager (Rodrigo Moya) (#634988) Translations: - bn (Jamil Ahmed) - ca (Jordi Serratosa) - cz (Marek Černocký) - da (Ask H. Larsen) - de (Christian Kirbach, Wolfgang Stöggl) - en_GB (Bruce Cowan) - eu (Iñaki Larrañaga Murgoitio) - he (Yaron Shahrabani) - hi (Rajesh Ranjan) - hu (Gabor Kelemen) - id (Dirgita) - ja (Takayuki KUSANO) - ko (Changwoo Ryu) - lv (Rudolfs Mazurs) - ml (Ani Peter) - nl (Wouter Bolsterlee, Hannie Dumoleyn) - pl (Piotr Drąg) - pt_BR (Djavan Fagundes) - ru (Yuri Myasoedov) - sr (Miroslav Nikolić) - sv (Daniel Nylander) - ta (Dr.T.Vasudevan) - ug (Abduxukur Abdurixit) - vi (Nguyễn Thái Ngọc Duy) - zh_CN (Aron Xu) =============== Version 2.91.93 =============== Power: - Don't suspend the computer when idle by default - Add back "interactive" option Date & Time: - Check for the correct PolicyKit action Accessibility settings: - Enable plugin by default, so that screen readers and on-screen keyboards work out-of-the-box And loads of translations =============== Version 2.91.92 =============== Common: - Update priority of a few plugins (Bastien Nocera) - gdk_display_get_device_manager() retval handling (Bastien Nocera) (#685020) - Improve CUPS detection (Saleem Abdulrasool) (#644063) - Make sure G_LOG_DOMAIN is set to the plugin name for each plugin (Richard Hughes) - Make sure we mop up stray idle handlers (Bastien Nocera) - Simplify input helper (Bastien Nocera) - Launch a custom script on input devices (Peter Hutterer) (#635486) Daemon: - Fix possible crasher on exit (Bastien Nocera) (#639347) Media keys: - Update gvc copy/paste from control-center (Bastien Nocera) - Make volume go up to 11 (Bastien Nocera) (#631030) - Simplify volume keys handling (Sjoerd Simons) (#640963) Mouse: - Fix possible memory leak (Bastien Nocera) - Implement touchpad motion settings (Bastien Nocera) (#642474) - Fix shape handling in locate-pointer (Gerd Kohlberger) (#645092) - Handle touchpad handedness changing (Bastien Nocera) - Don't apply any settings if XInput isn't present (Bastien Nocera) - Separate device dependent calls (Bastien Nocera) - Remove duplicated calls on start (Bastien Nocera) - Remove unused supports_xinput_devices() call (Bastien Nocera) - Make sure syndaemon is killed when touchpad disappears (Bastien Nocera) - Hook up input device customisation script (Bastien Nocera) - Fix double-free when handling one-button touchpad (Bastien Nocera) - Fix crash in GHashTable usage (Bastien Nocera) Power: - Set the default display off time to be same as session idle time (William Jon McCann) Updates: - g_get_real_time() returns microseconds, not seconds since the epoch (Richard Hughes) - Ensure te user gets the updates notification if it's never been shown (Richard Hughes) - Ensure the user gets notified of normal updates at the correct interval (Richard Hughes) Translations: - ar (Khaled Hosny) - de (Mario Blättermann) - el (Γιώργος Στεφανάνης) - et (Mattias Põldaru) - fr (Cyril Arnaud, Gérard Baylard, Alain Lojewski and Claude Paroz) - gl (Fran Diéguez) - he (Yaron Shahrabani) - hu (Gabor Kelemen) - lt (Gintautas Miliauskas) - lv (Rudolfs Mazurs) - pl (Piotr Drąg) - ro (Lucian Adrian Grijincu) - sl (Matej Urbančič, Andrej Žnidaršič) - sr (Miroslav Nikolić) - sv (Daniel Nylander) =============== Version 2.91.91 =============== Automount: - Fix crash when unlocking the screen saver - Don't queue volumes when session is inactive Housekeeping: - Use nautilus's D-Bus API to empty the trash Media keys: - Add magnifier in/out keybindings - Fix larger text/smaller text keybindings Mouse: - Make locate pointer feature work with GTK+ 3 Printers: - Use new CUPS D-Bus API Updates: - Use auto-download updates when possible XSettings: - Also accept .gtk-module for GTK+ modules - Don't set Xft.lcdfilter, it's broken - Use "text-scaling-factor" key instead of DPI =============== Version 2.91.90 =============== A11Y Settings: - Add new plugin (Bastien Nocera) Automount: - Look if the session is active before automounting new volumes (Cosimo Cecchi) - Disable automounting while screen is locked (Martin Pitt, Cosimo Cecchi) Background: - Stop pending fades if new ones initiated (Ray Strode) Date & Time: - Add Debian support to NTP service activation (Milan Bouchet-Valat) (#641598) - Fix gsd_datetime_check_tz_name() never working (Bastien Nocera) (#674999) Keyboard: - Update for new libgnomekbd API (Sergey V. Udaltsov) - Match shell behaviour for visibility (Bastien Nocera) - Explicitly calling gtk_widget_show_all for kbd layout (Sergey V. Udaltsov) Media keys: - Fix crash when keybindings change (Bastien Nocera) - Add more Universal Access keybindings (Bastien Nocera) (#641279) Mouse: - Use event driven mode for syndaemon (Pauli Nieminen) (#639623) - Use syndaemon -K to ignore Ctrl+C and other combos (Peter Hutterer) (#639487) Print notification: - Go back to using name in notifications (William Jon McCann) - Check that cups is recent enough (Marek Kasik) Updates: - Add an updates plugin to integrate with PackageKit (Richard Hughes) XSettings: - Fix memleak, using wrong unref function (Bastien Nocera) Translations: - ar (Khaled Hosny) - es (Daniel Mustieles, Jorge González) - gl (Fran Diéguez) - he (Yaron Shahrabani) - it (Luca Ferretti) - ko (Changwoo Ryu) - nb (Kjartan Maraas) - pa (A S Alam) - zh_HK (Chao-Hsiung Liao) - zh_TW (Chao-Hsiung Liao) ============== Version 2.91.9 ============== XSettings: - Initialize gtk-modules setting (Dan Winship) - Support GTK/AutoMnemonics setting (Matthias Clasen) Date & Time: - Use a single polkit action for this (Thomas Wood) Media keys: - Prevent volume underflow (Sjoerd Simons, Bastien Nocera) - Use symbolic icons for OSD (Matthias Clasen, Bastien Nocera) Keybindings: - Rename Accessibility keybindings to 'Universal Access' (William Jon McCann) - Mark Accessibility keybindings as system (William Jon McCann) Keyboard: - Don't create kbd indicators in the shell (Sergey V. Udaltsov) - Remove $GDM_KEYBOARD_LAYOUT handling (Bastien Nocera) - Fix control-center invocation (Yanko Kaneti) Housekeeping: - Fix an untranslatable string (Cosimo Cecchi) Print notification: - New plugin for print notifications (Marek Kasik) - Appearance and wording tweaks (William Jon McCann) - Translations: Arabic Estonian Galician Hebrew Italian Japanese Norwegian bokmål Simplified Chinese Spanish ============== Version 2.91.8 ============== - Connect to the right GnomeRRScreen signal ============== Version 2.91.7 ============== - Adapt to new gnome-desktop API (Giovanni Campagna) - Remove unused macros (Federico Mena Quintero) - Translations: - de (Paul Seyfert) - es (Jorge González) - et (Ivar Smolin, Mattias Põldaru) - gl (Fran Diéguez) - nb (Torstein Adolf Winterseth) - pa (A S Alam ) - sv (Daniel Nylander) - vi (Nguyễn Thái, Nguyen Vu Hung) - zh_HK (Chao-Hsiung Liao) - zh_TW (Chao-Hsiung Liao) ================ Version 2.91.6.2 ================ - Fix a crasher with GTK+ 2.91.7 (Cosimo Cecchi) ================ Version 2.91.6.1 ================ - Suppress warnings due to gdk_error_trap_pop (Cosimo Cecchi) - Fix build with GTK+ 2.91.7 (Cosimo Cecchi) ============== Version 2.91.6 ============== - Port to GtkStyleContext (Bastien Nocera) - Suspend by default on battery power (Colin Walters) - Timezone and NTP improvements (Bastien Nocera) - Port to GtkAppChooserButton (Cosimo Cecchi) - Port background code to GDBus (Dan Williams) - Support multiple smartcard drivers (Ray Strode) - Background plugin misc fixes (Tomas Bzatek, Owen W. Taylor) ================ Version 2.91.5.1 ================ - Handle rename of org.gnome.media-handling (Owen W. Taylor) ============== Version 2.91.5 ============== - Add automount plugin (Tomas Bzatek) - Don't pass NULL strings to g_variant_new() (Bastien Nocera) - Properly handle gnome-session EndSession signals (Cosimo Cecchi) ============== Version 2.91.4 ============== - Add Wacom configuration plugin (Peter Hutterer) - Add support for the XF86TouchpadOn/Off keys (Bastien Nocera) - Move some gnome-power-manager settings, so it can be used in the control center (Richard Hughes) - Only ever call g_bus_own_name() once for the main D-Bus name (BN) - Register with gnome-session to avoid timeouts, and transition problems on login (BN) - Fix possible warnings or crashers when _stop() is called without _start() having been completed (William Jon McCann) ============== Version 2.91.3 ============== - Remove xrdb plugin (Bastien Nocera) - Remove outdated GConf schemas (BN) - Handle a11y toggle shortcut keys in media-keys (BN) - Make volume down work when muted (BN) - Export the "cursor-blink-timeout" XSetting - Add test-system-timezone test program - Fix possible crasher in media-keys (William Jon McCann) - Make media-keys not crash when there are no listeners (BN) - Use a notification for the low space waring in housekeeping (WJMcC) - Make libnotify a hard-dependency (BN) - Add a real test application for housekeeping (BN) - Port daemon and xrandr plugin to GDBus (BN) - Fix possible warnings in keyboard plugin (BN) - Fix logout key shortcut not asking for a confirmation (BN) - Don't warn about low space when over 1GB is free (BN) ================ Version 2.91.2.1 ================ - Require a newer gnome-desktop with GSettings support for the background plugin (Tomas Bzatek) ============== Version 2.91.2 ============== - Migration to GSettings (Bastien Nocera, Rodrigo Moya, Gerd Kohlberger, Carlos García Campos) - Use MIME types for URL handlers (Rodrigo Moya) - Fix the GSD_API_VERSION definition in configure.ac (Matthias Clasen) - Update PolicyKit minimum requirement (Bastien Nocera) - Remove typing break plugin (Bastien Nocera) - Update the required version of gnome-desktop3/GTK3 (Bastien Nocera) - Require libnotify 0.6.0 (William Jon McCann) - KEY_SCROLL_METHOD is an enum not an int (Alban Browaeys) (#631963) - Don't use gdk_drawable_get_screen (Alban Browaeys) (#631931) - Fix version substitution in pkg-config file (Bastien Nocera) (#631866) - Remove status icon for monitors (Bastien Nocera) (#631995) - Make XInput a hard requirement (Bastien Nocera) - Use canberra-gtk for GTK3 (Bastien Nocera) - More network filesystems not to monitor (Josselin Mouette) (#606421) - Fix loading plugins information (Bastien Nocera) (#631933) - For media key, use the default application for audio/ogg (Rodrigo Moya) - Set priority for plugins based on settings (Bastien Nocera) - Never daemonise the "daemon" (Bastien Nocera) - Use Gdk to get events about input devices being added (Bastien Nocera) - Cleanup macro magic in plugin.h (Paolo Borelli) (#591798) - Update gnome-media cut'n'paste code (Bastien Nocera) (#612024) - Add gnome-settings-daemon man page (Joshua Cummings) (#588716) - Remove horrible xmodmap fallback code (Bastien Nocera) (#150542) - Remove outdated plugin (Bastien Nocera) - Use g_timeout_add_seconds (Bastien Nocera) (#582703) - Keyboard plugin improvements (Sergey V. Udaltsov) - Don't choke if there are old plugins laying around (William Jon McCann) - Check for touchpad before running syndaemon (Hernando Torque) (#632122) - Add icon to the "Keep settings" dialogue (Bastien Nocera) (#579021) - Add support for the enable-animation setting (Bastien Nocera) (#630535) - Export Xft.lcdfilter for OO.o's benefit (Chris Coleman) (#631924) - Remove XFree86 4.3.0 check (Bastien Nocera) (#632569) - Make fontconfig a hard dependency (Bastien Nocera) - Add GConf<->GSettings bridge plugin (Rodrigo Moya) - Show a touchpad-disabled if no touchpad (Bastien Nocera) - Make the "log out" key really do that (Bastien Nocera) - If the stored configuration fails at startup, use the fallback configurations (Gary Lin) - Add ability to hard-code media keys (Bastien Nocera) (#623223) - Use $(sysconfigdir) for .ad files, since they are settings (Rodrigo Moya) - Enable maintainer mode (Rodrigo Moya) - Don't display the gnome-settings-daemon autostart in the startup applications list (Rodrigo Moya) - Add settings key for disabling boot time configuration (Martin Pitt, Rodrigo Moya) (#631388) - Don't access free'd memory if a volume is unmounted whilst the dialog is running (Rodrigo Moya) - Port to GDBus (Bastien Nocera) - Add support for more multimedia keys (Bastien Nocera) - Handle video out keys in media-keys (Ray Strode) (#623223) - Use virtual modifier for the Windows key (Ray Strode) - Simplify the default XRandR behaviour (Bastien Nocera) (#634092) - Add middle-button-enabled key (Bastien Nocera) (#633863) - Prepare for the demise of size_request (Matthias Clasen) (#633320) - Translations: - ca (Carles Ferrando) - de (Mario Blättermann) - es (Jorge González) - gl (Fran Diéguez) - he (Yaron Shahrabani) - ja (Takayuki KUSANO) - ko (Changwoo Ryu) - nb (Kjartan Maraas) - pa (A S Alam ) ============== Version 2.91.0 ============== - Give a name to the keyboard status icon (Matthias Clasen) (#610319) - Fix include directory to match API version (Bastien Nocera) - Add daemon path to pkg-config files (Bastien Nocera) - Don't switch mouse buttons for XTest devices (Bastien Nocera) (#627084) - Remove GtkObject usage (Matthias Clasen) (#630678) - Use gtk3 draw event instead of expose-event (William Jon McCann) (#630975) - Use gdk-pixbuf header (William Jon McCann) (#630975) - Don't use GdkColormap (William Jon McCann) - Use cairo regions to set input shape (William Jon McCann) - Adapt to GnomeBG API changes (William Jon McCann) - Use an empty region to ignore events (William Jon McCann) - Don't destroy the cairo context in draw handler (William Jon McCann) - Adapt to libgnomekbd API changes (Sergey V. Udaltsov) - Translations: - ar (Khaled Hosny) - bg (Damyan Ivanov) - ca (Joan Duran) - cz (Petr Kovar) - gl (Fran Diéguez) =============== Version 2.90.1 =============== - Apply keyboard a11y settings for newly plugged keyboards - Loads of compilation fixes for GTK3 - Fix crasher when certain items are copied to the clipboard - Silent build by default Display: - Don't try to activate display configurations where all the outputs are off - Don't cycle through custom display configurations on XF86Display button press - Add logging infrastructure ================ Version 2.31.5.1 ================ - Include fixes from 2.31.4.2 - Translations: - nb (Kjartan Maraas) ============== Version 2.31.5 ============== - Depend on gnome-desktop-3.0 (Rodrigo Moya) - Translations: - es (Jorge González) - gl (Fran Diéguez) - he (Yaron Shahrabani) - sl (Matej Urbančič) ================ Version 2.31.4.2 ================ - Fix the binary name in the datetime DBus .service file (Thomas Wood) - Translations: - gl (Fran Diéguez) - he (Yaron Shahrabani) ================ Version 2.31.4.1 ================ - Fix the datetime DBus .service file (Thomas Wood) ============== Version 2.31.4 ============== - Fix build for --disable-smartcard-support (Ray Strode) (#617748) - Use gtk+-3.0 (Rodrigo Moya) - Fix launching the display configuration tool (Matthias Clasen) - Move clock service from gnome-panel (Rodrigo Moya, Thomas Wood) - Define plugindir in .pc file (Rodrigo Moya) - Translations: - et (Ivar Smolin) - lv (Rudols Mazurs) - nb (Kjartan Maraas) ============== Version 2.31.3 ============== - Fixed icon names, prefixed with kbd- (Sergey Udaltsov) - Use "show layout" dialog from libgnomekbd (Sergey Udaltsov) - Translations: - et (Ivar Smolin) - he (Yaron Shahrabani) - sl (Matej Urbančič) ============== Version 2.31.2 ============== - Fix installation of the xrandr helper binary (Jens Granseur) (#617782) - Always dist smartcard.gnome-settings-plugin (Ray Strode) (#617748) - Adjust XF86Display timestamps if they are out of order with RANDR timestamps (Chase Douglas) (#610482) - Don't install template files into the icon theme (Matthias Clasen) - Fix loading OSD icons when there's no SVG version (Bastien Nocera) (#618023) - Only check for baobob if we're about to show a dialog (Ross Burton) - Translations: - de (Mario Blättermann) - en@shaw (Thomas Thurman) - es (Jorge González) - gl (Fran Diéguez) - or (Manoj Kumar Giri) ============== Version 2.31.1 ============== - Create the directory for the system's RANDR configuration (Federico Mena Quintero) - Add the logic needed for the "Make Default" button in gnome-display-properties (Federico Mena Quintero) - Use $sysconfdir for /etc installation (Rodrigo Moya) - Replace deprecated GTK_WIDGET_STATE (Andre Klapper) - Compile with -DGSEAL_ENABLE (Andre Klapper) (#612588) - Use Layouts instead of Groups (Sergey Udaltsov) (#553108) - Add smartcard plugin (Ray Strode) - Software LED indicators (Sergey Udaltsov) (#616380) - Use LED icons instead of files (Sergey Udaltsov) - Translations: - de (Mario Blättermann) - en_GB (Philip Withnall) - es (Jorge Gonzalez) - gl (Francisco Diéguez) - mr (Sandeep Shedmake) - sk (Pavol Šimo) - sl (Matej Urbančič) - te (krishnababu k) ============== Version 2.30.1 ============== - Fix keyboard indicator displaying (Martin Pitt) (#613666) - Default to system settings for handling multiple keyboard layouts (Martin Pitt) - Introduce gconf key that allows hiding the indicator (Sergey Udaltsov) (#612240) (#613666) - Translations: - ca (Jordi Serratosa) - ca@valencia (Carles Ferrando) - crh (Reşat SABIQ) - et (Ivar Smolin) - kn (Shankar Prasad) - sl (Pavol Šimo) - th (Theppitak Karoonboonyanan) ============== Version 2.30.0 ============== - Protect XInput code by ifdefs if XInput isn't available (Daniel Macks) (#611670) - Don't play a sound when the volume doesn't change (Bastien Nocera) (#610001) - Fix linking with pedantic linkers (Bastien Nocera) (#610244) - Remove unused do_sleep_action function (Bastien Nocera) - Apply all keyboard settings to new keyboards (Bastien Nocera) (#610245) - Ensure the window is realized before we invalidate it (Richard Hughes) (#604918) - Replace "eject" spawn with GIO code (Bastien Nocera) (#580779) - Don't spawn xrdb (Martin Pitt) (#586276) - Add translator hint (Jens Granseuer) (#613647) - Disable font plugin by default (Bastien Nocera) (#613604) - Translations: - bn (Jamil Ahmed) - da (Ask H. Larsen) - et (Ivar Smolin) - eu (Inaki Larranaga Murgoitio) - he (Nikos Bakaoukas) - hu (Gabor Kelemen) - ko (Changwoo Ryu) - lt (Gintautas Miliauskas) - nl (Hannie Dumoleyn, Reinout van Schouwen) - nn (Torstein Adolf Winterseth) - pa (A S Alam) - pt (Duarte Loreto) - ro (Adi Roiban) - sl (Pavol Šimo) - sr (Miloš Popović) - uk (Maxim V. Dziumanenko) =============== Version 2.29.92 =============== - Translations: - bg (Alexander Shopov) - ca (Joan Duran) - en_GB (Bruce Cowan) - fi (Timo Jyrinki) - hu (Gabor Kelemen) - it (Luca Ferretti) - nb (Kjartan Maraas) - pt_BR (Antonio Fernandes C. Neto) - sv (Daniel Nylander) =============== Version 2.29.91 =============== - Fn-F8 should disable/enable touch points (Peter Hutterer) (#594831) - Always set the position of outputs, even if they are already turned on (Federico Mena Quintero) - Apply keyboard settings to newly plugged in devices (Federico Mena Quintero) (#610245) - Translations: - de (Jochen Skulj, Mario Blättermann) - es (Jorge González) - gl (Fran Diéguez) - ro (Lucian Adrian Grijincu) - sl (Matej Urbančič) - ta (vasudeven) - ru (Leonid Kanter) - zh_CN (Ray Wang) - zh_HK & zh_TW (Chao-Hsiung Liao) =============== Version 2.29.90 =============== - Add gthread-2.0 to required modules for the daemon (Jens Granseuer) (#608217) - Centralize the use of gnome_rr_config_apply_with_time (Federico Mena Quintero) - Translations: - et (Ivar Smolin) - sl (Matej Urbančič) ============== Version 2.29.6 ============== - Don't allow left-handed setting for single-button touchpads (Peter Hutterer) - Don't die on X servers without XKB (Matthias Clasen) (#604651) - Translations: - bg (Alexander Shopov) - bn (Jamil Ahmed) - es (Jorge González) - nb (Kjartan Maraas) - ta (vasudeven) ============== Version 2.29.5 ============== - Fix variant handling in $GDM_KEYBOARD_LAYOUT (Martin Pitt) (#596897) - Tighten check for XInput (Jens Granseuer) - Fix bluriness in level bar, and popup (Bastien Nocera) (#567249) - Remove unused variable (Bastien Nocera) (#599904) - Honour libexecdir when spawning gsd-locate-pointer (Jens Granseuer) (#599209) - Allow left-handed setting for touchpads (Peter Hutterer) - Use a rounded instead of curved rectangle (William Jon McCann) - Improve the media keys overlay design (William Jon McCann) (#596136) - Add brightness to the media-keys popup (Bastien Nocera) (#599677) - Fix for GSEAL goal (Bastien Nocera) (#599861) - Avoid volumes going over 100% (Bastien Nocera) (#600770) - Make OSD display more generic (Bastien Nocera) (#600951) - Support loading -rtl and -ltr variants of icons (Bastien Nocera) (#600984) - Relicense gsd-media-keys-window.[ch] to LGPL (Bastien Nocera) (#600986) - Hide the status icon before unreffing it (Matthias Clasen) (#601696) - Make eject behave better on OpenBSD (Jasper Lievisse Adriaanse) (#598573) - Export libexecdir in .pc file (DJ Lucas) (#596388) - Run gnome-color-manager apply program when the outputs change (Richard Hughes) - Factor out function to get keycodes from keysym names (Federico Mena Quintero) - Handle the XF86RotateWindows hotkey by rotating a laptop's display (Federico Mena Quintero) - Respond to monitor configuration changes when in charge (Matthias Clasen) (#601203) - Filter invalid layouts before looking for the index of one passed by gdm (Vincent Untz) (#585868) - Add linsysfs to list of virtual filesystems (Coleman Kane) (#604396) - Remove sleep keybindings (Bastien Nocera) (#170175) - Start an on-screen-display window (OSD) (Federico Mena Quintero) - Split the composited and non-composited code for the expose-event handler (Federico Mena Quintero) - Use a hand-drawn frame instead of a GtkBuilder frame (Federico Mena Quintero) - Using GkbdStatus for the automatic notification icon (Sergey V. Udaltsov) - Implement popup menu for the notification icon (Sergey V. Udaltsov) - Add extra API required by GsdMediaKeysWindow (Federico Mena Quintero) - Add timed exit option (William Jon McCann) - Fixes for new libxklavier (Sergey V. Udaltsov) - Translations: - ast (Xandru Armesto Fernandez) - en@shaw (Thomas Thurman) - es (Jorge González) - et (Mattias Põldaru, Ivar Smolin) - ja (Takayuki KUSANO) - nb (Kjartan Maraas) - nds (Nils-Christoph Fiedler) - ru (Leonid Kanter) - sl (Matej Urbančič) - sv (Daniel Nylander) - uk (Maxim V. Dziumanenko) - vi (Nguyễn Thái Ngọc Duy) - zh_CN (Aron Xu) ============== Version 2.28.1 ============== - Try harder to use the keyboard layout passed by gdm (Vincent Untz) - Translations: - ca (Joan Duran) - el (Kostas Papadimas) - or (Manoj Kumar Giri) - pl (Tomasz Dominikowski) - ru (Andrey Grigoriev, Alexandre Prokoudine) - sl (Matej Urbančič) - zh_HK (Chao-Hsiung Liao) - zh_TW (Chao-Hsiung Liao) ============== Version 2.28.0 ============== - Fix incomplete function declaration (Vincent Untz) - Don't install the dummy plugin whilst keeping the Makefile.am almost intact for copy/paste (Bastien Nocera) (#578538) - Fix Touchpad left-handed issues (Bastien Nocera) (#594617) - Add sound effect to volume key handling (Bastien Nocera) (#404683) - Remove useless custom eject icon (Bastien Nocera) - Validate xsettings GConf keys read from the configuration (Jens Granseuer) (#594821) - Fix compiler warnings (Jens Granseuer) - Translations: - as (Amitakhya Phukan) - cz (Petr Kovar) - da (Ask H. Larsen) - de (Mario Blättermann) - en_GB (Bruce Cowan) - hi (Rajesh Ranjan) - hu (Gabor Kelemen) - it (Luca Ferretti) - ja (Takayuki KUSANO) - kn (Shankar Prasad) - mai (Rajesh Ranjan) - ml (Ani) - mr (Sandeep Shedmake) - or (Manoj Kumar Giri) - pa (A S Alam ) - pl (Piotr Drąg) - ro (Adi Roiban, Dumitru Mișu Moldovan) - sr (Miloš Popović) - te (krishnababu k) - uk (Maxim V. Dziumanenko) =============== Version 2.27.92 =============== - Make 'Locate Pointer a separate process (Matthias Clasen) (#524499) - Skip button mappings only for core devices (Peter Hutterer) - Translations: - ar (Khaled Hosny) - bn (Jamil Ahmed) - bn_IN (Runa Bhattacharjee) - ca (Gil Forcada) - ca@valencia (Carles Ferrando) - et (Ivar Smolin) - eu (Inaki Larranaga Murgoitio) - gu (Sweta Kothari) - he (Yaron Shahrabani) - kn (Shankar Prasad) - lt (Gintautas Miliauskas) - nb (Kjartan Maraas) - pt (Duarte Loreto) - te (krishnababu k) - tr (Baris Cicek) =============== Version 2.27.91 =============== - Update gnome-volume-control code (Bastien Nocera) - Update cut'n'paste from gnome-media (Bastien Nocera) - Update volume control code for new API (Bastien Nocera) - Translations: - bg (Alexander Shopov) - fi (Tommi Vainikainen) - ga (Seán de Búrca) - ko (Changwoo Ryu) - pt_BR (Henrique P. Machado) =============== Version 2.27.90 =============== - Update gnome-volume-control from gnome-media (Bastien Nocera) (#589825) - Fix crash in gvc_mixer_stream_is_running() (Chris Coulson) (#590073) - Add '-k' option to syndaemon call for 'Disable touchpad while typing' (C de-Avillez) (#590588) - Low disk space warning bug-fixes (Chris Coulson) (#591153) - Translations: - br (Denis Arnaud) - es (Jorge González) - et (Ivar Smolin, Priit Laes and Mattias Põldaru) - fr (Nicolas Repentin and Claude Paroz) - gl (Antón Méixome) - nb (Kjartan Maraas) - or (Manoj Kumar Giri) - sv (Daniel Nylander) - ta (drtvasudevan) - zh_CN (Ray Wang) ============== Version 2.27.5 ============== - Only use applicable configurations for switching with the XF86Display hotkey (Federico Mena Quintero) - Only use applicable configurations when auto-configuring outputs during hotplug (Federico Mena Quintero) - Really lay out displays from left to right when using the XF86Display hotkey (Federico Mena Quintero) - For the XF86Display hotkey, preserve the cycle order when sanitizing the configurations (Federico Mena Quintero) - Remove last libglade dependency (Felix Riemann) - Improved low disk space warning (Chris Coulson) (#573980) - Fix compiler warnings (Jens Granseuer) - Translations: - es (Jorge González) - et (Ivar Smolin) - fr (Claude Paroz) - he (Yaron Sharabani) - sv (Daniel Nylander) - ta (drtvasudevan) - zh_HK (Chao-Hsiung Liao) - zh_TW (Chao-Hsiung Liao) ============== Version 2.27.4 ============== - Remove screensaver plugin, it's autostarted now (Matthias Clasen) - Don't take too long in RANDR D-Bus method implementation (Federico Mena Quintero) - Add support for Synaptics touchpads (Matthias Clasen) - Don't spawn more than one syncdaemon (Matthias Clasen) - Depend on gnome-desktop >= 2.26.3 (Rodrigo Moya) - Update gnome-volume-control code from master (Bastien Nocera) - Fix order of arguments to strstr (Federico Mena Quintero) - Depend on libxklavier 4.0 (Sergey V. Udaltsov) - Remove libglade dependency from media-keys and keyboard plugins (Felix Riemann) - Translations: - he (Yaron Shahrabani) - hu (Gabor Kelemen) - in_BN (Runa Bhattacharjee) - uk (Maxim V. Dziumanenko) ============== Version 2.27.3 ============== - Make the RANDR tray icon's per-monitor labels explicitly black (Federico Mena Quintero) (#556050) - Include config.h so that the notifications code in housekeeping plugin can actually be built (Jens Granseuer) (#584217) - Use "screen reader" instead of "screenreader" in schema (Gabor Kelemen) (#572911) - Lots of RANDR fixes and improvements (Federico Mena Quintero) - Nicer handling of broken XKB configuration in gconf (Sergey Udaltsov) (#585259) - Make 'locate pointer' deal with wm/cm changes (Matthias Clasen) (#585209) - Be more careful when comparing two key structs (Matthias Clasen) (#580616) - Translations: - da (Ask H. Larsen) - es (Jorge Gonzalez) - et (Ivar Smolin) - nb (Kjartan Maraas) - sv (Daniel Nylander) - ta (drtvasudevan) ============== Version 2.27.1 ============== - Use ngettext for the reset dialog (Jens Granseuer) (#575409) - Replace deprecated gtk_status_icon_set_tooltip (Thomas H.P. Andersen) (#578480) - Updated translations: - ca (Jordi Mas i Hernandez) - es (Jorge Gonzalez) - nb (Kjartan Maraas) - sl (Matej Urban) - zh_CN (Deng Xiyue) ============== Version 2.26.1 ============== - Fix crash when closing the lid on some laptops (Jens Granseuer) (#576875) - Fix crash when closing a11y notification bubble (Jens Granseuer) (#576535) (use of libnotify >= 0.4.5 highly recommended) - Fix problems with saving/restoring screen setup (Federico Mena Quintero) - Make the screen resolution confirmation dialog always appear in front of the settings window (Federico Mena Quintero) (#576006) - Increase confirmation timeout to 30 seconds to give slower devices (like projectors) time to adjust - Avoid some GConf roundtrips (Jens Granseuer) (#578539, #578542) - Build fixes (Jens Granseuer, yselkowitz@users.sourceforge.net) - Updated translations: - ar (Khaled Hosny) - as (Amitakhya Phukan) - kn (Shankar Prasad) - nb (Kjartan Maraas) - sr (Miloš Popović) - sr@latin (Miloš Popović) ============== Version 2.26.0 ============== - Make build work with -Wl,-z,defs (Christopher Taylor) (#574452) - Updated translations: - as (Amitakhya Phukan) - ca (Gil Forcada) - cs (Petr Kovar) - da (Kenneth Nielsen) - de (Mario Blättermann) - el (Kostas Papadimas) - eu (Inaki Larranaga Murgoitio) - gl (Ignacio Casal Quinteiro) - gu (Ankitkumar Patel) - he (Yair Hershkovitz) - hi (Rajesh Ranjan) - it (Luca Ferretti) - ja (Takeshi AIHANA) - lt (Gintautas Miliauskas) - ml (Ani Peter) - mr (Sandeep Shedmake) - or (Manoj Kumar Giri) - ro (Mișu Moldovan) - ru (Nickolay V. Shmyrev) - ta (I. Felix) - te (Krishnababu K) =============== Version 2.25.92 =============== - don't print warnings for disabled custom shortcuts (Jens Granseuer) - revert screen resolution change if the user closes the confirmation window using the close icon or by pressing escape (Jens Granseuer) (#571492) - add missing keys for a11y shortcut keys to GConf schemas (Jens Granseuer) (#572807) - install gnome-settings-daemon-plugin.h for custom plugin developement (Jens Granseuer) (#573610) - Updated translations: - bg (Alexander Shopov) - en_GB (Philip Withnall) - es (Jorge Gonzalez) - fi (Ilkka Tuohela) - fr (Claude Paroz) - gu (Sweta Kothari) - hu (Gabor Kelemen) - ko (Changwoo Ryu) - nl (Wouter Bolsterlee) - pl (Tomasz Dominikowski) - pt (Duarte Loreto) - pt_BR (Krix Apolinário, Vladimir Melo) - sv (Daniel Nylander) - th (Theppitak Karoonboonyanan) - zh_HK (Chao-Hsiung Liao) - zh_TW (Chao-Hsiung Liao) =============== Version 2.25.91 =============== - Have gnome-session restart g-s-d if it crashes (Matthias Clasen) - Add --without-libnotify to disable notifications (Nirbheek Chauchan) - Avoid warnings due to notifications on nonexisting status icons (Matthias Clasen) - Fix crash with invalid keyboard shortcuts (Jens Granseuer) - fix label for "Don't show this message again" checkbox (Luca Ferretti) (#517821) - HIG fix for button labels (Luca Ferretti) (#571819) - Don't use legacy icons for keyboard and mouse (Luca Ferretti) (#571823) - Fix alignment of the composited media window (Leo Iannacone) (#567249) - Updated translations: - ast (Mikel González) - ca (Gil Forcada) - da (Kenneth Nielsen) - es (Jorge Gonzalez) - eu (Iñaki Larrañaga Murgoitio) - ja (Takeshi AIHANA) - nl (Wouter Bolsterlee) - pl (Tomasz Dominikowski) - ro (Jani Monoses) - sv (Daniel Nylander) - vi (Clytie Siddall) =============== Version 2.25.90 =============== - Initialize thread system (Frederic Peters) (#565515) - Better support for Eject and Sleep actions on BSD (Jasper Lievisse Adriaanse) (#565472) - Spawn screensaver after a 30 second timeout instead of when idle so that it doesn't compete with other processes when the session starts (Jens Granseuer) (#564059) - Add low diskspace notification (Vincent Untz) (#557647) - Support hotkeys for a11y tools (Matthias Clasen) (#565310) - Quiet xrdb when there are duplicate rules in the .ad files (Bastien Nocera) (#566610) - Add debugging output when de/registering media players (Jens Granseuer) (#564433) - Add a new sound plugin that tells PulseAudio to drop its sample cache when the sound theme changes (Lennart Poettering) (#545386) - Don't pop up an error message when there's no randr configuration file (Federico Mena Quintero) - Ungrab keys when key-related plugins are disabled (Jens Granseuer) (#567867) - Use PulseAudio directly to change the volume (Bastien Nocera) (#567177) - Don't draw_background immediately when nautilus is disabled, GnomeBG will send a signal (Ray Strode) - Add crossfade transition when switching backgrounds (Ray Strode) (#552857) - Use XF86Explorer to launch the file manager (Bastien Nocera) - Fix possible crash when pressing Fn-F7 (Andres Freund) (#568713) - Delay drawing the background until SessionRunning (Ray Stode) - Ask for confirmation with a timeout after changing the randr configuration (Federico Mena Quintero) (#545115) - Require gnome-desktop 2.25.6 (Jen Granseuer) - Plug leaks - Build fixes - Updated translations: - es (Jorge González) - et (Mattias Põldaru) - he (Yuval Tanny) - hu (Gabor Kelemen) - it (Luca Ferretti) - ko (Changwoo Ryu) - nb (Kjartan Maraas) - pt_BR (Krix Apolinário) - sv (Daniel Nylander) - zh_CN (甘露(Gan Lu)) ============== Version 2.25.3 ============== - Add support for fn-f7 type keys (Søren Sandmann) - Use D-Bus instead of an X client mesage in the xrandr plugin, so the front-end can get error messages as well (Federico Mena Quintero) - Fix crash when the X server doesn't have the XInput extension (Jens Granseuer) (#562977) - Don't call umask (Behdad Esfahbod) (#563543) - Shut the daemon down properly when the SIGTERM signal is received or the D-Bus bus goes away (Ray Strode) - Restore AccessX bits to original values on exit, fixes sticky keys coming on when gnome-settings-daemon has exited (Ray Strode) - Use only top-level glib and gtk+ headers (Pedro Fragoso) (#563796) ============== Version 2.25.2 ============== - No need to trap XkbQueryExtension and friends errors (Jens Granseuer) (#559346) - Add some performance annotations around libxklavier calls (Behdad Esfahbod) - Start managers in idle callbacks (Behdad Esfahbod) (#559482, #559564) - Only initialize fontconfig when starting up (Behdad Esfahbod) (#559550) - Remove unnecessary X error traps (Jens Granseuer) (#559562) - Init a11y status icon only when needed (Behdad Esfahbod) (#559558) - Reshufle plugin priorities a bit (Behdad Esfhabod) - Delay constructing the GnomeBg object until we need it (Behdad Esfahbod) (#559639) - Listen for DeviceEnabled instead of DeviceAdded to be sure the mouse has been initialized (William Grant) (#559827) - Add debugging output for volume_step (Jens Granseuer) - Fork before gtk_init (Behdad Esfahbod) (#559695) - Lockdown in the keybinding plugin (Matthias Clasen) (#553434) - Trap X errors so we don't crash on X servers that don't support DevicePresence (Jens Granseuer) (#560618) - Fix handling of time = GDK_CURRENT_TIME (Jens Granseuer) (#559797) - Add bundle_loader linker flag to fix compilation on MacOS X (dmack@netspace.org) (#522673) - Grab all keycodes that match the respective keysim (Mario Limonciello) (#561275) - Fix --no-daemon (Behdad Esfahbod) - Depend on libxklavier 3.8 (Sergey Udaltsov) - Fix checks for various X libraries (Jens Granseuer) - Fix check for xklavier device discovery (Jens Granseuer) ============== Version 2.25.1 ============== - Ignore the 'activate' signal for deselected items so that the rotation setting doesn't reset when the systray menu is opened (Eric Piel) (#554951) - Don't make togglekeys_enable depend on global AccessX state (Jens Granseuer) (#555009) - Fix picking up of the GDM layout (Matthias Clasen) (#554525 and #555873) - Use printf safely (Christian Persch) (#555553) - Show the shutdown dialog when the power button is pressed (Matthias Clasen) (#556307) - Support the Gtk/ButtonImages XSetting (Matthias Clasen) (#556797) - Clean-up volume initialization (Jens Granseuer) (#552383) - Make the composited volume images more clear (Bogdan Butnaru) (#557307) - Spawn screensaver process in idle callback (Rodrigo Moya) - Remove sound plugin (Jens Granseuer) (#557806) - Replace gnome_help_display_desktop with gtk_show_uri (Jens Granseuer) (#557808) - Listen for X device changes and reconfigure the mouse if necessary (William Grant) (#549267) - Remove AM_MAINTAINER_MODE (Jens Granseuer) (#558503) - Disable xrdb plugin by default (Behdad Esfahbod) (#557807) - Improve performance logging annotations (Behdad Esfahbod) (#559162) - Cleanup font module (Behdad Esfahbod) (#559163) - Don't trap errors around grab_key (Behdad Esfahbod) (#559164) - Don't run 'mousetweaks -s' at startup (Behdad Esfahbod) (#559165) - Start fontconfig monitors, mouse and clipboard managers in idle callbacks (Behdad Esfahbod) (#559166) - Preload gconf dirs when feasible (Behdad Esfahbod) (#559167) - Wait for initialization processes to be done before spawning other processes (Behdad Esfahbod) (#559168) - Don't close stderr to not lose warnings (Behdad Esfahbod) - Use a pipe to communicate between children and parent process instead of a signal (Behdad Esfahbod) - Updated translations: - et (Priit Laes) - mk (Jovan Naumovski) - pt_BR (Leonardo Ferreira Fontenelle) - sk (Marcel Telka) ============== Version 2.24.0 ============== - Fix the fix for read-only home directories (Simon Zheng) (#530975) - Make the volume popup not crash when invoking it on any screen but the first when using a compositing manager (Jens Granseuer) (#551677) - Add GPLv2 copyright notice explicitly so that newer versions of autotools don't declare us GPLv3 (Jens Granseuer) (#551956) - Specify GTK modules to load in a GConf directory instead of the single /desktop/gnome/gtk-modules key (Jens Granseuer) (#539840) - Also allow linking the module state to other boolean keys by using a string value that is the name of the key to use (Jens Granseuer) - Made the housekeeping plugin less aggressive by default (Michael J. Chudobiak) (#552680) - Updated translations: - af (Friedel Wolff) - ar (Khaled Hosny) - bn_IN (Runa Bhattacharjee) - ca (Gil Forcada) - da (Kenneth Nielsen) - el (Kostas Papadimas) - et (Priit Laes) - he (Yair Hershkovitz) - hu (Gabor Kelemen) - it (Luca Ferretti) - kn (Shankar Prasad) - lt (Gintautas Miliauskas) - ml (Praveen Arimbrathodiyil) - mr (Sandeep Shedmake) - pl (Wadim Dziedzic) - pt_BR (Leonardo Ferreira Fontenelle) - ro (Mişu Moldovan) - ta (Tirumurthi Vasudevan) - zh_CN (Funda Wang) =============== Version 2.23.92 =============== - Try harder to use the keyboard layout passed by GDM (Matthias Clasen) (#551062) - Updated translations: - bg (Alexander Shopov) - de (Hendrik Richter) - en_GB (Philip Withnall) - ga (Seán de Búrca) - ko (Changwoo Ryu) - nl (Reinout van Schouwen) - pt (Duarte Loreto) - sv (Daniel Nylander) =============== Version 2.23.91 =============== - Removed translatable property on stock gtk-close (Claude Paroz) - Fix a constness warning (Jens Granseuer) - Fix a crash due to an incorrect signal handler definition (William Jon McCann) - Use a scale factor instead of a fixed DPI (William Jon McCann) - Use g_warning instead of g_error when setup fails so we don't abort (Jens Granseuer) (#549483) - Updated translations: - cs (Petr Kovar) - eu (Inaki Larranaga Murgoitio) - fi (Ilkka Tuohela) - fr (Claude Paroz) - ja (Takeshi AIHANA) - nb (Kjartan Maraas) - pt_BR (Leonardo Ferreira Fontenelle) - th (Theppitak Karoonboonyanan) - vi (Nguyễn Thái Ngọc Duy) - zh_HK (Chao-Hsiung Liao) - zh_TW (Chao-Hsiung Liao) =============== Version 2.23.90 =============== - PulseAudio check to not ouput "no" twice (Jens Granseuer) - Add status icon when a11y hotkeys are enabled, and display Universal Access preferences when it is clicked (William Jon McCann) (#526070) - Simplify libnotify check, fix fontconfig result output (Jens Granseuer) - Put the Glade file where all the others are (jens Granseuer) - Remove some unnecessary boilerplate (Jens Granseuer) - Use g_file_monitor instead of g_file_monitor_file/_directory (Jens Granseuer) (#546372) - Remove warning that isn't (Jens Granseuer) - Fixed crash in randr startup (Jens Granseuer) - Fail xrandr initialization if we couldn't start xrandr (Matthias Clasen) (#546446) - Try harder to clean up xrandr in _stop so we can enable/disable the plugin on the fly (Jens Granseuer) - For LIBSOUNDS, check for libgnomeui, not just libgnome (Federico Mena Quintero) - Add sexy labels when setting up dual monitors (Federico Mena Quintero) - Add a separator to the menu before "Configure display settings" (Federico Mena Quintero) - Use GDK to get DPI (William Jon McCann) - Updated translations: - ar (Djihed Afifi) - es (Jorge Gonzalez) - et (Priit Laes) - fi (Ilkka Tuohela) - gl (Ignacio Casal Quinteiro) - ja (Takeshi AIHANA) - he (Yair Hershkovitz) - ml (Praveen Arimbrathodiyil) - nb (Kjartan Maraas) - pt (Duarte Loreto) - pt_BR (Leonardo Ferreira Fontenelle) - th (Theppitak Karoonboonyanan) ============== Version 2.23.6 ============== - Remove libgnomeui dependency (James Sharpe) (#544347) - Bump glib dependency to 2.15 (Wouter Bolsterlee) (#544737) - Use standard icon names for the OSD (Matthias Clasen) (#544733) - Make the display notification icon configurable (Søren Sandmann) - Resolve NumLock dynamically (Jens Granseuer) (#165343) - Updated translations: - ar (Djihed Afifi) - es (Jorge Gonzalez) - gl (Ignacio Casal Quinteiro) - nb (Kjartan Maraas) - pt_BR (Leonardo Ferreira Fontenelle) ============== Version 2.23.5 ============== - New settings for event sounds (Lennart Poettering) (#539786) - Fix include path for building against uninstalled package. (Damien Carbery) (#543289) - Remove 'daemon' from the warning message (Gerd Kohlberger) (#543095) - Make more shortcuts with shift work (Jens Granseuer) (#542275) - Update RandR code to use new gnome-desktop API (Soren Sandmann) - Fix accelerator check (Jens Granseuer) (#538699) - Detect and enable PulseAudio (Colin Walters) (#533198) ============== Version 2.23.4 ============== - Check for fontconfig instead of xft2 (Behdad Esfahbod) - Send a Fontconfig/Timestamp xsettings notification whenever fontconfig configurations change (Behdad Esfahbod) (#490374) - Properly match keybindings that need Shift for resolving the keysym (Jens Granseuer, Bastien Nocera) (#536581) - If available use the esd_serverdir variable to locate the esd daemon so it can be started even if it's not in the PATH (Jens Granseuer, Brian Cameron) (#531868) - Updated translations: - ar (Djihed Afifi) - th (Theppitak Karoonboonyanan) ============== Version 2.23.3 ============== - Execute the correct action when there are multiple keyboard shortcuts with the same keycode but different keysyms (Bastien Nocera) (#530356) - Fix wallpaper handling for people running a session without nautilus (Matthias Clasen) (#531487) - Try to keep the keyboard layout from gdm (Matthias Clasen) (#531589) - Don't die when the user's home directory is read-only (Brian Cameron) (#530975) - Fix artifacts from the locate pointer animation in non-composited mode (Carlos Garnacho) (#531861) - Pass clicks to the media popup window through to the underlying window (Carlos Garnacho) (#531862) - Use new gnome-desktop background API and get rid of libbackground (William Jon McCann) - Don't eat keypresses for multimedia key events in the mouse plugin (Bastien Nocera) - Shutdown when receiving the "SessionOver" signal from gnome-session (Lucas Rocha, Jens Granseuer) (#522017) - Fix memory leaks in the font plugin (Jens Granseuer) - Move the locate pointer animation with the mouse cursor (Gerd Kohlberger) (#531665) - Fix build without GStreamer (Jens Granseuer) (#536177) - Updated translation: - ar (Djihed Afifi) - bg (Yavor Doganov) - es (Jorge Gonzalez) - gl (Ignacio Casal Quinteiro) - nb (Kjartan Maraas) - th (Theppitak Karoonboonyanan) - vi (Clytie Siddall) ================ Version 2.23.1.1 ================ - Install .desktop for gnome-settings-daemon in a standard autostart directory (Lucas Rocha) - Updated translations: - nb (Kjartan Maraas) ============== Version 2.23.1 ============== - Sound server startup based on GConf setting, even when esd is disabled (Alexey Shabalin) (#523743) - Added a new "housekeeping" plugin to set limits on the size and age of the thumbnail cache (Michael J. Chudobiak) (#523159) - Fix mismatched modifier maping between egg and GTK (Jens Granseuer) - Replace some custom functionality with stock GTK (Jens Granseuer) - Mark string for translation (Jens Granseuer) - Use G_DEFINE_TYPE instead of open-coding (Jens Granseuer) - Change data types to match glib, avoid using time_t (Jens Granseuer) - Add mapping for Gtk/Modules xsetting using GConf (Jens Granseuer) (#507386) - Set GConf keys back to false if mousetweaks is not installed (Gerd Kohlberger) (#525042) - Don't try to add grabas with invalid modifiers (Jens Granseuer) - Remove trailing newlines from messages since g_warning already takes care of those (Jens Granseuer) - Fix various leaks (Jens Granseuer) - Fix TYPE macro and remove unimplemented prototype (Lorne Applebaum) - Add a special volume subclass for better support of IBM Thinkpad hardware volume buttons (Lorne Applebaum) (#524425) - Initialize inited_ok or behaviour is undefined when xkb setup fails (Jens Granseuer) - Continued attempt at making XKB setup and error handling a bit less arcane and crufty (Jens Granseuer) - Only use the built-in default for volume_step if we get an error from GConf, not just when the value is 0 which might be what the user wants (Jens Granseuer) - Adds a "threshold" property to the AcmeVolume class that denotes the minimum percentage required to actually affect the volume (Jens Granseuer) - Don't install any listeners or callbacks when XKB is not available (Jens Granseuer) - Remove excessive key grab logging (Jens Granseuer) - Make plugins deactivation work (Jens Granseuer) - Properly null-terminate g_build_filename (Jens Granseuer) - Turn into a daemon by default and make --no-daemon work (Jens Granseuer) - DBus API has been stable for a while; don't define DBUS_API_SUBJECT_TO_CHANGE anymore (Jens Granseuer) - Drop GConf backup for xkb (Sergey Udaltsov) - Extract some functionality used by several plugins into a separate shared helper library (Jens Granseuer) (#525426) - Reset GConf keys when we can't launch the daemon (Jens Granseuer) - Updated translations: - bn_IN (Runa Bhattacharjee) - es (Jorge Gonzalez) - et (Priit Laes) - nn (Eskild Hustvedt) - sk (Marcel Telka) - te (Sunil Mohan Adapa) ============== Version 2.22.1 ============== - Fix segfault when shutting down the typing break monitor (Jens Granseuer) (#521786) - Set window type hint on the volume popup (Jens Granseuer) (#522232) - Remove unused properties from actions GUI (Jens Granseuer) - Reset opacity when removing the timeout (Jens Granseuer) (#522499) - Fix handling of child process (William Jon McCann) - Add a tool to test media keys (William Jon McCann) - Add some profiling code (William Jon McCann) - Fix compiler warnings (William Jon McCann) - Fix leaks (William Jon McCann) (#524183) - Add more stuff to the configuration summary (William Jon McCann) - Don't eat key events (Jens Granseuer) (#523676) - Apply keyboard settings on startup (Jens Granseuer) (#525440) - Make "Home" keybinding work again (Jens Granseuer) - Updated translations: - bn_IN (Runa Bhattacharjee) - et (Priit Laes) - nn (Eskild Hustvedt) - sk (Marcel Telka) - te (Sunil Mohan Adapa) - vi (Nguyễn Thái Ngọc Duy) ============== Version 2.22.0 ============== - Actually link against libXi when building with XInput support (Jens Granseuer) (#519488) - Disable debug by default (William Jon McCann) - Don't pass GError's if we're not going to use them (Jens Graseuer) - Remove obsolete settings for the removed default editor plugin (Jens Granseuer) - Updated translations: - da (Kenneth Nielsen) - el (Kostas Papadimas) - en_GB (Philip Withnall) - es (Jorge Gonzalez) - et (Priit Laes) - hu (Gabor Kelemen) - it (Luca Ferretti) - lt (Gintautas Miliauskas) - mk (Arangel Angov) - nb (Kjartan Maraas) - nl (Vincent van Adrighem) - ru (Leonid Kanter) - uk (Maxim Dziumanenko) - zh_HK (Chao-Hsiung Liao) - zh_TW (Chao-Hsiung Liao) =============== Version 2.21.92 =============== - Only print debug messages if --debug is used - Only load plugins when requested not at every start - Fixed #515340, Add a way to prioritise plugin load (William Jon McCann) - Fixed #515341, Signal when plugins finish loading (William Jon McCann) - Fixed #517259, Escape hostname for use in gconf key (Vincent Untz) - Fixed #517418, gnome-display-properties resolution change will not be used after logout or reboot (Jens Granseuer) - Fixed #518075, Sound plugin should start pulseaudio itself (Bastien Nocera) Translations: - Updated fr: Claude Paroz - Updated de: Hendrik Brandt - Updated nl: Vincent van Adrighem - Updated be@latin: Ihar Hrachyshka - Updated pt_BR: Jonh Wendell - Updated pt: Duarte Loreto - Updated ca: Gil Forcada - Updated *: Matthias Clasen - Updated oc: Yannig Marchegay - Updated sv: Daniel Nylander - Updated ja: Takeshi AIHANA - Updated cs: Petr Kovar - Updated ar: Djihed Afifi - Updated it: Luca Ferretti - Updated es: Jorge Gonzalez - Updated th: Theppitak Karoonboonyanan - Updated eu: Inaki Larranaga Murgoitio - Updated fi: bug #518255, Ilkka Tuohela - Updated gl: Ignacio Casal Quinteiro - Updated nb: Kjartan Maraas - Updated pl: Artur Flinta =============== Version 2.21.91 =============== - Use a flat directory instead of a hierarchy to install plugins into (Christian Persch) (#513246) - Don't scan the plugins directory recursively (Christian Persch) (#513246) - Install the settings plugin to a versioned directory to fix install with libdir == libexecdir (Christan Persch) (#504203) - Review short and long descriptions for GConf keys (Luca Ferretti) (#514047) - Don't crash when running the screensaver fails (Jens Granseuer) (#514385) - Rename src folder to gnome-settings-daemon (Damien Carberry, Jens Granseuer) (#511820) - Add uninstalled.pc file for building against an uninstalled copy of g-s-d (Damien Carberry, Jens Granseuer) (#511820) - Add separate checks for libbackground and use external copy (Jens Granseuer) - Use gnome_settings_daemon for the GConf path (Jens Granseuer) (#514411) - Release the Glade XML ASAP and keep track of the 2 widgets we need (Jens Granseuer) - Make sure we return a GError if initialization fails (Jens Granseuer) (#514926) - Load the XKB settings initially (Matthias Clasen) (#511771) - Fix leaks (Jens Granseuer) - Unref the GConfClient only after done with it (Jens Granseuer) - Check for xinput (Sebastien Bacher) (#514942) - Fix copy'n'paste error (Jens Granseuer) (#515426) - Declare variables at the beginning of a block to make older compilers happy (Jens Granseuer) - Add back support for defining plugin start order (Jens Granseuer) - Assign return value from g_slist_sort to the plugins list variable (Wouter Bolsterlee) (#515340) - Replace gnome_vfs usage with GIO (Rodrigo Moya) (#513990) ================= Version 2.21.90.2 ================= - Use correct binary path in DBus service file (Rodrigo Moya) - Updated translations: - sv (Daniel Nylander) ================= Version 2.21.90.1 ================= - Use plain $libexecdir for g-s-d binary (Rodrigo Moya) =============== Version 2.21.90 =============== - Add a more appealing animation for locate pointer feature if composite is available (Carlos Garnacho) - Quote function names in AC_DEFUN to fix autoconf warnings (Jens Granseuer) - Fix build with builddir != srcdir (Christian Persch) (#509142) - Use g_ascii_dtostr instead of setlocale (Christian Persch) (#505470) - Read check for XFT2 that got loast in the g-s-d split (Jens Granseuer) (#510925) - Fix typo in typing break key (Jens Granseuer) (#510429) - Define GNOME_DESKTOP_USE_UNSTABLE_API before including gnome-bg.h (Jens Granseuer) - No longer define DBUS_API_SUBJECT_TO_CHANGE (Jens Granseuer) - Initialize GnomeProgram to avoid critical warnings from libgnome (Wouter Bolsterlee) (#509770) - Hopefully allow $(libdir) to be the same directory as $(libexecdir) by installing the gnome-settings-daemon binary into a subdirectory of $(libexecdir) (Wouter Bolsterlee) (#504203) - Don't use weird autofoo stuff to install gnome-settings-daemon into another directory (Wouter Bolsterlee) (#504203) - Suppress verbose GConf schema installation output (Wouter Bolsterlee) ================ Version 2.21.5.2 ================ - Use libtool for building static libs also (Rodrigo Moya) - Automake fixes for allowing long file names (Rodrigo Moya) - Updated translations: - nb (Kjartan Maraas) ================ Version 2.21.5.1 ================ - Added translations from gnome-control-center module (Rodrigo Moya) (#509651) =============== Version 2.21.5 =============== - Support animated backgrounds (Soren Sandmann) - Init gnome-vfs and use correct name in desktop file (William Jon McCann) - Use new setting from libgnome to make toolbar icon size setting work (William Jon McCann) - Add Gtk/IMModule XSetting (Akira TAGOH) (#504182) - Reverted patch for SUPER key modifier (Rodrigo Moya) - Support mousetweaks (Gerd Kohlberger) (#503547) - Only consider /desktop/gnome/accessibility/keyboard/enable as option for enabling keyboard a11y features from the keyboard, not as global switch to turn all a11y features on/off (Denis Washington) =============== Version 2.21.4 =============== Initial development release of new gnome-settings-daemon design. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/README0000664000175000017500000000000000000000000017704 0ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/acinclude.m40000664000175000017500000000726000000000000021234 0ustar00jeremyjeremydnl EXTRA_COMPILE_WARNINGS dnl Turn on many useful compiler warnings dnl For now, only works on GCC AC_DEFUN([EXTRA_COMPILE_WARNINGS],[ dnl ****************************** dnl More compiler warnings dnl ****************************** AC_ARG_ENABLE(compile-warnings, AC_HELP_STRING([--enable-compile-warnings=@<:@no/minimum/yes/maximum/error@:>@], [Turn on compiler warnings]),, [enable_compile_warnings="m4_default([$1],[yes])"]) warnCFLAGS= if test "x$GCC" != xyes; then enable_compile_warnings=no fi warning_flags= realsave_CFLAGS="$CFLAGS" case "$enable_compile_warnings" in no) warning_flags= ;; minimum) warning_flags="-Wall" ;; yes) warning_flags="-Wall -Wmissing-prototypes" ;; maximum|error) warning_flags="-Wall -Wmissing-prototypes -Wnested-externs -Wpointer-arith" CFLAGS="$warning_flags $CFLAGS" for option in -Wno-sign-compare; do SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $option" AC_MSG_CHECKING([whether gcc understands $option]) AC_TRY_COMPILE([], [], has_option=yes, has_option=no,) CFLAGS="$SAVE_CFLAGS" AC_MSG_RESULT($has_option) if test $has_option = yes; then warning_flags="$warning_flags $option" fi unset has_option unset SAVE_CFLAGS done unset option if test "$enable_compile_warnings" = "error" ; then warning_flags="$warning_flags -Werror" fi ;; *) AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings) ;; esac CFLAGS="$realsave_CFLAGS" AC_MSG_CHECKING(what warning flags to pass to the C compiler) AC_MSG_RESULT($warning_flags) AC_ARG_ENABLE(iso-c, AC_HELP_STRING([--enable-iso-c], [Try to warn if code is not ISO C ]),, [enable_iso_c=no]) AC_MSG_CHECKING(what language compliance flags to pass to the C compiler) complCFLAGS= if test "x$enable_iso_c" != "xno"; then if test "x$GCC" = "xyes"; then case " $CFLAGS " in *[\ \ ]-ansi[\ \ ]*) ;; *) complCFLAGS="$complCFLAGS -ansi" ;; esac case " $CFLAGS " in *[\ \ ]-pedantic[\ \ ]*) ;; *) complCFLAGS="$complCFLAGS -pedantic" ;; esac fi fi AC_MSG_RESULT($complCFLAGS) WARN_CFLAGS="$warning_flags $complCFLAGS" AC_SUBST(WARN_CFLAGS) ]) dnl as-ac-expand.m4 0.2.0 -*- autoconf -*- dnl autostars m4 macro for expanding directories using configure's prefix dnl (C) 2003, 2004, 2005 Thomas Vander Stichele dnl Copying and distribution of this file, with or without modification, dnl are permitted in any medium without royalty provided the copyright dnl notice and this notice are preserved. dnl AS_AC_EXPAND(VAR, CONFIGURE_VAR) dnl example: dnl AS_AC_EXPAND(SYSCONFDIR, $sysconfdir) dnl will set SYSCONFDIR to /usr/local/etc if prefix=/usr/local AC_DEFUN([AS_AC_EXPAND], [ EXP_VAR=[$1] FROM_VAR=[$2] dnl first expand prefix and exec_prefix if necessary prefix_save=$prefix exec_prefix_save=$exec_prefix dnl if no prefix given, then use /usr/local, the default prefix if test "x$prefix" = "xNONE"; then prefix="$ac_default_prefix" fi dnl if no exec_prefix given, then use prefix if test "x$exec_prefix" = "xNONE"; then exec_prefix=$prefix fi full_var="$FROM_VAR" dnl loop until it doesn't change anymore while true; do new_full_var="`eval echo $full_var`" if test "x$new_full_var" = "x$full_var"; then break; fi full_var=$new_full_var done dnl clean up full_var=$new_full_var AC_SUBST([$1], "$full_var") dnl restore prefix and exec_prefix prefix=$prefix_save exec_prefix=$exec_prefix_save ]) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/autogen.sh0000775000175000017500000000200200000000000021031 0ustar00jeremyjeremy#!/bin/sh # Run this to generate all the initial makefiles, etc. test -n "$srcdir" || srcdir=$(dirname "$0") test -n "$srcdir" || srcdir=. olddir=$(pwd) cd $srcdir (test -f configure.ac) || { echo "*** ERROR: Directory '$srcdir' does not look like the top-level project directory ***" exit 1 } # shellcheck disable=SC2016 PKG_NAME=$(autoconf --trace 'AC_INIT:$1' configure.ac) if [ "$#" = 0 -a "x$NOCONFIGURE" = "x" ]; then echo "*** WARNING: I am going to run 'configure' with no arguments." >&2 echo "*** If you wish to pass any to it, please specify them on the" >&2 echo "*** '$0' command line." >&2 echo "" >&2 fi aclocal --install || exit 1 glib-gettextize --force --copy || exit 1 intltoolize --force --copy --automake || exit 1 autoreconf --verbose --force --install || exit 1 cd "$olddir" if [ "$NOCONFIGURE" = "" ]; then $srcdir/configure "$@" || exit 1 if [ "$1" = "--help" ]; then exit 0 else echo "Now type 'make' to compile $PKG_NAME" || exit 1 fi else echo "Skipping configure process." fi ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/configure.ac0000664000175000017500000005165100000000000021334 0ustar00jeremyjeremyAC_PREREQ([2.60]) AC_INIT([unity-settings-daemon], [1.0]) AC_CONFIG_SRCDIR([gnome-settings-daemon/gnome-settings-manager.c]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([1.9 tar-ustar dist-xz no-dist-gzip check-news]) AM_MAINTAINER_MODE([enable]) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) m4_define([gsd_api_version_major],[1]) m4_define([gsd_api_version_minor],[0]) m4_define([gsd_api_version],[gsd_api_version_major.gsd_api_version_minor]) GSD_API_VERSION="gsd_api_version" AC_SUBST(GSD_API_VERSION) AC_STDC_HEADERS AC_PROG_CXX AM_PROG_CC_C_O AC_PROG_LIBTOOL AC_HEADER_STDC AC_SUBST(VERSION) AC_CONFIG_HEADERS([config.h]) IT_PROG_INTLTOOL([0.37.1]) GETTEXT_PACKAGE=unity-settings-daemon AC_SUBST(GETTEXT_PACKAGE) AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [Name of default gettext domain]) AM_GLIB_GNU_GETTEXT GSD_INTLTOOL_PLUGIN_RULE='%.gnome-settings-plugin: %.gnome-settings-plugin.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< [$]@' AC_SUBST([GSD_INTLTOOL_PLUGIN_RULE]) dnl --------------------------------------------------------------------------- dnl - Dependencies dnl --------------------------------------------------------------------------- GLIB_REQUIRED_VERSION=2.35.3 GIO_REQUIRED_VERSION=${GLIB_REQUIRED_VERSION} GTK_REQUIRED_VERSION=3.7.8 GCONF_REQUIRED_VERSION=2.6.1 GNOME_DESKTOP_REQUIRED_VERSION=3.7.90 GDK_PIXBUF_REQUIRED_VERSION=2.23.0 LIBNOTIFY_REQUIRED_VERSION=0.7.3 UPOWER_GLIB_REQUIRED_VERSION=0.9.1 PA_REQUIRED_VERSION=2.0 LIBWACOM_REQUIRED_VERSION=0.7 LIBRSVG_REQUIRED_VERSION=2.36.2 UPOWER_REQUIRED_VERSION=0.9.11 IBUS_REQUIRED_VERSION=1.4.99 GSETTINGS_DESKTOP_SCHEMAS_REQUIRED_VERSION=3.7.2.1 GSETTINGS_UNITY_SCHEMAS_REQUIRED_VERSION=0.0.1 XRANDR_REQUIRED_VERSION=1.3 XEXT_REQUIRED_VERSION=1.1 NM_REQUIRED_VERSION=1.0 EXTRA_COMPILE_WARNINGS(yes) PKG_CHECK_MODULES(SETTINGS_DAEMON, gtk+-3.0 >= $GTK_REQUIRED_VERSION gio-2.0 >= $GIO_REQUIRED_VERSION gmodule-2.0 gthread-2.0 gsettings-desktop-schemas >= $GSETTINGS_DESKTOP_SCHEMAS_REQUIRED_VERSION gsettings-unity-schemas >= $GSETTINGS_UNITY_SCHEMAS_REQUIRED_VERSION ) PKG_CHECK_MODULES(SETTINGS_PLUGIN, gtk+-3.0 >= $GTK_REQUIRED_VERSION gio-2.0 >= $GIO_REQUIRED_VERSION libnotify >= $LIBNOTIFY_REQUIRED_VERSION gsettings-desktop-schemas >= $GSETTINGS_DESKTOP_SCHEMAS_REQUIRED_VERSION gsettings-unity-schemas >= $GSETTINGS_UNITY_SCHEMAS_REQUIRED_VERSION x11 ) GSD_PLUGIN_LDFLAGS="-export_dynamic -module -avoid-version -no-undefined" AC_SUBST([GSD_PLUGIN_LDFLAGS]) AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal) AC_PATH_PROG([GLIB_MKENUMS],[glib-mkenums]) dnl ================================================================ dnl GSettings stuff dnl ================================================================ GLIB_GSETTINGS dnl --------------------------------------------------------------------------- dnl - Check for gnome-desktop dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(GNOME_DESKTOP, gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION) dnl --------------------------------------------------------------------------- dnl - Check for LCMS2 dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(LCMS, lcms2 >= 2.2, have_new_lcms=yes, have_new_lcms=no) if test x$have_new_lcms = xyes; then AC_DEFINE(HAVE_NEW_LCMS,1,[Got new lcms2]) else PKG_CHECK_MODULES(LCMS, lcms2) fi dnl --------------------------------------------------------------------------- dnl - Check for libnotify dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= $LIBNOTIFY_REQUIRED_VERSION, [have_libnotify=yes], have_libnotify=no) if test "x$have_libnotify" = xno ; then AC_MSG_ERROR([libnotify is required to build unity-settings-daemon]) fi AC_SUBST(LIBNOTIFY_CFLAGS) AC_SUBST(LIBNOTIFY_LIBS) dnl --------------------------------------------------------------------------- dnl - GUdev integration (default enabled) dnl --------------------------------------------------------------------------- GUDEV_PKG="" AC_ARG_ENABLE(gudev, AS_HELP_STRING([--disable-gudev],[Disable GUdev support (not optional on Linux platforms)]), enable_gudev=$enableval) if test x$enable_gudev != xno; then PKG_CHECK_MODULES(GUDEV, gudev-1.0, have_gudev="yes", have_gudev="no") if test "x$have_gudev" = "xyes"; then AC_DEFINE(HAVE_GUDEV, 1, [define if GUdev is available]) GUDEV_PKG="gudev-1.0" else if test x$enable_gudev = xyes; then AC_MSG_ERROR([GUdev enabled but not found]) fi fi else have_gudev=no fi AM_CONDITIONAL(HAVE_GUDEV, test x$have_gudev = xyes) dnl --------------------------------------------------------------------------- dnl - common dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(COMMON, x11 kbproto xi) dnl --------------------------------------------------------------------------- dnl - libunity-settings-daemon dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(LIBUNITY_SETTINGS_DAEMON, gtk+-3.0 >= $GTK_REQUIRED_VERSION glib-2.0 >= GLIB_REQUIRED_VERSION gio-2.0 >= $GIO_REQUIRED_VERSION gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION gsettings-desktop-schemas >= $GSETTINGS_DESKTOP_SCHEMAS_REQUIRED_VERSION gsettings-unity-schemas >= $GSETTINGS_UNITY_SCHEMAS_REQUIRED_VERSION gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED_VERSION xrandr >= $XRANDR_REQUIRED_VERSION xext >= $XEXT_REQUIRED_VERSION x11) PKG_CHECK_MODULES(CHECK_GL_TEXTURE_SIZE, gl x11) dnl --------------------------------------------------------------------------- dnl - automount dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(AUTOMOUNT, x11 kbproto) dnl --------------------------------------------------------------------------- dnl - XTest dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(XTEST, x11 xtst) AC_SUBST(XTEST_CFLAGS) AC_SUBST(XTEST_LIBS) dnl --------------------------------------------------------------------------- dnl - background dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(BACKGROUND, gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED_VERSION gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION x11) dnl --------------------------------------------------------------------------- dnl - mouse dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(MOUSE, x11 xi) dnl --------------------------------------------------------------------------- dnl - cursor dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(CURSOR, xfixes gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION) dnl --------------------------------------------------------------------------- dnl - xsettings dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(XSETTINGS, fontconfig) dnl --------------------------------------------------------------------------- dnl - Keyboard plugin stuff dnl --------------------------------------------------------------------------- AC_ARG_ENABLE(ibus, AS_HELP_STRING([--disable-ibus], [Disable IBus support]), enable_ibus=$enableval, enable_ibus=yes) if test "x$enable_ibus" = "xyes" ; then IBUS_MODULE="ibus-1.0 >= $IBUS_REQUIRED_VERSION" AC_DEFINE(HAVE_IBUS, 1, [Defined if IBus support is enabled]) else IBUS_MODULE= fi AM_CONDITIONAL(HAVE_IBUS, test "x$enable_ibus" == "xyes") AC_ARG_ENABLE(fcitx, AS_HELP_STRING([--disable-fcitx], [Disable Fcitx support]), enable_fcitx=$enableval, enable_fcitx=yes) if test "x$enable_fcitx" = "xyes" ; then FCITX_MODULE="fcitx-config fcitx-gclient" AC_DEFINE(HAVE_FCITX, 1, [Defined if Fcitx support is enabled]) AC_CHECK_PROG(HAVE_GPERF, gperf, yes) if test "x$HAVE_GPERF" != "xyes" ; then AC_MSG_ERROR([gperf needed for Fcitx support]) fi else FCITX_MODULE= fi AM_CONDITIONAL(HAVE_FCITX, test "x$enable_fcitx" == "xyes") PKG_CHECK_MODULES(KEYBOARD, accountsservice xkbfile xkeyboard-config $IBUS_MODULE $FCITX_MODULE gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION) XKB_BASE=$($PKG_CONFIG --variable xkb_base xkeyboard-config) AC_SUBST(XKB_BASE) dnl --------------------------------------------------------------------------- dnl - Housekeeping plugin stuff dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(GIOUNIX, [gio-unix-2.0]) dnl --------------------------------------------------------------------------- dnl - media-keys plugin stuff dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(MEDIA_KEYS, [gio-unix-2.0 libpulse >= $PA_REQUIRED_VERSION $GUDEV_PKG libpulse-mainloop-glib >= $PA_REQUIRED_VERSION libcanberra-gtk3 libnotify alsa $FCITX_MODULE]) PKG_CHECK_MODULES(GVC, [gobject-2.0 libpulse >= $PA_REQUIRED_VERSION libpulse-mainloop-glib >= $PA_REQUIRED_VERSION]) AM_CONDITIONAL(HAVE_INTROSPECTION, false) dnl --------------------------------------------------------------------------- dnl - xrandr plugin stuff dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(XRANDR, [gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION upower-glib >= $UPOWER_REQUIRED_VERSION]) dnl --------------------------------------------------------------------------- dnl - orientation plugin stuff dnl --------------------------------------------------------------------------- if test x$have_gudev != xno; then PKG_CHECK_MODULES(ORIENTATION, [gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION gudev-1.0]) fi dnl --------------------------------------------------------------------------- dnl - sound plugin stuff dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(SOUND, [libpulse >= $PA_REQUIRED_VERSION $GUDEV_PKG libpulse-mainloop-glib >= $PA_REQUIRED_VERSION]) # --------------------------------------------------------------------------- # Power # --------------------------------------------------------------------------- PKG_CHECK_MODULES(POWER, upower-glib >= $UPOWER_REQUIRED_VERSION gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION $GUDEV_PKG libcanberra-gtk3 libnotify x11 xext xtst) if test x$have_gudev != xno; then PKG_CHECK_MODULES(BACKLIGHT_HELPER, glib-2.0 >= $GLIB_REQUIRED_VERSION gudev-1.0 ) fi dnl --------------------------------------------------------------------------- dnl - color dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(COLOR, [colord >= 0.1.9 gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION libcanberra-gtk3]) dnl --------------------------------------------------------------------------- dnl - wacom (disabled for s390/s390x and non Linux platforms) dnl --------------------------------------------------------------------------- case $host_os in linux*) if test "$host_cpu" = s390 -o "$host_cpu" = s390x; then have_wacom=no else if test x$enable_gudev != xno; then PKG_CHECK_MODULES(WACOM, [libwacom >= $LIBWACOM_REQUIRED_VERSION x11 xi xtst gudev-1.0 gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION xorg-wacom librsvg-2.0 >= $LIBRSVG_REQUIRED_VERSION]) else AC_MSG_ERROR([GUdev is necessary to compile Wacom support]) fi have_wacom=yes fi ;; *) have_wacom=no ;; esac AM_CONDITIONAL(HAVE_WACOM, test x$have_wacom = xyes) dnl ============================================== dnl PackageKit section dnl ============================================== have_packagekit=false AC_ARG_ENABLE(packagekit, AC_HELP_STRING([--disable-packagekit], [turn off PackageKit support]), [case "${enableval}" in yes) WANT_PACKAGEKIT=yes ;; no) WANT_PACKAGEKIT=no ;; *) AC_MSG_ERROR(bad value ${enableval} for --disable-packagekit) ;; esac], [WANT_PACKAGEKIT=yes]) dnl Default value if test x$WANT_PACKAGEKIT = xyes ; then PK_REQUIRED_VERSION=0.7.4 PKG_CHECK_MODULES(PACKAGEKIT, glib-2.0 packagekit-glib2 >= $PK_REQUIRED_VERSION upower-glib >= $UPOWER_REQUIRED_VERSION gudev-1.0 libnotify >= $LIBNOTIFY_REQUIRED_VERSION, [have_packagekit=true AC_DEFINE(HAVE_PACKAGEKIT, 1, [Define if PackageKit should be used])], [have_packagekit=false]) fi AM_CONDITIONAL(HAVE_PACKAGEKIT, test "x$have_packagekit" = "xtrue") AC_SUBST(PACKAGEKIT_CFLAGS) AC_SUBST(PACKAGEKIT_LIBS) dnl ============================================== dnl smartcard section dnl ============================================== have_smartcard_support=false AC_ARG_ENABLE(smartcard-support, AC_HELP_STRING([--disable-smartcard-support], [turn off smartcard support]), [case "${enableval}" in yes) WANT_SMARTCARD_SUPPORT=yes ;; no) WANT_SMARTCARD_SUPPORT=no ;; *) AC_MSG_ERROR(bad value ${enableval} for --disable-smartcard-support) ;; esac], [WANT_SMARTCARD_SUPPORT=no]) if test x$WANT_SMARTCARD_SUPPORT = xyes ; then AC_MSG_ERROR(Smartcard support is broken in this version) NSS_REQUIRED_VERSION=3.11.2 PKG_CHECK_MODULES(NSS, nss >= $NSS_REQUIRED_VERSION, [have_smartcard_support=true AC_DEFINE(SMARTCARD_SUPPORT, 1, [Define if smartcard support should be enabled])], [have_smartcard_support=false]) fi AM_CONDITIONAL(SMARTCARD_SUPPORT, test "x$have_smartcard_support" = "xtrue") AC_SUBST(NSS_CFLAGS) AC_SUBST(NSS_LIBS) AC_ARG_WITH(nssdb, AC_HELP_STRING([--with-nssdb], [where system NSS database is])) NSS_DATABASE="" if test "x$have_smartcard_support" = "xtrue"; then if ! test -z "$with_nssdb" ; then NSS_DATABASE="$with_nssdb" else NSS_DATABASE="${sysconfdir}/pki/nssdb" fi else if ! test -z "$with_nssdb" ; then AC_MSG_WARN([nssdb specified when smartcard support is disabled]) fi fi AC_SUBST(NSS_DATABASE) dnl --------------------------------------------------------------------------- dnl Sharing plugin dnl --------------------------------------------------------------------------- AC_ARG_ENABLE(network-manager, AS_HELP_STRING([--disable-network-manager], [Disable NetworkManager support]), enable_network_manager=$enableval, enable_network_manager=yes) if test "x$enable_network_manager" = "xyes" ; then NM_MODULE="libnm >= $NM_REQUIRED_VERSION" AC_DEFINE(HAVE_NETWORK_MANAGER, 1, [Defined if NetworkManager support is enabled]) else NM_MODULE= fi PKG_CHECK_MODULES(SHARING, gio-2.0 $NM_MODULE) # --------------------------------------------------------------------------- # Rfkill # --------------------------------------------------------------------------- AC_ARG_ENABLE(rfkill, AS_HELP_STRING([--disable-rfkill], [disable rfkill support (default: enabled)]),, enable_rfkill=yes, enabled_rfkill=no) if test x"$enable_rfkill" != x"no" ; then AC_CHECK_HEADERS([linux/rfkill.h],, AC_MSG_ERROR([RFKill headers not found but rfkill support requested])) fi AM_CONDITIONAL(BUILD_RFKILL, [test x"$enable_rfkill" = x"yes"]) # --------------------------------------------------------------------------- # Enable Profiling # --------------------------------------------------------------------------- AC_ARG_ENABLE(profiling, [AC_HELP_STRING([--enable-profiling], [turn on profiling])], , enable_profiling=no) if test "x$enable_profiling" = "xyes"; then AC_DEFINE(ENABLE_PROFILING,1,[enable profiling]) fi # --------------------------------------------------------------------------- # Plugins # --------------------------------------------------------------------------- plugindir='$(libdir)/unity-settings-daemon-gsd_api_version' AC_SUBST([plugindir]) PLUGIN_CFLAGS="-DG_LOG_DOMAIN=\"\\\"\$(plugin_name)-plugin\\\"\" -DPLUGIN_NAME=\"\\\"\$(plugin_name)\\\"\" " AC_SUBST(PLUGIN_CFLAGS) AC_ARG_ENABLE(man, [AS_HELP_STRING([--enable-man], [generate man pages [default=yes]])],, enable_man=yes) if test "$enable_man" != no; then AC_PATH_PROG([XSLTPROC], [xsltproc]) if test -z "$XSLTPROC"; then AC_MSG_ERROR([xsltproc is required for --enable-man]) fi fi AM_CONDITIONAL(ENABLE_MAN, test "$enable_man" != no) dnl --------------------------------------------------------------------------- dnl - Finish dnl --------------------------------------------------------------------------- # Turn on the additional warnings last, so warnings don't affect other tests. AC_ARG_ENABLE(more-warnings, [AC_HELP_STRING([--enable-more-warnings], [Maximum compiler warnings])], set_more_warnings="$enableval",[ if test -d $srcdir/.git; then set_more_warnings=yes else set_more_warnings=no fi ]) AC_MSG_CHECKING(for more warnings) if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then AC_MSG_RESULT(yes) CFLAGS="\ -Wall \ -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes \ -Wnested-externs -Wpointer-arith \ -Wcast-align -Wsign-compare \ $CFLAGS" for option in -Wno-strict-aliasing -Wno-sign-compare; do SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $option" AC_MSG_CHECKING([whether gcc understands $option]) AC_TRY_COMPILE([], [], has_option=yes, has_option=no,) if test $has_option = no; then CFLAGS="$SAVE_CFLAGS" fi AC_MSG_RESULT($has_option) unset has_option unset SAVE_CFLAGS done unset option else AC_MSG_RESULT(no) fi # # Enable Debug # AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug], [turn on debugging])], , enable_debug=yes) if test "$enable_debug" = "yes"; then DEBUG_CFLAGS="-DG_ENABLE_DEBUG" else if test "x$enable_debug" = "xno"; then DEBUG_CFLAGS="-DG_DISABLE_ASSERT -DG_DISABLE_CHECKS" else DEBUG_CFLAGS="" fi fi AC_SUBST(DEBUG_CFLAGS) AC_OUTPUT([ Makefile gnome-settings-daemon/Makefile plugins/Makefile plugins/a11y-keyboard/Makefile plugins/a11y-settings/Makefile plugins/automount/Makefile plugins/background/Makefile plugins/clipboard/Makefile plugins/color/Makefile plugins/common/Makefile plugins/cursor/Makefile plugins/dummy/Makefile plugins/power/Makefile plugins/housekeeping/Makefile plugins/keyboard/Makefile plugins/media-keys/Makefile plugins/media-keys/gvc/Makefile plugins/mouse/Makefile plugins/orientation/Makefile plugins/remote-display/Makefile plugins/rfkill/Makefile plugins/screensaver-proxy/Makefile plugins/sharing/Makefile plugins/smartcard/Makefile plugins/sound/Makefile plugins/updates/Makefile plugins/wacom/Makefile plugins/xrandr/Makefile plugins/xsettings/Makefile data/Makefile data/unity-settings-daemon.pc data/unity-settings-daemon-uninstalled.pc data/libunity-settings-daemon.pc po/Makefile.in man/Makefile tests/Makefile ]) dnl --------------------------------------------------------------------------- dnl - Show summary dnl --------------------------------------------------------------------------- echo " untiy-settings-daemon $VERSION ============================= prefix: ${prefix} exec_prefix: ${exec_prefix} libdir: ${libdir} bindir: ${bindir} sbindir: ${sbindir} sysconfdir: ${sysconfdir} sysconfsubdir: ${sysconfsubdir} localstatedir: ${localstatedir} plugindir: ${plugindir} datadir: ${datadir} source code location: ${srcdir} compiler: ${CC} cflags: ${CFLAGS} Maintainer mode: ${USE_MAINTAINER_MODE} Session tracking: ${SESSION_TRACKING} LCMS DICT support: ${have_new_lcms} NetworkManager support: ${enable_network_manager} IBus support: ${enable_ibus} Fcitx support: ${enable_fcitx} Libnotify support: ${have_libnotify} PackageKit support: ${have_packagekit} Smartcard support: ${have_smartcard_support} Cups support: ${enable_cups} Wacom support: ${have_wacom} RFKill support: ${enable_rfkill} ${NSS_DATABASE:+\ System nssdb: ${NSS_DATABASE} }\ Profiling support: ${enable_profiling} " ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1644246191.563767 unity-settings-daemon-15.04.1+21.10.20220207/data/0000775000175000017500000000000000000000000017747 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/Makefile.am0000664000175000017500000000457700000000000022020 0ustar00jeremyjeremyNULL = apidir = $(includedir)/unity-settings-daemon-$(GSD_API_VERSION)/unity-settings-daemon api_DATA = gsd-enums.h gsettings_ENUM_NAMESPACE = com.canonical.unity.settings-daemon gsettings_ENUM_FILES = $(top_srcdir)/data/$(api_DATA) gschema_in_files = \ com.canonical.unity.settings-daemon.peripherals.gschema.xml.in.in \ com.canonical.unity.settings-daemon.peripherals.wacom.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.color.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.datetime.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.housekeeping.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.keyboard.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.media-keys.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.orientation.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.power.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.print-notifications.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.sharing.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.xrandr.gschema.xml.in.in \ com.canonical.unity.settings-daemon.plugins.xsettings.gschema.xml.in.in gsettings_SCHEMAS = $(gschema_in_files:.xml.in.in=.xml) gsettingsdir = $(datadir)/glib-2.0/schemas %.gschema.xml.in: %.gschema.xml.in.in $(AM_V_GEN) sed -e "s|\@GETTEXT_PACKAGE\@|$(GETTEXT_PACKAGE)|g" $< > $@ @INTLTOOL_XML_NOMERGE_RULE@ @GSETTINGS_RULES@ @INTLTOOL_DESKTOP_RULE@ desktopdir = $(sysconfdir)/xdg/autostart desktop_in_files = unity-settings-daemon.desktop.in.in desktop_DATA = $(desktop_in_files:.desktop.in.in=.desktop) unity-settings-daemon.desktop.in: unity-settings-daemon.desktop.in.in $(AM_V_GEN) sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@.tmp && mv $@.tmp $@ pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = unity-settings-daemon.pc libunity-settings-daemon.pc @INTLTOOL_XML_NOMERGE_RULE@ EXTRA_DIST = \ $(convert_DATA) \ $(gschema_in_files) \ $(desktop_in_files) \ $(gsettings_ENUM_FILES) \ unity-settings-daemon.pc.in \ libunity-settings-daemon.pc.in \ $(api_DATA) \ $(NULL) DISTCLEANFILES = \ $(desktop_DATA) \ unity-settings-daemon.desktop.in \ $(NULL) MAINTAINERCLEANFILES = \ *~ \ Makefile.in \ $(gsettings_SCHEMAS:.xml=.valid) ././@PaxHeader0000000000000000000000000000023100000000000010211 xustar00125 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.peripherals.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.peripherals.gs0000664000175000017500000002271400000000000031600 0ustar00jeremyjeremy 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 'none' Smartcard removal action Set this to one of “none”, “lock-screen”, or “force-logout”. The action will get performed when the smartcard used for log in is removed. true 0 'on' Possible values are “on”, “off”, and “custom”. 400 100 '' Keyboard Bell Custom Filename File name of the bell sound to be played. true Remember NumLock state When set to true, GNOME will remember the state of the NumLock LED between sessions. 'unknown' NumLock state The remembered state of the NumLock LED. false Highlights the current location of the pointer when the Control key is pressed and released. 400 Double click time Length of a double click in milliseconds. 8 Drag threshold Distance before a drag is started. 'two-finger-scrolling' Select the touchpad scroll method Select the touchpad scroll method. Supported values are: “disabled”, “edge-scrolling”, “two-finger-scrolling”. false Whether the tablet’s orientation is locked, or rotated automatically. '' Device hotplug custom command Command to be run when a device is added or removed. An exit value of 1 means that the device will not be handled further by gnome-settings-daemon. false Mouse button orientation Swap left and right mouse buttons for left-handed mice. -1 Single Click Acceleration multiplier for mouse motion. A value of -1 is the system default. -1 Motion Threshold Distance in pixels the pointer must move before accelerated mouse motion is activated. A value of -1 is the system default. false Middle button emulation Enables middle mouse button emulation through simultaneous left and right button click. true 30 Key Repeat Interval Delay between repeats in milliseconds. 500 Initial Key Repeat Delay Initial key repeat delay in milliseconds. false Disable touchpad while typing Set this to TRUE if you have problems with accidentally hitting the touchpad while typing. true Enable horizontal scrolling Set this to TRUE to allow horizontal scrolling by the same method selected with the scroll_method key. false Enable mouse clicks with touchpad Set this to TRUE to be able to send mouse clicks by tapping on the touchpad. true Enable touchpad Set this to TRUE to enable all touchpads. 'mouse' Touchpad button orientation Swap left and right mouse buttons for left-handed mice with “left”, “right” for right-handed, “mouse” to follow the mouse setting. -1 Single Click Acceleration multiplier for mouse motion. A value of -1 is the system default. -1 Motion Threshold Distance in pixels the pointer must move before accelerated mouse motion is activated. A value of -1 is the system default. false Natural scrolling Set this to TRUE to enable natural (reverse) scrolling for touchpads. 0 Mouse wheel emulation button. 0 to disable the feature. ././@PaxHeader0000000000000000000000000000023700000000000010217 xustar00131 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.peripherals.wacom.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.peripherals.wa0000664000175000017500000002454100000000000031576 0ustar00jeremyjeremy true Wacom stylus absolute mode Enable this to set the tablet to absolute mode. [-1, -1, -1, -1] Wacom tablet area Set this to x1, y1 and x2, y2 of the area usable by the tools. false Wacom tablet aspect ratio Enable this to restrict the Wacom tablet area to match the aspect ratio of the output. 'none' Wacom tablet rotation Set this to “none”, “cw” for 90 degree clockwise, “half” for 180 degree, and “ccw” for 90 degree counterclockwise. true Wacom touch feature Enable this to move the cursor when the user touches the tablet. [0, 0, 100, 100] Wacom stylus pressure curve Set this to x1, y1 and x2, y2 of the pressure curve applied to the stylus. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] Wacom stylus button mapping Set this to the logical button mapping. -1 Wacom stylus pressure threshold Set this to the pressure value at which a stylus click event is generated. [0, 0, 100, 100] Wacom eraser pressure curve Set this to x1, y1 and x2, y2 of the pressure curve applied to the eraser. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] Wacom eraser button mapping Set this to the logical button mapping. -1 Wacom eraser pressure threshold Set this to the pressure value at which an eraser click event is generated. 'none' Wacom button action type The type of action triggered by the button being pressed. '' Key combination for the custom action The keyboard shortcut generated when the button is pressed for custom actions. ['', ''] Key combinations for a touchring or touchstrip custom action The keyboard shortcuts generated when a touchring or touchstrip is used for custom actions (up followed by down). '' Button label for OLED display. Label will be rendered to OLED display belonging to the button ["", "", ""] 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not true Wacom stylus absolute mode Enable this to set the tablet to absolute mode for unity-settings-daemon. [-1, -1, -1, -1] Wacom tablet area Set this to x1, y1 and x2, y2 of the area usable by the tools. false Wacom tablet aspect ratio Enable this to restrict the Wacom tablet area to match the aspect ratio of the output. 'none' Wacom tablet rotation Set this to “none”, “cw” for 90 degree clockwise, “half” for 180 degree, and “ccw” for 90 degree counterclockwise. true Wacom touch feature Enable this to move the cursor when the user touches the tablet. false Wacom tablet PC feature Enable this to only report stylus events when the tip is pressed. ["", "", ""] Wacom display mapping EDID information of monitor to map tablet to. Must be in the format [vendor, product, serial]. ["","",""] disables mapping. [0, 0, 100, 100] Wacom stylus pressure curve Set this to x1, y1 and x2, y2 of the pressure curve applied to the stylus. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] Wacom stylus button mapping Set this to the logical button mapping. -1 Wacom stylus pressure threshold Set this to the pressure value at which a stylus click event is generated. [0, 0, 100, 100] Wacom eraser pressure curve Set this to x1, y1 and x2, y2 of the pressure curve applied to the eraser. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] Wacom eraser button mapping Set this to the logical button mapping. -1 Wacom eraser pressure threshold Set this to the pressure value at which an eraser click event is generated. 'none' Wacom button action type The type of action triggered by the button being pressed. '' Key combination for the custom action The keyboard shortcut generated when the button is pressed for custom actions. ['', ''] Key combinations for a touchring or touchstrip custom action The keyboard shortcuts generated when a touchring or touchstrip is used for custom actions (up followed by down). ././@PaxHeader0000000000000000000000000000023300000000000010213 xustar00127 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.color.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.color.0000664000175000017500000000570600000000000031530 0ustar00jeremyjeremy 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 0 The duration a display profile is valid This is the number of days after which the display color profile is considered invalid. 0 The duration a printer profile is valid This is the number of days after which the printer color profile is considered invalid. false If the night light mode is enabled Night light mode changes the color temperature of your display when the sun has gone down or at preset times. 4000 Temperature of the display when enabled This temperature in Kelvin is used to modify the screen tones when night light mode is enabled. Higher values are bluer, lower redder. true Use the sunrise and sunset Calculate the sunrise and sunset times automatically, from the current location. 20.00 The start time When “night-light-schedule-automatic” is disabled, use this start time in hours from midnight. 6.00 The end time When “night-light-schedule-automatic” is disabled, use this end time in hours from midnight. (91,181) The last detected position When location services are available this represents the last detected location. The default value is an invalid value to ensure it is always updated at startup. ././@PaxHeader0000000000000000000000000000023600000000000010216 xustar00130 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.datetime.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.dateti0000664000175000017500000000130200000000000031572 0ustar00jeremyjeremy 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not ././@PaxHeader0000000000000000000000000000022500000000000010214 xustar00121 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.gschem0000664000175000017500000002277400000000000031606 0ustar00jeremyjeremy ['all'] List of plugins that are allowed to be loaded A list of strings representing the plugins that are allowed to be loaded (default: “all”). This is only evaluated on startup. 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not ././@PaxHeader0000000000000000000000000000024200000000000010213 xustar00134 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.housekeeping.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.housek0000664000175000017500000000422400000000000031624 0ustar00jeremyjeremy 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not [] Mount paths to ignore Specify a list of mount paths to ignore when they run low on space. 0.05 Free percentage notify threshold Percentage free space threshold for initial warning of low disk space. If the percentage free space drops below this, a warning will be shown. 0.01 Subsequent free space percentage notify threshold Specify the percentage that the free disk space should reduce by before issuing a subsequent warning. 1 Free space notify threshold Specify an amount in GB. If the amount of free space is more than this, no warning will be shown. 10 Minimum notify period for repeated warnings Specify a time in minutes. Subsequent warnings for a volume will not appear more often than this period. ././@PaxHeader0000000000000000000000000000023600000000000010216 xustar00130 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.keyboard.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.keyboa0000664000175000017500000000130200000000000031572 0ustar00jeremyjeremy 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not ././@PaxHeader0000000000000000000000000000024000000000000010211 xustar00132 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.media-keys.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.media-0000664000175000017500000002231100000000000031457 0ustar00jeremyjeremy 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not [] Custom keybindings List of custom keybindings 'XF86Calculator' Launch calculator Binding to launch the calculator. 'XF86Tools' Launch settings Binding to launch GNOME settings. 'XF86Mail' Launch email client Binding to launch the email client. 'XF86Eject' Eject Binding to eject an optical disc. '' Launch help browser Binding to launch the help browser. 'XF86Explorer' Home folder Binding to open the Home folder. 'XF86AudioMedia' Launch media player Binding to launch the media player. 'XF86AudioNext' Next track Binding to skip to next track. 'XF86AudioPause' Pause playback Binding to pause playback. 'XF86AudioPlay' Play (or play/pause) Binding to start playback (or toggle play/pause). '<Control><Alt>Delete' Log out Binding to log out. 'XF86AudioPrev' Previous track Binding to skip to previous track. '<Control><Alt>l' Lock screen Binding to lock the screen. 'XF86Search' Search Binding to launch the search tool. 'XF86AudioStop' Stop playback Binding to stop playback. '<Super>p' Video output Binding to switch the video output device. 'XF86AudioLowerVolume' Volume down Binding to lower the volume. 'XF86AudioMute' Volume mute/unmute Binding to mute/unmute the volume. 'XF86AudioRaiseVolume' Volume up Binding to raise the volume. 'XF86AudioMicMute' Microphone mute/unmute Binding to mute/unmute the microphone. 'Print' Take a screenshot Binding to take a screenshot. '<Alt>Print' Take a screenshot of a window Binding to take a screenshot of a window. '<Shift>Print' Take a screenshot of an area Binding to take a screenshot of an area. '<Ctrl>Print' Copy a screenshot to clipboard Binding to copy a screenshot to clipboard. '<Ctrl><Alt>Print' Copy a screenshot of a window to clipboard Binding to copy a screenshot of a window to clipboard. '<Ctrl><Shift>Print' Copy a screenshot of an area to clipboard Binding to copy a screenshot of an area to clipboard. '<Ctrl><Shift><Alt>R' Record a short video of the screen Binding to record a short video of the screen '<Primary><Alt>t' Launch terminal Binding to launch the terminal. 'XF86WWW' Launch web browser Binding to launch the web browser. '<Alt><Super>8' Toggle magnifier Binding to show the screen magnifier '<Alt><Super>s' Toggle screen reader Binding to start the screen reader '' Toggle on-screen keyboard Binding to show the on-screen keyboard '' Increase text size Binding to increase the text size '' Decrease text size Binding to decrease the text size '' Toggle contrast Binding to toggle the interface contrast '<Alt><Super>equal' Magnifier zoom in Binding for the magnifier to zoom in '<Alt><Super>minus' Magnifier zoom out Binding for the magnifier to zoom out 30 Maximum length of screen recordings The maximum length of single screen cast recordings in seconds or 0 for unlimited '' Name Name of the custom binding '' Binding Binding for the custom binding '' Command Command to run when the binding is invoked ././@PaxHeader0000000000000000000000000000024100000000000010212 xustar00133 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.orientation.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.orient0000664000175000017500000000131000000000000031617 0ustar00jeremyjeremy 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not ././@PaxHeader0000000000000000000000000000023300000000000010213 xustar00127 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.power.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.power.0000664000175000017500000002056100000000000031542 0ustar00jeremyjeremy 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 30 The brightness of the screen when idle This is the laptop panel screen brightness used when the session is idle. true Dim the screen after a period of inactivity If the screen should be dimmed to save power when the computer is idle. 1200 Sleep timeout computer when on AC The amount of time in seconds the computer on AC power needs to be inactive before it goes to sleep. A value of 0 means never. 'suspend' Whether to hibernate, suspend or do nothing when inactive The type of sleeping that should be performed when the computer is inactive. 1200 Sleep timeout computer when on battery The amount of time in seconds the computer on battery power needs to be inactive before it goes to sleep. A value of 0 means never. 'suspend' Whether to hibernate, suspend or do nothing when inactive The type of sleeping that should be performed when the computer is inactive. 'suspend' Laptop lid close action on battery The action to take when the laptop lid is closed and the laptop is on battery power. 'suspend' Laptop lid close action when on AC The action to take when the laptop lid is closed and the laptop is on AC power. false Laptop lid, when closed, will suspend even if there is an external monitor plugged in With no external monitors plugged in, closing a laptop's lid will suspend the machine (as set by the lid-close-battery-action and lid-close-ac-action keys). By default, however, closing the lid when an external monitor is present will not suspend the machine, so that one can keep working on that monitor (e.g. for docking stations or media viewers). Set this key to False to keep the default behavior, or to True to suspend the laptop whenever the lid is closed and regardless of external monitors. true Enable the ALS sensor If the ambient light sensor functionality is enabled. 'suspend' Power button action The action to take when the system power button is pressed. This action is hard-coded (and the setting ignored) on virtual machines (power off) and tablets (suspend). 'suspend' Suspend button action The action to take when the system suspend button is pressed. 'hibernate' Hibernate button action The action to take when the system hibernate button is pressed. 'hibernate' Sleep button action The action to take when the system sleep (non-specific type) button is pressed. 'interactive' Power button action The action to take when the system power button is pressed. 'hibernate' Battery critical low action The action to take when the battery is critically low. 10 Percentage considered low The percentage of the battery when it is considered low. Only valid when use-time-for-policy is false. 3 Percentage considered critical The percentage of the battery when it is considered critical. Only valid when use-time-for-policy is false. 2 Percentage action is taken The percentage of the battery when the critical action is performed. Only valid when use-time-for-policy is false. 1200 The time remaining when low The time remaining in seconds of the battery when it is considered low. Only valid when use-time-for-policy is true. 300 The time remaining when critical The time remaining in seconds of the battery when it is considered critical. Only valid when use-time-for-policy is true. 120 The time remaining when action is taken The time remaining in seconds of the battery when critical action is taken. Only valid when use-time-for-policy is true. true Whether to use time-based notifications If time based notifications should be used. If set to false, then the percentage change is used instead, which may fix a broken ACPI BIOS. true If we should show the recalled battery warning for a broken battery If we should show the recalled battery warning for a broken battery. Set this to false only if you know your battery is okay. ././@PaxHeader0000000000000000000000000000025100000000000010213 xustar00141 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.print-notifications.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.print-0000664000175000017500000000133000000000000031532 0ustar00jeremyjeremy 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not ././@PaxHeader0000000000000000000000000000023500000000000010215 xustar00129 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.sharing.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.sharin0000664000175000017500000000216100000000000031610 0ustar00jeremyjeremy 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not [] On which connections the service is enabled The list of NetworkManager connections (each one represented with its UUID) on which this service is enabled and started. ././@PaxHeader0000000000000000000000000000023400000000000010214 xustar00128 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.xrandr.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.xrandr0000664000175000017500000000355400000000000031631 0ustar00jeremyjeremy '/etc/gnome-settings-daemon/xrandr/monitors.xml' File for default configuration for RandR The XRandR plugin will look for a default configuration in the file specified by this key. This is similar to the ~/.config/monitors.xml that normally gets stored in users’ home directories. If a user does not have such a file, or has one that does not match the user’s setup of monitors, then the file specified by this key will be used instead. 'follow-lid' Whether to turn off specific monitors after boot “clone” will display the same thing on all monitors, “dock” will switch off the internal monitor, “do-nothing” will use the default Xorg behaviour (extend the desktop in recent versions). The default, “follow-lid”, will choose between “do-nothing” and “dock” depending on whether the lid is (respectively) open or closed. 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not ././@PaxHeader0000000000000000000000000000023700000000000010217 xustar00131 path=unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.xsettings.gschema.xml.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/com.canonical.unity.settings-daemon.plugins.xsetti0000664000175000017500000000667100000000000031656 0ustar00jeremyjeremy 0 Priority to use for this plugin Priority to use for this plugin in unity-settings-daemon startup queue true Activation of this plugin Whether this plugin would be activated by unity-settings-daemon or not 'grayscale' Antialiasing The type of antialiasing to use when rendering fonts. Possible values are: “none” for no antialiasing, “grayscale” for standard grayscale antialiasing, and “rgba” for subpixel antialiasing (LCD screens only). 'slight' Hinting The type of hinting to use when rendering fonts. Possible values are: “none” for no hinting and “slight” for fitting only to the Y-axis like Microsoft’s ClearType, DirectWrite and Adobe’s proprietary font rendering engine. Ignores native hinting within the font, generates hints algorithmically. Used on Ubuntu by default. Recommended. The meaning of “medium” and “full” depends on the font format (.ttf, .otf, .pfa/.pfb) and the installed version of FreeType. They usually try to fit glyphs to both the X and the Y axis (except for .otf: Y-only). This can lead to distortion and/or inconsistent rendering depending on the quality of the font, the font format and the state of FreeType’s font engines. 'rgb' RGBA order The order of subpixel elements on an LCD screen; only used when antialiasing is set to “rgba”. Possible values are: “rgb” for red on left (most common), “bgr” for blue on left, “vrgb” for red on top, “vbgr” for red on bottom. [] List of explicitly disabled GTK+ modules A list of strings representing the GTK+ modules that will not be loaded, even if enabled by default in their configuration. [] List of explicitly enabled GTK+ modules A list of strings representing the GTK+ modules that will be loaded, usually in addition to conditional and forcibly disabled ones. {} A dictionary of XSETTINGS to override This dictionary maps XSETTINGS names to overrides values. The values must be either strings, signed int32s or (in the case of colors), 4-tuples of uint16 (red, green, blue, alpha; 65535 is fully opaque). ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/gnome-settings-daemon.convert0000664000175000017500000001234700000000000025564 0ustar00jeremyjeremy[com.canonical.unity.settings-daemon.peripherals.smartcard] removal-action = /desktop/gnome/peripherals/smartcard/removal_action [com.canonical.unity.settings-daemon.peripherals.touchpad] disable-while-typing = /desktop/gnome/peripherals/touchpad/disable_while_typing horiz-scroll-enabled = /desktop/gnome/peripherals/touchpad/horiz_scroll_enabled scroll-method = /desktop/gnome/peripherals/touchpad/scroll_method tap-to-click = /desktop/gnome/peripherals/touchpad/tap_to_click touchpad-enabled = /desktop/gnome/peripherals/touchpad/touchpad_enabled motion-acceleration = /desktop/gnome/peripherals/mouse/motion_acceleration motion-threshold = /desktop/gnome/peripherals/mouse/motion_threshold [com.canonical.unity.settings-daemon.plugins.a11y-keyboard] active = /apps/gnome_settings_daemon/plugins/a11y-keyboard/active priority = /apps/gnome_settings_daemon/plugins/a11y-keyboard/priority [com.canonical.unity.settings-daemon.plugins.background] active = /apps/gnome_settings_daemon/plugins/background/active priority = /apps/gnome_settings_daemon/plugins/background/priority [com.canonical.unity.settings-daemon.plugins.clipboard] active = /apps/gnome_settings_daemon/plugins/clipboard/active priority = /apps/gnome_settings_daemon/plugins/clipboard/priority [com.canonical.unity.settings-daemon.plugins.font] active = /apps/gnome_settings_daemon/plugins/font/active priority = /apps/gnome_settings_daemon/plugins/font/priority [com.canonical.unity.settings-daemon.plugins.housekeeping] active = /apps/gnome_settings_daemon/plugins/housekeeping/active free-percent-notify = /apps/gnome_settings_daemon/plugins/housekeeping/free_percent_notify free-percent-notify-again = /apps/gnome_settings_daemon/plugins/housekeeping/free_percent_notify_again free-size-gb-no-notify = /apps/gnome_settings_daemon/plugins/housekeeping/free_size_gb_no_notify ignore-paths = /apps/gnome_settings_daemon/plugins/housekeeping/ignore_paths min-notify-period = /apps/gnome_settings_daemon/plugins/housekeeping/min_notify_period priority = /apps/gnome_settings_daemon/plugins/housekeeping/priority [com.canonical.unity.settings-daemon.plugins.keyboard] active = /apps/gnome_settings_daemon/plugins/keyboard/active priority = /apps/gnome_settings_daemon/plugins/keyboard/priority [com.canonical.unity.settings-daemon.plugins.media-keys] active = /apps/gnome_settings_daemon/plugins/keybindings/active calculator = /apps/gnome_settings_daemon/keybindings/calculator email = /apps/gnome_settings_daemon/keybindings/email eject = /apps/gnome_settings_daemon/keybindings/eject help = /apps/gnome_settings_daemon/keybindings/help home = /apps/gnome_settings_daemon/keybindings/home logout = /apps/gnome_settings_daemon/keybindings/power media = /apps/gnome_settings_daemon/keybindings/media next = /apps/gnome_settings_daemon/keybindings/next pause = /apps/gnome_settings_daemon/keybindings/pause play = /apps/gnome_settings_daemon/keybindings/play previous = /apps/gnome_settings_daemon/keybindings/previous priority = /apps/gnome_settings_daemon/plugins/keybindings/priority screensaver = /apps/gnome_settings_daemon/keybindings/screensaver search = /apps/gnome_settings_daemon/keybindings/search stop = /apps/gnome_settings_daemon/keybindings/stop touchpad = /apps/gnome_settings_daemon/keybindings/touchpad volume-down = /apps/gnome_settings_daemon/keybindings/volume_down volume-mute = /apps/gnome_settings_daemon/keybindings/volume_mute volume-up = /apps/gnome_settings_daemon/keybindings/volume_up www = /apps/gnome_settings_daemon/keybindings/www screenshot = /apps/metacity/global_keybindings/run_command_screenshot window-screenshot = /apps/metacity/global_keybindings/run_command_window_screenshot terminal = /apps/metacity/global_keybindings/run_command_terminal [com.canonical.unity.settings-daemon.plugins.mouse] active = /apps/gnome_settings_daemon/plugins/mouse/active priority = /apps/gnome_settings_daemon/plugins/mouse/priority [com.canonical.unity.settings-daemon.peripherals.mouse] locate-pointer = /desktop/gnome/peripherals/mouse/locate_pointer double-click = /desktop/gnome/peripherals/mouse/double_click drag-threshold = /desktop/gnome/peripherals/mouse/drag_threshold left-handed = /desktop/gnome/peripherals/mouse/left_handed motion-acceleration = /desktop/gnome/peripherals/mouse/motion_acceleration motion-threshold = /desktop/gnome/peripherals/mouse/motion_threshold [com.canonical.unity.settings-daemon.plugins.smartcard] active = /apps/gnome_settings_daemon/plugins/smartcard/active priority = /apps/gnome_settings_daemon/plugins/smartcard/priority [com.canonical.unity.settings-daemon.plugins.sound] active = /apps/gnome_settings_daemon/plugins/sound/active priority = /apps/gnome_settings_daemon/plugins/sound/priority [com.canonical.unity.settings-daemon.plugins.xrandr] active = /apps/gnome_settings_daemon/plugins/xrandr/active default-configuration-file = /apps/gnome_settings_daemon/xrandr/default_configuration_file priority = /apps/gnome_settings_daemon/plugins/xrandr/priority [com.canonical.unity.settings-daemon.plugins.xsettings] active = /apps/gnome_settings_daemon/plugins/xsettings/active antialiasing = /desktop/gnome/font_rendering/antialiasing hinting = /desktop/gnome/font_rendering/hinting priority = /apps/gnome_settings_daemon/plugins/xsettings/priority rgba-order = /desktop/gnome/font_rendering/rgba_order ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/gsd-enums.h0000664000175000017500000000765000000000000022032 0ustar00jeremyjeremy/* * Copyright © 2010 Bastien Nocera * * 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. * * Authors: * Bastien Nocera */ #ifndef __gsd_enums_h__ #define __gsd_enums_h__ typedef enum { GSD_FONT_ANTIALIASING_MODE_NONE, GSD_FONT_ANTIALIASING_MODE_GRAYSCALE, GSD_FONT_ANTIALIASING_MODE_RGBA } GsdFontAntialiasingMode; typedef enum { GSD_FONT_HINTING_NONE, GSD_FONT_HINTING_SLIGHT, GSD_FONT_HINTING_MEDIUM, GSD_FONT_HINTING_FULL } GsdFontHinting; typedef enum { GSD_FONT_RGBA_ORDER_RGBA, GSD_FONT_RGBA_ORDER_RGB, GSD_FONT_RGBA_ORDER_BGR, GSD_FONT_RGBA_ORDER_VRGB, GSD_FONT_RGBA_ORDER_VBGR } GsdFontRgbaOrder; typedef enum { GSD_SMARTCARD_REMOVAL_ACTION_NONE, GSD_SMARTCARD_REMOVAL_ACTION_LOCK_SCREEN, GSD_SMARTCARD_REMOVAL_ACTION_FORCE_LOGOUT } GsdSmartcardRemovalAction; typedef enum { GSD_TOUCHPAD_SCROLL_METHOD_DISABLED, GSD_TOUCHPAD_SCROLL_METHOD_EDGE_SCROLLING, GSD_TOUCHPAD_SCROLL_METHOD_TWO_FINGER_SCROLLING } GsdTouchpadScrollMethod; typedef enum { GSD_BELL_MODE_ON, GSD_BELL_MODE_OFF, GSD_BELL_MODE_CUSTOM } GsdBellMode; typedef enum { GSD_TOUCHPAD_HANDEDNESS_RIGHT, GSD_TOUCHPAD_HANDEDNESS_LEFT, GSD_TOUCHPAD_HANDEDNESS_MOUSE } GsdTouchpadHandedness; typedef enum { GSD_XRANDR_BOOT_BEHAVIOUR_DO_NOTHING, GSD_XRANDR_BOOT_BEHAVIOUR_CLONE, GSD_XRANDR_BOOT_BEHAVIOUR_DOCK, GSD_XRANDR_BOOT_BEHAVIOUR_FOLLOW_LID } GsdXrandrBootBehaviour; typedef enum { GSD_WACOM_ROTATION_NONE, GSD_WACOM_ROTATION_CW, GSD_WACOM_ROTATION_CCW, GSD_WACOM_ROTATION_HALF } GsdWacomRotation; typedef enum { GSD_WACOM_ACTION_TYPE_NONE, GSD_WACOM_ACTION_TYPE_CUSTOM, GSD_WACOM_ACTION_TYPE_SWITCH_MONITOR, GSD_WACOM_ACTION_TYPE_HELP } GsdWacomActionType; typedef enum { GSD_POWER_ACTION_BLANK, GSD_POWER_ACTION_SUSPEND, GSD_POWER_ACTION_SHUTDOWN, GSD_POWER_ACTION_HIBERNATE, GSD_POWER_ACTION_INTERACTIVE, GSD_POWER_ACTION_NOTHING, GSD_POWER_ACTION_LOGOUT, } GsdPowerActionType; typedef enum { GSD_POWER_BUTTON_ACTION_NOTHING, GSD_POWER_BUTTON_ACTION_SUSPEND, GSD_POWER_BUTTON_ACTION_HIBERNATE, GSD_POWER_BUTTON_ACTION_INTERACTIVE } GsdPowerButtonActionType; typedef enum { GSD_UPDATE_TYPE_ALL, GSD_UPDATE_TYPE_SECURITY, GSD_UPDATE_TYPE_NONE } GsdUpdateType; typedef enum { GSD_NUM_LOCK_STATE_UNKNOWN, GSD_NUM_LOCK_STATE_ON, GSD_NUM_LOCK_STATE_OFF } GsdNumLockState; typedef enum { GSD_INPUT_SOURCES_SWITCHER_OFF, GSD_INPUT_SOURCES_SWITCHER_SHIFT_L, GSD_INPUT_SOURCES_SWITCHER_ALT_L, GSD_INPUT_SOURCES_SWITCHER_CTRL_L, GSD_INPUT_SOURCES_SWITCHER_SHIFT_R, GSD_INPUT_SOURCES_SWITCHER_ALT_R, GSD_INPUT_SOURCES_SWITCHER_CTRL_R, GSD_INPUT_SOURCES_SWITCHER_ALT_SHIFT_L, GSD_INPUT_SOURCES_SWITCHER_ALT_SHIFT_R, GSD_INPUT_SOURCES_SWITCHER_CTRL_SHIFT_L, GSD_INPUT_SOURCES_SWITCHER_CTRL_SHIFT_R, GSD_INPUT_SOURCES_SWITCHER_SHIFT_L_SHIFT_R, GSD_INPUT_SOURCES_SWITCHER_ALT_L_ALT_R, GSD_INPUT_SOURCES_SWITCHER_CTRL_L_CTRL_R, GSD_INPUT_SOURCES_SWITCHER_ALT_SHIFT, GSD_INPUT_SOURCES_SWITCHER_CTRL_SHIFT, GSD_INPUT_SOURCES_SWITCHER_ALT_CTRL, GSD_INPUT_SOURCES_SWITCHER_CAPS, GSD_INPUT_SOURCES_SWITCHER_SHIFT_CAPS, GSD_INPUT_SOURCES_SWITCHER_ALT_CAPS, GSD_INPUT_SOURCES_SWITCHER_CTRL_CAPS, } GsdInputSourcesSwitcher; #endif /* __gsd_enums_h__ */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/libunity-settings-daemon.pc.in0000664000175000017500000000052500000000000025640 0ustar00jeremyjeremyprefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ libexecdir=@libexecdir@ Name: libunity-settings-daemon Description: Helper library for accessing settings Requires: glib-2.0 gdk-3.0 Version: @VERSION@ Libs: -L${libdir} -lunity-settings-daemon Cflags: -I${includedir}/unity-settings-daemon-@GSD_API_VERSION@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/unity-settings-daemon-uninstalled.pc.in0000664000175000017500000000063400000000000027472 0ustar00jeremyjeremyprefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ binary=${pc_top_builddir}/unity-settings-daemon/unity-settings-daemon Name: unity-settings-daemon Description: Utility library for accessing unity-settings-daemon over DBUS Requires: glib-2.0 Version: @VERSION@ Libs: ${pc_top_builddir}/${pcfiledir}/../unity-settings-daemon/libgsd.la Cflags: -I${pc_top_builddir}/${pcfiledir}/.. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/unity-settings-daemon.desktop.in.in0000664000175000017500000000035700000000000026630 0ustar00jeremyjeremy[Desktop Entry] Type=Application _Name=Unity Settings Daemon Exec=@libexecdir@/unity-settings-daemon-localeexec OnlyShowIn=Unity; NoDisplay=true X-GNOME-Autostart-Phase=Initialization X-GNOME-Autostart-Notify=true X-GNOME-AutoRestart=true ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/data/unity-settings-daemon.pc.in0000664000175000017500000000066100000000000025152 0ustar00jeremyjeremyprefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ libexecdir=@libexecdir@ plugindir=${libdir}/unity-settings-daemon-@GSD_API_VERSION@ binary=${libexecdir}/unity-settings-daemon Name: unity-settings-daemon Description: Utility library for accessing unity-settings-daemon over DBUS Requires: glib-2.0 Version: @VERSION@ Libs: -L${libdir} Cflags: -I${includedir}/unity-settings-daemon-@GSD_API_VERSION@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5717669 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/0000775000175000017500000000000000000000000023242 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/Makefile.am0000664000175000017500000001227700000000000025307 0ustar00jeremyjeremyNULL = BUILT_SOURCES = $(NULL) INCLUDES = \ -DDATADIR=\""$(datadir)"\" \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ -DGNOME_SETTINGS_PLUGINDIR=\""$(plugindir)"\" \ -I$(top_srcdir)/plugins/common/ \ $(WARN_CFLAGS) \ $(DISABLE_DEPRECATED_CFLAGS) \ $(SETTINGS_DAEMON_CFLAGS) \ $(LIBNOTIFY_CFLAGS) \ $(GNOME_DESKTOP_CFLAGS) \ $(NULL) privlibdir = $(pkglibdir)-$(GSD_API_VERSION) lib_LTLIBRARIES = libunity-settings-daemon.la libexec_PROGRAMS = check_gl_texture_size libunity_settings_daemon_la_SOURCES = \ gsd-pnp-ids.c \ gsd-pnp-ids.h \ gsd-rr.c \ gsd-rr.h \ gsd-rr-config.c \ gsd-rr-config.h \ gsd-rr-output-info.c \ gsd-rr-private.h \ display-name.c \ edid-parse.c \ edid.h \ gsd-idle-monitor.c \ gsd-idle-monitor.h \ gsd-bg.c \ gsd-bg.h \ gsd-bg-crossfade.c \ gsd-bg-crossfade.h \ gsd-bg-slide-show.c \ gsd-bg-slide-show.h nodist_libunity_settings_daemon_la_SOURCES = \ $(dbus_idle_built_sources) libunity_settings_daemon_include_HEADERS = \ gsd-pnp-ids.h \ gsd-rr.h \ gsd-rr-config.h \ gsd-idle-monitor.h \ gsd-bg.h \ gsd-bg-crossfade.h \ gsd-bg-slide-show.h libunity_settings_daemon_includedir = $(includedir)/unity-settings-daemon-$(GSD_API_VERSION)/libunity-settings-daemon libunity_settings_daemon_la_CFLAGS = \ -DLIBEXECDIR=\""$(libexecdir)\"" \ -DPNP_IDS=\""$(datadir)/hwdata/pnp.ids"\" \ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ $(LIBUNITY_SETTINGS_DAEMON_CFLAGS) libunity_settings_daemon_la_LIBADD = \ -lm \ $(LIBUNITY_SETTINGS_DAEMON_LIBS) libunity_settings_daemon_la_LDFLAGS = \ -version-info 1:0:0 \ -export-symbols-regex \^gsd_.* BUILT_SOURCES = $(dbus_idle_built_sources) dbus_idle_built_sources = meta-dbus-idle-monitor.c meta-dbus-idle-monitor.h $(dbus_idle_built_sources) : Makefile.am idle-monitor.xml $(AM_V_GEN)gdbus-codegen \ --interface-prefix org.gnome.Mutter \ --c-namespace MetaDBus \ --generate-c-code meta-dbus-idle-monitor \ --c-generate-object-manager \ $(srcdir)/idle-monitor.xml check_gl_texture_size_CPPFLAGS = \ $(CHECK_GL_TEXTURE_SIZE_CFLAGS) check_gl_texture_size_LDADD = \ $(CHECK_GL_TEXTURE_SIZE_LIBS) privlib_LTLIBRARIES = \ libgsd.la \ $(NULL) session_manager_dbus_built_sources = gsd-session-manager-glue.c gsd-session-manager-glue.h BUILT_SOURCES += $(session_manager_dbus_built_sources) $(session_manager_dbus_built_sources) : Makefile.am org.gnome.SessionManager.xml gdbus-codegen \ --interface-prefix org.gnome.SessionManager. \ --generate-c-code gsd-session-manager-glue \ --c-namespace Gsd \ --annotate "org.gnome.SessionManager" \ "org.gtk.GDBus.C.Name" SessionManager \ $(srcdir)/org.gnome.SessionManager.xml screen_saver_dbus_built_sources = gsd-screen-saver-glue.c gsd-screen-saver-glue.h BUILT_SOURCES += $(screen_saver_dbus_built_sources) $(screen_saver_dbus_built_sources) : Makefile.am org.gnome.ScreenSaver.xml gdbus-codegen \ --interface-prefix org.gnome.ScreenSaver. \ --generate-c-code gsd-screen-saver-glue \ --c-namespace Gsd \ --annotate "org.gnome.ScreenSaver" \ "org.gtk.GDBus.C.Name" ScreenSaver \ $(srcdir)/org.gnome.ScreenSaver.xml libgsd_la_SOURCES = \ $(session_manager_dbus_built_sources) \ $(screen_saver_dbus_built_sources) \ gnome-settings-profile.c \ gnome-settings-profile.h \ gnome-settings-bus.c \ gnome-settings-bus.h \ gnome-settings-plugin.c \ gnome-settings-plugin.h \ $(NULL) libgsd_la_CPPFLAGS = \ $(DISABLE_DEPRECATED_CFLAGS) \ $(NULL) libgsd_la_CFLAGS = \ $(NULL) libgsd_la_LIBADD = \ $(SETTINGS_DAEMON_LIBS) \ $(GIOUNIX_LIBS) \ $(NULL) libgsd_la_LDFLAGS = \ -export-dynamic \ -avoid-version \ -no-undefined \ $(NULL) gsddir = $(libexecdir) gsd_PROGRAMS = \ unity-settings-daemon gsd_SCRIPTS = \ unity-settings-daemon-localeexec EXTRA_DIST = \ unity-settings-daemon-localeexec.in \ org.gnome.SessionManager.xml \ org.gnome.ScreenSaver.xml \ idle-monitor.xml \ $(NULL) unity-settings-daemon-localeexec: unity-settings-daemon-localeexec.in $(AM_V_GEN) sed -e "s|\@libexecdir\@|$(libexecdir)|" -e "s|\@prefix\@|$(prefix)|" $< > $@.tmp && mv $@.tmp $@ apidir = $(includedir)/unity-settings-daemon-$(GSD_API_VERSION)/unity-settings-daemon api_DATA = \ gnome-settings-plugin.h unity_settings_daemon_SOURCES = \ main.c \ gnome-settings-manager.c \ gnome-settings-manager.h \ gnome-settings-plugin.c \ gnome-settings-plugin.h \ gnome-settings-plugin-info.c \ gnome-settings-plugin-info.h \ gnome-settings-module.c \ gnome-settings-module.h \ $(NULL) unity_settings_daemon_CPPFLAGS = \ $(AM_CPPFLAGS) unity_settings_daemon_CFLAGS = \ $(AM_CFLAGS) unity_settings_daemon_LDFLAGS = \ $(AM_LDFLAGS) unity_settings_daemon_LDADD = \ libgsd.la \ libunity-settings-daemon.la \ $(SETTINGS_DAEMON_LIBS) \ $(LIBNOTIFY_LIBS) \ $(GNOME_DESKTOP_LIBS) \ $(NULL) CLEANFILES = $(gsd_SCRIPTS) \ $(dbus_idle_built_sources) # vim: ts=8 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/check_gl_texture_size.c0000664000175000017500000000370000000000000027757 0ustar00jeremyjeremy#include #include #include #include #include #include int main (int argc, char **argv) { Display *dpy = XOpenDisplay (NULL); Window win; int attribSingle[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, None }; int attribDouble[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None }; XSetWindowAttributes attr; unsigned long mask; GLXContext ctx = NULL; XVisualInfo *visinfo; int exit_status = EXIT_SUCCESS; GLint max_texture_size = 0; if (!dpy) { /* We have, for some reason, been unable to connect to X * Bail cleanly, and leave a little note */ fprintf (stderr, "check_gl_texture_size: Unable to open display %s", getenv("DISPLAY")); exit (EXIT_FAILURE); } visinfo = glXChooseVisual (dpy, DefaultScreen (dpy), attribSingle); if (!visinfo) visinfo = glXChooseVisual (dpy, DefaultScreen (dpy), attribDouble); if (visinfo) ctx = glXCreateContext (dpy, visinfo, NULL, GL_TRUE); if (!visinfo) { exit_status = EXIT_FAILURE; goto child_out; } if (!ctx) { XFree (visinfo); exit_status = EXIT_FAILURE; goto child_out; } attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap (dpy, DefaultRootWindow (dpy), visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0, 100, 100, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); if (!glXMakeCurrent (dpy, win, ctx)) { exit_status = EXIT_FAILURE; goto child_out; } glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_texture_size); printf ("%u", max_texture_size); child_out: XCloseDisplay (dpy); exit (exit_status); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/display-name.c0000664000175000017500000000773200000000000026002 0ustar00jeremyjeremy/* * Copyright 2007 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * on the rights to use, copy, modify, merge, publish, distribute, sub * license, and/or sell copies of the Software, and to permit persons to whom * the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* Author: Soren Sandmann */ #include #include #include #include #include #include #include #include "gsd-pnp-ids.h" #include "edid.h" static const char * find_vendor (const char *code) { const char *vendor_name; GsdPnpIds *pnp_ids; pnp_ids = gsd_pnp_ids_new (); vendor_name = gsd_pnp_ids_get_pnp_id (pnp_ids, code); g_object_unref (pnp_ids); if (vendor_name) return vendor_name; return code; } static const double known_diagonals[] = { 12.1, 13.3, 15.6 }; static char * diagonal_to_str (double d) { int i; for (i = 0; i < G_N_ELEMENTS (known_diagonals); i++) { double delta; delta = fabs(known_diagonals[i] - d); if (delta < 0.1) return g_strdup_printf ("%0.1lf\"", known_diagonals[i]); } return g_strdup_printf ("%d\"", (int) (d + 0.5)); } char * make_display_size_string (int width_mm, int height_mm) { char *inches = NULL; if (width_mm > 0 && height_mm > 0) { double d = sqrt (width_mm * width_mm + height_mm * height_mm); inches = diagonal_to_str (d / 25.4); } return inches; } static gboolean has_aspect_as_size(int width_mm, int height_mm) { return (width_mm == 1600 && height_mm == 900) || (width_mm == 1600 && height_mm == 1000) || (width_mm == 160 && height_mm == 90) || (width_mm == 160 && height_mm == 100) || (width_mm == 16 && height_mm == 9) || (width_mm == 16 && height_mm == 10); } char * make_display_name (const MonitorInfo *info) { const char *vendor; int width_mm, height_mm; char *suffix, *ret; if (info) { vendor = find_vendor (info->manufacturer_code); } else { /* Translators: "Unknown" here is used to identify a monitor for which * we don't know the vendor. When a vendor is known, the name of the * vendor is used. */ vendor = C_("Monitor vendor", "Unknown"); } if (info && info->width_mm != -1 && info->height_mm) { width_mm = info->width_mm; height_mm = info->height_mm; } else if (info && info->n_detailed_timings) { width_mm = info->detailed_timings[0].width_mm; height_mm = info->detailed_timings[0].height_mm; } else { width_mm = -1; height_mm = -1; } // are we dealing with aspect coded in EDID size fields? if (has_aspect_as_size(width_mm, height_mm)) { suffix = g_strdup(info->dsc_product_name); } else if (width_mm != -1 && height_mm != -1) { double d = sqrt (width_mm * width_mm + height_mm * height_mm); suffix = diagonal_to_str (d / 25.4); } else { suffix = NULL; } if (!suffix) return g_strdup (vendor); ret = g_strdup_printf ("%s %s", vendor, suffix); g_free (suffix); return ret; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/edid-parse.c0000664000175000017500000003140700000000000025430 0ustar00jeremyjeremy/* * Copyright 2007 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * on the rights to use, copy, modify, merge, publish, distribute, sub * license, and/or sell copies of the Software, and to permit persons to whom * the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* Author: Soren Sandmann */ #include "edid.h" #include #include #include #include static int get_bit (int in, int bit) { return (in & (1 << bit)) >> bit; } static int get_bits (int in, int begin, int end) { int mask = (1 << (end - begin + 1)) - 1; return (in >> begin) & mask; } static int decode_header (const uchar *edid) { if (memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0) return TRUE; return FALSE; } static int decode_vendor_and_product_identification (const uchar *edid, MonitorInfo *info) { int is_model_year; /* Manufacturer Code */ info->manufacturer_code[0] = get_bits (edid[0x08], 2, 6); info->manufacturer_code[1] = get_bits (edid[0x08], 0, 1) << 3; info->manufacturer_code[1] |= get_bits (edid[0x09], 5, 7); info->manufacturer_code[2] = get_bits (edid[0x09], 0, 4); info->manufacturer_code[3] = '\0'; info->manufacturer_code[0] += 'A' - 1; info->manufacturer_code[1] += 'A' - 1; info->manufacturer_code[2] += 'A' - 1; /* Product Code */ info->product_code = edid[0x0b] << 8 | edid[0x0a]; /* Serial Number */ info->serial_number = edid[0x0c] | edid[0x0d] << 8 | edid[0x0e] << 16 | edid[0x0f] << 24; /* Week and Year */ is_model_year = FALSE; switch (edid[0x10]) { case 0x00: info->production_week = -1; break; case 0xff: info->production_week = -1; is_model_year = TRUE; break; default: info->production_week = edid[0x10]; break; } if (is_model_year) { info->production_year = -1; info->model_year = 1990 + edid[0x11]; } else { info->production_year = 1990 + edid[0x11]; info->model_year = -1; } return TRUE; } static int decode_edid_version (const uchar *edid, MonitorInfo *info) { info->major_version = edid[0x12]; info->minor_version = edid[0x13]; return TRUE; } static int decode_display_parameters (const uchar *edid, MonitorInfo *info) { /* Digital vs Analog */ info->is_digital = get_bit (edid[0x14], 7); if (info->is_digital) { int bits; static const int bit_depth[8] = { -1, 6, 8, 10, 12, 14, 16, -1 }; static const Interface interfaces[6] = { UNDEFINED, DVI, HDMI_A, HDMI_B, MDDI, DISPLAY_PORT }; bits = get_bits (edid[0x14], 4, 6); info->connector.digital.bits_per_primary = bit_depth[bits]; bits = get_bits (edid[0x14], 0, 3); if (bits <= 5) info->connector.digital.interface = interfaces[bits]; else info->connector.digital.interface = UNDEFINED; } else { int bits = get_bits (edid[0x14], 5, 6); static const double levels[][3] = { { 0.7, 0.3, 1.0 }, { 0.714, 0.286, 1.0 }, { 1.0, 0.4, 1.4 }, { 0.7, 0.0, 0.7 }, }; info->connector.analog.video_signal_level = levels[bits][0]; info->connector.analog.sync_signal_level = levels[bits][1]; info->connector.analog.total_signal_level = levels[bits][2]; info->connector.analog.blank_to_black = get_bit (edid[0x14], 4); info->connector.analog.separate_hv_sync = get_bit (edid[0x14], 3); info->connector.analog.composite_sync_on_h = get_bit (edid[0x14], 2); info->connector.analog.composite_sync_on_green = get_bit (edid[0x14], 1); info->connector.analog.serration_on_vsync = get_bit (edid[0x14], 0); } /* Screen Size / Aspect Ratio */ if (edid[0x15] == 0 && edid[0x16] == 0) { info->width_mm = -1; info->height_mm = -1; info->aspect_ratio = -1.0; } else if (edid[0x16] == 0) { info->width_mm = -1; info->height_mm = -1; info->aspect_ratio = 100.0 / (edid[0x15] + 99); } else if (edid[0x15] == 0) { info->width_mm = -1; info->height_mm = -1; info->aspect_ratio = 100.0 / (edid[0x16] + 99); info->aspect_ratio = 1/info->aspect_ratio; /* portrait */ } else { info->width_mm = 10 * edid[0x15]; info->height_mm = 10 * edid[0x16]; } /* Gamma */ if (edid[0x17] == 0xFF) info->gamma = -1.0; else info->gamma = (edid[0x17] + 100.0) / 100.0; /* Features */ info->standby = get_bit (edid[0x18], 7); info->suspend = get_bit (edid[0x18], 6); info->active_off = get_bit (edid[0x18], 5); if (info->is_digital) { info->connector.digital.rgb444 = TRUE; if (get_bit (edid[0x18], 3)) info->connector.digital.ycrcb444 = 1; if (get_bit (edid[0x18], 4)) info->connector.digital.ycrcb422 = 1; } else { int bits = get_bits (edid[0x18], 3, 4); ColorType color_type[4] = { MONOCHROME, RGB, OTHER_COLOR, UNDEFINED_COLOR }; info->connector.analog.color_type = color_type[bits]; } info->srgb_is_standard = get_bit (edid[0x18], 2); /* In 1.3 this is called "has preferred timing" */ info->preferred_timing_includes_native = get_bit (edid[0x18], 1); /* FIXME: In 1.3 this indicates whether the monitor accepts GTF */ info->continuous_frequency = get_bit (edid[0x18], 0); return TRUE; } static double decode_fraction (int high, int low) { double result = 0.0; int i; high = (high << 2) | low; for (i = 0; i < 10; ++i) result += get_bit (high, i) * pow (2, i - 10); return result; } static int decode_color_characteristics (const uchar *edid, MonitorInfo *info) { info->red_x = decode_fraction (edid[0x1b], get_bits (edid[0x19], 6, 7)); info->red_y = decode_fraction (edid[0x1c], get_bits (edid[0x19], 5, 4)); info->green_x = decode_fraction (edid[0x1d], get_bits (edid[0x19], 2, 3)); info->green_y = decode_fraction (edid[0x1e], get_bits (edid[0x19], 0, 1)); info->blue_x = decode_fraction (edid[0x1f], get_bits (edid[0x1a], 6, 7)); info->blue_y = decode_fraction (edid[0x20], get_bits (edid[0x1a], 4, 5)); info->white_x = decode_fraction (edid[0x21], get_bits (edid[0x1a], 2, 3)); info->white_y = decode_fraction (edid[0x22], get_bits (edid[0x1a], 0, 1)); return TRUE; } static int decode_established_timings (const uchar *edid, MonitorInfo *info) { static const Timing established[][8] = { { { 800, 600, 60 }, { 800, 600, 56 }, { 640, 480, 75 }, { 640, 480, 72 }, { 640, 480, 67 }, { 640, 480, 60 }, { 720, 400, 88 }, { 720, 400, 70 } }, { { 1280, 1024, 75 }, { 1024, 768, 75 }, { 1024, 768, 70 }, { 1024, 768, 60 }, { 1024, 768, 87 }, { 832, 624, 75 }, { 800, 600, 75 }, { 800, 600, 72 } }, { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 1152, 870, 75 } }, }; int i, j, idx; idx = 0; for (i = 0; i < 3; ++i) { for (j = 0; j < 8; ++j) { int byte = edid[0x23 + i]; if (get_bit (byte, j) && established[i][j].frequency != 0) info->established[idx++] = established[i][j]; } } return TRUE; } static int decode_standard_timings (const uchar *edid, MonitorInfo *info) { int i; for (i = 0; i < 8; i++) { int first = edid[0x26 + 2 * i]; int second = edid[0x27 + 2 * i]; if (first != 0x01 && second != 0x01) { int w = 8 * (first + 31); int h = 0; switch (get_bits (second, 6, 7)) { case 0x00: h = (w / 16) * 10; break; case 0x01: h = (w / 4) * 3; break; case 0x02: h = (w / 5) * 4; break; case 0x03: h = (w / 16) * 9; break; } info->standard[i].width = w; info->standard[i].height = h; info->standard[i].frequency = get_bits (second, 0, 5) + 60; } } return TRUE; } static void decode_lf_string (const uchar *s, int n_chars, char *result) { int i; for (i = 0; i < n_chars; ++i) { if (s[i] == 0x0a) { *result++ = '\0'; break; } else if (s[i] == 0x00) { /* Convert embedded 0's to spaces */ *result++ = ' '; } else { *result++ = s[i]; } } } static void decode_display_descriptor (const uchar *desc, MonitorInfo *info) { switch (desc[0x03]) { case 0xFC: decode_lf_string (desc + 5, 13, info->dsc_product_name); break; case 0xFF: decode_lf_string (desc + 5, 13, info->dsc_serial_number); break; case 0xFE: decode_lf_string (desc + 5, 13, info->dsc_string); break; case 0xFD: /* Range Limits */ break; case 0xFB: /* Color Point */ break; case 0xFA: /* Timing Identifications */ break; case 0xF9: /* Color Management */ break; case 0xF8: /* Timing Codes */ break; case 0xF7: /* Established Timings */ break; case 0x10: break; } } static void decode_detailed_timing (const uchar *timing, DetailedTiming *detailed) { int bits; StereoType stereo[] = { NO_STEREO, NO_STEREO, FIELD_RIGHT, FIELD_LEFT, TWO_WAY_RIGHT_ON_EVEN, TWO_WAY_LEFT_ON_EVEN, FOUR_WAY_INTERLEAVED, SIDE_BY_SIDE }; detailed->pixel_clock = (timing[0x00] | timing[0x01] << 8) * 10000; detailed->h_addr = timing[0x02] | ((timing[0x04] & 0xf0) << 4); detailed->h_blank = timing[0x03] | ((timing[0x04] & 0x0f) << 8); detailed->v_addr = timing[0x05] | ((timing[0x07] & 0xf0) << 4); detailed->v_blank = timing[0x06] | ((timing[0x07] & 0x0f) << 8); detailed->h_front_porch = timing[0x08] | get_bits (timing[0x0b], 6, 7) << 8; detailed->h_sync = timing[0x09] | get_bits (timing[0x0b], 4, 5) << 8; detailed->v_front_porch = get_bits (timing[0x0a], 4, 7) | get_bits (timing[0x0b], 2, 3) << 4; detailed->v_sync = get_bits (timing[0x0a], 0, 3) | get_bits (timing[0x0b], 0, 1) << 4; detailed->width_mm = timing[0x0c] | get_bits (timing[0x0e], 4, 7) << 8; detailed->height_mm = timing[0x0d] | get_bits (timing[0x0e], 0, 3) << 8; detailed->right_border = timing[0x0f]; detailed->top_border = timing[0x10]; detailed->interlaced = get_bit (timing[0x11], 7); /* Stereo */ bits = get_bits (timing[0x11], 5, 6) << 1 | get_bit (timing[0x11], 0); detailed->stereo = stereo[bits]; /* Sync */ bits = timing[0x11]; detailed->digital_sync = get_bit (bits, 4); if (detailed->digital_sync) { detailed->connector.digital.composite = !get_bit (bits, 3); if (detailed->connector.digital.composite) { detailed->connector.digital.serrations = get_bit (bits, 2); detailed->connector.digital.negative_vsync = FALSE; } else { detailed->connector.digital.serrations = FALSE; detailed->connector.digital.negative_vsync = !get_bit (bits, 2); } detailed->connector.digital.negative_hsync = !get_bit (bits, 0); } else { detailed->connector.analog.bipolar = get_bit (bits, 3); detailed->connector.analog.serrations = get_bit (bits, 2); detailed->connector.analog.sync_on_green = !get_bit (bits, 1); } } static int decode_descriptors (const uchar *edid, MonitorInfo *info) { int i; int timing_idx; timing_idx = 0; for (i = 0; i < 4; ++i) { int index = 0x36 + i * 18; if (edid[index + 0] == 0x00 && edid[index + 1] == 0x00) { decode_display_descriptor (edid + index, info); } else { decode_detailed_timing ( edid + index, &(info->detailed_timings[timing_idx++])); } } info->n_detailed_timings = timing_idx; return TRUE; } static void decode_check_sum (const uchar *edid, MonitorInfo *info) { int i; uchar check = 0; for (i = 0; i < 128; ++i) check += edid[i]; info->checksum = check; } MonitorInfo * decode_edid (const uchar *edid) { MonitorInfo *info = g_new0 (MonitorInfo, 1); decode_check_sum (edid, info); if (decode_header (edid) && decode_vendor_and_product_identification (edid, info) && decode_edid_version (edid, info) && decode_display_parameters (edid, info) && decode_color_characteristics (edid, info) && decode_established_timings (edid, info) && decode_standard_timings (edid, info) && decode_descriptors (edid, info)) { return info; } else { g_free (info); return NULL; } } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/edid.h0000664000175000017500000001012700000000000024321 0ustar00jeremyjeremy/* edid.h * * Copyright 2007, 2008, Red Hat, Inc. * * This file is part of the Gnome Library. * * The Gnome Library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * The Gnome 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with the Gnome Library; see the file COPYING.LIB. If not, * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * Author: Soren Sandmann */ #ifndef EDID_H #define EDID_H typedef unsigned char uchar; typedef struct MonitorInfo MonitorInfo; typedef struct Timing Timing; typedef struct DetailedTiming DetailedTiming; typedef enum { UNDEFINED, DVI, HDMI_A, HDMI_B, MDDI, DISPLAY_PORT } Interface; typedef enum { UNDEFINED_COLOR, MONOCHROME, RGB, OTHER_COLOR } ColorType; typedef enum { NO_STEREO, FIELD_RIGHT, FIELD_LEFT, TWO_WAY_RIGHT_ON_EVEN, TWO_WAY_LEFT_ON_EVEN, FOUR_WAY_INTERLEAVED, SIDE_BY_SIDE } StereoType; struct Timing { int width; int height; int frequency; }; struct DetailedTiming { int pixel_clock; int h_addr; int h_blank; int h_sync; int h_front_porch; int v_addr; int v_blank; int v_sync; int v_front_porch; int width_mm; int height_mm; int right_border; int top_border; int interlaced; StereoType stereo; int digital_sync; union { struct { int bipolar; int serrations; int sync_on_green; } analog; struct { int composite; int serrations; int negative_vsync; int negative_hsync; } digital; } connector; }; struct MonitorInfo { int checksum; char manufacturer_code[4]; int product_code; unsigned int serial_number; int production_week; /* -1 if not specified */ int production_year; /* -1 if not specified */ int model_year; /* -1 if not specified */ int major_version; int minor_version; int is_digital; union { struct { int bits_per_primary; Interface interface; int rgb444; int ycrcb444; int ycrcb422; } digital; struct { double video_signal_level; double sync_signal_level; double total_signal_level; int blank_to_black; int separate_hv_sync; int composite_sync_on_h; int composite_sync_on_green; int serration_on_vsync; ColorType color_type; } analog; } connector; int width_mm; /* -1 if not specified */ int height_mm; /* -1 if not specified */ double aspect_ratio; /* -1.0 if not specififed */ double gamma; /* -1.0 if not specified */ int standby; int suspend; int active_off; int srgb_is_standard; int preferred_timing_includes_native; int continuous_frequency; double red_x; double red_y; double green_x; double green_y; double blue_x; double blue_y; double white_x; double white_y; Timing established[24]; /* Terminated by 0x0x0 */ Timing standard[8]; int n_detailed_timings; DetailedTiming detailed_timings[4]; /* If monitor has a preferred * mode, it is the first one * (whether it has, is * determined by the * preferred_timing_includes * bit. */ /* Optional product description */ char dsc_serial_number[14]; char dsc_product_name[14]; char dsc_string[14]; /* Unspecified ASCII data */ }; MonitorInfo *decode_edid (const uchar *data); char *make_display_name (const MonitorInfo *info); char *make_display_size_string (int width_mm, int height_mm); #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/edid_parse.c0000664000175000017500000003140700000000000025512 0ustar00jeremyjeremy/* * Copyright 2007 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * on the rights to use, copy, modify, merge, publish, distribute, sub * license, and/or sell copies of the Software, and to permit persons to whom * the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* Author: Soren Sandmann */ #include "edid.h" #include #include #include #include static int get_bit (int in, int bit) { return (in & (1 << bit)) >> bit; } static int get_bits (int in, int begin, int end) { int mask = (1 << (end - begin + 1)) - 1; return (in >> begin) & mask; } static int decode_header (const uchar *edid) { if (memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0) return TRUE; return FALSE; } static int decode_vendor_and_product_identification (const uchar *edid, MonitorInfo *info) { int is_model_year; /* Manufacturer Code */ info->manufacturer_code[0] = get_bits (edid[0x08], 2, 6); info->manufacturer_code[1] = get_bits (edid[0x08], 0, 1) << 3; info->manufacturer_code[1] |= get_bits (edid[0x09], 5, 7); info->manufacturer_code[2] = get_bits (edid[0x09], 0, 4); info->manufacturer_code[3] = '\0'; info->manufacturer_code[0] += 'A' - 1; info->manufacturer_code[1] += 'A' - 1; info->manufacturer_code[2] += 'A' - 1; /* Product Code */ info->product_code = edid[0x0b] << 8 | edid[0x0a]; /* Serial Number */ info->serial_number = edid[0x0c] | edid[0x0d] << 8 | edid[0x0e] << 16 | edid[0x0f] << 24; /* Week and Year */ is_model_year = FALSE; switch (edid[0x10]) { case 0x00: info->production_week = -1; break; case 0xff: info->production_week = -1; is_model_year = TRUE; break; default: info->production_week = edid[0x10]; break; } if (is_model_year) { info->production_year = -1; info->model_year = 1990 + edid[0x11]; } else { info->production_year = 1990 + edid[0x11]; info->model_year = -1; } return TRUE; } static int decode_edid_version (const uchar *edid, MonitorInfo *info) { info->major_version = edid[0x12]; info->minor_version = edid[0x13]; return TRUE; } static int decode_display_parameters (const uchar *edid, MonitorInfo *info) { /* Digital vs Analog */ info->is_digital = get_bit (edid[0x14], 7); if (info->is_digital) { int bits; static const int bit_depth[8] = { -1, 6, 8, 10, 12, 14, 16, -1 }; static const Interface interfaces[6] = { UNDEFINED, DVI, HDMI_A, HDMI_B, MDDI, DISPLAY_PORT }; bits = get_bits (edid[0x14], 4, 6); info->connector.digital.bits_per_primary = bit_depth[bits]; bits = get_bits (edid[0x14], 0, 3); if (bits <= 5) info->connector.digital.interface = interfaces[bits]; else info->connector.digital.interface = UNDEFINED; } else { int bits = get_bits (edid[0x14], 5, 6); static const double levels[][3] = { { 0.7, 0.3, 1.0 }, { 0.714, 0.286, 1.0 }, { 1.0, 0.4, 1.4 }, { 0.7, 0.0, 0.7 }, }; info->connector.analog.video_signal_level = levels[bits][0]; info->connector.analog.sync_signal_level = levels[bits][1]; info->connector.analog.total_signal_level = levels[bits][2]; info->connector.analog.blank_to_black = get_bit (edid[0x14], 4); info->connector.analog.separate_hv_sync = get_bit (edid[0x14], 3); info->connector.analog.composite_sync_on_h = get_bit (edid[0x14], 2); info->connector.analog.composite_sync_on_green = get_bit (edid[0x14], 1); info->connector.analog.serration_on_vsync = get_bit (edid[0x14], 0); } /* Screen Size / Aspect Ratio */ if (edid[0x15] == 0 && edid[0x16] == 0) { info->width_mm = -1; info->height_mm = -1; info->aspect_ratio = -1.0; } else if (edid[0x16] == 0) { info->width_mm = -1; info->height_mm = -1; info->aspect_ratio = 100.0 / (edid[0x15] + 99); } else if (edid[0x15] == 0) { info->width_mm = -1; info->height_mm = -1; info->aspect_ratio = 100.0 / (edid[0x16] + 99); info->aspect_ratio = 1/info->aspect_ratio; /* portrait */ } else { info->width_mm = 10 * edid[0x15]; info->height_mm = 10 * edid[0x16]; } /* Gamma */ if (edid[0x17] == 0xFF) info->gamma = -1.0; else info->gamma = (edid[0x17] + 100.0) / 100.0; /* Features */ info->standby = get_bit (edid[0x18], 7); info->suspend = get_bit (edid[0x18], 6); info->active_off = get_bit (edid[0x18], 5); if (info->is_digital) { info->connector.digital.rgb444 = TRUE; if (get_bit (edid[0x18], 3)) info->connector.digital.ycrcb444 = 1; if (get_bit (edid[0x18], 4)) info->connector.digital.ycrcb422 = 1; } else { int bits = get_bits (edid[0x18], 3, 4); ColorType color_type[4] = { MONOCHROME, RGB, OTHER_COLOR, UNDEFINED_COLOR }; info->connector.analog.color_type = color_type[bits]; } info->srgb_is_standard = get_bit (edid[0x18], 2); /* In 1.3 this is called "has preferred timing" */ info->preferred_timing_includes_native = get_bit (edid[0x18], 1); /* FIXME: In 1.3 this indicates whether the monitor accepts GTF */ info->continuous_frequency = get_bit (edid[0x18], 0); return TRUE; } static double decode_fraction (int high, int low) { double result = 0.0; int i; high = (high << 2) | low; for (i = 0; i < 10; ++i) result += get_bit (high, i) * pow (2, i - 10); return result; } static int decode_color_characteristics (const uchar *edid, MonitorInfo *info) { info->red_x = decode_fraction (edid[0x1b], get_bits (edid[0x19], 6, 7)); info->red_y = decode_fraction (edid[0x1c], get_bits (edid[0x19], 5, 4)); info->green_x = decode_fraction (edid[0x1d], get_bits (edid[0x19], 2, 3)); info->green_y = decode_fraction (edid[0x1e], get_bits (edid[0x19], 0, 1)); info->blue_x = decode_fraction (edid[0x1f], get_bits (edid[0x1a], 6, 7)); info->blue_y = decode_fraction (edid[0x20], get_bits (edid[0x1a], 4, 5)); info->white_x = decode_fraction (edid[0x21], get_bits (edid[0x1a], 2, 3)); info->white_y = decode_fraction (edid[0x22], get_bits (edid[0x1a], 0, 1)); return TRUE; } static int decode_established_timings (const uchar *edid, MonitorInfo *info) { static const Timing established[][8] = { { { 800, 600, 60 }, { 800, 600, 56 }, { 640, 480, 75 }, { 640, 480, 72 }, { 640, 480, 67 }, { 640, 480, 60 }, { 720, 400, 88 }, { 720, 400, 70 } }, { { 1280, 1024, 75 }, { 1024, 768, 75 }, { 1024, 768, 70 }, { 1024, 768, 60 }, { 1024, 768, 87 }, { 832, 624, 75 }, { 800, 600, 75 }, { 800, 600, 72 } }, { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 1152, 870, 75 } }, }; int i, j, idx; idx = 0; for (i = 0; i < 3; ++i) { for (j = 0; j < 8; ++j) { int byte = edid[0x23 + i]; if (get_bit (byte, j) && established[i][j].frequency != 0) info->established[idx++] = established[i][j]; } } return TRUE; } static int decode_standard_timings (const uchar *edid, MonitorInfo *info) { int i; for (i = 0; i < 8; i++) { int first = edid[0x26 + 2 * i]; int second = edid[0x27 + 2 * i]; if (first != 0x01 && second != 0x01) { int w = 8 * (first + 31); int h = 0; switch (get_bits (second, 6, 7)) { case 0x00: h = (w / 16) * 10; break; case 0x01: h = (w / 4) * 3; break; case 0x02: h = (w / 5) * 4; break; case 0x03: h = (w / 16) * 9; break; } info->standard[i].width = w; info->standard[i].height = h; info->standard[i].frequency = get_bits (second, 0, 5) + 60; } } return TRUE; } static void decode_lf_string (const uchar *s, int n_chars, char *result) { int i; for (i = 0; i < n_chars; ++i) { if (s[i] == 0x0a) { *result++ = '\0'; break; } else if (s[i] == 0x00) { /* Convert embedded 0's to spaces */ *result++ = ' '; } else { *result++ = s[i]; } } } static void decode_display_descriptor (const uchar *desc, MonitorInfo *info) { switch (desc[0x03]) { case 0xFC: decode_lf_string (desc + 5, 13, info->dsc_product_name); break; case 0xFF: decode_lf_string (desc + 5, 13, info->dsc_serial_number); break; case 0xFE: decode_lf_string (desc + 5, 13, info->dsc_string); break; case 0xFD: /* Range Limits */ break; case 0xFB: /* Color Point */ break; case 0xFA: /* Timing Identifications */ break; case 0xF9: /* Color Management */ break; case 0xF8: /* Timing Codes */ break; case 0xF7: /* Established Timings */ break; case 0x10: break; } } static void decode_detailed_timing (const uchar *timing, DetailedTiming *detailed) { int bits; StereoType stereo[] = { NO_STEREO, NO_STEREO, FIELD_RIGHT, FIELD_LEFT, TWO_WAY_RIGHT_ON_EVEN, TWO_WAY_LEFT_ON_EVEN, FOUR_WAY_INTERLEAVED, SIDE_BY_SIDE }; detailed->pixel_clock = (timing[0x00] | timing[0x01] << 8) * 10000; detailed->h_addr = timing[0x02] | ((timing[0x04] & 0xf0) << 4); detailed->h_blank = timing[0x03] | ((timing[0x04] & 0x0f) << 8); detailed->v_addr = timing[0x05] | ((timing[0x07] & 0xf0) << 4); detailed->v_blank = timing[0x06] | ((timing[0x07] & 0x0f) << 8); detailed->h_front_porch = timing[0x08] | get_bits (timing[0x0b], 6, 7) << 8; detailed->h_sync = timing[0x09] | get_bits (timing[0x0b], 4, 5) << 8; detailed->v_front_porch = get_bits (timing[0x0a], 4, 7) | get_bits (timing[0x0b], 2, 3) << 4; detailed->v_sync = get_bits (timing[0x0a], 0, 3) | get_bits (timing[0x0b], 0, 1) << 4; detailed->width_mm = timing[0x0c] | get_bits (timing[0x0e], 4, 7) << 8; detailed->height_mm = timing[0x0d] | get_bits (timing[0x0e], 0, 3) << 8; detailed->right_border = timing[0x0f]; detailed->top_border = timing[0x10]; detailed->interlaced = get_bit (timing[0x11], 7); /* Stereo */ bits = get_bits (timing[0x11], 5, 6) << 1 | get_bit (timing[0x11], 0); detailed->stereo = stereo[bits]; /* Sync */ bits = timing[0x11]; detailed->digital_sync = get_bit (bits, 4); if (detailed->digital_sync) { detailed->connector.digital.composite = !get_bit (bits, 3); if (detailed->connector.digital.composite) { detailed->connector.digital.serrations = get_bit (bits, 2); detailed->connector.digital.negative_vsync = FALSE; } else { detailed->connector.digital.serrations = FALSE; detailed->connector.digital.negative_vsync = !get_bit (bits, 2); } detailed->connector.digital.negative_hsync = !get_bit (bits, 0); } else { detailed->connector.analog.bipolar = get_bit (bits, 3); detailed->connector.analog.serrations = get_bit (bits, 2); detailed->connector.analog.sync_on_green = !get_bit (bits, 1); } } static int decode_descriptors (const uchar *edid, MonitorInfo *info) { int i; int timing_idx; timing_idx = 0; for (i = 0; i < 4; ++i) { int index = 0x36 + i * 18; if (edid[index + 0] == 0x00 && edid[index + 1] == 0x00) { decode_display_descriptor (edid + index, info); } else { decode_detailed_timing ( edid + index, &(info->detailed_timings[timing_idx++])); } } info->n_detailed_timings = timing_idx; return TRUE; } static void decode_check_sum (const uchar *edid, MonitorInfo *info) { int i; uchar check = 0; for (i = 0; i < 128; ++i) check += edid[i]; info->checksum = check; } MonitorInfo * decode_edid (const uchar *edid) { MonitorInfo *info = g_new0 (MonitorInfo, 1); decode_check_sum (edid, info); if (decode_header (edid) && decode_vendor_and_product_identification (edid, info) && decode_edid_version (edid, info) && decode_display_parameters (edid, info) && decode_color_characteristics (edid, info) && decode_established_timings (edid, info) && decode_standard_timings (edid, info) && decode_descriptors (edid, info)) { return info; } else { g_free (info); return NULL; } } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-bus.c0000664000175000017500000001314000000000000027137 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2006-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #include #include #include #include "gnome-settings-bus.h" #define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager" #define GNOME_SESSION_DBUS_OBJECT "/org/gnome/SessionManager" #define GNOME_SCREENSAVER_DBUS_NAME "org.gnome.ScreenSaver" #define GNOME_SCREENSAVER_DBUS_OBJECT "/org/gnome/ScreenSaver" GsdSessionManager * gnome_settings_bus_get_session_proxy (void) { static GsdSessionManager *session_proxy; GError *error = NULL; if (session_proxy != NULL) { g_object_ref (session_proxy); } else { session_proxy = gsd_session_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, GNOME_SESSION_DBUS_NAME, GNOME_SESSION_DBUS_OBJECT, NULL, &error); if (error) { g_warning ("Failed to connect to the session manager: %s", error->message); g_error_free (error); } else { g_object_add_weak_pointer (G_OBJECT (session_proxy), (gpointer*)&session_proxy); } } return session_proxy; } GsdScreenSaver * gnome_settings_bus_get_screen_saver_proxy (void) { static GsdScreenSaver *screen_saver_proxy; GError *error = NULL; if (screen_saver_proxy != NULL) { g_object_ref (screen_saver_proxy); } else { screen_saver_proxy = gsd_screen_saver_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, GNOME_SCREENSAVER_DBUS_NAME, GNOME_SCREENSAVER_DBUS_OBJECT, NULL, &error); if (error) { g_warning ("Failed to connect to the screen saver: %s", error->message); g_error_free (error); } else { g_object_add_weak_pointer (G_OBJECT (screen_saver_proxy), (gpointer*)&screen_saver_proxy); } } return screen_saver_proxy; } char * gnome_settings_get_chassis_type (void) { char *ret = NULL; GError *error = NULL; GVariant *inner; GVariant *variant = NULL; GDBusConnection *connection; connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (connection == NULL) { g_warning ("system bus not available: %s", error->message); g_error_free (error); goto out; } variant = g_dbus_connection_call_sync (connection, "org.freedesktop.hostname1", "/org/freedesktop/hostname1", "org.freedesktop.DBus.Properties", "Get", g_variant_new ("(ss)", "org.freedesktop.hostname1", "Chassis"), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (variant == NULL) { g_debug ("Failed to get property '%s': %s", "Chassis", error->message); g_error_free (error); goto out; } g_variant_get (variant, "(v)", &inner); ret = g_variant_dup_string (inner, NULL); g_variant_unref (inner); out: g_clear_object (&connection); g_clear_pointer (&variant, g_variant_unref); return ret; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-bus.h0000664000175000017500000000255100000000000027150 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2010-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __GNOME_SETTINGS_BUS_H #define __GNOME_SETTINGS_BUS_H #include #include "gsd-session-manager-glue.h" #include "gsd-screen-saver-glue.h" G_BEGIN_DECLS GsdSessionManager *gnome_settings_bus_get_session_proxy (void); GsdScreenSaver *gnome_settings_bus_get_screen_saver_proxy (void); char * gnome_settings_get_chassis_type (void); G_END_DECLS #endif /* __GNOME_SETTINGS_BUS_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-manager.c0000664000175000017500000004077700000000000030000 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include "gnome-settings-plugin.h" #include "gnome-settings-plugin-info.h" #include "gnome-settings-manager.h" #include "gnome-settings-profile.h" #include "gsd-pnp-ids.h" #define DEFAULT_SETTINGS_PREFIX "com.canonical.unity.settings-daemon" #define PLUGIN_EXT ".gnome-settings-plugin" #define GNOME_SETTINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNOME_TYPE_SETTINGS_MANAGER, GnomeSettingsManagerPrivate)) static const gchar introspection_xml[] = "" " " " " " " " " " " " " " " " " " " ""; typedef struct { const char *signal; const char *name; } SignalCache; struct GnomeSettingsManagerPrivate { guint owner_id; GDBusNodeInfo *introspection_data; GDBusConnection *connection; GSettings *settings; char **whitelist; GsdPnpIds *pnp_ids; GSList *plugins; GQueue *signal_queue; }; static void gnome_settings_manager_class_init (GnomeSettingsManagerClass *klass); static void gnome_settings_manager_init (GnomeSettingsManager *settings_manager); static void gnome_settings_manager_finalize (GObject *object); G_DEFINE_TYPE (GnomeSettingsManager, gnome_settings_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static void signal_cache_free (SignalCache *cache) { if (cache == NULL) { return; } g_free (cache->signal); g_free (cache->name); g_free (cache); } GQuark gnome_settings_manager_error_quark (void) { static GQuark ret = 0; if (ret == 0) { ret = g_quark_from_static_string ("gnome_settings_manager_error"); } return ret; } static void maybe_activate_plugin (GnomeSettingsPluginInfo *info, gpointer user_data) { if (gnome_settings_plugin_info_get_enabled (info)) { gboolean res; res = gnome_settings_plugin_info_activate (info); if (res) { g_debug ("Plugin %s: active", gnome_settings_plugin_info_get_location (info)); } else { g_debug ("Plugin %s: activation failed", gnome_settings_plugin_info_get_location (info)); } } else { g_debug ("Plugin %s: inactive", gnome_settings_plugin_info_get_location (info)); } } static gint compare_location (GnomeSettingsPluginInfo *a, GnomeSettingsPluginInfo *b) { const char *loc_a; const char *loc_b; loc_a = gnome_settings_plugin_info_get_location (a); loc_b = gnome_settings_plugin_info_get_location (b); if (loc_a == NULL || loc_b == NULL) { return -1; } return strcmp (loc_a, loc_b); } static int compare_priority (GnomeSettingsPluginInfo *a, GnomeSettingsPluginInfo *b) { int prio_a; int prio_b; prio_a = gnome_settings_plugin_info_get_priority (a); prio_b = gnome_settings_plugin_info_get_priority (b); return prio_a - prio_b; } static void emit_signal (GnomeSettingsManager *manager, const char *signal, const char *name) { GError *error = NULL; GQueue *signal_queue = manager->priv->signal_queue; /* Queue up signal if there's no D-Bus connection */ if (manager->priv->connection == NULL) { g_debug ("Connection is null, cannot emit signal, queue instead"); SignalCache *cache = g_new0 (SignalCache, 1); cache->signal = g_strdup (signal); cache->name = g_strdup (name); g_queue_push_tail (signal_queue, cache); return; } if (g_dbus_connection_emit_signal (manager->priv->connection, NULL, GSD_DBUS_PATH, GSD_DBUS_NAME, signal, g_variant_new ("(s)", name), &error) == FALSE) { g_debug ("Error emitting signal: %s", error->message); g_error_free (error); } } static void on_plugin_activated (GnomeSettingsPluginInfo *info, GnomeSettingsManager *manager) { const char *name; name = gnome_settings_plugin_info_get_location (info); g_debug ("GnomeSettingsManager: emitting plugin-activated %s", name); emit_signal (manager, "PluginActivated", name); } static void on_plugin_deactivated (GnomeSettingsPluginInfo *info, GnomeSettingsManager *manager) { const char *name; name = gnome_settings_plugin_info_get_location (info); g_debug ("GnomeSettingsManager: emitting plugin-deactivated %s", name); emit_signal (manager, "PluginDeactivated", name); } static gboolean contained (const char * const *items, const char *item) { while (*items) { if (g_strcmp0 (*items++, item) == 0) { return TRUE; } } return FALSE; } static gboolean is_schema (const char *schema) { return contained (g_settings_list_schemas (), schema); } static gboolean is_whitelisted (char **whitelist, const char *plugin_name) { if (whitelist == NULL || whitelist[0] == NULL || g_strcmp0 (whitelist[0], "all") == 0) return TRUE; return contained ((const char * const *) whitelist, plugin_name); } static void _load_file (GnomeSettingsManager *manager, const char *filename) { GnomeSettingsPluginInfo *info; char *key_name; GSList *l; g_debug ("Loading plugin: %s", filename); gnome_settings_profile_start ("%s", filename); info = gnome_settings_plugin_info_new_from_file (filename); if (info == NULL) { goto out; } l = g_slist_find_custom (manager->priv->plugins, info, (GCompareFunc) compare_location); if (l != NULL) { goto out; } if (!is_whitelisted (manager->priv->whitelist, gnome_settings_plugin_info_get_location (info))) { g_debug ("Plugin %s ignored as it's not whitelisted", gnome_settings_plugin_info_get_location (info)); goto out; } key_name = g_strdup_printf ("%s.plugins.%s", DEFAULT_SETTINGS_PREFIX, gnome_settings_plugin_info_get_location (info)); /* Ignore unknown schemas or else we'll assert */ if (is_schema (key_name)) { manager->priv->plugins = g_slist_prepend (manager->priv->plugins, g_object_ref (info)); g_signal_connect (info, "activated", G_CALLBACK (on_plugin_activated), manager); g_signal_connect (info, "deactivated", G_CALLBACK (on_plugin_deactivated), manager); gnome_settings_plugin_info_set_settings_prefix (info, key_name); } else { g_warning ("Ignoring unknown module '%s'", key_name); } /* Priority is set in the call above */ g_free (key_name); out: if (info != NULL) { g_object_unref (info); } gnome_settings_profile_end ("%s", filename); } static void _load_dir (GnomeSettingsManager *manager, const char *path) { GError *error; GDir *d; const char *name; g_debug ("Loading settings plugins from dir: %s", path); gnome_settings_profile_start (NULL); error = NULL; d = g_dir_open (path, 0, &error); if (d == NULL) { g_warning ("%s", error->message); g_error_free (error); return; } while ((name = g_dir_read_name (d))) { char *filename; if (!g_str_has_suffix (name, PLUGIN_EXT)) { continue; } filename = g_build_filename (path, name, NULL); if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { _load_file (manager, filename); } g_free (filename); } g_dir_close (d); gnome_settings_profile_end (NULL); } static void _load_all (GnomeSettingsManager *manager) { gnome_settings_profile_start (NULL); /* load system plugins */ _load_dir (manager, GNOME_SETTINGS_PLUGINDIR G_DIR_SEPARATOR_S); manager->priv->plugins = g_slist_sort (manager->priv->plugins, (GCompareFunc) compare_priority); g_slist_foreach (manager->priv->plugins, (GFunc) maybe_activate_plugin, NULL); gnome_settings_profile_end (NULL); } static void _unload_plugin (GnomeSettingsPluginInfo *info, gpointer user_data) { if (gnome_settings_plugin_info_get_enabled (info)) { gnome_settings_plugin_info_deactivate (info); } g_object_unref (info); } static void _unload_all (GnomeSettingsManager *manager) { g_slist_foreach (manager->priv->plugins, (GFunc) _unload_plugin, NULL); g_slist_free (manager->priv->plugins); manager->priv->plugins = NULL; } static void on_bus_gotten (GObject *source_object, GAsyncResult *res, GnomeSettingsManager *manager) { GDBusConnection *connection; GError *error = NULL; GQueue *signal_queue = manager->priv->signal_queue; connection = g_bus_get_finish (res, &error); if (connection == NULL) { g_warning ("Could not get session bus: %s", error->message); g_error_free (error); return; } manager->priv->connection = connection; g_dbus_connection_register_object (connection, GSD_DBUS_PATH, manager->priv->introspection_data->interfaces[0], NULL, NULL, NULL, NULL); /* Emit queued up signals after got D-Bus connection */ if (!g_queue_is_empty (signal_queue)) { g_debug ("Emit queued up signals"); while (!g_queue_is_empty (signal_queue)) { SignalCache *cache = g_queue_pop_head (signal_queue); emit_signal (manager, cache->signal, cache->name); signal_cache_free (cache); } } } static void register_manager (GnomeSettingsManager *manager) { manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (manager->priv->introspection_data != NULL); g_bus_get (G_BUS_TYPE_SESSION, NULL, (GAsyncReadyCallback) on_bus_gotten, manager); } gboolean gnome_settings_manager_start (GnomeSettingsManager *manager, GError **error) { gboolean ret; g_debug ("Starting settings manager"); ret = FALSE; gnome_settings_profile_start (NULL); if (!g_module_supported ()) { g_warning ("gnome-settings-daemon is not able to initialize the plugins."); g_set_error (error, GNOME_SETTINGS_MANAGER_ERROR, GNOME_SETTINGS_MANAGER_ERROR_GENERAL, "Plugins not supported"); goto out; } manager->priv->signal_queue = g_queue_new (); g_debug ("loading PNPIDs"); manager->priv->pnp_ids = gsd_pnp_ids_new (); gnome_settings_profile_start ("initializing plugins"); manager->priv->settings = g_settings_new (DEFAULT_SETTINGS_PREFIX ".plugins"); manager->priv->whitelist = g_settings_get_strv (manager->priv->settings, "whitelisted-plugins"); _load_all (manager); gnome_settings_profile_end ("initializing plugins"); ret = TRUE; out: gnome_settings_profile_end (NULL); return ret; } void gnome_settings_manager_stop (GnomeSettingsManager *manager) { g_debug ("Stopping settings manager"); _unload_all (manager); if (manager->priv->owner_id > 0) { g_bus_unown_name (manager->priv->owner_id); manager->priv->owner_id = 0; } /* This will be called from both stop_manager and dispose, so we need to * prevent the queue being freed twice */ if (manager->priv->signal_queue != NULL) { g_queue_free_full (manager->priv->signal_queue, signal_cache_free); manager->priv->signal_queue = NULL; } g_clear_pointer (&manager->priv->whitelist, g_strfreev); g_clear_object (&manager->priv->settings); g_clear_object (&manager->priv->pnp_ids); } static void gnome_settings_manager_dispose (GObject *object) { GnomeSettingsManager *manager; manager = GNOME_SETTINGS_MANAGER (object); gnome_settings_manager_stop (manager); G_OBJECT_CLASS (gnome_settings_manager_parent_class)->dispose (object); } static void gnome_settings_manager_class_init (GnomeSettingsManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = gnome_settings_manager_dispose; object_class->finalize = gnome_settings_manager_finalize; g_type_class_add_private (klass, sizeof (GnomeSettingsManagerPrivate)); } static void gnome_settings_manager_init (GnomeSettingsManager *manager) { manager->priv = GNOME_SETTINGS_MANAGER_GET_PRIVATE (manager); } static void gnome_settings_manager_finalize (GObject *object) { GnomeSettingsManager *manager; g_return_if_fail (object != NULL); g_return_if_fail (GNOME_IS_SETTINGS_MANAGER (object)); manager = GNOME_SETTINGS_MANAGER (object); g_return_if_fail (manager->priv != NULL); G_OBJECT_CLASS (gnome_settings_manager_parent_class)->finalize (object); } GnomeSettingsManager * gnome_settings_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GNOME_TYPE_SETTINGS_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); register_manager (manager_object); } return GNOME_SETTINGS_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-manager.h0000664000175000017500000000563300000000000027775 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GNOME_SETTINGS_MANAGER_H #define __GNOME_SETTINGS_MANAGER_H #include G_BEGIN_DECLS #define GNOME_TYPE_SETTINGS_MANAGER (gnome_settings_manager_get_type ()) #define GNOME_SETTINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNOME_TYPE_SETTINGS_MANAGER, GnomeSettingsManager)) #define GNOME_SETTINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GNOME_TYPE_SETTINGS_MANAGER, GnomeSettingsManagerClass)) #define GNOME_IS_SETTINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNOME_TYPE_SETTINGS_MANAGER)) #define GNOME_IS_SETTINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GNOME_TYPE_SETTINGS_MANAGER)) #define GNOME_SETTINGS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GNOME_TYPE_SETTINGS_MANAGER, GnomeSettingsManagerClass)) typedef struct GnomeSettingsManagerPrivate GnomeSettingsManagerPrivate; typedef struct { GObject parent; GnomeSettingsManagerPrivate *priv; } GnomeSettingsManager; typedef struct { GObjectClass parent_class; void (* plugin_activated) (GnomeSettingsManager *manager, const char *name); void (* plugin_deactivated) (GnomeSettingsManager *manager, const char *name); } GnomeSettingsManagerClass; typedef enum { GNOME_SETTINGS_MANAGER_ERROR_GENERAL } GnomeSettingsManagerError; #define GNOME_SETTINGS_MANAGER_ERROR gnome_settings_manager_error_quark () GQuark gnome_settings_manager_error_quark (void); GType gnome_settings_manager_get_type (void); GnomeSettingsManager * gnome_settings_manager_new (void); gboolean gnome_settings_manager_start (GnomeSettingsManager *manager, GError **error); void gnome_settings_manager_stop (GnomeSettingsManager *manager); G_END_DECLS #endif /* __GNOME_SETTINGS_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-module.c0000664000175000017500000001054500000000000027641 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ #include "config.h" #include "gnome-settings-module.h" #include typedef struct _GnomeSettingsModuleClass GnomeSettingsModuleClass; struct _GnomeSettingsModuleClass { GTypeModuleClass parent_class; }; struct _GnomeSettingsModule { GTypeModule parent_instance; GModule *library; char *path; GType type; }; typedef GType (*GnomeSettingsModuleRegisterFunc) (GTypeModule *); G_DEFINE_TYPE (GnomeSettingsModule, gnome_settings_module, G_TYPE_TYPE_MODULE) static gboolean gnome_settings_module_load (GTypeModule *gmodule) { GnomeSettingsModule *module; GnomeSettingsModuleRegisterFunc register_func; gboolean res; module = GNOME_SETTINGS_MODULE (gmodule); g_debug ("Loading %s", module->path); module->library = g_module_open (module->path, 0); if (module->library == NULL) { g_warning ("%s", g_module_error ()); return FALSE; } /* extract symbols from the lib */ res = g_module_symbol (module->library, "register_gnome_settings_plugin", (void *) ®ister_func); if (! res) { g_warning ("%s", g_module_error ()); g_module_close (module->library); return FALSE; } g_assert (register_func); module->type = register_func (gmodule); if (module->type == 0) { g_warning ("Invalid gnome settings plugin in module %s", module->path); return FALSE; } return TRUE; } static void gnome_settings_module_unload (GTypeModule *gmodule) { GnomeSettingsModule *module = GNOME_SETTINGS_MODULE (gmodule); g_debug ("Unloading %s", module->path); g_module_close (module->library); module->library = NULL; module->type = 0; } const gchar * gnome_settings_module_get_path (GnomeSettingsModule *module) { g_return_val_if_fail (GNOME_IS_SETTINGS_MODULE (module), NULL); return module->path; } GObject * gnome_settings_module_new_object (GnomeSettingsModule *module) { g_debug ("Creating object of type %s", g_type_name (module->type)); if (module->type == 0) { return NULL; } return g_object_new (module->type, NULL); } static void gnome_settings_module_init (GnomeSettingsModule *module) { g_debug ("GnomeSettingsModule %p initialising", module); } static void gnome_settings_module_finalize (GObject *object) { GnomeSettingsModule *module = GNOME_SETTINGS_MODULE (object); g_debug ("GnomeSettingsModule %p finalizing", module); g_free (module->path); G_OBJECT_CLASS (gnome_settings_module_parent_class)->finalize (object); } static void gnome_settings_module_class_init (GnomeSettingsModuleClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class); object_class->finalize = gnome_settings_module_finalize; module_class->load = gnome_settings_module_load; module_class->unload = gnome_settings_module_unload; } GnomeSettingsModule * gnome_settings_module_new (const char *path) { GnomeSettingsModule *result; if (path == NULL || path[0] == '\0') { return NULL; } result = g_object_new (GNOME_TYPE_SETTINGS_MODULE, NULL); g_type_module_set_name (G_TYPE_MODULE (result), path); result->path = g_strdup (path); return result; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-module.h0000664000175000017500000000410100000000000027635 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2005 - Paolo Maggi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ #ifndef GNOME_SETTINGS_MODULE_H #define GNOME_SETTINGS_MODULE_H #include G_BEGIN_DECLS #define GNOME_TYPE_SETTINGS_MODULE (gnome_settings_module_get_type ()) #define GNOME_SETTINGS_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_SETTINGS_MODULE, GnomeSettingsModule)) #define GNOME_SETTINGS_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_SETTINGS_MODULE, GnomeSettingsModuleClass)) #define GNOME_IS_SETTINGS_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_SETTINGS_MODULE)) #define GNOME_IS_SETTINGS_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), GNOME_TYPE_SETTINGS_MODULE)) #define GNOME_SETTINGS_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNOME_TYPE_SETTINGS_MODULE, GnomeSettingsModuleClass)) typedef struct _GnomeSettingsModule GnomeSettingsModule; GType gnome_settings_module_get_type (void) G_GNUC_CONST; GnomeSettingsModule *gnome_settings_module_new (const gchar *path); const char *gnome_settings_module_get_path (GnomeSettingsModule *module); GObject *gnome_settings_module_new_object (GnomeSettingsModule *module); G_END_DECLS #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-plugin-info.c0000664000175000017500000003746600000000000030616 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ #include "config.h" #include #include #include #include #include #include "gnome-settings-plugin-info.h" #include "gnome-settings-module.h" #include "gnome-settings-plugin.h" #include "gnome-settings-profile.h" #define GNOME_SETTINGS_PLUGIN_INFO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNOME_TYPE_SETTINGS_PLUGIN_INFO, GnomeSettingsPluginInfoPrivate)) #define PLUGIN_GROUP "GNOME Settings Plugin" #define PLUGIN_PRIORITY_MAX 1 #define PLUGIN_PRIORITY_DEFAULT 100 struct GnomeSettingsPluginInfoPrivate { char *file; GSettings *settings; char *location; GTypeModule *module; char *name; char *desc; char **authors; char *copyright; char *website; GnomeSettingsPlugin *plugin; int enabled : 1; int active : 1; /* A plugin is unavailable if it is not possible to activate it due to an error loading the plugin module (e.g. for Python plugins when the interpreter has not been correctly initializated) */ int available : 1; /* Priority determines the order in which plugins are started and * stopped. A lower number means higher priority. */ guint priority; }; enum { ACTIVATED, DEACTIVATED, LAST_SIGNAL }; static guint signals [LAST_SIGNAL] = { 0, }; G_DEFINE_TYPE (GnomeSettingsPluginInfo, gnome_settings_plugin_info, G_TYPE_OBJECT) static void gnome_settings_plugin_info_finalize (GObject *object) { GnomeSettingsPluginInfo *info; g_return_if_fail (object != NULL); g_return_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (object)); info = GNOME_SETTINGS_PLUGIN_INFO (object); g_return_if_fail (info->priv != NULL); if (info->priv->plugin != NULL) { g_debug ("Unref plugin %s", info->priv->name); g_object_unref (info->priv->plugin); /* info->priv->module must not be unref since it is not possible to finalize * a type module */ } g_free (info->priv->file); g_free (info->priv->location); g_free (info->priv->name); g_free (info->priv->desc); g_free (info->priv->website); g_free (info->priv->copyright); g_strfreev (info->priv->authors); if (info->priv->settings != NULL) { g_object_unref (info->priv->settings); } G_OBJECT_CLASS (gnome_settings_plugin_info_parent_class)->finalize (object); } static void gnome_settings_plugin_info_class_init (GnomeSettingsPluginInfoClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gnome_settings_plugin_info_finalize; signals [ACTIVATED] = g_signal_new ("activated", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GnomeSettingsPluginInfoClass, activated), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); signals [DEACTIVATED] = g_signal_new ("deactivated", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GnomeSettingsPluginInfoClass, deactivated), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); g_type_class_add_private (klass, sizeof (GnomeSettingsPluginInfoPrivate)); } static void gnome_settings_plugin_info_init (GnomeSettingsPluginInfo *info) { info->priv = GNOME_SETTINGS_PLUGIN_INFO_GET_PRIVATE (info); } static void debug_info (GnomeSettingsPluginInfo *info) { g_debug ("GnomeSettingsPluginInfo: name='%s' file='%s' location='%s'", info->priv->name, info->priv->file, info->priv->location); } static gboolean gnome_settings_plugin_info_fill_from_file (GnomeSettingsPluginInfo *info, const char *filename) { GKeyFile *plugin_file = NULL; char *str; int priority; gboolean ret; gnome_settings_profile_start ("%s", filename); ret = FALSE; info->priv->file = g_strdup (filename); plugin_file = g_key_file_new (); if (! g_key_file_load_from_file (plugin_file, filename, G_KEY_FILE_NONE, NULL)) { g_warning ("Bad plugin file: %s", filename); goto out; } if (! g_key_file_has_key (plugin_file, PLUGIN_GROUP, "IAge", NULL)) { g_debug ("IAge key does not exist in file: %s", filename); goto out; } /* Check IAge=2 */ if (g_key_file_get_integer (plugin_file, PLUGIN_GROUP, "IAge", NULL) != 0) { g_debug ("Wrong IAge in file: %s", filename); goto out; } /* Get Location */ str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, "Module", NULL); if ((str != NULL) && (*str != '\0')) { info->priv->location = str; } else { g_free (str); g_warning ("Could not find 'Module' in %s", filename); goto out; } /* Get Name */ str = g_key_file_get_locale_string (plugin_file, PLUGIN_GROUP, "Name", NULL, NULL); if (str != NULL) { info->priv->name = str; } else { g_warning ("Could not find 'Name' in %s", filename); goto out; } /* Get Description */ str = g_key_file_get_locale_string (plugin_file, PLUGIN_GROUP, "Description", NULL, NULL); if (str != NULL) { info->priv->desc = str; } else { g_debug ("Could not find 'Description' in %s", filename); } /* Get Authors */ info->priv->authors = g_key_file_get_string_list (plugin_file, PLUGIN_GROUP, "Authors", NULL, NULL); if (info->priv->authors == NULL) { g_debug ("Could not find 'Authors' in %s", filename); } /* Get Copyright */ str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, "Copyright", NULL); if (str != NULL) { info->priv->copyright = str; } else { g_debug ("Could not find 'Copyright' in %s", filename); } /* Get Website */ str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, "Website", NULL); if (str != NULL) { info->priv->website = str; } else { g_debug ("Could not find 'Website' in %s", filename); } /* Get Priority */ priority = g_key_file_get_integer (plugin_file, PLUGIN_GROUP, "Priority", NULL); if (priority >= PLUGIN_PRIORITY_MAX) { info->priv->priority = priority; } else { info->priv->priority = PLUGIN_PRIORITY_DEFAULT; } g_key_file_free (plugin_file); debug_info (info); /* If we know nothing about the availability of the plugin, set it as available */ info->priv->available = TRUE; ret = TRUE; out: gnome_settings_profile_end ("%s", filename); return ret; } GnomeSettingsPluginInfo * gnome_settings_plugin_info_new_from_file (const char *filename) { GnomeSettingsPluginInfo *info; gboolean res; info = g_object_new (GNOME_TYPE_SETTINGS_PLUGIN_INFO, NULL); res = gnome_settings_plugin_info_fill_from_file (info, filename); if (! res) { g_object_unref (info); info = NULL; } return info; } static void plugin_enabled_cb (GSettings *settings, const gchar *key, GnomeSettingsPluginInfo *info) { if (g_strcmp0 (key, "active") == 0) { if (g_settings_get_boolean (settings, "active")) gnome_settings_plugin_info_activate (info); else gnome_settings_plugin_info_deactivate (info); } } void gnome_settings_plugin_info_set_settings_prefix (GnomeSettingsPluginInfo *info, const char *settings_prefix) { int priority; info->priv->settings = g_settings_new (settings_prefix); info->priv->enabled = g_settings_get_boolean (info->priv->settings, "active"); priority = g_settings_get_int (info->priv->settings, "priority"); if (priority > 0) info->priv->priority = priority; g_signal_connect (G_OBJECT (info->priv->settings), "changed", G_CALLBACK (plugin_enabled_cb), info); } static void _deactivate_plugin (GnomeSettingsPluginInfo *info) { gnome_settings_plugin_deactivate (info->priv->plugin); g_signal_emit (info, signals [DEACTIVATED], 0); } gboolean gnome_settings_plugin_info_deactivate (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), FALSE); if (!info->priv->active || !info->priv->available) { return TRUE; } _deactivate_plugin (info); /* Update plugin state */ info->priv->active = FALSE; return TRUE; } static gboolean load_plugin_module (GnomeSettingsPluginInfo *info) { char *path; char *dirname; gboolean ret; ret = FALSE; g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), FALSE); g_return_val_if_fail (info->priv->file != NULL, FALSE); g_return_val_if_fail (info->priv->location != NULL, FALSE); g_return_val_if_fail (info->priv->plugin == NULL, FALSE); g_return_val_if_fail (info->priv->available, FALSE); gnome_settings_profile_start ("%s", info->priv->location); dirname = g_path_get_dirname (info->priv->file); g_return_val_if_fail (dirname != NULL, FALSE); path = g_module_build_path (dirname, info->priv->location); g_free (dirname); g_return_val_if_fail (path != NULL, FALSE); info->priv->module = G_TYPE_MODULE (gnome_settings_module_new (path)); g_free (path); if (!g_type_module_use (info->priv->module)) { g_warning ("Cannot load plugin '%s' since file '%s' cannot be read.", info->priv->name, gnome_settings_module_get_path (GNOME_SETTINGS_MODULE (info->priv->module))); g_object_unref (G_OBJECT (info->priv->module)); info->priv->module = NULL; /* Mark plugin as unavailable and fails */ info->priv->available = FALSE; goto out; } info->priv->plugin = GNOME_SETTINGS_PLUGIN (gnome_settings_module_new_object (GNOME_SETTINGS_MODULE (info->priv->module))); g_type_module_unuse (info->priv->module); ret = TRUE; out: gnome_settings_profile_end ("%s", info->priv->location); return ret; } static gboolean _activate_plugin (GnomeSettingsPluginInfo *info) { gboolean res = TRUE; if (!info->priv->available) { /* Plugin is not available, don't try to activate/load it */ return FALSE; } if (info->priv->plugin == NULL) { res = load_plugin_module (info); } if (res) { gnome_settings_plugin_activate (info->priv->plugin); g_signal_emit (info, signals [ACTIVATED], 0); } else { g_warning ("Error activating plugin '%s'", info->priv->name); } return res; } gboolean gnome_settings_plugin_info_activate (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), FALSE); if (! info->priv->available) { return FALSE; } if (info->priv->active) { return TRUE; } if (_activate_plugin (info)) { info->priv->active = TRUE; return TRUE; } return FALSE; } gboolean gnome_settings_plugin_info_is_active (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), FALSE); return (info->priv->available && info->priv->active); } gboolean gnome_settings_plugin_info_get_enabled (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), FALSE); return (info->priv->enabled); } gboolean gnome_settings_plugin_info_is_available (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), FALSE); return (info->priv->available != FALSE); } const char * gnome_settings_plugin_info_get_name (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), NULL); return info->priv->name; } const char * gnome_settings_plugin_info_get_description (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), NULL); return info->priv->desc; } const char ** gnome_settings_plugin_info_get_authors (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), (const char **)NULL); return (const char **)info->priv->authors; } const char * gnome_settings_plugin_info_get_website (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), NULL); return info->priv->website; } const char * gnome_settings_plugin_info_get_copyright (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), NULL); return info->priv->copyright; } const char * gnome_settings_plugin_info_get_location (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), NULL); return info->priv->location; } int gnome_settings_plugin_info_get_priority (GnomeSettingsPluginInfo *info) { g_return_val_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info), PLUGIN_PRIORITY_DEFAULT); return info->priv->priority; } void gnome_settings_plugin_info_set_priority (GnomeSettingsPluginInfo *info, int priority) { g_return_if_fail (GNOME_IS_SETTINGS_PLUGIN_INFO (info)); info->priv->priority = priority; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-plugin-info.h0000664000175000017500000000747400000000000030617 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ #ifndef __GNOME_SETTINGS_PLUGIN_INFO_H__ #define __GNOME_SETTINGS_PLUGIN_INFO_H__ #include #include G_BEGIN_DECLS #define GNOME_TYPE_SETTINGS_PLUGIN_INFO (gnome_settings_plugin_info_get_type()) #define GNOME_SETTINGS_PLUGIN_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNOME_TYPE_SETTINGS_PLUGIN_INFO, GnomeSettingsPluginInfo)) #define GNOME_SETTINGS_PLUGIN_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNOME_TYPE_SETTINGS_PLUGIN_INFO, GnomeSettingsPluginInfoClass)) #define GNOME_IS_SETTINGS_PLUGIN_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNOME_TYPE_SETTINGS_PLUGIN_INFO)) #define GNOME_IS_SETTINGS_PLUGIN_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_SETTINGS_PLUGIN_INFO)) #define GNOME_SETTINGS_PLUGIN_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNOME_TYPE_SETTINGS_PLUGIN_INFO, GnomeSettingsPluginInfoClass)) typedef struct GnomeSettingsPluginInfoPrivate GnomeSettingsPluginInfoPrivate; typedef struct { GObject parent; GnomeSettingsPluginInfoPrivate *priv; } GnomeSettingsPluginInfo; typedef struct { GObjectClass parent_class; void (* activated) (GnomeSettingsPluginInfo *info); void (* deactivated) (GnomeSettingsPluginInfo *info); } GnomeSettingsPluginInfoClass; GType gnome_settings_plugin_info_get_type (void) G_GNUC_CONST; GnomeSettingsPluginInfo *gnome_settings_plugin_info_new_from_file (const char *filename); void gnome_settings_plugin_info_set_settings_prefix (GnomeSettingsPluginInfo *info, const char *settings_prefix); gboolean gnome_settings_plugin_info_activate (GnomeSettingsPluginInfo *info); gboolean gnome_settings_plugin_info_deactivate (GnomeSettingsPluginInfo *info); gboolean gnome_settings_plugin_info_is_active (GnomeSettingsPluginInfo *info); gboolean gnome_settings_plugin_info_get_enabled (GnomeSettingsPluginInfo *info); gboolean gnome_settings_plugin_info_is_available (GnomeSettingsPluginInfo *info); const char *gnome_settings_plugin_info_get_name (GnomeSettingsPluginInfo *info); const char *gnome_settings_plugin_info_get_description (GnomeSettingsPluginInfo *info); const char **gnome_settings_plugin_info_get_authors (GnomeSettingsPluginInfo *info); const char *gnome_settings_plugin_info_get_website (GnomeSettingsPluginInfo *info); const char *gnome_settings_plugin_info_get_copyright (GnomeSettingsPluginInfo *info); const char *gnome_settings_plugin_info_get_location (GnomeSettingsPluginInfo *info); int gnome_settings_plugin_info_get_priority (GnomeSettingsPluginInfo *info); void gnome_settings_plugin_info_set_priority (GnomeSettingsPluginInfo *info, int priority); G_END_DECLS #endif /* __GNOME_SETTINGS_PLUGIN_INFO_H__ */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-plugin.c0000664000175000017500000000334500000000000027652 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2002-2005 Paolo Maggi * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ #include "config.h" #include "gnome-settings-plugin.h" G_DEFINE_TYPE (GnomeSettingsPlugin, gnome_settings_plugin, G_TYPE_OBJECT) static void dummy (GnomeSettingsPlugin *plugin) { /* Empty */ } static void gnome_settings_plugin_class_init (GnomeSettingsPluginClass *klass) { klass->activate = dummy; klass->deactivate = dummy; } static void gnome_settings_plugin_init (GnomeSettingsPlugin *plugin) { /* Empty */ } void gnome_settings_plugin_activate (GnomeSettingsPlugin *plugin) { g_return_if_fail (GNOME_IS_SETTINGS_PLUGIN (plugin)); GNOME_SETTINGS_PLUGIN_GET_CLASS (plugin)->activate (plugin); } void gnome_settings_plugin_deactivate (GnomeSettingsPlugin *plugin) { g_return_if_fail (GNOME_IS_SETTINGS_PLUGIN (plugin)); GNOME_SETTINGS_PLUGIN_GET_CLASS (plugin)->deactivate (plugin); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-plugin.h0000664000175000017500000002311100000000000027650 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2002-2005 Paolo Maggi * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ #ifndef __GNOME_SETTINGS_PLUGIN_H__ #define __GNOME_SETTINGS_PLUGIN_H__ #include #include G_BEGIN_DECLS #define GNOME_TYPE_SETTINGS_PLUGIN (gnome_settings_plugin_get_type()) #define GNOME_SETTINGS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNOME_TYPE_SETTINGS_PLUGIN, GnomeSettingsPlugin)) #define GNOME_SETTINGS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNOME_TYPE_SETTINGS_PLUGIN, GnomeSettingsPluginClass)) #define GNOME_IS_SETTINGS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNOME_TYPE_SETTINGS_PLUGIN)) #define GNOME_IS_SETTINGS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_SETTINGS_PLUGIN)) #define GNOME_SETTINGS_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNOME_TYPE_SETTINGS_PLUGIN, GnomeSettingsPluginClass)) typedef struct { GObject parent; } GnomeSettingsPlugin; typedef struct { GObjectClass parent_class; /* Virtual public methods */ void (*activate) (GnomeSettingsPlugin *plugin); void (*deactivate) (GnomeSettingsPlugin *plugin); } GnomeSettingsPluginClass; GType gnome_settings_plugin_get_type (void) G_GNUC_CONST; void gnome_settings_plugin_activate (GnomeSettingsPlugin *plugin); void gnome_settings_plugin_deactivate (GnomeSettingsPlugin *plugin); #define GSD_DBUS_NAME "org.gnome.SettingsDaemon" #define GSD_DBUS_PATH "/org/gnome/SettingsDaemon" #define GSD_DBUS_BASE_INTERFACE "org.gnome.SettingsDaemon" /* * Utility macro used to register plugins * * use: GNOME_SETTINGS_PLUGIN_REGISTER (PluginName, plugin_name) */ #define GNOME_SETTINGS_PLUGIN_REGISTER(PluginName, plugin_name) \ typedef struct { \ PluginName##Manager *manager; \ } PluginName##PluginPrivate; \ typedef struct { \ GnomeSettingsPlugin parent; \ PluginName##PluginPrivate *priv; \ } PluginName##Plugin; \ typedef struct { \ GnomeSettingsPluginClass parent_class; \ } PluginName##PluginClass; \ GType plugin_name##_plugin_get_type (void) G_GNUC_CONST; \ G_MODULE_EXPORT GType register_gnome_settings_plugin (GTypeModule *module); \ \ G_DEFINE_DYNAMIC_TYPE (PluginName##Plugin, \ plugin_name##_plugin, \ GNOME_TYPE_SETTINGS_PLUGIN) \ \ G_MODULE_EXPORT GType \ register_gnome_settings_plugin (GTypeModule *type_module) \ { \ plugin_name##_plugin_register_type (type_module); \ \ return plugin_name##_plugin_get_type(); \ } \ \ static void \ plugin_name##_plugin_class_finalize (PluginName##PluginClass * plugin_name##_class) \ { \ } \ \ static void \ plugin_name##_plugin_init (PluginName##Plugin *plugin) \ { \ plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE ((plugin), \ plugin_name##_plugin_get_type(), PluginName##PluginPrivate); \ g_debug (#PluginName " initializing"); \ plugin->priv->manager = plugin_name##_manager_new (); \ } \ \ static void \ plugin_name##_plugin_finalize (GObject *object) \ { \ PluginName##Plugin *plugin; \ g_return_if_fail (object != NULL); \ g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (object, plugin_name##_plugin_get_type())); \ g_debug ("PluginName## finalizing"); \ plugin = G_TYPE_CHECK_INSTANCE_CAST ((object), plugin_name##_plugin_get_type(), PluginName##Plugin); \ g_return_if_fail (plugin->priv != NULL); \ if (plugin->priv->manager != NULL) \ g_object_unref (plugin->priv->manager); \ G_OBJECT_CLASS (plugin_name##_plugin_parent_class)->finalize (object); \ } \ \ static void \ impl_activate (GnomeSettingsPlugin *plugin) \ { \ GError *error = NULL; \ PluginName##Plugin *plugin_cast; \ g_debug ("Activating %s plugin", G_STRINGIFY(plugin_name)); \ plugin_cast = G_TYPE_CHECK_INSTANCE_CAST ((plugin), plugin_name##_plugin_get_type(), PluginName##Plugin); \ if (!plugin_name##_manager_start (plugin_cast->priv->manager, &error)) { \ g_warning ("Unable to start %s manager: %s", G_STRINGIFY(plugin_name), error->message); \ g_error_free (error); \ } \ } \ \ static void \ impl_deactivate (GnomeSettingsPlugin *plugin) \ { \ PluginName##Plugin *plugin_cast; \ plugin_cast = G_TYPE_CHECK_INSTANCE_CAST ((plugin), plugin_name##_plugin_get_type(), PluginName##Plugin); \ g_debug ("Deactivating %s plugin", G_STRINGIFY (plugin_name)); \ plugin_name##_manager_stop (plugin_cast->priv->manager); \ } \ \ static void \ plugin_name##_plugin_class_init (PluginName##PluginClass *klass) \ { \ GObjectClass *object_class = G_OBJECT_CLASS (klass); \ GnomeSettingsPluginClass *plugin_class = GNOME_SETTINGS_PLUGIN_CLASS (klass); \ \ object_class->finalize = plugin_name##_plugin_finalize; \ plugin_class->activate = impl_activate; \ plugin_class->deactivate = impl_deactivate; \ g_type_class_add_private (klass, sizeof (PluginName##PluginPrivate)); \ } G_END_DECLS #endif /* __GNOME_SETTINGS_PLUGIN_H__ */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-profile.c0000664000175000017500000000367300000000000030020 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2005 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Authors: William Jon McCann * */ #include "config.h" #include #include #include #include #include #include #include #include #include "gnome-settings-profile.h" void _gnome_settings_profile_log (const char *func, const char *note, const char *format, ...) { va_list args; char *str; char *formatted; if (format == NULL) { formatted = g_strdup (""); } else { va_start (args, format); formatted = g_strdup_vprintf (format, args); va_end (args); } if (func != NULL) { str = g_strdup_printf ("MARK: %s %s: %s %s", g_get_prgname(), func, note ? note : "", formatted); } else { str = g_strdup_printf ("MARK: %s: %s %s", g_get_prgname(), note ? note : "", formatted); } g_free (formatted); g_access (str, F_OK); g_free (str); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gnome-settings-profile.h0000664000175000017500000000420500000000000030015 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2005 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Authors: William Jon McCann * */ #ifndef __GNOME_SETTINGS_PROFILE_H #define __GNOME_SETTINGS_PROFILE_H #include G_BEGIN_DECLS #ifdef ENABLE_PROFILING #ifdef G_HAVE_ISO_VARARGS #define gnome_settings_profile_start(...) _gnome_settings_profile_log (G_STRFUNC, "start", __VA_ARGS__) #define gnome_settings_profile_end(...) _gnome_settings_profile_log (G_STRFUNC, "end", __VA_ARGS__) #define gnome_settings_profile_msg(...) _gnome_settings_profile_log (NULL, NULL, __VA_ARGS__) #elif defined(G_HAVE_GNUC_VARARGS) #define gnome_settings_profile_start(format...) _gnome_settings_profile_log (G_STRFUNC, "start", format) #define gnome_settings_profile_end(format...) _gnome_settings_profile_log (G_STRFUNC, "end", format) #define gnome_settings_profile_msg(format...) _gnome_settings_profile_log (NULL, NULL, format) #endif #else #define gnome_settings_profile_start(...) #define gnome_settings_profile_end(...) #define gnome_settings_profile_msg(...) #endif void _gnome_settings_profile_log (const char *func, const char *note, const char *format, ...) G_GNUC_PRINTF (3, 4); G_END_DECLS #endif /* __GNOME_SETTINGS_PROFILE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-bg-crossfade.c0000664000175000017500000003540700000000000026531 0ustar00jeremyjeremy/* gsd-bg-crossfade.h - fade window background between two surfaces * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * as published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. * * Author: Ray Strode */ #include #include #include #include #include #include #include #include #include #include #include #include "gsd-bg.h" #include "gsd-bg-crossfade.h" struct _GsdBGCrossfadePrivate { GdkWindow *window; int width; int height; cairo_surface_t *fading_surface; cairo_surface_t *end_surface; gdouble start_time; gdouble total_duration; guint timeout_id; guint is_first_frame : 1; }; enum { PROP_0, PROP_WIDTH, PROP_HEIGHT, }; enum { FINISHED, NUMBER_OF_SIGNALS }; static guint signals[NUMBER_OF_SIGNALS] = { 0 }; G_DEFINE_TYPE_WITH_PRIVATE (GsdBGCrossfade, gsd_bg_crossfade, G_TYPE_OBJECT) static void gsd_bg_crossfade_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GsdBGCrossfade *fade; g_assert (GSD_IS_BG_CROSSFADE (object)); fade = GSD_BG_CROSSFADE (object); switch (property_id) { case PROP_WIDTH: fade->priv->width = g_value_get_int (value); break; case PROP_HEIGHT: fade->priv->height = g_value_get_int (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void gsd_bg_crossfade_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { GsdBGCrossfade *fade; g_assert (GSD_IS_BG_CROSSFADE (object)); fade = GSD_BG_CROSSFADE (object); switch (property_id) { case PROP_WIDTH: g_value_set_int (value, fade->priv->width); break; case PROP_HEIGHT: g_value_set_int (value, fade->priv->height); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void gsd_bg_crossfade_finalize (GObject *object) { GsdBGCrossfade *fade; fade = GSD_BG_CROSSFADE (object); gsd_bg_crossfade_stop (fade); if (fade->priv->fading_surface != NULL) { cairo_surface_destroy (fade->priv->fading_surface); fade->priv->fading_surface = NULL; } if (fade->priv->end_surface != NULL) { g_object_unref (fade->priv->end_surface); fade->priv->end_surface = NULL; } } static void gsd_bg_crossfade_class_init (GsdBGCrossfadeClass *fade_class) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (fade_class); gobject_class->get_property = gsd_bg_crossfade_get_property; gobject_class->set_property = gsd_bg_crossfade_set_property; gobject_class->finalize = gsd_bg_crossfade_finalize; /** * GsdBGCrossfade:width: * * When a crossfade is running, this is width of the fading * surface. */ g_object_class_install_property (gobject_class, PROP_WIDTH, g_param_spec_int ("width", "Window Width", "Width of window to fade", 0, G_MAXINT, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); /** * GsdBGCrossfade:height: * * When a crossfade is running, this is height of the fading * surface. */ g_object_class_install_property (gobject_class, PROP_HEIGHT, g_param_spec_int ("height", "Window Height", "Height of window to fade on", 0, G_MAXINT, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); /** * GsdBGCrossfade::finished: * @fade: the #GsdBGCrossfade that received the signal * @window: the #GdkWindow the crossfade happend on. * * When a crossfade finishes, @window will have a copy * of the end surface as its background, and this signal will * get emitted. */ signals[FINISHED] = g_signal_new ("finished", G_OBJECT_CLASS_TYPE (gobject_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); } static void gsd_bg_crossfade_init (GsdBGCrossfade *fade) { fade->priv = gsd_bg_crossfade_get_instance_private (fade); fade->priv->fading_surface = NULL; fade->priv->end_surface = NULL; fade->priv->timeout_id = 0; } /** * gsd_bg_crossfade_new: * @width: The width of the crossfading window * @height: The height of the crossfading window * * Creates a new object to manage crossfading a * window background between two #cairo_surface_ts. * * Return value: the new #GsdBGCrossfade **/ GsdBGCrossfade * gsd_bg_crossfade_new (int width, int height) { GObject *object; object = g_object_new (GSD_TYPE_BG_CROSSFADE, "width", width, "height", height, NULL); return (GsdBGCrossfade *) object; } static cairo_surface_t * tile_surface (cairo_surface_t *surface, int width, int height) { cairo_surface_t *copy; cairo_t *cr; if (surface == NULL) { copy = gdk_window_create_similar_surface (gdk_get_default_root_window (), CAIRO_CONTENT_COLOR, width, height); } else { copy = cairo_surface_create_similar (surface, cairo_surface_get_content (surface), width, height); } cr = cairo_create (copy); if (surface != NULL) { cairo_pattern_t *pattern; cairo_set_source_surface (cr, surface, 0.0, 0.0); pattern = cairo_get_source (cr); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); } else { GtkStyle *style; style = gtk_widget_get_default_style (); gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]); } cairo_paint (cr); if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { cairo_surface_destroy (copy); copy = NULL; } cairo_destroy (cr); return copy; } /** * gsd_bg_crossfade_set_start_surface: * @fade: a #GsdBGCrossfade * @surface: The cairo surface to fade from * * Before initiating a crossfade with gsd_bg_crossfade_start() * a start and end surface have to be set. This function sets * the surface shown at the beginning of the crossfade effect. * * Return value: %TRUE if successful, or %FALSE if the surface * could not be copied. **/ gboolean gsd_bg_crossfade_set_start_surface (GsdBGCrossfade *fade, cairo_surface_t *surface) { g_return_val_if_fail (GSD_IS_BG_CROSSFADE (fade), FALSE); if (fade->priv->fading_surface != NULL) { cairo_surface_destroy (fade->priv->fading_surface); fade->priv->fading_surface = NULL; } fade->priv->fading_surface = tile_surface (surface, fade->priv->width, fade->priv->height); return fade->priv->fading_surface != NULL; } static gdouble get_current_time (void) { const double microseconds_per_second = (double) G_USEC_PER_SEC; double timestamp; GTimeVal now; g_get_current_time (&now); timestamp = ((microseconds_per_second * now.tv_sec) + now.tv_usec) / microseconds_per_second; return timestamp; } /** * gsd_bg_crossfade_set_end_surface: * @fade: a #GsdBGCrossfade * @surface: The cairo surface to fade to * * Before initiating a crossfade with gsd_bg_crossfade_start() * a start and end surface have to be set. This function sets * the surface shown at the end of the crossfade effect. * * Return value: %TRUE if successful, or %FALSE if the surface * could not be copied. **/ gboolean gsd_bg_crossfade_set_end_surface (GsdBGCrossfade *fade, cairo_surface_t *surface) { g_return_val_if_fail (GSD_IS_BG_CROSSFADE (fade), FALSE); if (fade->priv->end_surface != NULL) { cairo_surface_destroy (fade->priv->end_surface); fade->priv->end_surface = NULL; } fade->priv->end_surface = tile_surface (surface, fade->priv->width, fade->priv->height); /* Reset timer in case we're called while animating */ fade->priv->start_time = get_current_time (); return fade->priv->end_surface != NULL; } static gboolean animations_are_disabled (GsdBGCrossfade *fade) { GtkSettings *settings; GdkScreen *screen; gboolean are_enabled; g_assert (fade->priv->window != NULL); screen = gdk_window_get_screen (fade->priv->window); settings = gtk_settings_get_for_screen (screen); g_object_get (settings, "gtk-enable-animations", &are_enabled, NULL); return !are_enabled; } static void send_root_property_change_notification (GsdBGCrossfade *fade) { long zero_length_pixmap; /* We do a zero length append to force a change notification, * without changing the value */ XChangeProperty (GDK_WINDOW_XDISPLAY (fade->priv->window), GDK_WINDOW_XID (fade->priv->window), gdk_x11_get_xatom_by_name ("_XROOTPMAP_ID"), XA_PIXMAP, 32, PropModeAppend, (guchar *) &zero_length_pixmap, 0); } static void draw_background (GsdBGCrossfade *fade) { if (gdk_window_get_window_type (fade->priv->window) == GDK_WINDOW_ROOT) { XClearArea (GDK_WINDOW_XDISPLAY (fade->priv->window), GDK_WINDOW_XID (fade->priv->window), 0, 0, gdk_window_get_width (fade->priv->window), gdk_window_get_height (fade->priv->window), False); send_root_property_change_notification (fade); gdk_flush (); } else { gdk_window_invalidate_rect (fade->priv->window, NULL, FALSE); gdk_window_process_updates (fade->priv->window, FALSE); } } static gboolean on_tick (GsdBGCrossfade *fade) { gdouble now, percent_done; cairo_t *cr; cairo_status_t status; g_return_val_if_fail (GSD_IS_BG_CROSSFADE (fade), FALSE); now = get_current_time (); percent_done = (now - fade->priv->start_time) / fade->priv->total_duration; percent_done = CLAMP (percent_done, 0.0, 1.0); /* If it's taking a long time to get to the first frame, * then lengthen the duration, so the user will get to see * the effect. */ if (fade->priv->is_first_frame && percent_done > .33) { fade->priv->is_first_frame = FALSE; fade->priv->total_duration *= 1.5; return on_tick (fade); } if (fade->priv->fading_surface == NULL) { return FALSE; } if (animations_are_disabled (fade)) { return FALSE; } /* We accumulate the results in place for performance reasons. * * This means 1) The fade is exponential, not linear (looks good!) * 2) The rate of fade is not independent of frame rate. Slower machines * will get a slower fade (but never longer than .75 seconds), and * even the fastest machines will get *some* fade because the framerate * is capped. */ cr = cairo_create (fade->priv->fading_surface); cairo_set_source_surface (cr, fade->priv->end_surface, 0.0, 0.0); cairo_paint_with_alpha (cr, percent_done); status = cairo_status (cr); cairo_destroy (cr); if (status == CAIRO_STATUS_SUCCESS) { draw_background (fade); } return percent_done <= .99; } static void on_finished (GsdBGCrossfade *fade) { cairo_pattern_t *pattern; if (fade->priv->timeout_id == 0) return; g_assert (fade->priv->end_surface != NULL); pattern = cairo_pattern_create_for_surface (fade->priv->end_surface); gdk_window_set_background_pattern (fade->priv->window, pattern); cairo_pattern_destroy (pattern); draw_background (fade); cairo_surface_destroy (fade->priv->end_surface); fade->priv->end_surface = NULL; g_assert (fade->priv->fading_surface != NULL); cairo_surface_destroy (fade->priv->fading_surface); fade->priv->fading_surface = NULL; fade->priv->timeout_id = 0; g_signal_emit (fade, signals[FINISHED], 0, fade->priv->window); } /** * gsd_bg_crossfade_start: * @fade: a #GsdBGCrossfade * @window: The #GdkWindow to draw crossfade on * * This function initiates a quick crossfade between two surfaces on * the background of @window. Before initiating the crossfade both * gsd_bg_crossfade_start() and gsd_bg_crossfade_end() need to * be called. If animations are disabled, the crossfade is skipped, * and the window background is set immediately to the end surface. **/ void gsd_bg_crossfade_start (GsdBGCrossfade *fade, GdkWindow *window) { GSource *source; GMainContext *context; cairo_pattern_t *pattern; g_return_if_fail (GSD_IS_BG_CROSSFADE (fade)); g_return_if_fail (window != NULL); g_return_if_fail (fade->priv->fading_surface != NULL); g_return_if_fail (fade->priv->end_surface != NULL); g_return_if_fail (!gsd_bg_crossfade_is_started (fade)); g_return_if_fail (gdk_window_get_window_type (window) != GDK_WINDOW_FOREIGN); source = g_timeout_source_new (1000 / 60.0); g_source_set_callback (source, (GSourceFunc) on_tick, fade, (GDestroyNotify) on_finished); context = g_main_context_default (); fade->priv->timeout_id = g_source_attach (source, context); g_source_unref (source); fade->priv->window = window; pattern = cairo_pattern_create_for_surface (fade->priv->fading_surface); gdk_window_set_background_pattern (fade->priv->window, pattern); cairo_pattern_destroy (pattern); draw_background (fade); fade->priv->is_first_frame = TRUE; fade->priv->total_duration = .75; fade->priv->start_time = get_current_time (); } /** * gsd_bg_crossfade_is_started: * @fade: a #GsdBGCrossfade * * This function reveals whether or not @fade is currently * running on a window. See gsd_bg_crossfade_start() for * information on how to initiate a crossfade. * * Return value: %TRUE if fading, or %FALSE if not fading **/ gboolean gsd_bg_crossfade_is_started (GsdBGCrossfade *fade) { g_return_val_if_fail (GSD_IS_BG_CROSSFADE (fade), FALSE); return fade->priv->timeout_id != 0; } /** * gsd_bg_crossfade_stop: * @fade: a #GsdBGCrossfade * * This function stops any in progress crossfades that may be * happening. It's harmless to call this function if @fade is * already stopped. **/ void gsd_bg_crossfade_stop (GsdBGCrossfade *fade) { g_return_if_fail (GSD_IS_BG_CROSSFADE (fade)); if (!gsd_bg_crossfade_is_started (fade)) return; g_assert (fade->priv->timeout_id != 0); g_source_remove (fade->priv->timeout_id); fade->priv->timeout_id = 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-bg-crossfade.h0000664000175000017500000000550400000000000026531 0ustar00jeremyjeremy/* gsd-bg-crossfade.h - fade window background between two surfaces Copyright 2008, Red Hat, Inc. This file is part of the Gnome Library. The Gnome Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The Gnome 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the Gnome Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Author: Ray Strode */ #ifndef __GSD_BG_CROSSFADE_H__ #define __GSD_BG_CROSSFADE_H__ #include G_BEGIN_DECLS #define GSD_TYPE_BG_CROSSFADE (gsd_bg_crossfade_get_type ()) #define GSD_BG_CROSSFADE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_BG_CROSSFADE, GsdBGCrossfade)) #define GSD_BG_CROSSFADE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_BG_CROSSFADE, GsdBGCrossfadeClass)) #define GSD_IS_BG_CROSSFADE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_BG_CROSSFADE)) #define GSD_IS_BG_CROSSFADE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_BG_CROSSFADE)) #define GSD_BG_CROSSFADE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_BG_CROSSFADE, GsdBGCrossfadeClass)) typedef struct _GsdBGCrossfadePrivate GsdBGCrossfadePrivate; typedef struct _GsdBGCrossfade GsdBGCrossfade; typedef struct _GsdBGCrossfadeClass GsdBGCrossfadeClass; struct _GsdBGCrossfade { GObject parent_object; GsdBGCrossfadePrivate *priv; }; struct _GsdBGCrossfadeClass { GObjectClass parent_class; void (* finished) (GsdBGCrossfade *fade, GdkWindow *window); }; G_DEFINE_AUTOPTR_CLEANUP_FUNC(GsdBGCrossfade, g_object_unref) GType gsd_bg_crossfade_get_type (void); GsdBGCrossfade *gsd_bg_crossfade_new (int width, int height); gboolean gsd_bg_crossfade_set_start_surface (GsdBGCrossfade *fade, cairo_surface_t *surface); gboolean gsd_bg_crossfade_set_end_surface (GsdBGCrossfade *fade, cairo_surface_t *surface); void gsd_bg_crossfade_start (GsdBGCrossfade *fade, GdkWindow *window); gboolean gsd_bg_crossfade_is_started (GsdBGCrossfade *fade); void gsd_bg_crossfade_stop (GsdBGCrossfade *fade); G_END_DECLS #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-bg-slide-show.c0000664000175000017500000006165300000000000026640 0ustar00jeremyjeremy/* gsd-bg-slide-show.h * * Copyright (C) 2008, 2013 Red Hat, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * as published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. * */ #include #include #include #include #include #include "gsd-bg-slide-show.h" struct _GsdBGSlideShowPrivate { GFile *file; double start_time; double total_duration; GQueue *slides; gboolean has_multiple_sizes; /* used during parsing */ struct tm start_tm; GQueue *stack; }; typedef struct _Slide Slide; struct _Slide { double duration; /* in seconds */ gboolean fixed; GSList *file1; GSList *file2; /* NULL if fixed is TRUE */ }; typedef struct _FileSize FileSize; struct _FileSize { gint width; gint height; char *file; }; enum { PROP_0, PROP_FILE, PROP_START_TIME, PROP_TOTAL_DURATION, PROP_HAS_MULTIPLE_SIZES, }; G_DEFINE_TYPE_WITH_PRIVATE (GsdBGSlideShow, gsd_bg_slide_show, G_TYPE_OBJECT) static void gsd_bg_slide_show_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GsdBGSlideShow *self; g_assert (GSD_BG_IS_SLIDE_SHOW (object)); self = GSD_BG_SLIDE_SHOW (object); switch (property_id) { case PROP_FILE: self->priv->file = g_object_ref (g_value_get_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void gsd_bg_slide_show_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { GsdBGSlideShow *self; g_assert (GSD_BG_IS_SLIDE_SHOW (object)); self = GSD_BG_SLIDE_SHOW (object); switch (property_id) { case PROP_FILE: g_value_set_object (value, self->priv->file); break; case PROP_START_TIME: g_value_set_int (value, self->priv->start_time); break; case PROP_TOTAL_DURATION: g_value_set_int (value, self->priv->total_duration); break; case PROP_HAS_MULTIPLE_SIZES: g_value_set_boolean (value, self->priv->has_multiple_sizes); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void gsd_bg_slide_show_finalize (GObject *object) { GsdBGSlideShow *self; GList *list; GSList *slist; FileSize *size; self = GSD_BG_SLIDE_SHOW (object); for (list = self->priv->slides->head; list != NULL; list = list->next) { Slide *slide = list->data; for (slist = slide->file1; slist != NULL; slist = slist->next) { size = slist->data; g_free (size->file); g_free (size); } g_slist_free (slide->file1); for (slist = slide->file2; slist != NULL; slist = slist->next) { size = slist->data; g_free (size->file); g_free (size); } g_slist_free (slide->file2); g_free (slide); } g_queue_free (self->priv->slides); g_queue_free_full (self->priv->stack, g_free); g_object_unref (self->priv->file); } static void gsd_bg_slide_show_class_init (GsdBGSlideShowClass *self_class) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (self_class); gobject_class->get_property = gsd_bg_slide_show_get_property; gobject_class->set_property = gsd_bg_slide_show_set_property; gobject_class->finalize = gsd_bg_slide_show_finalize; g_object_class_install_property (gobject_class, PROP_FILE, g_param_spec_object ("file", "File", "File", G_TYPE_FILE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (gobject_class, PROP_START_TIME, g_param_spec_double ("start-time", "Start time", "start time", 0.0, G_MAXDOUBLE, 0.0, G_PARAM_READABLE)); g_object_class_install_property (gobject_class, PROP_TOTAL_DURATION, g_param_spec_double ("total-duration", "Start duration", "total duration", 0.0, G_MAXDOUBLE, 0.0, G_PARAM_READABLE)); g_object_class_install_property (gobject_class, PROP_HAS_MULTIPLE_SIZES, g_param_spec_boolean ("has-multiple-sizes", "Has multiple sizes", "Has multiple sizes", FALSE, G_PARAM_READABLE)); } static void gsd_bg_slide_show_init (GsdBGSlideShow *self) { self->priv = gsd_bg_slide_show_get_instance_private (self); self->priv->stack = g_queue_new (); self->priv->slides = g_queue_new (); } /** * gsd_bg_slide_show_new: * @filename: The filename of the slide show * * Creates a new object to manage a slide show. * window background between two #cairo_surface_ts. * * Return value: the new #GsdBGSlideShow **/ GsdBGSlideShow * gsd_bg_slide_show_new (const char *filename) { GFile *file; GsdBGSlideShow *self; file = g_file_new_for_path (filename); self = GSD_BG_SLIDE_SHOW (g_object_new (GSD_BG_TYPE_SLIDE_SHOW, "file", file, NULL)); g_object_unref (file); return self; } static void threadsafe_localtime (time_t time, struct tm *tm) { struct tm *res; G_LOCK_DEFINE_STATIC (localtime_mutex); G_LOCK (localtime_mutex); res = localtime (&time); if (tm) { *tm = *res; } G_UNLOCK (localtime_mutex); } static gboolean stack_is (GsdBGSlideShow *self, const char *s1, ...); /* Parser for fading background */ static void handle_start_element (GMarkupParseContext *context, const gchar *name, const gchar **attr_names, const gchar **attr_values, gpointer user_data, GError **err) { GsdBGSlideShow *self = user_data; gint i; if (strcmp (name, "static") == 0 || strcmp (name, "transition") == 0) { Slide *slide = g_new0 (Slide, 1); if (strcmp (name, "static") == 0) slide->fixed = TRUE; g_queue_push_tail (self->priv->slides, slide); } else if (strcmp (name, "size") == 0) { Slide *slide = self->priv->slides->tail->data; FileSize *size = g_new0 (FileSize, 1); for (i = 0; attr_names[i]; i++) { if (strcmp (attr_names[i], "width") == 0) size->width = atoi (attr_values[i]); else if (strcmp (attr_names[i], "height") == 0) size->height = atoi (attr_values[i]); } if (self->priv->stack->tail && (strcmp (self->priv->stack->tail->data, "file") == 0 || strcmp (self->priv->stack->tail->data, "from") == 0)) { slide->file1 = g_slist_prepend (slide->file1, size); } else if (self->priv->stack->tail && strcmp (self->priv->stack->tail->data, "to") == 0) { slide->file2 = g_slist_prepend (slide->file2, size); } } g_queue_push_tail (self->priv->stack, g_strdup (name)); } static void handle_end_element (GMarkupParseContext *context, const gchar *name, gpointer user_data, GError **err) { GsdBGSlideShow *self = user_data; g_free (g_queue_pop_tail (self->priv->stack)); } static gboolean stack_is (GsdBGSlideShow *self, const char *s1, ...) { GList *stack = NULL; const char *s; GList *l1, *l2; va_list args; stack = g_list_prepend (stack, (gpointer)s1); va_start (args, s1); s = va_arg (args, const char *); while (s) { stack = g_list_prepend (stack, (gpointer)s); s = va_arg (args, const char *); } l1 = stack; l2 = self->priv->stack->head; while (l1 && l2) { if (strcmp (l1->data, l2->data) != 0) { g_list_free (stack); return FALSE; } l1 = l1->next; l2 = l2->next; } g_list_free (stack); return (!l1 && !l2); } static int parse_int (const char *text) { return strtol (text, NULL, 0); } static void handle_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **err) { GsdBGSlideShow *self = user_data; Slide *slide = self->priv->slides->tail? self->priv->slides->tail->data : NULL; FileSize *fs; gint i; if (stack_is (self, "year", "starttime", "background", NULL)) { self->priv->start_tm.tm_year = parse_int (text) - 1900; } else if (stack_is (self, "month", "starttime", "background", NULL)) { self->priv->start_tm.tm_mon = parse_int (text) - 1; } else if (stack_is (self, "day", "starttime", "background", NULL)) { self->priv->start_tm.tm_mday = parse_int (text); } else if (stack_is (self, "hour", "starttime", "background", NULL)) { self->priv->start_tm.tm_hour = parse_int (text) - 1; } else if (stack_is (self, "minute", "starttime", "background", NULL)) { self->priv->start_tm.tm_min = parse_int (text); } else if (stack_is (self, "second", "starttime", "background", NULL)) { self->priv->start_tm.tm_sec = parse_int (text); } else if (stack_is (self, "duration", "static", "background", NULL) || stack_is (self, "duration", "transition", "background", NULL)) { slide->duration = g_strtod (text, NULL); self->priv->total_duration += slide->duration; } else if (stack_is (self, "file", "static", "background", NULL) || stack_is (self, "from", "transition", "background", NULL)) { for (i = 0; text[i]; i++) { if (!g_ascii_isspace (text[i])) break; } if (text[i] == 0) return; fs = g_new (FileSize, 1); fs->width = -1; fs->height = -1; fs->file = g_strdup (text); slide->file1 = g_slist_prepend (slide->file1, fs); if (slide->file1->next != NULL) self->priv->has_multiple_sizes = TRUE; } else if (stack_is (self, "size", "file", "static", "background", NULL) || stack_is (self, "size", "from", "transition", "background", NULL)) { fs = slide->file1->data; fs->file = g_strdup (text); if (slide->file1->next != NULL) self->priv->has_multiple_sizes = TRUE; } else if (stack_is (self, "to", "transition", "background", NULL)) { for (i = 0; text[i]; i++) { if (!g_ascii_isspace (text[i])) break; } if (text[i] == 0) return; fs = g_new (FileSize, 1); fs->width = -1; fs->height = -1; fs->file = g_strdup (text); slide->file2 = g_slist_prepend (slide->file2, fs); if (slide->file2->next != NULL) self->priv->has_multiple_sizes = TRUE; } else if (stack_is (self, "size", "to", "transition", "background", NULL)) { fs = slide->file2->data; fs->file = g_strdup (text); if (slide->file2->next != NULL) self->priv->has_multiple_sizes = TRUE; } } /* * Find the FileSize that best matches the given size. * Do two passes; the first pass only considers FileSizes * that are larger than the given size. * We are looking for the image that best matches the aspect ratio. * When two images have the same aspect ratio, prefer the one whose * width is closer to the given width. */ static const char * find_best_size (GSList *sizes, gint width, gint height) { GSList *s; gdouble a, d, distance; FileSize *best = NULL; gint pass; a = width/(gdouble)height; distance = 10000.0; for (pass = 0; pass < 2; pass++) { for (s = sizes; s; s = s->next) { FileSize *size = s->data; if (pass == 0 && (size->width < width || size->height < height)) continue; d = fabs (a - size->width/(gdouble)size->height); if (d < distance) { distance = d; best = size; } else if (d == distance) { if (abs (size->width - width) < abs (best->width - width)) { best = size; } } } if (best) break; } return best->file; } static double now (void) { GTimeVal tv; g_get_current_time (&tv); return (double)tv.tv_sec + (tv.tv_usec / 1000000.0); } /** * gsd_bg_slide_show_get_current_slide: * @self: a #GsdBGSlideShow * @width: monitor width * @height: monitor height * @progress: (out) (allow-none): slide progress * @duration: (out) (allow-none): slide duration * @is_fixed: (out) (allow-none): if slide is fixed * @file1: (out) (allow-none) (transfer none): first file in slide * @file2: (out) (allow-none) (transfer none): second file in slide * * Returns the current slides progress. **/ void gsd_bg_slide_show_get_current_slide (GsdBGSlideShow *self, int width, int height, gdouble *progress, double *duration, gboolean *is_fixed, const char **file1, const char **file2) { double delta = fmod (now() - self->priv->start_time, self->priv->total_duration); GList *list; double elapsed; int i; if (delta < 0) delta += self->priv->total_duration; elapsed = 0; i = 0; for (list = self->priv->slides->head; list != NULL; list = list->next) { Slide *slide = list->data; if (elapsed + slide->duration > delta) { if (progress) *progress = (delta - elapsed) / (double)slide->duration; if (duration) *duration = slide->duration; if (is_fixed) *is_fixed = slide->fixed; if (file1) *file1 = find_best_size (slide->file1, width, height); if (file2 && slide->file2) *file2 = find_best_size (slide->file2, width, height); return; } i++; elapsed += slide->duration; } /* this should never happen since we have slides and we should always * find a current slide for the elapsed time since beginning -- we're * looping with fmod() */ g_assert_not_reached (); } /** * gsd_bg_slide_show_get_slide: * @self: a #GsdBGSlideShow * @frame_number: frame number * @width: monitor width * @height: monitor height * @progress: (out) (allow-none): slide progress * @duration: (out) (allow-none): slide duration * @is_fixed: (out) (allow-none): if slide is fixed * @file1: (out) (allow-none) (transfer none): first file in slide * @file2: (out) (allow-none) (transfer none): second file in slide * * Retrieves slide by frame number * * Return value: %TRUE if successful **/ gboolean gsd_bg_slide_show_get_slide (GsdBGSlideShow *self, int frame_number, int width, int height, double *progress, double *duration, gboolean *is_fixed, const char **file1, const char **file2) { double delta = fmod (now() - self->priv->start_time, self->priv->total_duration); GList *l; int i, skipped; gboolean found; double elapsed; Slide *slide; if (delta < 0) delta += self->priv->total_duration; elapsed = 0; i = 0; skipped = 0; found = FALSE; for (l = self->priv->slides->head; l; l = l->next) { slide = l->data; if (!slide->fixed) { elapsed += slide->duration; skipped++; continue; } if (i == frame_number) { found = TRUE; break; } i++; elapsed += slide->duration; } if (!found) return FALSE; if (progress) { if (elapsed + slide->duration > delta) { *progress = (delta - elapsed) / (double)slide->duration; } else { *progress = 0.0; } } if (duration) *duration = slide->duration; if (is_fixed) *is_fixed = slide->fixed; if (file1) *file1 = find_best_size (slide->file1, width, height); if (file2 && slide->file2) *file2 = find_best_size (slide->file2, width, height); return TRUE; } static gboolean parse_file_contents (GsdBGSlideShow *self, const char *contents, gsize len, GError **error) { GMarkupParser parser = { handle_start_element, handle_end_element, handle_text, NULL, /* passthrough */ NULL, /* error */ }; GMarkupParseContext *context = NULL; time_t t; gboolean failed = FALSE; threadsafe_localtime ((time_t)0, &self->priv->start_tm); context = g_markup_parse_context_new (&parser, 0, self, NULL); if (!g_markup_parse_context_parse (context, contents, len, error)) { failed = TRUE; } if (!failed && !g_markup_parse_context_end_parse (context, error)) { failed = TRUE; } g_markup_parse_context_free (context); if (!failed) { guint queue_length; t = mktime (&self->priv->start_tm); self->priv->start_time = (double)t; queue_length = g_queue_get_length (self->priv->slides); /* no slides, that's not a slideshow */ if (queue_length == 0) { g_set_error_literal (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "file is not a slide show since it has no slides"); failed = TRUE; /* one slide, there's no transition */ } else if (queue_length == 1) { Slide *slide = self->priv->slides->head->data; slide->duration = self->priv->total_duration = G_MAXUINT; } } return !failed; } /** * gsd_bg_slide_show_load: * @self: a #GsdBGSlideShow * @error: a #GError * * Tries to load the slide show. * * Return value: %TRUE if successful **/ gboolean gsd_bg_slide_show_load (GsdBGSlideShow *self, GError **error) { char *contents; gsize length; gboolean parsed; if (!g_file_load_contents (self->priv->file, NULL, &contents, &length, NULL, NULL)) { return FALSE; } parsed = parse_file_contents (self, contents, length, error); g_free (contents); return parsed; } static void on_file_loaded (GFile *file, GAsyncResult *result, GTask *task) { gboolean loaded; char *contents; gsize length; GError *error = NULL; loaded = g_file_load_contents_finish (file, result, &contents, &length, NULL, &error); if (!loaded) { g_task_return_error (task, error); g_object_unref (task); return; } if (!parse_file_contents (g_task_get_source_object (task), contents, length, &error)) { g_task_return_error (task, error); g_object_unref (task); g_free (contents); return; } g_free (contents); g_task_return_boolean (task, TRUE); g_object_unref (task); } /** * gsd_bg_slide_show_load_async: * @self: a #GsdBGSlideShow * @cancellable: a #GCancellable * @callback: the callback * @user_data: user data * * Tries to load the slide show asynchronously. **/ void gsd_bg_slide_show_load_async (GsdBGSlideShow *self, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; task = g_task_new (self, cancellable, callback, user_data); g_file_load_contents_async (self->priv->file, cancellable, (GAsyncReadyCallback) on_file_loaded, task); } /** * gsd_bg_slide_show_get_start_time: * @self: a #GsdBGSlideShow * * gets the start time of the slide show * * Return value: a timestamp **/ double gsd_bg_slide_show_get_start_time (GsdBGSlideShow *self) { return self->priv->start_time; } /** * gsd_bg_slide_show_get_total_duration: * @self: a #GsdBGSlideShow * * gets the total duration of the slide show * * Return value: a timestamp **/ double gsd_bg_slide_show_get_total_duration (GsdBGSlideShow *self) { return self->priv->total_duration; } /** * gsd_bg_slide_show_get_has_multiple_sizes: * @self: a #GsdBGSlideShow * * gets whether or not the slide show has multiple sizes for different monitors * * Return value: %TRUE if multiple sizes **/ gboolean gsd_bg_slide_show_get_has_multiple_sizes (GsdBGSlideShow *self) { return self->priv->has_multiple_sizes; } /** * gsd_bg_slide_show_get_num_slides: * @self: a #GsdBGSlideShow * * Returns number of slides in slide show **/ int gsd_bg_slide_show_get_num_slides (GsdBGSlideShow *self) { return g_queue_get_length (self->priv->slides); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-bg-slide-show.h0000664000175000017500000001033600000000000026635 0ustar00jeremyjeremy/* gsd-bg-slide_show.h - fade window background between two surfaces Copyright 2008, Red Hat, Inc. This file is part of the Gnome Library. The Gnome Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The Gnome 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the Gnome Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Author: Ray Strode */ #ifndef __GSD_BG_SLIDE_SHOW_H__ #define __GSD_BG_SLIDE_SHOW_H__ #include G_BEGIN_DECLS #define GSD_BG_TYPE_SLIDE_SHOW (gsd_bg_slide_show_get_type ()) #define GSD_BG_SLIDE_SHOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_BG_TYPE_SLIDE_SHOW, GsdBGSlideShow)) #define GSD_BG_SLIDE_SHOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_BG_TYPE_SLIDE_SHOW, GsdBGSlideShowClass)) #define GSD_BG_IS_SLIDE_SHOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_BG_TYPE_SLIDE_SHOW)) #define GSD_BG_IS_SLIDE_SHOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_BG_TYPE_SLIDE_SHOW)) #define GSD_BG_SLIDE_SHOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_BG_TYPE_SLIDE_SHOW, GsdBGSlideShowClass)) typedef struct _GsdBGSlideShowPrivate GsdBGSlideShowPrivate; typedef struct _GsdBGSlideShow GsdBGSlideShow; typedef struct _GsdBGSlideShowClass GsdBGSlideShowClass; struct _GsdBGSlideShow { GObject parent_object; GsdBGSlideShowPrivate *priv; }; struct _GsdBGSlideShowClass { GObjectClass parent_class; }; G_DEFINE_AUTOPTR_CLEANUP_FUNC(GsdBGSlideShow, g_object_unref) GType gsd_bg_slide_show_get_type (void); GsdBGSlideShow *gsd_bg_slide_show_new (const char *filename); gboolean gsd_bg_slide_show_load (GsdBGSlideShow *self, GError **error); void gsd_bg_slide_show_load_async (GsdBGSlideShow *self, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean gsd_bg_slide_show_get_slide (GsdBGSlideShow *self, int frame_number, int width, int height, gdouble *progress, double *duration, gboolean *is_fixed, const char **file1, const char **file2); void gsd_bg_slide_show_get_current_slide (GsdBGSlideShow *self, int width, int height, gdouble *progress, double *duration, gboolean *is_fixed, const char **file1, const char **file2); double gsd_bg_slide_show_get_start_time (GsdBGSlideShow *self); double gsd_bg_slide_show_get_total_duration (GsdBGSlideShow *self); gboolean gsd_bg_slide_show_get_has_multiple_sizes (GsdBGSlideShow *self); int gsd_bg_slide_show_get_num_slides (GsdBGSlideShow *self); G_END_DECLS #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-bg.c0000664000175000017500000022151000000000000024552 0ustar00jeremyjeremy/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- gnomebg.c: Object for the desktop background. Copyright (C) 2000 Eazel, Inc. Copyright (C) 2007-2008 Red Hat, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Derived from eel-background.c and eel-gdk-pixbuf-extensions.c by Darin Adler and Ramiro Estrugo Author: Soren Sandmann */ #include #include #include #include #include #include #include #include #include #include #include #include "gsd-bg.h" #include "gsd-bg-slide-show.h" #include "gsd-bg-crossfade.h" #define BG_KEY_DRAW_BACKGROUND "draw-background" #define BG_KEY_PRIMARY_COLOR "primary-color" #define BG_KEY_SECONDARY_COLOR "secondary-color" #define BG_KEY_COLOR_TYPE "color-shading-type" #define BG_KEY_PICTURE_PLACEMENT "picture-options" #define BG_KEY_PICTURE_OPACITY "picture-opacity" #define BG_KEY_PICTURE_URI "picture-uri" /* We keep the large pixbufs around if the next update in the slideshow is less than 60 seconds away */ #define KEEP_EXPENSIVE_CACHE_SECS 60 #define QUAD_MAX_LEVEL_OF_RECURSION 16 #define QUAD_MIN_LEVEL_OF_RECURSION 2 /* We're weighting the left side of the screen higher than the right because the launcher and dash are on that side of the screen. */ #define QUAD_CORNER_WEIGHT_NW 3 #define QUAD_CORNER_WEIGHT_NE 1 #define QUAD_CORNER_WEIGHT_SE 1 #define QUAD_CORNER_WEIGHT_SW 3 #define QUAD_CORNER_WEIGHT_CENTER 2 #define QUAD_CORNER_WEIGHT_TOTAL (QUAD_CORNER_WEIGHT_NW + QUAD_CORNER_WEIGHT_NE + QUAD_CORNER_WEIGHT_SE + QUAD_CORNER_WEIGHT_SW + QUAD_CORNER_WEIGHT_CENTER) /* This is the size of the GdkRGB dither matrix, in order to avoid * bad dithering when tiling the gradient */ #define GRADIENT_PIXMAP_TILE_SIZE 128 #define THUMBNAIL_SIZE 256 typedef struct FileCacheEntry FileCacheEntry; #define CACHE_SIZE 4 /* * Implementation of the GsdBG class */ struct _GsdBG { GObject parent_instance; char * filename; GDesktopBackgroundStyle placement; GDesktopBackgroundShading color_type; GdkRGBA primary; GdkRGBA secondary; gboolean is_enabled; GFileMonitor * file_monitor; guint changed_id; guint transitioned_id; guint blow_caches_id; /* Cached information, only access through cache accessor functions */ GsdBGSlideShow * slideshow; time_t file_mtime; GdkPixbuf * pixbuf_cache; int timeout_id; GList * file_cache; }; struct _GsdBGClass { GObjectClass parent_class; }; enum { CHANGED, TRANSITIONED, N_SIGNALS }; static const cairo_user_data_key_t average_color_key; static guint signals[N_SIGNALS] = { 0 }; G_DEFINE_TYPE (GsdBG, gsd_bg, G_TYPE_OBJECT) static cairo_surface_t *make_root_pixmap (GdkScreen *screen, gint width, gint height); /* Pixbuf utils */ static void pixbuf_average_value (GdkPixbuf *pixbuf, GdkRGBA *result); static GdkPixbuf *pixbuf_scale_to_fit (GdkPixbuf *src, int max_width, int max_height); static GdkPixbuf *pixbuf_scale_to_min (GdkPixbuf *src, int min_width, int min_height); static void pixbuf_draw_gradient (GdkPixbuf *pixbuf, gboolean horizontal, GdkRGBA *c1, GdkRGBA *c2, GdkRectangle *rect); static void pixbuf_tile (GdkPixbuf *src, GdkPixbuf *dest); static void pixbuf_blend (GdkPixbuf *src, GdkPixbuf *dest, int src_x, int src_y, int width, int height, int dest_x, int dest_y, double alpha); /* Thumbnail utilities */ static GdkPixbuf *create_thumbnail_for_filename (GnomeDesktopThumbnailFactory *factory, const char *filename); static gboolean get_thumb_annotations (GdkPixbuf *thumb, int *orig_width, int *orig_height); /* Cache */ static GdkPixbuf *get_pixbuf_for_size (GsdBG *bg, gint num_monitor, int width, int height); static void clear_cache (GsdBG *bg); static gboolean is_different (GsdBG *bg, const char *filename); static time_t get_mtime (const char *filename); static GdkPixbuf *create_img_thumbnail (GsdBG *bg, GnomeDesktopThumbnailFactory *factory, GdkScreen *screen, int dest_width, int dest_height, int frame_num); static GsdBGSlideShow * get_as_slideshow (GsdBG *bg, const char *filename); static GsdBGSlideShow *read_slideshow_file (const char *filename, GError **err); static void color_from_string (const char *string, GdkRGBA *colorp) { /* If all else fails use black */ gdk_rgba_parse (colorp, "black"); if (!string) return; gdk_rgba_parse (colorp, string); } static char * color_to_string (const GdkRGBA *color) { return g_strdup_printf ("#%02x%02x%02x", (int) (0.5 + color->red * 255), (int) (0.5 + color->green * 255), (int) (0.5 + color->blue * 255)); } static gboolean do_changed (GsdBG *bg) { gboolean ignore_pending_change; bg->changed_id = 0; ignore_pending_change = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (bg), "ignore-pending-change")); if (!ignore_pending_change) { g_signal_emit (G_OBJECT (bg), signals[CHANGED], 0); } return FALSE; } static void queue_changed (GsdBG *bg) { if (bg->changed_id > 0) { g_source_remove (bg->changed_id); } /* We unset this here to allow apps to set it if they don't want to get the change event. This is used by nautilus when it gets the pixmap from the bg (due to a reason other than the changed event). Because if there is no other change after this time the pending changed event will just uselessly cause us to recreate the pixmap. */ g_object_set_data (G_OBJECT (bg), "ignore-pending-change", GINT_TO_POINTER (FALSE)); bg->changed_id = g_timeout_add_full (G_PRIORITY_LOW, 100, (GSourceFunc)do_changed, bg, NULL); } static gboolean do_transitioned (GsdBG *bg) { bg->transitioned_id = 0; if (bg->pixbuf_cache) { g_object_unref (bg->pixbuf_cache); bg->pixbuf_cache = NULL; } g_signal_emit (G_OBJECT (bg), signals[TRANSITIONED], 0); return FALSE; } static void queue_transitioned (GsdBG *bg) { if (bg->transitioned_id > 0) { g_source_remove (bg->transitioned_id); } bg->transitioned_id = g_timeout_add_full (G_PRIORITY_LOW, 100, (GSourceFunc)do_transitioned, bg, NULL); } static gboolean bg_gsettings_mapping (GVariant *value, gpointer *result, gpointer user_data) { const gchar *bg_key_value; char *filename = NULL; /* The final fallback if nothing matches is with a NULL value. */ if (value == NULL) { *result = NULL; return TRUE; } bg_key_value = g_variant_get_string (value, NULL); if (bg_key_value && *bg_key_value != '\0') { filename = g_filename_from_uri (bg_key_value, NULL, NULL); if (filename != NULL && g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE) { g_free (filename); return FALSE; } if (filename != NULL) { *result = filename; return TRUE; } } return FALSE; } void gsd_bg_load_from_preferences (GsdBG *bg, GSettings *settings) { char *tmp; char *filename; GDesktopBackgroundShading ctype; GdkRGBA c1, c2; GDesktopBackgroundStyle placement; GSettings *background_settings; g_return_if_fail (GSD_IS_BG (bg)); g_return_if_fail (G_IS_SETTINGS (settings)); background_settings = g_settings_new ("com.canonical.unity.desktop.background"); bg->is_enabled = g_settings_get_boolean (background_settings, BG_KEY_DRAW_BACKGROUND); g_object_unref (background_settings); /* Filename */ filename = g_settings_get_mapped (settings, BG_KEY_PICTURE_URI, bg_gsettings_mapping, NULL); /* Colors */ tmp = g_settings_get_string (settings, BG_KEY_PRIMARY_COLOR); color_from_string (tmp, &c1); g_free (tmp); tmp = g_settings_get_string (settings, BG_KEY_SECONDARY_COLOR); color_from_string (tmp, &c2); g_free (tmp); /* Color type */ ctype = g_settings_get_enum (settings, BG_KEY_COLOR_TYPE); /* Placement */ placement = g_settings_get_enum (settings, BG_KEY_PICTURE_PLACEMENT); gsd_bg_set_rgba (bg, ctype, &c1, &c2); gsd_bg_set_placement (bg, placement); gsd_bg_set_filename (bg, filename); g_free (filename); } void gsd_bg_save_to_preferences (GsdBG *bg, GSettings *settings) { gchar *primary; gchar *secondary; gchar *uri; GSettings *background_settings; g_return_if_fail (GSD_IS_BG (bg)); g_return_if_fail (G_IS_SETTINGS (settings)); primary = color_to_string (&bg->primary); secondary = color_to_string (&bg->secondary); g_settings_delay (settings); uri = NULL; if (bg->filename != NULL) uri = g_filename_to_uri (bg->filename, NULL, NULL); if (uri == NULL) uri = g_strdup (""); background_settings = g_settings_new ("com.canonical.unity.desktop.background"); g_settings_set_boolean (background_settings, BG_KEY_DRAW_BACKGROUND, bg->is_enabled); g_object_unref (background_settings); g_settings_set_string (settings, BG_KEY_PICTURE_URI, uri); g_settings_set_string (settings, BG_KEY_PRIMARY_COLOR, primary); g_settings_set_string (settings, BG_KEY_SECONDARY_COLOR, secondary); g_settings_set_enum (settings, BG_KEY_COLOR_TYPE, bg->color_type); g_settings_set_enum (settings, BG_KEY_PICTURE_PLACEMENT, bg->placement); /* Apply changes atomically. */ g_settings_apply (settings); g_free (primary); g_free (secondary); g_free (uri); } static void gsd_bg_init (GsdBG *bg) { } static void gsd_bg_dispose (GObject *object) { GsdBG *bg = GSD_BG (object); if (bg->file_monitor) { g_object_unref (bg->file_monitor); bg->file_monitor = NULL; } clear_cache (bg); G_OBJECT_CLASS (gsd_bg_parent_class)->dispose (object); } static void gsd_bg_finalize (GObject *object) { GsdBG *bg = GSD_BG (object); if (bg->changed_id != 0) { g_source_remove (bg->changed_id); bg->changed_id = 0; } if (bg->transitioned_id != 0) { g_source_remove (bg->transitioned_id); bg->transitioned_id = 0; } if (bg->blow_caches_id != 0) { g_source_remove (bg->blow_caches_id); bg->blow_caches_id = 0; } g_free (bg->filename); bg->filename = NULL; G_OBJECT_CLASS (gsd_bg_parent_class)->finalize (object); } static void gsd_bg_class_init (GsdBGClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = gsd_bg_dispose; object_class->finalize = gsd_bg_finalize; signals[CHANGED] = g_signal_new ("changed", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); signals[TRANSITIONED] = g_signal_new ("transitioned", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } GsdBG * gsd_bg_new (void) { return g_object_new (GSD_TYPE_BG, NULL); } void gsd_bg_set_rgba (GsdBG *bg, GDesktopBackgroundShading type, GdkRGBA *primary, GdkRGBA *secondary) { g_return_if_fail (bg != NULL); g_return_if_fail (primary != NULL); if (bg->color_type != type || !gdk_rgba_equal (&bg->primary, primary) || (secondary && !gdk_rgba_equal (&bg->secondary, secondary))) { bg->color_type = type; bg->primary = *primary; if (secondary) { bg->secondary = *secondary; } queue_changed (bg); } } void gsd_bg_set_placement (GsdBG *bg, GDesktopBackgroundStyle placement) { g_return_if_fail (bg != NULL); if (bg->placement != placement) { bg->placement = placement; queue_changed (bg); } } GDesktopBackgroundStyle gsd_bg_get_placement (GsdBG *bg) { g_return_val_if_fail (bg != NULL, -1); return bg->placement; } void gsd_bg_get_rgba (GsdBG *bg, GDesktopBackgroundShading *type, GdkRGBA *primary, GdkRGBA *secondary) { g_return_if_fail (bg != NULL); if (type) *type = bg->color_type; if (primary) *primary = bg->primary; if (secondary) *secondary = bg->secondary; } void gsd_bg_set_draw_background (GsdBG *bg, gboolean draw_background) { g_return_if_fail (bg != NULL); if (bg->is_enabled != draw_background) { bg->is_enabled = draw_background; queue_changed (bg); } } gboolean gsd_bg_get_draw_background (GsdBG *bg) { g_return_val_if_fail (bg != NULL, FALSE); return bg->is_enabled; } const gchar * gsd_bg_get_filename (GsdBG *bg) { g_return_val_if_fail (bg != NULL, NULL); return bg->filename; } static inline gchar * get_wallpaper_cache_dir (void) { return g_build_filename (g_get_user_cache_dir(), "wallpaper", NULL); } static inline gchar * get_wallpaper_cache_prefix_name (gint num_monitor, GDesktopBackgroundStyle placement, gint width, gint height) { return g_strdup_printf ("%i_%i_%i_%i", num_monitor, (gint) placement, width, height); } static char * get_wallpaper_cache_filename (const char *filename, gint num_monitor, GDesktopBackgroundStyle placement, gint width, gint height) { gchar *cache_filename; gchar *cache_prefix_name; gchar *md5_filename; gchar *cache_basename; gchar *cache_dir; md5_filename = g_compute_checksum_for_data (G_CHECKSUM_MD5, (const guchar *) filename, strlen (filename)); cache_prefix_name = get_wallpaper_cache_prefix_name (num_monitor, placement, width, height); cache_basename = g_strdup_printf ("%s_%s", cache_prefix_name, md5_filename); cache_dir = get_wallpaper_cache_dir (); cache_filename = g_build_filename (cache_dir, cache_basename, NULL); g_free (cache_prefix_name); g_free (md5_filename); g_free (cache_basename); g_free (cache_dir); return cache_filename; } static void cleanup_cache_for_monitor (gchar *cache_dir, gint num_monitor) { GDir *g_cache_dir; gchar *monitor_prefix; const gchar *file; g_cache_dir = g_dir_open (cache_dir, 0, NULL); monitor_prefix = g_strdup_printf ("%i_", num_monitor); file = g_dir_read_name (g_cache_dir); while (file != NULL) { gchar *path; path = g_build_filename (cache_dir, file, NULL); /* purge files with same monitor id */ if (g_str_has_prefix (file, monitor_prefix) && g_file_test (path, G_FILE_TEST_IS_REGULAR)) g_unlink (path); g_free (path); file = g_dir_read_name (g_cache_dir); } g_free (monitor_prefix); g_dir_close (g_cache_dir); } static gboolean cache_file_is_valid (const char *filename, const char *cache_filename) { time_t mtime; time_t cache_mtime; if (!g_file_test (cache_filename, G_FILE_TEST_IS_REGULAR)) return FALSE; mtime = get_mtime (filename); cache_mtime = get_mtime (cache_filename); return (mtime < cache_mtime); } static void refresh_cache_file (GsdBG *bg, GdkPixbuf *new_pixbuf, gint num_monitor, gint width, gint height) { gchar *cache_filename; gchar *cache_dir; GdkPixbufFormat *format; gchar *format_name; if ((num_monitor == -1) || (width <= 300) || (height <= 300)) return; cache_filename = get_wallpaper_cache_filename (bg->filename, num_monitor, bg->placement, width, height); cache_dir = get_wallpaper_cache_dir (); /* Only refresh scaled file on disk if useful (and don't cache slideshow) */ if (!cache_file_is_valid (bg->filename, cache_filename)) { format = gdk_pixbuf_get_file_info (bg->filename, NULL, NULL); if (format != NULL) { if (!g_file_test (cache_dir, G_FILE_TEST_IS_DIR)) { g_mkdir_with_parents (cache_dir, 0700); } else { cleanup_cache_for_monitor (cache_dir, num_monitor); } format_name = gdk_pixbuf_format_get_name (format); if (strcmp (format_name, "jpeg") == 0) gdk_pixbuf_save (new_pixbuf, cache_filename, format_name, NULL, "quality", "100", NULL); else gdk_pixbuf_save (new_pixbuf, cache_filename, format_name, NULL, NULL); g_free (format_name); } } g_free (cache_filename); g_free (cache_dir); } static void file_changed (GFileMonitor *file_monitor, GFile *child, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { GsdBG *bg = GSD_BG (user_data); clear_cache (bg); queue_changed (bg); } void gsd_bg_set_filename (GsdBG *bg, const char *filename) { g_return_if_fail (bg != NULL); if (is_different (bg, filename)) { g_free (bg->filename); bg->filename = g_strdup (filename); bg->file_mtime = get_mtime (bg->filename); if (bg->file_monitor) { g_object_unref (bg->file_monitor); bg->file_monitor = NULL; } if (bg->filename) { GFile *f = g_file_new_for_path (bg->filename); bg->file_monitor = g_file_monitor_file (f, 0, NULL, NULL); g_signal_connect (bg->file_monitor, "changed", G_CALLBACK (file_changed), bg); g_object_unref (f); } clear_cache (bg); queue_changed (bg); } } static void draw_color_area (GsdBG *bg, GdkPixbuf *dest, GdkRectangle *rect) { guint32 pixel; GdkRectangle extent; extent.x = 0; extent.y = 0; extent.width = gdk_pixbuf_get_width (dest); extent.height = gdk_pixbuf_get_height (dest); gdk_rectangle_intersect (rect, &extent, rect); switch (bg->color_type) { case G_DESKTOP_BACKGROUND_SHADING_SOLID: /* not really a big deal to ignore the area of interest */ pixel = ((int) (0.5 + bg->primary.red * 255) << 24) | ((int) (0.5 + bg->primary.green * 255) << 16) | ((int) (0.5 + bg->primary.blue * 255) << 8) | (0xff); gdk_pixbuf_fill (dest, pixel); break; case G_DESKTOP_BACKGROUND_SHADING_HORIZONTAL: pixbuf_draw_gradient (dest, TRUE, &(bg->primary), &(bg->secondary), rect); break; case G_DESKTOP_BACKGROUND_SHADING_VERTICAL: pixbuf_draw_gradient (dest, FALSE, &(bg->primary), &(bg->secondary), rect); break; default: break; } } static void draw_color (GsdBG *bg, GdkPixbuf *dest) { GdkRectangle rect; rect.x = 0; rect.y = 0; rect.width = gdk_pixbuf_get_width (dest); rect.height = gdk_pixbuf_get_height (dest); draw_color_area (bg, dest, &rect); } static void draw_color_each_monitor (GsdBG *bg, GdkPixbuf *dest, GdkScreen *screen, gint scale) { GdkRectangle rect; gint num_monitors; int monitor; num_monitors = gdk_screen_get_n_monitors (screen); for (monitor = 0; monitor < num_monitors; monitor++) { gdk_screen_get_monitor_geometry (screen, monitor, &rect); rect.x *= scale; rect.y *= scale; rect.width *= scale; rect.height *= scale; draw_color_area (bg, dest, &rect); } } static GdkPixbuf * pixbuf_clip_to_fit (GdkPixbuf *src, int max_width, int max_height) { int src_width, src_height; int w, h; int src_x, src_y; GdkPixbuf *pixbuf; src_width = gdk_pixbuf_get_width (src); src_height = gdk_pixbuf_get_height (src); if (src_width < max_width && src_height < max_height) return g_object_ref (src); w = MIN(src_width, max_width); h = MIN(src_height, max_height); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, gdk_pixbuf_get_has_alpha (src), 8, w, h); src_x = (src_width - w) / 2; src_y = (src_height - h) / 2; gdk_pixbuf_copy_area (src, src_x, src_y, w, h, pixbuf, 0, 0); return pixbuf; } static GdkPixbuf * get_scaled_pixbuf (GDesktopBackgroundStyle placement, GdkPixbuf *pixbuf, int width, int height, int *x, int *y, int *w, int *h) { GdkPixbuf *new; #if 0 g_print ("original_width: %d %d\n", gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf)); #endif switch (placement) { case G_DESKTOP_BACKGROUND_STYLE_SPANNED: new = pixbuf_scale_to_fit (pixbuf, width, height); break; case G_DESKTOP_BACKGROUND_STYLE_ZOOM: new = pixbuf_scale_to_min (pixbuf, width, height); break; case G_DESKTOP_BACKGROUND_STYLE_STRETCHED: new = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); break; case G_DESKTOP_BACKGROUND_STYLE_SCALED: new = pixbuf_scale_to_fit (pixbuf, width, height); break; case G_DESKTOP_BACKGROUND_STYLE_NONE: /* This shouldn’t be true, but if it is, assert and * fall through, in case assertions are disabled. */ g_assert_not_reached (); case G_DESKTOP_BACKGROUND_STYLE_CENTERED: case G_DESKTOP_BACKGROUND_STYLE_WALLPAPER: default: new = pixbuf_clip_to_fit (pixbuf, width, height); break; } *w = gdk_pixbuf_get_width (new); *h = gdk_pixbuf_get_height (new); *x = (width - *w) / 2; *y = (height - *h) / 2; return new; } static void draw_image_area (GsdBG *bg, gint num_monitor, GdkPixbuf *pixbuf, GdkPixbuf *dest, GdkRectangle *area) { int dest_width = area->width; int dest_height = area->height; int x, y, w, h; GdkPixbuf *scaled; if (!pixbuf) return; scaled = get_scaled_pixbuf (bg->placement, pixbuf, dest_width, dest_height, &x, &y, &w, &h); switch (bg->placement) { case G_DESKTOP_BACKGROUND_STYLE_WALLPAPER: pixbuf_tile (scaled, dest); break; case G_DESKTOP_BACKGROUND_STYLE_ZOOM: case G_DESKTOP_BACKGROUND_STYLE_CENTERED: case G_DESKTOP_BACKGROUND_STYLE_STRETCHED: case G_DESKTOP_BACKGROUND_STYLE_SCALED: pixbuf_blend (scaled, dest, 0, 0, w, h, x + area->x, y + area->y, 1.0); break; case G_DESKTOP_BACKGROUND_STYLE_SPANNED: pixbuf_blend (scaled, dest, 0, 0, w, h, x, y, 1.0); break; case G_DESKTOP_BACKGROUND_STYLE_NONE: default: g_assert_not_reached (); break; } refresh_cache_file (bg, scaled, num_monitor, dest_width, dest_height); g_object_unref (scaled); } static void draw_image_for_thumb (GsdBG *bg, GdkPixbuf *pixbuf, GdkPixbuf *dest) { GdkRectangle rect; rect.x = 0; rect.y = 0; rect.width = gdk_pixbuf_get_width (dest); rect.height = gdk_pixbuf_get_height (dest); draw_image_area (bg, -1, pixbuf, dest, &rect); } static void draw_once (GsdBG *bg, GdkPixbuf *dest) { GdkRectangle rect; GdkPixbuf *pixbuf; gint num_monitor; /* we just draw on the whole screen */ num_monitor = 0; rect.x = 0; rect.y = 0; rect.width = gdk_pixbuf_get_width (dest); rect.height = gdk_pixbuf_get_height (dest); pixbuf = get_pixbuf_for_size (bg, num_monitor, rect.width, rect.height); if (pixbuf) { GdkPixbuf *rotated; rotated = gdk_pixbuf_apply_embedded_orientation (pixbuf); if (rotated != NULL) { g_object_unref (pixbuf); pixbuf = rotated; } draw_image_area (bg, num_monitor, pixbuf, dest, &rect); g_object_unref (pixbuf); } } static void draw_each_monitor (GsdBG *bg, GdkPixbuf *dest, GdkScreen *screen, gint scale) { GdkRectangle rect; gint num_monitors; int monitor; num_monitors = gdk_screen_get_n_monitors (screen); for (monitor = 0; monitor < num_monitors; monitor++) { GdkPixbuf *pixbuf; gdk_screen_get_monitor_geometry (screen, monitor, &rect); rect.x *= scale; rect.y *= scale; rect.width *= scale; rect.height *= scale; pixbuf = get_pixbuf_for_size (bg, monitor, rect.width, rect.height); if (pixbuf) { draw_image_area (bg, monitor, pixbuf, dest, &rect); g_object_unref (pixbuf); } } } void gsd_bg_draw (GsdBG *bg, GdkPixbuf *dest, GdkScreen *screen, gboolean is_root) { if (!bg) return; if (is_root && (bg->placement != G_DESKTOP_BACKGROUND_STYLE_SPANNED)) { draw_color_each_monitor (bg, dest, screen, 1); if (bg->placement != G_DESKTOP_BACKGROUND_STYLE_NONE) { draw_each_monitor (bg, dest, screen, 1); } } else { draw_color (bg, dest); if (bg->placement != G_DESKTOP_BACKGROUND_STYLE_NONE) { draw_once (bg, dest); } } } static void gsd_bg_draw_at_scale (GsdBG *bg, GdkPixbuf *dest, gint scale, GdkScreen *screen, gboolean is_root) { if (is_root && (bg->placement != G_DESKTOP_BACKGROUND_STYLE_SPANNED)) { draw_color_each_monitor (bg, dest, screen, scale); if (bg->placement != G_DESKTOP_BACKGROUND_STYLE_NONE) { draw_each_monitor (bg, dest, screen, scale); } } else { draw_color (bg, dest); if (bg->placement != G_DESKTOP_BACKGROUND_STYLE_NONE) { draw_once (bg, dest); } } } gboolean gsd_bg_has_multiple_sizes (GsdBG *bg) { GsdBGSlideShow *show; gboolean ret; g_return_val_if_fail (bg != NULL, FALSE); ret = FALSE; show = get_as_slideshow (bg, bg->filename); if (show) { ret = gsd_bg_slide_show_get_has_multiple_sizes (show); g_object_unref (show); } return ret; } static void gsd_bg_get_pixmap_size (GsdBG *bg, int width, int height, int *pixmap_width, int *pixmap_height) { int dummy; if (!pixmap_width) pixmap_width = &dummy; if (!pixmap_height) pixmap_height = &dummy; *pixmap_width = width; *pixmap_height = height; if (!bg->filename) { switch (bg->color_type) { case G_DESKTOP_BACKGROUND_SHADING_SOLID: *pixmap_width = 1; *pixmap_height = 1; break; case G_DESKTOP_BACKGROUND_SHADING_HORIZONTAL: case G_DESKTOP_BACKGROUND_SHADING_VERTICAL: default: break; } return; } } /** * gsd_bg_create_surface: * @bg: GsdBG * @window: * @width: * @height: * @root: * * Create a surface that can be set as background for @window. If @is_root is * TRUE, the surface created will be created by a temporary X server connection * so that if someone calls XKillClient on it, it won't affect the application * who created it. * * Returns: %NULL on error (e.g. out of X connections) **/ cairo_surface_t * gsd_bg_create_surface (GsdBG *bg, GdkWindow *window, int width, int height, gboolean root) { gint scale; int pm_width, pm_height; cairo_surface_t *surface; GdkRGBA average; cairo_t *cr; g_return_val_if_fail (bg != NULL, NULL); g_return_val_if_fail (window != NULL, NULL); scale = gdk_window_get_scale_factor (window); if (bg->pixbuf_cache && gdk_pixbuf_get_width (bg->pixbuf_cache) != width && gdk_pixbuf_get_height (bg->pixbuf_cache) != height) { g_object_unref (bg->pixbuf_cache); bg->pixbuf_cache = NULL; } /* has the side effect of loading and caching pixbuf only when in tile mode */ gsd_bg_get_pixmap_size (bg, width, height, &pm_width, &pm_height); if (root) { surface = make_root_pixmap (gdk_window_get_screen (window), scale * pm_width, scale * pm_height); cairo_surface_set_device_scale (surface, scale, scale); } else { surface = gdk_window_create_similar_surface (window, CAIRO_CONTENT_COLOR, pm_width, pm_height); } if (surface == NULL) return NULL; cr = cairo_create (surface); if (!bg->filename && bg->color_type == G_DESKTOP_BACKGROUND_SHADING_SOLID) { gdk_cairo_set_source_rgba (cr, &(bg->primary)); average = bg->primary; } else { GdkPixbuf *pixbuf; cairo_surface_t *pixbuf_surface; pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, scale * width, scale * height); gsd_bg_draw_at_scale (bg, pixbuf, scale, gdk_window_get_screen (window), root); pixbuf_average_value (pixbuf, &average); pixbuf_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 0, window); cairo_set_source_surface (cr, pixbuf_surface, 0, 0); cairo_surface_destroy (pixbuf_surface); g_object_unref (pixbuf); } cairo_paint (cr); cairo_destroy (cr); cairo_surface_set_user_data (surface, &average_color_key, gdk_rgba_copy (&average), (cairo_destroy_func_t) gdk_rgba_free); return surface; } /* determine if a background is darker or lighter than average, to help * clients know what colors to draw on top with */ gboolean gsd_bg_is_dark (GsdBG *bg, int width, int height) { GdkRGBA color; gdouble intensity; GdkPixbuf *pixbuf; g_return_val_if_fail (bg != NULL, FALSE); if (bg->color_type == G_DESKTOP_BACKGROUND_SHADING_SOLID) { color = bg->primary; } else { color.red = (bg->primary.red + bg->secondary.red) / 2; color.green = (bg->primary.green + bg->secondary.green) / 2; color.blue = (bg->primary.blue + bg->secondary.blue) / 2; } pixbuf = get_pixbuf_for_size (bg, -1, width, height); if (pixbuf) { GdkRGBA average; pixbuf_average_value (pixbuf, &average); color.red = color.red * (1.0 - average.alpha) + average.red * average.alpha; color.green = color.green * (1.0 - average.alpha) + average.green * average.alpha; color.blue = color.blue * (1.0 - average.alpha) + average.blue * average.alpha; g_object_unref (pixbuf); } intensity = color.red * 77 + color.green * 150 + color.blue * 28; return intensity < 160; /* biased slightly to be dark */ } /* * Create a persistent pixmap. We create a separate display * and set the closedown mode on it to RetainPermanent. */ static cairo_surface_t * make_root_pixmap (GdkScreen *screen, gint width, gint height) { Display *display; const char *display_name; Pixmap result; cairo_surface_t *surface; int screen_num; int depth; screen_num = gdk_screen_get_number (screen); gdk_flush (); display_name = gdk_display_get_name (gdk_screen_get_display (screen)); display = XOpenDisplay (display_name); if (display == NULL) { g_warning ("Unable to open display '%s' when setting " "background pixmap\n", (display_name) ? display_name : "NULL"); return NULL; } /* Desktop background pixmap should be created from * dummy X client since most applications will try to * kill it with XKillClient later when changing pixmap */ XSetCloseDownMode (display, RetainPermanent); depth = DefaultDepth (display, screen_num); result = XCreatePixmap (display, RootWindow (display, screen_num), width, height, depth); XCloseDisplay (display); surface = cairo_xlib_surface_create (GDK_SCREEN_XDISPLAY (screen), result, GDK_VISUAL_XVISUAL (gdk_screen_get_system_visual (screen)), width, height); return surface; } static gboolean get_original_size (const char *filename, int *orig_width, int *orig_height) { gboolean result; if (gdk_pixbuf_get_file_info (filename, orig_width, orig_height)) result = TRUE; else result = FALSE; return result; } static const char * get_filename_for_size (GsdBG *bg, gint best_width, gint best_height) { GsdBGSlideShow *show; const char *file = NULL; if (!bg->filename) return NULL; show = get_as_slideshow (bg, bg->filename); if (!show) { return bg->filename; } gsd_bg_slide_show_get_current_slide (show, best_width, best_height, NULL, NULL, NULL, &file, NULL); g_object_unref (show); return file; } gboolean gsd_bg_get_image_size (GsdBG *bg, GnomeDesktopThumbnailFactory *factory, int best_width, int best_height, int *width, int *height) { GdkPixbuf *thumb; gboolean result = FALSE; const gchar *filename; g_return_val_if_fail (bg != NULL, FALSE); g_return_val_if_fail (factory != NULL, FALSE); if (!bg->filename) return FALSE; filename = get_filename_for_size (bg, best_width, best_height); thumb = create_thumbnail_for_filename (factory, filename); if (thumb) { if (get_thumb_annotations (thumb, width, height)) result = TRUE; g_object_unref (thumb); } if (!result) { if (get_original_size (filename, width, height)) result = TRUE; } return result; } static double fit_factor (int from_width, int from_height, int to_width, int to_height) { return MIN (to_width / (double) from_width, to_height / (double) from_height); } /** * gsd_bg_create_thumbnail: * * Returns: (transfer full): a #GdkPixbuf showing the background as a thumbnail */ GdkPixbuf * gsd_bg_create_thumbnail (GsdBG *bg, GnomeDesktopThumbnailFactory *factory, GdkScreen *screen, int dest_width, int dest_height) { GdkPixbuf *result; GdkPixbuf *thumb; g_return_val_if_fail (bg != NULL, NULL); result = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, dest_width, dest_height); draw_color (bg, result); if (bg->placement != G_DESKTOP_BACKGROUND_STYLE_NONE) { thumb = create_img_thumbnail (bg, factory, screen, dest_width, dest_height, -1); if (thumb) { draw_image_for_thumb (bg, thumb, result); g_object_unref (thumb); } } return result; } /** * gsd_bg_get_surface_from_root: * @screen: a #GdkScreen * * This function queries the _XROOTPMAP_ID property from * the root window associated with @screen to determine * the current root window background pixmap and returns * a copy of it. If the _XROOTPMAP_ID is not set, then * a black surface is returned. * * Return value: a #cairo_surface_t if successful or %NULL **/ cairo_surface_t * gsd_bg_get_surface_from_root (GdkScreen *screen) { int result; gint format; gulong nitems; gulong bytes_after; gpointer data; Atom type; Display *display; int screen_num; cairo_surface_t *surface; cairo_surface_t *source_pixmap; int width, height; cairo_t *cr; display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen)); screen_num = gdk_screen_get_number (screen); result = XGetWindowProperty (display, RootWindow (display, screen_num), gdk_x11_get_xatom_by_name ("_XROOTPMAP_ID"), 0L, 1L, False, XA_PIXMAP, &type, &format, &nitems, &bytes_after, (guchar **) &data); surface = NULL; source_pixmap = NULL; if (result != Success || type != XA_PIXMAP || format != 32 || nitems != 1) { XFree (data); data = NULL; } if (data != NULL) { Pixmap xpixmap = *(Pixmap *) data; Window root_return; int x_ret, y_ret; unsigned int w_ret, h_ret, bw_ret, depth_ret; gdk_error_trap_push (); if (XGetGeometry (GDK_SCREEN_XDISPLAY (screen), xpixmap, &root_return, &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret)) { source_pixmap = cairo_xlib_surface_create (GDK_SCREEN_XDISPLAY (screen), xpixmap, GDK_VISUAL_XVISUAL (gdk_screen_get_system_visual (screen)), w_ret, h_ret); } gdk_error_trap_pop_ignored (); } width = gdk_screen_get_width (screen); height = gdk_screen_get_height (screen); if (source_pixmap) { surface = cairo_surface_create_similar (source_pixmap, CAIRO_CONTENT_COLOR, width, height); cr = cairo_create (surface); cairo_set_source_surface (cr, source_pixmap, 0, 0); cairo_paint (cr); if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { cairo_surface_destroy (surface); surface = NULL; } cairo_destroy (cr); } if (surface == NULL) { surface = gdk_window_create_similar_surface (gdk_screen_get_root_window (screen), CAIRO_CONTENT_COLOR, width, height); } if (source_pixmap != NULL) cairo_surface_destroy (source_pixmap); if (data != NULL) XFree (data); return surface; } static void gsd_bg_set_root_pixmap_id (GdkScreen *screen, cairo_surface_t *surface) { int result; gint format; gulong nitems; gulong bytes_after; gpointer data_esetroot; Pixmap pixmap_id; Atom type; Display *display; int screen_num; GdkRGBA *average; screen_num = gdk_screen_get_number (screen); data_esetroot = NULL; display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen)); result = XGetWindowProperty (display, RootWindow (display, screen_num), gdk_x11_get_xatom_by_name ("ESETROOT_PMAP_ID"), 0L, 1L, False, XA_PIXMAP, &type, &format, &nitems, &bytes_after, (guchar **) &data_esetroot); if (data_esetroot != NULL) { if (result == Success && type == XA_PIXMAP && format == 32 && nitems == 1) { gdk_error_trap_push (); XKillClient (display, *(Pixmap *)data_esetroot); gdk_error_trap_pop_ignored (); } XFree (data_esetroot); } pixmap_id = cairo_xlib_surface_get_drawable (surface); XChangeProperty (display, RootWindow (display, screen_num), gdk_x11_get_xatom_by_name ("ESETROOT_PMAP_ID"), XA_PIXMAP, 32, PropModeReplace, (guchar *) &pixmap_id, 1); XChangeProperty (display, RootWindow (display, screen_num), gdk_x11_get_xatom_by_name ("_XROOTPMAP_ID"), XA_PIXMAP, 32, PropModeReplace, (guchar *) &pixmap_id, 1); average = cairo_surface_get_user_data (surface, &average_color_key); if (average != NULL) { gchar *string; string = gdk_rgba_to_string (average); /* X encodes string lists as one big string with a nul * terminator after each item in the list. That's why * the strlen has to be given; scanning for nul would * only find the first item. * * For now, we only want to set a single string. * Fortunately, since this is C, it comes with its own * nul and we can just give strlen + 1 for the size of * our "list". */ XChangeProperty (display, RootWindow (display, screen_num), gdk_x11_get_xatom_by_name ("_GNOME_BACKGROUND_REPRESENTATIVE_COLORS"), XA_STRING, 8, PropModeReplace, (guchar *) string, strlen (string) + 1); g_free (string); } else { /* Could happen if we didn't create the surface... */ XDeleteProperty (display, RootWindow (display, screen_num), gdk_x11_get_xatom_by_name ("_GNOME_BACKGROUND_REPRESENTATIVE_COLORS")); } } /** * gsd_bg_set_surface_as_root: * @screen: the #GdkScreen to change root background on * @surface: the #cairo_surface_t to set root background from. * Must be an xlib surface backing a pixmap. * * Set the root pixmap, and properties pointing to it. We * do this atomically with a server grab to make sure that * we won't leak the pixmap if somebody else it setting * it at the same time. (This assumes that they follow the * same conventions we do). @surface should come from a call * to gsd_bg_create_surface(). **/ void gsd_bg_set_surface_as_root (GdkScreen *screen, cairo_surface_t *surface) { Display *display; int screen_num; g_return_if_fail (screen != NULL); g_return_if_fail (surface != NULL); g_return_if_fail (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB); screen_num = gdk_screen_get_number (screen); display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen)); gdk_x11_display_grab (gdk_screen_get_display (screen)); gsd_bg_set_root_pixmap_id (screen, surface); XSetWindowBackgroundPixmap (display, RootWindow (display, screen_num), cairo_xlib_surface_get_drawable (surface)); XClearWindow (display, RootWindow (display, screen_num)); gdk_display_flush (gdk_screen_get_display (screen)); gdk_x11_display_ungrab (gdk_screen_get_display (screen)); } /** * gsd_bg_set_surface_as_root_with_crossfade: * @screen: the #GdkScreen to change root background on * @surface: the cairo xlib surface to set root background from * * Set the root pixmap, and properties pointing to it. * This function differs from gsd_bg_set_surface_as_root() * in that it adds a subtle crossfade animation from the * current root pixmap to the new one. * * Return value: (transfer full): a #GsdBGCrossfade object **/ GsdBGCrossfade * gsd_bg_set_surface_as_root_with_crossfade (GdkScreen *screen, cairo_surface_t *surface) { GdkDisplay *display; GdkWindow *root_window; cairo_surface_t *old_surface; int width, height; GsdBGCrossfade *fade; g_return_val_if_fail (screen != NULL, NULL); g_return_val_if_fail (surface != NULL, NULL); root_window = gdk_screen_get_root_window (screen); width = gdk_screen_get_width (screen); height = gdk_screen_get_height (screen); fade = gsd_bg_crossfade_new (width, height); display = gdk_screen_get_display (screen); gdk_x11_display_grab (display); old_surface = gsd_bg_get_surface_from_root (screen); gsd_bg_set_root_pixmap_id (screen, surface); gsd_bg_crossfade_set_start_surface (fade, old_surface); cairo_surface_destroy (old_surface); gsd_bg_crossfade_set_end_surface (fade, surface); gdk_display_flush (display); gdk_x11_display_ungrab (display); gsd_bg_crossfade_start (fade, root_window); return fade; } /* Implementation of the pixbuf cache */ struct _SlideShow { gint ref_count; double start_time; double total_duration; GQueue *slides; gboolean has_multiple_sizes; /* used during parsing */ struct tm start_tm; GQueue *stack; }; static GdkPixbuf * blend (GdkPixbuf *p1, GdkPixbuf *p2, double alpha) { GdkPixbuf *result = gdk_pixbuf_copy (p1); GdkPixbuf *tmp; if (gdk_pixbuf_get_width (p2) != gdk_pixbuf_get_width (p1) || gdk_pixbuf_get_height (p2) != gdk_pixbuf_get_height (p1)) { tmp = gdk_pixbuf_scale_simple (p2, gdk_pixbuf_get_width (p1), gdk_pixbuf_get_height (p1), GDK_INTERP_BILINEAR); } else { tmp = g_object_ref (p2); } pixbuf_blend (tmp, result, 0, 0, -1, -1, 0, 0, alpha); g_object_unref (tmp); return result; } typedef enum { PIXBUF, SLIDESHOW, THUMBNAIL } FileType; struct FileCacheEntry { FileType type; char *filename; union { GdkPixbuf *pixbuf; GsdBGSlideShow *slideshow; GdkPixbuf *thumbnail; } u; }; static void file_cache_entry_delete (FileCacheEntry *ent) { g_free (ent->filename); switch (ent->type) { case PIXBUF: g_object_unref (ent->u.pixbuf); break; case SLIDESHOW: g_object_unref (ent->u.slideshow); break; case THUMBNAIL: g_object_unref (ent->u.thumbnail); break; default: break; } g_free (ent); } static void bound_cache (GsdBG *bg) { while (g_list_length (bg->file_cache) >= CACHE_SIZE) { GList *last_link = g_list_last (bg->file_cache); FileCacheEntry *ent = last_link->data; file_cache_entry_delete (ent); bg->file_cache = g_list_delete_link (bg->file_cache, last_link); } } static const FileCacheEntry * file_cache_lookup (GsdBG *bg, FileType type, const char *filename) { GList *list; for (list = bg->file_cache; list != NULL; list = list->next) { FileCacheEntry *ent = list->data; if (ent && ent->type == type && strcmp (ent->filename, filename) == 0) { return ent; } } return NULL; } static FileCacheEntry * file_cache_entry_new (GsdBG *bg, FileType type, const char *filename) { FileCacheEntry *ent = g_new0 (FileCacheEntry, 1); g_assert (!file_cache_lookup (bg, type, filename)); ent->type = type; ent->filename = g_strdup (filename); bg->file_cache = g_list_prepend (bg->file_cache, ent); bound_cache (bg); return ent; } static void file_cache_add_pixbuf (GsdBG *bg, const char *filename, GdkPixbuf *pixbuf) { FileCacheEntry *ent = file_cache_entry_new (bg, PIXBUF, filename); ent->u.pixbuf = g_object_ref (pixbuf); } static void file_cache_add_thumbnail (GsdBG *bg, const char *filename, GdkPixbuf *pixbuf) { FileCacheEntry *ent = file_cache_entry_new (bg, THUMBNAIL, filename); ent->u.thumbnail = g_object_ref (pixbuf); } static void file_cache_add_slide_show (GsdBG *bg, const char *filename, GsdBGSlideShow *show) { FileCacheEntry *ent = file_cache_entry_new (bg, SLIDESHOW, filename); ent->u.slideshow = g_object_ref (show); } static GdkPixbuf * load_from_cache_file (GsdBG *bg, const char *filename, gint num_monitor, gint best_width, gint best_height) { GdkPixbuf *pixbuf = NULL; gchar *cache_filename; cache_filename = get_wallpaper_cache_filename (filename, num_monitor, bg->placement, best_width, best_height); if (cache_file_is_valid (filename, cache_filename)) pixbuf = gdk_pixbuf_new_from_file (cache_filename, NULL); g_free (cache_filename); return pixbuf; } static GdkPixbuf * get_as_pixbuf_for_size (GsdBG *bg, const char *filename, gint num_monitor, gint best_width, gint best_height) { const FileCacheEntry *ent; if ((ent = file_cache_lookup (bg, PIXBUF, filename))) { return g_object_ref (ent->u.pixbuf); } else { GdkPixbufFormat *format; GdkPixbuf *pixbuf; gchar *tmp; pixbuf = NULL; /* Try to hit local cache first if relevant */ if (num_monitor != -1) pixbuf = load_from_cache_file (bg, filename, num_monitor, best_width, best_height); if (!pixbuf) { /* If scalable choose maximum size */ format = gdk_pixbuf_get_file_info (filename, NULL, NULL); if (format != NULL) { tmp = gdk_pixbuf_format_get_name (format); } else { tmp = NULL; } if (tmp != NULL && strcmp (tmp, "svg") == 0 && (best_width > 0 && best_height > 0) && (bg->placement == G_DESKTOP_BACKGROUND_STYLE_STRETCHED || bg->placement == G_DESKTOP_BACKGROUND_STYLE_SCALED || bg->placement == G_DESKTOP_BACKGROUND_STYLE_ZOOM)) pixbuf = gdk_pixbuf_new_from_file_at_size (filename, best_width, best_height, NULL); else pixbuf = gdk_pixbuf_new_from_file (filename, NULL); g_free (tmp); } if (pixbuf) file_cache_add_pixbuf (bg, filename, pixbuf); return pixbuf; } } static GsdBGSlideShow * get_as_slideshow (GsdBG *bg, const char *filename) { const FileCacheEntry *ent; if ((ent = file_cache_lookup (bg, SLIDESHOW, filename))) { return g_object_ref (ent->u.slideshow); } else { GsdBGSlideShow *show = read_slideshow_file (filename, NULL); if (show) file_cache_add_slide_show (bg, filename, show); return show; } } static GdkPixbuf * get_as_thumbnail (GsdBG *bg, GnomeDesktopThumbnailFactory *factory, const char *filename) { const FileCacheEntry *ent; if ((ent = file_cache_lookup (bg, THUMBNAIL, filename))) { return g_object_ref (ent->u.thumbnail); } else { GdkPixbuf *thumb = create_thumbnail_for_filename (factory, filename); if (thumb) file_cache_add_thumbnail (bg, filename, thumb); return thumb; } } static gboolean blow_expensive_caches (gpointer data) { GsdBG *bg = data; GList *list, *next; bg->blow_caches_id = 0; for (list = bg->file_cache; list != NULL; list = next) { FileCacheEntry *ent = list->data; next = list->next; if (ent->type == PIXBUF) { file_cache_entry_delete (ent); bg->file_cache = g_list_delete_link (bg->file_cache, list); } } if (bg->pixbuf_cache) { g_object_unref (bg->pixbuf_cache); bg->pixbuf_cache = NULL; } return FALSE; } static void blow_expensive_caches_in_idle (GsdBG *bg) { if (bg->blow_caches_id == 0) { bg->blow_caches_id = g_idle_add (blow_expensive_caches, bg); } } static gboolean on_timeout (gpointer data) { GsdBG *bg = data; bg->timeout_id = 0; queue_transitioned (bg); return FALSE; } static double get_slide_timeout (gboolean is_fixed, gdouble duration) { double timeout; if (is_fixed) { timeout = duration; } else { /* Maybe the number of steps should be configurable? */ /* In the worst case we will do a fade from 0 to 256, which mean * we will never use more than 255 steps, however in most cases * the first and last value are similar and users can't percieve * changes in pixel values as small as 1/255th. So, lets not waste * CPU cycles on transitioning to often. * * 64 steps is enough for each step to be just detectable in a 16bit * color mode in the worst case, so we'll use this as an approximation * of whats detectable. */ timeout = duration / 64.0; } return timeout; } static void ensure_timeout (GsdBG *bg, gdouble timeout) { if (!bg->timeout_id) { /* G_MAXUINT means "only one slide" */ if (timeout < G_MAXUINT) { bg->timeout_id = g_timeout_add_full ( G_PRIORITY_LOW, timeout * 1000, on_timeout, bg, NULL); } } } static time_t get_mtime (const char *filename) { GFile *file; GFileInfo *info; time_t mtime; mtime = (time_t)-1; if (filename) { file = g_file_new_for_path (filename); info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info) { mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); g_object_unref (info); } g_object_unref (file); } return mtime; } static GdkPixbuf * scale_thumbnail (GDesktopBackgroundStyle placement, const char *filename, GdkPixbuf *thumb, GdkScreen *screen, int dest_width, int dest_height) { int o_width; int o_height; if (placement != G_DESKTOP_BACKGROUND_STYLE_WALLPAPER && placement != G_DESKTOP_BACKGROUND_STYLE_CENTERED) { /* In this case, the pixbuf will be scaled to fit the screen anyway, * so just return the pixbuf here */ return g_object_ref (thumb); } if (get_thumb_annotations (thumb, &o_width, &o_height) || (filename && get_original_size (filename, &o_width, &o_height))) { int scr_height = gdk_screen_get_height (screen); int scr_width = gdk_screen_get_width (screen); int thumb_width = gdk_pixbuf_get_width (thumb); int thumb_height = gdk_pixbuf_get_height (thumb); double screen_to_dest = fit_factor (scr_width, scr_height, dest_width, dest_height); double thumb_to_orig = fit_factor (thumb_width, thumb_height, o_width, o_height); double f = thumb_to_orig * screen_to_dest; int new_width, new_height; new_width = floor (thumb_width * f + 0.5); new_height = floor (thumb_height * f + 0.5); if (placement == G_DESKTOP_BACKGROUND_STYLE_WALLPAPER) { /* Heuristic to make sure tiles don't become so small that * they turn into a blur. * * This is strictly speaking incorrect, but the resulting * thumbnail gives a much better idea what the background * will actually look like. */ if ((new_width < 32 || new_height < 32) && (new_width < o_width / 4 || new_height < o_height / 4)) { new_width = o_width / 4; new_height = o_height / 4; } } thumb = gdk_pixbuf_scale_simple (thumb, new_width, new_height, GDK_INTERP_BILINEAR); } else g_object_ref (thumb); return thumb; } /* frame_num determines which slide to thumbnail. * -1 means 'current slide'. */ static GdkPixbuf * create_img_thumbnail (GsdBG *bg, GnomeDesktopThumbnailFactory *factory, GdkScreen *screen, int dest_width, int dest_height, int frame_num) { if (bg->filename) { GdkPixbuf *thumb; thumb = get_as_thumbnail (bg, factory, bg->filename); if (thumb) { GdkPixbuf *result; result = scale_thumbnail (bg->placement, bg->filename, thumb, screen, dest_width, dest_height); g_object_unref (thumb); return result; } else { GsdBGSlideShow *show = get_as_slideshow (bg, bg->filename); if (show) { double alpha; double duration; gboolean is_fixed; const char *file1; const char *file2; GdkPixbuf *tmp; if (frame_num == -1) gsd_bg_slide_show_get_current_slide (show, dest_width, dest_height, &alpha, &duration, &is_fixed, &file1, &file2); else gsd_bg_slide_show_get_slide (show, frame_num, dest_width, dest_height, &alpha, &duration, &is_fixed, &file1, &file2); if (is_fixed) { tmp = get_as_thumbnail (bg, factory, file1); if (tmp) { thumb = scale_thumbnail (bg->placement, file1, tmp, screen, dest_width, dest_height); g_object_unref (tmp); } } else { GdkPixbuf *p1, *p2; p1 = get_as_thumbnail (bg, factory, file1); p2 = get_as_thumbnail (bg, factory, file2); if (p1 && p2) { GdkPixbuf *thumb1, *thumb2; thumb1 = scale_thumbnail (bg->placement, file1, p1, screen, dest_width, dest_height); thumb2 = scale_thumbnail (bg->placement, file2, p2, screen, dest_width, dest_height); thumb = blend (thumb1, thumb2, alpha); g_object_unref (thumb1); g_object_unref (thumb2); } if (p1) g_object_unref (p1); if (p2) g_object_unref (p2); } ensure_timeout (bg, (guint)get_slide_timeout (is_fixed, duration)); g_object_unref (show); } } return thumb; } return NULL; } static GdkPixbuf * get_pixbuf_for_size (GsdBG *bg, gint num_monitor, gint best_width, gint best_height) { guint time_until_next_change; gboolean hit_cache = FALSE; /* only hit the cache if the aspect ratio matches */ if (bg->pixbuf_cache) { int width, height; width = gdk_pixbuf_get_width (bg->pixbuf_cache); height = gdk_pixbuf_get_height (bg->pixbuf_cache); hit_cache = 0.2 > fabs ((best_width / (double)best_height) - (width / (double)height)); if (!hit_cache) { g_object_unref (bg->pixbuf_cache); bg->pixbuf_cache = NULL; } } if (!hit_cache && bg->filename) { bg->file_mtime = get_mtime (bg->filename); bg->pixbuf_cache = get_as_pixbuf_for_size (bg, bg->filename, num_monitor, best_width, best_height); time_until_next_change = G_MAXUINT; if (!bg->pixbuf_cache) { GsdBGSlideShow *show = get_as_slideshow (bg, bg->filename); if (show) { double alpha; double duration; gboolean is_fixed; const char *file1; const char *file2; g_object_ref (show); gsd_bg_slide_show_get_current_slide (show, best_width, best_height, &alpha, &duration, &is_fixed, &file1, &file2); time_until_next_change = (guint)get_slide_timeout (is_fixed, duration); if (is_fixed) { bg->pixbuf_cache = get_as_pixbuf_for_size (bg, file1, num_monitor, best_width, best_height); } else { GdkPixbuf *p1, *p2; p1 = get_as_pixbuf_for_size (bg, file1, num_monitor, best_width, best_height); p2 = get_as_pixbuf_for_size (bg, file2, num_monitor, best_width, best_height); if (p1 && p2) { bg->pixbuf_cache = blend (p1, p2, alpha); } if (p1) g_object_unref (p1); if (p2) g_object_unref (p2); } ensure_timeout (bg, time_until_next_change); g_object_unref (show); } } /* If the next slideshow step is a long time away then we blow away the expensive stuff (large pixbufs) from the cache */ if (time_until_next_change > KEEP_EXPENSIVE_CACHE_SECS) blow_expensive_caches_in_idle (bg); } if (bg->pixbuf_cache) g_object_ref (bg->pixbuf_cache); return bg->pixbuf_cache; } static gboolean is_different (GsdBG *bg, const char *filename) { if (!filename && bg->filename) { return TRUE; } else if (filename && !bg->filename) { return TRUE; } else if (!filename && !bg->filename) { return FALSE; } else { time_t mtime = get_mtime (filename); if (mtime != bg->file_mtime) return TRUE; if (strcmp (filename, bg->filename) != 0) return TRUE; return FALSE; } } static void clear_cache (GsdBG *bg) { GList *list; if (bg->file_cache) { for (list = bg->file_cache; list != NULL; list = list->next) { FileCacheEntry *ent = list->data; file_cache_entry_delete (ent); } g_list_free (bg->file_cache); bg->file_cache = NULL; } if (bg->pixbuf_cache) { g_object_unref (bg->pixbuf_cache); bg->pixbuf_cache = NULL; } if (bg->timeout_id) { g_source_remove (bg->timeout_id); bg->timeout_id = 0; } } /* Pixbuf utilities */ G_INLINE_FUNC GdkRGBA get_pixbuf_sample (guchar *pixels, gint rowstride, gint channels, gint x, gint y) { GdkRGBA sample; gdouble dd = 0xFF; guchar *p = pixels + ((y * rowstride) + (x * channels)); sample.red = *p++ / dd; sample.green = *p++ / dd; sample.blue = *p++ / dd; sample.alpha = 1.0f; return sample; } G_INLINE_FUNC gboolean is_color_different (const GdkRGBA color_a, const GdkRGBA color_b) { GdkRGBA diff; diff.red = color_a.red - color_b.red; diff.green = color_a.green - color_b.green; diff.blue = color_a.blue - color_b.blue; diff.alpha = 1.0f; if (fabs (diff.red) > 0.15 || fabs (diff.green) > 0.15 || fabs (diff.blue) > 0.15) return TRUE; return FALSE; } static GdkRGBA get_quad_average (gint x, gint y, gint width, gint height, gint level_of_recursion, guchar *pixels, gint rowstride, gint channels) { // samples four corners // c1-----c2 // | | // c3-----c4 GdkRGBA average; GdkRGBA corner1 = get_pixbuf_sample (pixels, rowstride, channels, x , y ); GdkRGBA corner2 = get_pixbuf_sample (pixels, rowstride, channels, x + width, y ); GdkRGBA corner3 = get_pixbuf_sample (pixels, rowstride, channels, x , y + height); GdkRGBA corner4 = get_pixbuf_sample (pixels, rowstride, channels, x + width, y + height); GdkRGBA centre = get_pixbuf_sample (pixels, rowstride, channels, x + (width / 2), y + (height / 2)); /* If we're over the max we want to just take the average and be happy with that value */ if (level_of_recursion < QUAD_MAX_LEVEL_OF_RECURSION) { /* Otherwise we want to look at each value and check it's distance from the center color and take the average if they're far apart. */ /* corner 1 */ if (level_of_recursion < QUAD_MIN_LEVEL_OF_RECURSION || is_color_different(corner1, centre)) { corner1 = get_quad_average (x, y, width/2, height/2, level_of_recursion + 1, pixels, rowstride, channels); } /* corner 2 */ if (level_of_recursion < QUAD_MIN_LEVEL_OF_RECURSION || is_color_different(corner2, centre)) { corner2 = get_quad_average (x + width/2, y, width/2, height/2, level_of_recursion + 1, pixels, rowstride, channels); } /* corner 3 */ if (level_of_recursion < QUAD_MIN_LEVEL_OF_RECURSION || is_color_different(corner3, centre)) { corner3 = get_quad_average (x, y + height/2, width/2, height/2, level_of_recursion + 1, pixels, rowstride, channels); } /* corner 4 */ if (level_of_recursion < QUAD_MIN_LEVEL_OF_RECURSION || is_color_different(corner4, centre)) { corner4 = get_quad_average (x + width/2, y + height/2, width/2, height/2, level_of_recursion + 1, pixels, rowstride, channels); } } average.red = ((corner1.red * QUAD_CORNER_WEIGHT_NW) + (corner3.red * QUAD_CORNER_WEIGHT_SW) + (centre.red * QUAD_CORNER_WEIGHT_CENTER) + (corner2.red * QUAD_CORNER_WEIGHT_NE) + (corner4.red * QUAD_CORNER_WEIGHT_SE)) / QUAD_CORNER_WEIGHT_TOTAL; average.green = ((corner1.green * QUAD_CORNER_WEIGHT_NW) + (corner3.green * QUAD_CORNER_WEIGHT_SW) + (centre.green * QUAD_CORNER_WEIGHT_CENTER) + (corner2.green * QUAD_CORNER_WEIGHT_NE) + (corner4.green * QUAD_CORNER_WEIGHT_SE)) / QUAD_CORNER_WEIGHT_TOTAL; average.blue = ((corner1.blue * QUAD_CORNER_WEIGHT_NW) + (corner3.blue * QUAD_CORNER_WEIGHT_SW) + (centre.blue * QUAD_CORNER_WEIGHT_CENTER) + (corner2.blue * QUAD_CORNER_WEIGHT_NE) + (corner4.blue * QUAD_CORNER_WEIGHT_SE)) / QUAD_CORNER_WEIGHT_TOTAL; average.alpha = 1.0f; return average; } static void pixbuf_average_value (GdkPixbuf *pixbuf, GdkRGBA *result) { GdkRGBA average; average = get_quad_average (0, 0, gdk_pixbuf_get_width (pixbuf) - 1, gdk_pixbuf_get_height (pixbuf) - 1, 1, gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), gdk_pixbuf_get_n_channels (pixbuf)); result->red = average.red; result->green = average.green; result->blue = average.blue; result->alpha = average.alpha; #if 0 guint64 a_total, r_total, g_total, b_total; guint row, column; int row_stride; const guchar *pixels, *p; int r, g, b, a; guint64 dividend; guint width, height; gdouble dd; width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); row_stride = gdk_pixbuf_get_rowstride (pixbuf); pixels = gdk_pixbuf_get_pixels (pixbuf); /* iterate through the pixbuf, counting up each component */ a_total = 0; r_total = 0; g_total = 0; b_total = 0; if (gdk_pixbuf_get_has_alpha (pixbuf)) { for (row = 0; row < height; row++) { p = pixels + (row * row_stride); for (column = 0; column < width / 2; column++) { r = *p++; g = *p++; b = *p++; a = *p++; a_total += a; r_total += r * a; g_total += g * a; b_total += b * a; } } dividend = height * width * 0xFF; a_total *= 0xFF; } else { for (row = 0; row < height; row++) { p = pixels + (row * row_stride); for (column = 0; column < width / 2; column++) { r = *p++; g = *p++; b = *p++; r_total += r; g_total += g; b_total += b; } } dividend = height * width; a_total = dividend * 0xFF; } dd = dividend * 0xFF; result->alpha = a_total / dd; result->red = r_total / dd; result->green = g_total / dd; result->blue = b_total / dd; #endif } static GdkPixbuf * pixbuf_scale_to_fit (GdkPixbuf *src, int max_width, int max_height) { double factor; int src_width, src_height; int new_width, new_height; src_width = gdk_pixbuf_get_width (src); src_height = gdk_pixbuf_get_height (src); factor = MIN (max_width / (double) src_width, max_height / (double) src_height); new_width = floor (src_width * factor + 0.5); new_height = floor (src_height * factor + 0.5); return gdk_pixbuf_scale_simple (src, new_width, new_height, GDK_INTERP_BILINEAR); } static GdkPixbuf * pixbuf_scale_to_min (GdkPixbuf *src, int min_width, int min_height) { double factor; int src_width, src_height; int new_width, new_height; GdkPixbuf *dest; src_width = gdk_pixbuf_get_width (src); src_height = gdk_pixbuf_get_height (src); factor = MAX (min_width / (double) src_width, min_height / (double) src_height); new_width = floor (src_width * factor + 0.5); new_height = floor (src_height * factor + 0.5); dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, gdk_pixbuf_get_has_alpha (src), 8, min_width, min_height); if (!dest) return NULL; /* crop the result */ gdk_pixbuf_scale (src, dest, 0, 0, min_width, min_height, (new_width - min_width) / -2, (new_height - min_height) / -2, factor, factor, GDK_INTERP_BILINEAR); return dest; } static guchar * create_gradient (const GdkRGBA *primary, const GdkRGBA *secondary, int n_pixels) { guchar *result = g_malloc (n_pixels * 3); int i; for (i = 0; i < n_pixels; ++i) { double ratio = (i + 0.5) / n_pixels; result[3 * i + 0] = (int) (0.5 + (primary->red * (1 - ratio) + secondary->red * ratio) * 255); result[3 * i + 1] = (int) (0.5 + (primary->green * (1 - ratio) + secondary->green * ratio) * 255); result[3 * i + 2] = (int) (0.5 + (primary->blue * (1 - ratio) + secondary->blue * ratio) * 255); } return result; } static void pixbuf_draw_gradient (GdkPixbuf *pixbuf, gboolean horizontal, GdkRGBA *primary, GdkRGBA *secondary, GdkRectangle *rect) { int width; int height; int rowstride; guchar *dst; int n_channels = 3; rowstride = gdk_pixbuf_get_rowstride (pixbuf); width = rect->width; height = rect->height; dst = gdk_pixbuf_get_pixels (pixbuf) + rect->x * n_channels + rowstride * rect->y; if (horizontal) { guchar *gradient = create_gradient (primary, secondary, width); int copy_bytes_per_row = width * n_channels; int i; for (i = 0; i < height; i++) { guchar *d; d = dst + rowstride * i; memcpy (d, gradient, copy_bytes_per_row); } g_free (gradient); } else { guchar *gb, *gradient; int i; gradient = create_gradient (primary, secondary, height); for (i = 0; i < height; i++) { int j; guchar *d; d = dst + rowstride * i; gb = gradient + n_channels * i; for (j = width; j > 0; j--) { int k; for (k = 0; k < n_channels; k++) { *(d++) = gb[k]; } } } g_free (gradient); } } static void pixbuf_blend (GdkPixbuf *src, GdkPixbuf *dest, int src_x, int src_y, int src_width, int src_height, int dest_x, int dest_y, double alpha) { int dest_width = gdk_pixbuf_get_width (dest); int dest_height = gdk_pixbuf_get_height (dest); int offset_x = dest_x - src_x; int offset_y = dest_y - src_y; if (src_width < 0) src_width = gdk_pixbuf_get_width (src); if (src_height < 0) src_height = gdk_pixbuf_get_height (src); if (dest_x < 0) dest_x = 0; if (dest_y < 0) dest_y = 0; if (dest_x + src_width > dest_width) { src_width = dest_width - dest_x; } if (dest_y + src_height > dest_height) { src_height = dest_height - dest_y; } gdk_pixbuf_composite (src, dest, dest_x, dest_y, src_width, src_height, offset_x, offset_y, 1, 1, GDK_INTERP_NEAREST, alpha * 0xFF + 0.5); } static void pixbuf_tile (GdkPixbuf *src, GdkPixbuf *dest) { int x, y; int tile_width, tile_height; int dest_width = gdk_pixbuf_get_width (dest); int dest_height = gdk_pixbuf_get_height (dest); tile_width = gdk_pixbuf_get_width (src); tile_height = gdk_pixbuf_get_height (src); for (y = 0; y < dest_height; y += tile_height) { for (x = 0; x < dest_width; x += tile_width) { pixbuf_blend (src, dest, 0, 0, tile_width, tile_height, x, y, 1.0); } } } static GsdBGSlideShow * read_slideshow_file (const char *filename, GError **err) { GsdBGSlideShow *show; show = gsd_bg_slide_show_new (filename); if (!gsd_bg_slide_show_load (show, err)) { g_object_unref (show); return NULL; } return show; } /* Thumbnail utilities */ static GdkPixbuf * create_thumbnail_for_filename (GnomeDesktopThumbnailFactory *factory, const char *filename) { char *thumb; time_t mtime; GdkPixbuf *orig, *result = NULL; char *uri; mtime = get_mtime (filename); if (mtime == (time_t)-1) return NULL; uri = g_filename_to_uri (filename, NULL, NULL); if (uri == NULL) return NULL; thumb = gnome_desktop_thumbnail_factory_lookup (factory, uri, mtime); if (thumb) { result = gdk_pixbuf_new_from_file (thumb, NULL); g_free (thumb); } else { orig = gdk_pixbuf_new_from_file (filename, NULL); if (orig) { int orig_width, orig_height; GdkPixbuf *rotated; rotated = gdk_pixbuf_apply_embedded_orientation (orig); if (rotated != NULL) { g_object_unref (orig); orig = rotated; } orig_width = gdk_pixbuf_get_width (orig); orig_height = gdk_pixbuf_get_height (orig); result = pixbuf_scale_to_fit (orig, THUMBNAIL_SIZE, THUMBNAIL_SIZE); g_object_set_data_full (G_OBJECT (result), "gnome-thumbnail-height", g_strdup_printf ("%d", orig_height), g_free); g_object_set_data_full (G_OBJECT (result), "gnome-thumbnail-width", g_strdup_printf ("%d", orig_width), g_free); g_object_unref (orig); gnome_desktop_thumbnail_factory_save_thumbnail (factory, result, uri, mtime); } else { gnome_desktop_thumbnail_factory_create_failed_thumbnail (factory, uri, mtime); } } g_free (uri); return result; } static gboolean get_thumb_annotations (GdkPixbuf *thumb, int *orig_width, int *orig_height) { char *end; const char *wstr, *hstr; wstr = gdk_pixbuf_get_option (thumb, "tEXt::Thumb::Image::Width"); hstr = gdk_pixbuf_get_option (thumb, "tEXt::Thumb::Image::Height"); if (hstr && wstr) { *orig_width = strtol (wstr, &end, 10); if (*end != 0) return FALSE; *orig_height = strtol (hstr, &end, 10); if (*end != 0) return FALSE; return TRUE; } return FALSE; } /* * Returns whether the background is a slideshow. */ gboolean gsd_bg_changes_with_time (GsdBG *bg) { GsdBGSlideShow *show; gboolean ret = FALSE; g_return_val_if_fail (bg != NULL, FALSE); if (!bg->filename) return FALSE; show = get_as_slideshow (bg, bg->filename); if (show) { ret = gsd_bg_slide_show_get_num_slides (show) > 1; g_object_unref (show); } return ret; } /** * gsd_bg_create_frame_thumbnail: * * Creates a thumbnail for a certain frame, where 'frame' is somewhat * vaguely defined as 'suitable point to show while single-stepping * through the slideshow'. * * Returns: (transfer full): the newly created thumbnail or * or NULL if frame_num is out of bounds. */ GdkPixbuf * gsd_bg_create_frame_thumbnail (GsdBG *bg, GnomeDesktopThumbnailFactory *factory, GdkScreen *screen, int dest_width, int dest_height, int frame_num) { GsdBGSlideShow *show; GdkPixbuf *result; GdkPixbuf *thumb; int skipped; gboolean is_fixed; g_return_val_if_fail (bg != NULL, FALSE); show = get_as_slideshow (bg, bg->filename); if (!show) return NULL; if (frame_num < 0 || frame_num >= gsd_bg_slide_show_get_num_slides (show)) return NULL; gsd_bg_slide_show_get_slide (show, frame_num, dest_width, dest_height, NULL, NULL, &is_fixed, NULL, NULL); skipped = 0; while (!is_fixed) { skipped++; gsd_bg_slide_show_get_slide (show, frame_num, dest_width, dest_height, NULL, NULL, &is_fixed, NULL, NULL); } result = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, dest_width, dest_height); draw_color (bg, result); if (bg->placement != G_DESKTOP_BACKGROUND_STYLE_NONE) { thumb = create_img_thumbnail (bg, factory, screen, dest_width, dest_height, frame_num + skipped); if (thumb) { draw_image_for_thumb (bg, thumb, result); g_object_unref (thumb); } } return result; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-bg.h0000664000175000017500000001243400000000000024562 0ustar00jeremyjeremy/* gsd-bg.h - Copyright 2007, Red Hat, Inc. This file is part of the Gnome Library. The Gnome Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The Gnome 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the Gnome Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Author: Soren Sandmann */ #ifndef __GSD_BG_H__ #define __GSD_BG_H__ #define GNOME_DESKTOP_USE_UNSTABLE_API #include #include #include #include #include #include "gsd-bg-crossfade.h" G_BEGIN_DECLS #define GSD_TYPE_BG (gsd_bg_get_type ()) #define GSD_BG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_BG, GsdBG)) #define GSD_BG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_BG, GsdBGClass)) #define GSD_IS_BG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_BG)) #define GSD_IS_BG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_BG)) #define GSD_BG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_BG, GsdBGClass)) typedef struct _GsdBG GsdBG; typedef struct _GsdBGClass GsdBGClass; G_DEFINE_AUTOPTR_CLEANUP_FUNC(GsdBG, g_object_unref) GType gsd_bg_get_type (void); GsdBG * gsd_bg_new (void); void gsd_bg_load_from_preferences (GsdBG *bg, GSettings *settings); void gsd_bg_save_to_preferences (GsdBG *bg, GSettings *settings); /* Setters */ void gsd_bg_set_filename (GsdBG *bg, const char *filename); void gsd_bg_set_placement (GsdBG *bg, GDesktopBackgroundStyle placement); void gsd_bg_set_rgba (GsdBG *bg, GDesktopBackgroundShading type, GdkRGBA *primary, GdkRGBA *secondary); void gsd_bg_set_draw_background (GsdBG *bg, gboolean draw_background); /* Getters */ GDesktopBackgroundStyle gsd_bg_get_placement (GsdBG *bg); gboolean gsd_bg_get_draw_background (GsdBG *bg); void gsd_bg_get_rgba (GsdBG *bg, GDesktopBackgroundShading *type, GdkRGBA *primary, GdkRGBA *secondary); const gchar * gsd_bg_get_filename (GsdBG *bg); /* Drawing and thumbnailing */ void gsd_bg_draw (GsdBG *bg, GdkPixbuf *dest, GdkScreen *screen, gboolean is_root); cairo_surface_t *gsd_bg_create_surface (GsdBG *bg, GdkWindow *window, int width, int height, gboolean root); gboolean gsd_bg_get_image_size (GsdBG *bg, GnomeDesktopThumbnailFactory *factory, int best_width, int best_height, int *width, int *height); GdkPixbuf * gsd_bg_create_thumbnail (GsdBG *bg, GnomeDesktopThumbnailFactory *factory, GdkScreen *screen, int dest_width, int dest_height); gboolean gsd_bg_is_dark (GsdBG *bg, int dest_width, int dest_height); gboolean gsd_bg_has_multiple_sizes (GsdBG *bg); gboolean gsd_bg_changes_with_time (GsdBG *bg); GdkPixbuf * gsd_bg_create_frame_thumbnail (GsdBG *bg, GnomeDesktopThumbnailFactory *factory, GdkScreen *screen, int dest_width, int dest_height, int frame_num); /* Set a surface as root - not a GsdBG method. At some point * if we decide to stabilize the API then we may want to make * these object methods, drop gsd_bg_create_surface, etc. */ void gsd_bg_set_surface_as_root (GdkScreen *screen, cairo_surface_t *surface); GsdBGCrossfade *gsd_bg_set_surface_as_root_with_crossfade (GdkScreen *screen, cairo_surface_t *surface); cairo_surface_t *gsd_bg_get_surface_from_root (GdkScreen *screen); G_END_DECLS #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-idle-monitor-private.h0000664000175000017500000000204500000000000030241 0ustar00jeremyjeremy/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* * Copyright 2013 Red Hat, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . * * Adapted from gnome-session/gnome-session/gs-idle-monitor.c and * from gnome-desktop/libgnome-desktop/gnome-idle-monitor.c */ #include #include void gsd_idle_monitor_handle_xevent_all (XEvent *xevent); void gsd_idle_monitor_init_dbus (gboolean replace); ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-idle-monitor.c0000664000175000017500000006577300000000000026605 0ustar00jeremyjeremy/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* * Copyright 2013 Red Hat, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Adapted from gnome-session/gnome-session/gs-idle-monitor.c and * from gnome-desktop/libgnome-desktop/gnome-idle-monitor.c */ /** * SECTION:idle-monitor * @title: GsdIdleMonitor * @short_description: Mutter idle counter (similar to X's IDLETIME) */ #include "config.h" #include #include #include #include #include #include "gsd-idle-monitor.h" #include "gsd-idle-monitor-private.h" #include "meta-dbus-idle-monitor.h" G_STATIC_ASSERT(sizeof(unsigned long) == sizeof(gpointer)); struct _GsdIdleMonitor { GObject parent_instance; GHashTable *watches; GHashTable *alarms; int device_id; /* X11 implementation */ Display *display; int sync_event_base; XSyncCounter counter; XSyncAlarm user_active_alarm; }; struct _GsdIdleMonitorClass { GObjectClass parent_class; }; typedef struct { GsdIdleMonitor *monitor; guint id; GsdIdleMonitorWatchFunc callback; gpointer user_data; GDestroyNotify notify; guint64 timeout_msec; /* x11 */ XSyncAlarm xalarm; int idle_source_id; } GsdIdleMonitorWatch; typedef struct { /* X11 implementation */ Display *display; int sync_event_base; int sync_error_base; unsigned int have_xsync : 1; }GsdXSync; static GsdXSync *xsync; enum { PROP_0, PROP_DEVICE_ID, PROP_LAST, }; static GParamSpec *obj_props[PROP_LAST]; G_DEFINE_TYPE (GsdIdleMonitor, gsd_idle_monitor, G_TYPE_OBJECT) static GsdIdleMonitor *device_monitors[256]; static int device_id_max; static gint64 _xsyncvalue_to_int64 (XSyncValue value) { return ((guint64) XSyncValueHigh32 (value)) << 32 | (guint64) XSyncValueLow32 (value); } #define GUINT64_TO_XSYNCVALUE(value, ret) XSyncIntsToValue (ret, (value) & 0xFFFFFFFF, ((guint64)(value)) >> 32) static void fire_watch (GsdIdleMonitorWatch *watch) { GsdIdleMonitor *monitor; guint id; gboolean is_user_active_watch; monitor = watch->monitor; g_object_ref (monitor); if (watch->idle_source_id) { g_source_remove (watch->idle_source_id); watch->idle_source_id = 0; } id = watch->id; is_user_active_watch = (watch->timeout_msec == 0); if (watch->callback) watch->callback (monitor, id, watch->user_data); if (is_user_active_watch) gsd_idle_monitor_remove_watch (monitor, id); g_object_unref (monitor); } static XSyncAlarm _xsync_alarm_set (GsdIdleMonitor *monitor, XSyncTestType test_type, guint64 interval, gboolean want_events) { XSyncAlarmAttributes attr; XSyncValue delta; guint flags; flags = XSyncCACounter | XSyncCAValueType | XSyncCATestType | XSyncCAValue | XSyncCADelta | XSyncCAEvents; XSyncIntToValue (&delta, 0); attr.trigger.counter = monitor->counter; attr.trigger.value_type = XSyncAbsolute; attr.delta = delta; attr.events = want_events; GUINT64_TO_XSYNCVALUE (interval, &attr.trigger.wait_value); attr.trigger.test_type = test_type; return XSyncCreateAlarm (monitor->display, flags, &attr); } static void ensure_alarm_rescheduled (Display *dpy, XSyncAlarm alarm) { XSyncAlarmAttributes attr; /* Some versions of Xorg have an issue where alarms aren't * always rescheduled. Calling XSyncChangeAlarm, even * without any attributes, will reschedule the alarm. */ XSyncChangeAlarm (dpy, alarm, 0, &attr); } static void set_alarm_enabled (Display *dpy, XSyncAlarm alarm, gboolean enabled) { XSyncAlarmAttributes attr; attr.events = enabled; XSyncChangeAlarm (dpy, alarm, XSyncCAEvents, &attr); } static void check_x11_watch (gpointer data, gpointer user_data) { GsdIdleMonitorWatch *watch = data; XSyncAlarm alarm = (XSyncAlarm) user_data; if (watch->xalarm != alarm) return; fire_watch (watch); } static void gsd_idle_monitor_handle_xevent (GsdIdleMonitor *monitor, XSyncAlarmNotifyEvent *alarm_event) { XSyncAlarm alarm; GList *watches; gboolean has_alarm; if (alarm_event->state != XSyncAlarmActive) return; alarm = alarm_event->alarm; has_alarm = FALSE; if (alarm == monitor->user_active_alarm) { set_alarm_enabled (monitor->display, alarm, FALSE); has_alarm = TRUE; } else if (g_hash_table_contains (monitor->alarms, (gpointer) alarm)) { ensure_alarm_rescheduled (monitor->display, alarm); has_alarm = TRUE; } if (has_alarm) { watches = g_hash_table_get_values (monitor->watches); g_list_foreach (watches, check_x11_watch, (gpointer) alarm); g_list_free (watches); } } void gsd_idle_monitor_handle_xevent_all (XEvent *xevent) { int i; for (i = 0; i <= device_id_max; i++) if (device_monitors[i]) gsd_idle_monitor_handle_xevent (device_monitors[i], (XSyncAlarmNotifyEvent*)xevent); } static char * counter_name_for_device (int device_id) { if (device_id > 0) return g_strdup_printf ("DEVICEIDLETIME %d", device_id); return g_strdup ("IDLETIME"); } static XSyncCounter find_idletime_counter (GsdIdleMonitor *monitor) { int i; int ncounters; XSyncSystemCounter *counters; XSyncCounter counter = None; char *counter_name; counter_name = counter_name_for_device (monitor->device_id); counters = XSyncListSystemCounters (monitor->display, &ncounters); for (i = 0; i < ncounters; i++) { if (counters[i].name != NULL && strcmp (counters[i].name, counter_name) == 0) { counter = counters[i].counter; break; } } XSyncFreeSystemCounterList (counters); g_free (counter_name); return counter; } static guint32 get_next_watch_serial (void) { static guint32 serial = 0; g_atomic_int_inc (&serial); return serial; } static void idle_monitor_watch_free (GsdIdleMonitorWatch *watch) { GsdIdleMonitor *monitor; if (watch == NULL) return; monitor = watch->monitor; g_object_ref (monitor); if (watch->idle_source_id) { g_source_remove (watch->idle_source_id); watch->idle_source_id = 0; } if (watch->notify != NULL) watch->notify (watch->user_data); if (watch->xalarm != monitor->user_active_alarm && watch->xalarm != None) { XSyncDestroyAlarm (monitor->display, watch->xalarm); g_hash_table_remove (monitor->alarms, (gpointer) watch->xalarm); } g_object_unref (monitor); g_slice_free (GsdIdleMonitorWatch, watch); } static GdkFilterReturn xevent_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data) { XEvent *ev; ev = xevent; if (ev->xany.type == xsync->sync_event_base + XSyncAlarmNotify) { gsd_idle_monitor_handle_xevent_all (ev); } return GDK_FILTER_CONTINUE; } static void init_xsync (GsdIdleMonitor *monitor) { monitor->counter = find_idletime_counter (monitor); /* IDLETIME counter not found? */ if (monitor->counter == None) { g_warning ("IDLETIME counter not found\n"); return; } monitor->user_active_alarm = _xsync_alarm_set (monitor, XSyncNegativeTransition, 1, FALSE); } static void gsd_idle_monitor_dispose (GObject *object) { GsdIdleMonitor *monitor; monitor = gsd_idle_monitor (object); g_clear_pointer (&monitor->watches, g_hash_table_destroy); g_clear_pointer (&monitor->alarms, g_hash_table_destroy); if (monitor->user_active_alarm != None) { XSyncDestroyAlarm (monitor->display, monitor->user_active_alarm); monitor->user_active_alarm = None; } /* The device in device_monitors is cleared when the device is * removed. Ensure that the object is not deleted before that. */ g_assert_null (device_monitors[monitor->device_id]); G_OBJECT_CLASS (gsd_idle_monitor_parent_class)->dispose (object); } static void gsd_idle_monitor_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GsdIdleMonitor *monitor = gsd_idle_monitor (object); switch (prop_id) { case PROP_DEVICE_ID: g_value_set_int (value, monitor->device_id); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gsd_idle_monitor_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GsdIdleMonitor *monitor = gsd_idle_monitor (object); switch (prop_id) { case PROP_DEVICE_ID: monitor->device_id = g_value_get_int (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gsd_idle_monitor_constructed (GObject *object) { GsdIdleMonitor *monitor = gsd_idle_monitor (object); monitor->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); init_xsync (monitor); } static void gsd_idle_monitor_class_init (GsdIdleMonitorClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = gsd_idle_monitor_dispose; object_class->constructed = gsd_idle_monitor_constructed; object_class->get_property = gsd_idle_monitor_get_property; object_class->set_property = gsd_idle_monitor_set_property; /** * GsdIdleMonitor:device_id: * * The device to listen to idletime on. */ obj_props[PROP_DEVICE_ID] = g_param_spec_int ("device-id", "Device ID", "The device to listen to idletime on", 0, 255, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_DEVICE_ID, obj_props[PROP_DEVICE_ID]); } static void gsd_idle_monitor_init (GsdIdleMonitor *monitor) { monitor->watches = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)idle_monitor_watch_free); monitor->alarms = g_hash_table_new (NULL, NULL); } static void ensure_device_monitor (int device_id) { if (device_monitors[device_id]) return; device_monitors[device_id] = g_object_new (GSD_TYPE_IDLE_MONITOR, "device-id", device_id, NULL); device_id_max = MAX (device_id_max, device_id); } /** * gsd_idle_monitor_get_core: * * Returns: (transfer none): the #GsdIdleMonitor that tracks the server-global * idletime for all devices. To track device-specific idletime, * use gsd_idle_monitor_get_for_device(). */ GsdIdleMonitor * gsd_idle_monitor_get_core (void) { ensure_device_monitor (0); return device_monitors[0]; } /** * gsd_idle_monitor_get_for_device: * @device_id: the device to get the idle time for. * * Returns: (transfer none): a new #GsdIdleMonitor that tracks the * device-specific idletime for @device. To track server-global idletime * for all devices, use gsd_idle_monitor_get_core(). */ GsdIdleMonitor * gsd_idle_monitor_get_for_device (int device_id) { g_return_val_if_fail (device_id > 0 && device_id < 256, NULL); ensure_device_monitor (device_id); return device_monitors[device_id]; } static gboolean fire_watch_idle (gpointer data) { GsdIdleMonitorWatch *watch = data; watch->idle_source_id = 0; fire_watch (watch); return FALSE; } static GsdIdleMonitorWatch * make_watch (GsdIdleMonitor *monitor, guint64 timeout_msec, GsdIdleMonitorWatchFunc callback, gpointer user_data, GDestroyNotify notify) { GsdIdleMonitorWatch *watch; watch = g_slice_new0 (GsdIdleMonitorWatch); watch->monitor = monitor; watch->id = get_next_watch_serial (); watch->callback = callback; watch->user_data = user_data; watch->notify = notify; watch->timeout_msec = timeout_msec; if (timeout_msec != 0) { watch->xalarm = _xsync_alarm_set (monitor, XSyncPositiveTransition, timeout_msec, TRUE); g_hash_table_add (monitor->alarms, (gpointer) watch->xalarm); if (gsd_idle_monitor_get_idletime (monitor) > (gint64)timeout_msec) watch->idle_source_id = g_idle_add (fire_watch_idle, watch); } else if (monitor->user_active_alarm != None) { watch->xalarm = monitor->user_active_alarm; set_alarm_enabled (monitor->display, monitor->user_active_alarm, TRUE); } g_hash_table_insert (monitor->watches, GUINT_TO_POINTER (watch->id), watch); return watch; } /** * gsd_idle_monitor_add_idle_watch: * @monitor: A #GsdIdleMonitor * @interval_msec: The idletime interval, in milliseconds * @callback: (allow-none): The callback to call when the user has * accumulated @interval_msec milliseconds of idle time. * @user_data: (allow-none): The user data to pass to the callback * @notify: A #GDestroyNotify * * Returns: a watch id * * Adds a watch for a specific idle time. The callback will be called * when the user has accumulated @interval_msec milliseconds of idle time. * This function will return an ID that can either be passed to * gsd_idle_monitor_remove_watch(), or can be used to tell idle time * watches apart if you have more than one. * * Also note that this function will only care about positive transitions * (user's idle time exceeding a certain time). If you want to know about * when the user has become active, use * gsd_idle_monitor_add_user_active_watch(). */ guint gsd_idle_monitor_add_idle_watch (GsdIdleMonitor *monitor, guint64 interval_msec, GsdIdleMonitorWatchFunc callback, gpointer user_data, GDestroyNotify notify) { GsdIdleMonitorWatch *watch; g_return_val_if_fail (GSD_IS_IDLE_MONITOR (monitor), 0); g_return_val_if_fail (interval_msec > 0, 0); watch = make_watch (monitor, interval_msec, callback, user_data, notify); return watch->id; } /** * gsd_idle_monitor_add_user_active_watch: * @monitor: A #GsdIdleMonitor * @callback: (allow-none): The callback to call when the user is * active again. * @user_data: (allow-none): The user data to pass to the callback * @notify: A #GDestroyNotify * * Returns: a watch id * * Add a one-time watch to know when the user is active again. * Note that this watch is one-time and will de-activate after the * function is called, for efficiency purposes. It's most convenient * to call this when an idle watch, as added by * gsd_idle_monitor_add_idle_watch(), has triggered. */ guint gsd_idle_monitor_add_user_active_watch (GsdIdleMonitor *monitor, GsdIdleMonitorWatchFunc callback, gpointer user_data, GDestroyNotify notify) { GsdIdleMonitorWatch *watch; g_return_val_if_fail (GSD_IS_IDLE_MONITOR (monitor), 0); watch = make_watch (monitor, 0, callback, user_data, notify); return watch->id; } /** * gsd_idle_monitor_remove_watch: * @monitor: A #GsdIdleMonitor * @id: A watch ID * * Removes an idle time watcher, previously added by * gsd_idle_monitor_add_idle_watch() or * gsd_idle_monitor_add_user_active_watch(). */ void gsd_idle_monitor_remove_watch (GsdIdleMonitor *monitor, guint id) { g_return_if_fail (GSD_IS_IDLE_MONITOR (monitor)); g_object_ref (monitor); g_hash_table_remove (monitor->watches, GUINT_TO_POINTER (id)); g_object_unref (monitor); } /** * gsd_idle_monitor_get_idletime: * @monitor: A #GsdIdleMonitor * * Returns: The current idle time, in milliseconds, or -1 for not supported */ gint64 gsd_idle_monitor_get_idletime (GsdIdleMonitor *monitor) { XSyncValue value; g_return_val_if_fail (GSD_IS_IDLE_MONITOR (monitor), -1); if (monitor->counter == None) return -1; if (!XSyncQueryCounter (monitor->display, monitor->counter, &value)) return -1; return _xsyncvalue_to_int64 (value); } static gboolean handle_get_idletime (MetaDBusIdleMonitor *skeleton, GDBusMethodInvocation *invocation, GsdIdleMonitor *monitor) { guint64 idletime; idletime = gsd_idle_monitor_get_idletime (monitor); meta_dbus_idle_monitor_complete_get_idletime (skeleton, invocation, idletime); return TRUE; } typedef struct { MetaDBusIdleMonitor *dbus_monitor; GsdIdleMonitor *monitor; char *dbus_name; guint watch_id; guint name_watcher_id; } DBusWatch; static void destroy_dbus_watch (gpointer data) { DBusWatch *watch = data; g_object_unref (watch->dbus_monitor); g_object_unref (watch->monitor); g_free (watch->dbus_name); g_bus_unwatch_name (watch->name_watcher_id); g_slice_free (DBusWatch, watch); } static void dbus_idle_callback (GsdIdleMonitor *monitor, guint watch_id, gpointer user_data) { DBusWatch *watch = user_data; GDBusInterfaceSkeleton *skeleton = G_DBUS_INTERFACE_SKELETON (watch->dbus_monitor); g_dbus_connection_emit_signal (g_dbus_interface_skeleton_get_connection (skeleton), watch->dbus_name, g_dbus_interface_skeleton_get_object_path (skeleton), "org.gnome.Mutter.IdleMonitor", "WatchFired", g_variant_new ("(u)", watch_id), NULL); } static void name_vanished_callback (GDBusConnection *connection, const char *name, gpointer user_data) { DBusWatch *watch = user_data; gsd_idle_monitor_remove_watch (watch->monitor, watch->watch_id); if (xsync) g_slice_free(GsdXSync, xsync); } static DBusWatch * make_dbus_watch (MetaDBusIdleMonitor *skeleton, GDBusMethodInvocation *invocation, GsdIdleMonitor *monitor) { DBusWatch *watch; watch = g_slice_new (DBusWatch); watch->dbus_monitor = g_object_ref (skeleton); watch->monitor = g_object_ref (monitor); watch->dbus_name = g_strdup (g_dbus_method_invocation_get_sender (invocation)); watch->name_watcher_id = g_bus_watch_name_on_connection (g_dbus_method_invocation_get_connection (invocation), watch->dbus_name, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, /* appeared */ name_vanished_callback, watch, NULL); return watch; } static gboolean handle_add_idle_watch (MetaDBusIdleMonitor *skeleton, GDBusMethodInvocation *invocation, guint64 interval, GsdIdleMonitor *monitor) { DBusWatch *watch; watch = make_dbus_watch (skeleton, invocation, monitor); watch->watch_id = gsd_idle_monitor_add_idle_watch (monitor, interval, dbus_idle_callback, watch, destroy_dbus_watch); meta_dbus_idle_monitor_complete_add_idle_watch (skeleton, invocation, watch->watch_id); return TRUE; } static gboolean handle_add_user_active_watch (MetaDBusIdleMonitor *skeleton, GDBusMethodInvocation *invocation, GsdIdleMonitor *monitor) { DBusWatch *watch; watch = make_dbus_watch (skeleton, invocation, monitor); watch->watch_id = gsd_idle_monitor_add_user_active_watch (monitor, dbus_idle_callback, watch, destroy_dbus_watch); meta_dbus_idle_monitor_complete_add_user_active_watch (skeleton, invocation, watch->watch_id); return TRUE; } static gboolean handle_remove_watch (MetaDBusIdleMonitor *skeleton, GDBusMethodInvocation *invocation, guint id, GsdIdleMonitor *monitor) { gsd_idle_monitor_remove_watch (monitor, id); meta_dbus_idle_monitor_complete_remove_watch (skeleton, invocation); return TRUE; } static void create_monitor_skeleton (GDBusObjectManagerServer *manager, GsdIdleMonitor *monitor, const char *path) { MetaDBusIdleMonitor *skeleton; MetaDBusObjectSkeleton *object; skeleton = meta_dbus_idle_monitor_skeleton_new (); g_signal_connect_object (skeleton, "handle-add-idle-watch", G_CALLBACK (handle_add_idle_watch), monitor, 0); g_signal_connect_object (skeleton, "handle-add-user-active-watch", G_CALLBACK (handle_add_user_active_watch), monitor, 0); g_signal_connect_object (skeleton, "handle-remove-watch", G_CALLBACK (handle_remove_watch), monitor, 0); g_signal_connect_object (skeleton, "handle-get-idletime", G_CALLBACK (handle_get_idletime), monitor, 0); object = meta_dbus_object_skeleton_new (path); meta_dbus_object_skeleton_set_idle_monitor (object, skeleton); g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object)); g_object_unref (skeleton); g_object_unref (object); } static void on_device_added (GdkDeviceManager *device_manager, GdkDevice *device, GDBusObjectManagerServer *manager) { GsdIdleMonitor *monitor; int device_id; char *path; device_id = gdk_x11_device_get_id (device); monitor = gsd_idle_monitor_get_for_device (device_id); g_object_ref(monitor); path = g_strdup_printf ("/org/gnome/Mutter/IdleMonitor/Device%d", device_id); create_monitor_skeleton (manager, monitor, path); g_free (path); } static void on_device_removed (GdkDeviceManager *device_manager, GdkDevice *device, GDBusObjectManagerServer *manager) { int device_id; char *path; device_id = gdk_x11_device_get_id (device); path = g_strdup_printf ("/org/gnome/Mutter/IdleMonitor/Device%d", device_id); g_dbus_object_manager_server_unexport (manager, path); g_free (path); g_clear_object (&device_monitors[device_id]); if (device_id == device_id_max) device_id_max--; } static void on_bus_acquired (GDBusConnection *connection, const char *name, gpointer user_data) { GDBusObjectManagerServer *manager; GdkDeviceManager *device_manager; GsdIdleMonitor *monitor; GList *devices, *iter; char *path; manager = g_dbus_object_manager_server_new ("/org/gnome/Mutter/IdleMonitor"); /* We never clear the core monitor, as that's supposed to cumulate idle times from all devices */ monitor = gsd_idle_monitor_get_core (); path = g_strdup ("/org/gnome/Mutter/IdleMonitor/Core"); create_monitor_skeleton (manager, monitor, path); g_free (path); device_manager = gdk_display_get_device_manager (gdk_display_get_default ()); g_object_ref (device_manager); devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER); devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE)); devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING)); for (iter = devices; iter; iter = iter->next) on_device_added (device_manager, iter->data, manager); g_list_free (devices); g_signal_connect_object (device_manager, "device-added", G_CALLBACK (on_device_added), manager, 0); g_signal_connect_object (device_manager, "device-removed", G_CALLBACK (on_device_removed), manager, 0); g_dbus_object_manager_server_set_connection (manager, connection); gdk_window_add_filter (NULL, xevent_filter, NULL); } static void on_name_acquired (GDBusConnection *connection, const char *name, gpointer user_data) { g_debug ("Acquired name %s\n", name); } static void on_name_lost (GDBusConnection *connection, const char *name, gpointer user_data) { g_warning ("Lost or failed to acquire name %s\n", name); gdk_window_remove_filter (NULL, xevent_filter, NULL); } static void init_xsync_global (void) { int major, minor; xsync->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); xsync->have_xsync = FALSE; xsync->sync_error_base = 0; xsync->sync_event_base = 0; /* I don't think we really have to fill these in */ major = SYNC_MAJOR_VERSION; minor = SYNC_MINOR_VERSION; if (!XSyncQueryExtension (xsync->display, &xsync->sync_event_base, &xsync->sync_error_base) || !XSyncInitialize (xsync->display, &major, &minor)) { xsync->sync_error_base = 0; xsync->sync_event_base = 0; } else { xsync->have_xsync = TRUE; XSyncSetPriority (xsync->display, None, 10); } } void gsd_idle_monitor_init_dbus (gboolean replace) { static int dbus_name_id; if (dbus_name_id > 0) return; xsync = g_slice_new0 (GsdXSync); init_xsync_global(); dbus_name_id = g_bus_own_name (G_BUS_TYPE_SESSION, "org.gnome.Mutter.IdleMonitor", G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | (replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0), on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-idle-monitor.h0000664000175000017500000000533000000000000026571 0ustar00jeremyjeremy/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* * Copyright 2013 Red Hat, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #ifndef gsd_idle_monitor_H #define gsd_idle_monitor_H #include #define GSD_TYPE_IDLE_MONITOR (gsd_idle_monitor_get_type ()) #define gsd_idle_monitor(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitor)) #define gsd_idle_monitor_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitorClass)) #define GSD_IS_IDLE_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_IDLE_MONITOR)) #define GSD_IS_IDLE_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_IDLE_MONITOR)) #define gsd_idle_monitor_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitorClass)) typedef struct _GsdIdleMonitor GsdIdleMonitor; typedef struct _GsdIdleMonitorClass GsdIdleMonitorClass; GType gsd_idle_monitor_get_type (void); typedef void (*GsdIdleMonitorWatchFunc) (GsdIdleMonitor *monitor, guint watch_id, gpointer user_data); GsdIdleMonitor *gsd_idle_monitor_get_core (void); GsdIdleMonitor *gsd_idle_monitor_get_for_device (int device_id); guint gsd_idle_monitor_add_idle_watch (GsdIdleMonitor *monitor, guint64 interval_msec, GsdIdleMonitorWatchFunc callback, gpointer user_data, GDestroyNotify notify); guint gsd_idle_monitor_add_user_active_watch (GsdIdleMonitor *monitor, GsdIdleMonitorWatchFunc callback, gpointer user_data, GDestroyNotify notify); void gsd_idle_monitor_remove_watch (GsdIdleMonitor *monitor, guint id); gint64 gsd_idle_monitor_get_idletime (GsdIdleMonitor *monitor); #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-pnp-ids.c0000664000175000017500000002322000000000000025532 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2009-2011 Richard Hughes * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include "gsd-pnp-ids.h" static void gsd_pnp_ids_finalize (GObject *object); #define GSD_PNP_IDS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_PNP_IDS, GsdPnpIdsPrivate)) struct _GsdPnpIdsPrivate { gchar *table_data; GHashTable *pnp_table; }; static gpointer gsd_pnp_ids_object = NULL; G_DEFINE_TYPE (GsdPnpIds, gsd_pnp_ids, G_TYPE_OBJECT) typedef struct Vendor Vendor; struct Vendor { const char vendor_id[4]; const char vendor_name[28]; }; /* This list of vendor codes derived from lshw * * http://ezix.org/project/wiki/HardwareLiSter * * Note: we now prefer to use data coming from hwdata (and shipped with * gnome-desktop). See * http://git.fedorahosted.org/git/?p=hwdata.git;a=blob_plain;f=pnp.ids;hb=HEAD * All contributions to the list of vendors should go there. */ static const struct Vendor vendors[] = { { "AIC", "AG Neovo" }, { "ACR", "Acer" }, { "DEL", "DELL" }, { "SAM", "SAMSUNG" }, { "SNY", "SONY" }, { "SEC", "Epson" }, { "WAC", "Wacom" }, { "NEC", "NEC" }, { "CMO", "CMO" }, /* Chi Mei */ { "BNQ", "BenQ" }, { "ABP", "Advansys" }, { "ACC", "Accton" }, { "ACE", "Accton" }, { "ADP", "Adaptec" }, { "ADV", "AMD" }, { "AIR", "AIR" }, { "AMI", "AMI" }, { "ASU", "ASUS" }, { "ATI", "ATI" }, { "ATK", "Allied Telesyn" }, { "AZT", "Aztech" }, { "BAN", "Banya" }, { "BRI", "Boca Research" }, { "BUS", "Buslogic" }, { "CCI", "Cache Computers Inc." }, { "CHA", "Chase" }, { "CMD", "CMD Technology, Inc." }, { "COG", "Cogent" }, { "CPQ", "Compaq" }, { "CRS", "Crescendo" }, { "CSC", "Crystal" }, { "CSI", "CSI" }, { "CTL", "Creative Labs" }, { "DBI", "Digi" }, { "DEC", "Digital Equipment" }, { "DBK", "Databook" }, { "EGL", "Eagle Technology" }, { "ELS", "ELSA" }, { "ESS", "ESS" }, { "FAR", "Farallon" }, { "FDC", "Future Domain" }, { "HWP", "Hewlett-Packard" }, { "IBM", "IBM" }, { "INT", "Intel" }, { "ISA", "Iomega" }, { "LEN", "Lenovo" }, { "MDG", "Madge" }, { "MDY", "Microdyne" }, { "MET", "Metheus" }, { "MIC", "Micronics" }, { "MLX", "Mylex" }, { "NVL", "Novell" }, { "OLC", "Olicom" }, { "PRO", "Proteon" }, { "RII", "Racal" }, { "RTL", "Realtek" }, { "SCM", "SCM" }, { "SKD", "SysKonnect" }, { "SGI", "SGI" }, { "SMC", "SMC" }, { "SNI", "Siemens Nixdorf" }, { "STL", "Stallion Technologies" }, { "SUN", "Sun" }, { "SUP", "SupraExpress" }, { "SVE", "SVEC" }, { "TCC", "Thomas-Conrad" }, { "TCI", "Tulip" }, { "TCM", "3Com" }, { "TCO", "Thomas-Conrad" }, { "TEC", "Tecmar" }, { "TRU", "Truevision" }, { "TOS", "Toshiba" }, { "TYN", "Tyan" }, { "UBI", "Ungermann-Bass" }, { "USC", "UltraStor" }, { "VDM", "Vadem" }, { "VMI", "Vermont" }, { "WDC", "Western Digital" }, { "ZDS", "Zeos" }, /* From http://faydoc.tripod.com/structures/01/0136.htm */ { "ACT", "Targa" }, { "ADI", "ADI" }, { "AOC", "AOC Intl" }, { "API", "Acer America" }, { "APP", "Apple Computer" }, { "ART", "ArtMedia" }, { "AST", "AST Research" }, { "CPL", "Compal" }, { "CTX", "Chuntex Electronic Co." }, { "DPC", "Delta Electronics" }, { "DWE", "Daewoo" }, { "ECS", "ELITEGROUP" }, { "EIZ", "EIZO" }, { "FCM", "Funai" }, { "GSM", "LG Electronics" }, { "GWY", "Gateway 2000" }, { "HEI", "Hyundai" }, { "HIT", "Hitachi" }, { "HSL", "Hansol" }, { "HTC", "Hitachi" }, { "ICL", "Fujitsu ICL" }, { "IVM", "Idek Iiyama" }, { "KFC", "KFC Computek" }, { "LKM", "ADLAS" }, { "LNK", "LINK Tech" }, { "LTN", "Lite-On" }, { "MAG", "MAG InnoVision" }, { "MAX", "Maxdata" }, { "MEI", "Panasonic" }, { "MEL", "Mitsubishi" }, { "MIR", "miro" }, { "MTC", "MITAC" }, { "NAN", "NANAO" }, { "NEC", "NEC Tech" }, { "NOK", "Nokia" }, { "OQI", "OPTIQUEST" }, { "PBN", "Packard Bell" }, { "PGS", "Princeton" }, { "PHL", "Philips" }, { "REL", "Relisys" }, { "SDI", "Samtron" }, { "SMI", "Smile" }, { "SPT", "Sceptre" }, { "SRC", "Shamrock Technology" }, { "STP", "Sceptre" }, { "TAT", "Tatung" }, { "TRL", "Royal Information Company" }, { "TSB", "Toshiba, Inc." }, { "UNM", "Unisys" }, { "VSC", "ViewSonic" }, { "WTC", "Wen Tech" }, { "ZCM", "Zenith Data Systems" }, { "???", "Unknown" }, }; static gboolean gsd_pnp_ids_load (GsdPnpIds *pnp_ids, GError **error) { gchar *retval = NULL; GsdPnpIdsPrivate *priv = pnp_ids->priv; guint i; /* load the contents */ g_debug ("loading: %s", PNP_IDS); if (g_file_get_contents (PNP_IDS, &priv->table_data, NULL, error) == FALSE) return FALSE; /* parse into lines */ retval = priv->table_data; for (i = 0; priv->table_data[i] != '\0'; i++) { /* ignore */ if (priv->table_data[i] != '\n') continue; /* convert newline to NULL */ priv->table_data[i] = '\0'; /* the ID to text is a fixed offset */ if (retval[0] && retval[1] && retval[2] && retval[3] == '\t' && retval[4]) { retval[3] = '\0'; g_hash_table_insert (priv->pnp_table, retval, retval+4); retval = &priv->table_data[i+1]; } } g_debug ("Added %i items to the vendor hashtable", i); return TRUE; } static const char * find_vendor (const char *pnp_id) { guint i; for (i = 0; i < G_N_ELEMENTS (vendors); i++) { if (g_strcmp0 (vendors[i].vendor_id, pnp_id) == 0) return vendors[i].vendor_name; } return NULL; } /** * gsd_pnp_ids_get_pnp_id: * @pnp_ids: a #GsdPnpIds object * @pnp_id: the PNP ID to look for * * Find the full manufacturer name for the given PNP ID. * * Returns: (transfer full): a new string representing the manufacturer name, * or %NULL when not found. */ gchar * gsd_pnp_ids_get_pnp_id (GsdPnpIds *pnp_ids, const gchar *pnp_id) { GsdPnpIdsPrivate *priv = pnp_ids->priv; const char *found; GError *error = NULL; guint size; g_return_val_if_fail (GSD_IS_PNP_IDS (pnp_ids), NULL); g_return_val_if_fail (pnp_id != NULL, NULL); /* if table is empty, try to load it */ size = g_hash_table_size (priv->pnp_table); if (size == 0) { if (gsd_pnp_ids_load (pnp_ids, &error) == FALSE) { g_warning ("Failed to load PNP ids: %s", error->message); g_error_free (error); return NULL; } } /* look this up in the table */ found = g_hash_table_lookup (priv->pnp_table, pnp_id); if (found == NULL) { found = find_vendor (pnp_id); if (found == NULL) return NULL; } return g_strdup (found); } static void gsd_pnp_ids_class_init (GsdPnpIdsClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_pnp_ids_finalize; g_type_class_add_private (klass, sizeof (GsdPnpIdsPrivate)); } static void gsd_pnp_ids_init (GsdPnpIds *pnp_ids) { pnp_ids->priv = GSD_PNP_IDS_GET_PRIVATE (pnp_ids); /* we don't keep malloc'd data in the hash; instead we read it * out into priv->table_data and then link to it in the hash */ pnp_ids->priv->pnp_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); } static void gsd_pnp_ids_finalize (GObject *object) { GsdPnpIds *pnp_ids = GSD_PNP_IDS (object); GsdPnpIdsPrivate *priv = pnp_ids->priv; g_free (priv->table_data); g_hash_table_unref (priv->pnp_table); G_OBJECT_CLASS (gsd_pnp_ids_parent_class)->finalize (object); } /** * gsd_pnp_ids_new: * * Returns a reference to a #GsdPnpIds object, or creates * a new one if none have been created. * * Returns: (transfer full): a #GsdPnpIds object. */ GsdPnpIds * gsd_pnp_ids_new (void) { if (gsd_pnp_ids_object != NULL) { g_object_ref (gsd_pnp_ids_object); } else { gsd_pnp_ids_object = g_object_new (GSD_TYPE_PNP_IDS, NULL); g_object_add_weak_pointer (gsd_pnp_ids_object, &gsd_pnp_ids_object); } return GSD_PNP_IDS (gsd_pnp_ids_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-pnp-ids.h0000664000175000017500000000430300000000000025540 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2009-2010 Richard Hughes * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __GSD_PNP_IDS_H #define __GSD_PNP_IDS_H #include G_BEGIN_DECLS #define GSD_TYPE_PNP_IDS (gsd_pnp_ids_get_type ()) #define GSD_PNP_IDS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_PNP_IDS, GsdPnpIds)) #define GSD_PNP_IDS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_PNP_IDS, GsdPnpIdsClass)) #define GSD_IS_PNP_IDS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_PNP_IDS)) #define GSD_IS_PNP_IDS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_PNP_IDS)) #define GSD_PNP_IDS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_PNP_IDS, GsdPnpIdsClass)) #define GSD_PNP_IDS_ERROR (gsd_pnp_ids_error_quark ()) typedef struct _GsdPnpIdsPrivate GsdPnpIdsPrivate; typedef struct _GsdPnpIds GsdPnpIds; typedef struct _GsdPnpIdsClass GsdPnpIdsClass; struct _GsdPnpIds { GObject parent; GsdPnpIdsPrivate *priv; }; struct _GsdPnpIdsClass { GObjectClass parent_class; }; GType gsd_pnp_ids_get_type (void); GsdPnpIds *gsd_pnp_ids_new (void); gchar *gsd_pnp_ids_get_pnp_id (GsdPnpIds *pnp_ids, const gchar *pnp_id); G_END_DECLS #endif /* __GSD_PNP_IDS_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-rr-config.c0000664000175000017500000015034000000000000026052 0ustar00jeremyjeremy/* gnome-rr-config.c * -*- c-basic-offset: 4 -*- * * Copyright 2007, 2008, Red Hat, Inc. * Copyright 2010 Giovanni Campagna * * This file is part of the Gnome Library. * * The Gnome Library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * The Gnome 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with the Gnome Library; see the file COPYING.LIB. If not, * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * Author: Soren Sandmann */ #include #include #include #include #include #include #include #include #include #include #include #include "gsd-rr-config.h" #include "edid.h" #include "gsd-rr-private.h" #define CONFIG_INTENDED_BASENAME "unity-monitors.xml" #define CONFIG_BACKUP_BASENAME "unity-monitors.xml.backup" /* Look for DPI_FALLBACK in: * http://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/xsettings/gsd-xsettings-manager.c * for the reasoning */ #define DPI_FALLBACK 96.0 /* In version 0 of the config file format, we had several * toplevel elements and no explicit version number. So, the filed looked * like * * * ... * * * ... * * * Since version 1 of the config file, the file has a toplevel * element to group all the configurations. That element has a "version" * attribute which is an integer. So, the file looks like this: * * * * ... * * * ... * * */ /* A helper wrapper around the GMarkup parser stuff */ static gboolean parse_file_gmarkup (const gchar *file, const GMarkupParser *parser, gpointer data, GError **err); typedef struct CrtcAssignment CrtcAssignment; static gboolean crtc_assignment_apply (CrtcAssignment *assign, guint32 timestamp, GError **error); static CrtcAssignment *crtc_assignment_new (GsdRRScreen *screen, GsdRROutputInfo **outputs, GError **error); static void crtc_assignment_free (CrtcAssignment *assign); enum { PROP_0, PROP_SCREEN, PROP_LAST }; G_DEFINE_TYPE (GsdRRConfig, gsd_rr_config, G_TYPE_OBJECT) typedef struct Parser Parser; /* Parser for monitor configurations */ struct Parser { int config_file_version; GsdRROutputInfo * output; GsdRRConfig * configuration; GPtrArray * outputs; GPtrArray * configurations; GQueue * stack; }; static int parse_int (const char *text) { return strtol (text, NULL, 0); } static guint parse_uint (const char *text) { return strtoul (text, NULL, 0); } static gboolean stack_is (Parser *parser, const char *s1, ...) { GList *stack = NULL; const char *s; GList *l1, *l2; va_list args; stack = g_list_prepend (stack, (gpointer)s1); va_start (args, s1); s = va_arg (args, const char *); while (s) { stack = g_list_prepend (stack, (gpointer)s); s = va_arg (args, const char *); } l1 = stack; l2 = parser->stack->head; while (l1 && l2) { if (strcmp (l1->data, l2->data) != 0) { g_list_free (stack); return FALSE; } l1 = l1->next; l2 = l2->next; } g_list_free (stack); return (!l1 && !l2); } static void handle_start_element (GMarkupParseContext *context, const gchar *name, const gchar **attr_names, const gchar **attr_values, gpointer user_data, GError **err) { Parser *parser = user_data; if (strcmp (name, "output") == 0) { int i; g_assert (parser->output == NULL); parser->output = g_object_new (GSD_TYPE_RR_OUTPUT_INFO, NULL); parser->output->priv->rotation = 0; for (i = 0; attr_names[i] != NULL; ++i) { if (strcmp (attr_names[i], "name") == 0) { parser->output->priv->name = g_strdup (attr_values[i]); break; } } if (!parser->output->priv->name) { /* This really shouldn't happen, but it's better to make * something up than to crash later. */ g_warning ("Malformed monitor configuration file"); parser->output->priv->name = g_strdup ("default"); } parser->output->priv->connected = FALSE; parser->output->priv->on = FALSE; parser->output->priv->primary = FALSE; } else if (strcmp (name, "configuration") == 0) { g_assert (parser->configuration == NULL); parser->configuration = g_object_new (GSD_TYPE_RR_CONFIG, NULL); parser->configuration->priv->clone = FALSE; parser->configuration->priv->outputs = NULL; } else if (strcmp (name, "monitors") == 0) { int i; for (i = 0; attr_names[i] != NULL; i++) { if (strcmp (attr_names[i], "version") == 0) { parser->config_file_version = parse_int (attr_values[i]); break; } } } g_queue_push_tail (parser->stack, g_strdup (name)); } static void handle_end_element (GMarkupParseContext *context, const gchar *name, gpointer user_data, GError **err) { Parser *parser = user_data; if (strcmp (name, "output") == 0) { /* If no rotation properties were set, just use GSD_RR_ROTATION_0 */ if (parser->output->priv->rotation == 0) parser->output->priv->rotation = GSD_RR_ROTATION_0; g_ptr_array_add (parser->outputs, parser->output); parser->output = NULL; } else if (strcmp (name, "configuration") == 0) { g_ptr_array_add (parser->outputs, NULL); parser->configuration->priv->outputs = (GsdRROutputInfo **)g_ptr_array_free (parser->outputs, FALSE); parser->outputs = g_ptr_array_new (); g_ptr_array_add (parser->configurations, parser->configuration); parser->configuration = NULL; } g_free (g_queue_pop_tail (parser->stack)); } #define TOPLEVEL_ELEMENT (parser->config_file_version > 0 ? "monitors" : NULL) static void handle_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **err) { Parser *parser = user_data; if (stack_is (parser, "vendor", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { parser->output->priv->connected = TRUE; strncpy ((gchar*) parser->output->priv->vendor, text, 3); parser->output->priv->vendor[3] = 0; } else if (stack_is (parser, "clone", "configuration", TOPLEVEL_ELEMENT, NULL)) { if (strcmp (text, "yes") == 0) parser->configuration->priv->clone = TRUE; } else if (stack_is (parser, "product", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { parser->output->priv->connected = TRUE; parser->output->priv->product = parse_int (text); } else if (stack_is (parser, "serial", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { parser->output->priv->connected = TRUE; parser->output->priv->serial = parse_uint (text); } else if (stack_is (parser, "width", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { parser->output->priv->on = TRUE; parser->output->priv->width = parse_int (text); } else if (stack_is (parser, "x", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { parser->output->priv->on = TRUE; parser->output->priv->x = parse_int (text); } else if (stack_is (parser, "y", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { parser->output->priv->on = TRUE; parser->output->priv->y = parse_int (text); } else if (stack_is (parser, "height", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { parser->output->priv->on = TRUE; parser->output->priv->height = parse_int (text); } else if (stack_is (parser, "rate", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { parser->output->priv->on = TRUE; parser->output->priv->rate = parse_int (text); } else if (stack_is (parser, "rotation", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { if (strcmp (text, "normal") == 0) { parser->output->priv->rotation |= GSD_RR_ROTATION_0; } else if (strcmp (text, "left") == 0) { parser->output->priv->rotation |= GSD_RR_ROTATION_90; } else if (strcmp (text, "upside_down") == 0) { parser->output->priv->rotation |= GSD_RR_ROTATION_180; } else if (strcmp (text, "right") == 0) { parser->output->priv->rotation |= GSD_RR_ROTATION_270; } } else if (stack_is (parser, "reflect_x", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { if (strcmp (text, "yes") == 0) { parser->output->priv->rotation |= GSD_RR_REFLECT_X; } } else if (stack_is (parser, "reflect_y", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { if (strcmp (text, "yes") == 0) { parser->output->priv->rotation |= GSD_RR_REFLECT_Y; } } else if (stack_is (parser, "primary", "output", "configuration", TOPLEVEL_ELEMENT, NULL)) { if (strcmp (text, "yes") == 0) { parser->output->priv->primary = TRUE; } } else { /* Ignore other properties so we can expand the format in the future */ } } static void parser_free (Parser *parser) { int i; GList *list; g_assert (parser != NULL); if (parser->output) g_object_unref (parser->output); if (parser->configuration) g_object_unref (parser->configuration); for (i = 0; i < parser->outputs->len; ++i) { GsdRROutputInfo *output = parser->outputs->pdata[i]; g_object_unref (output); } g_ptr_array_free (parser->outputs, TRUE); for (i = 0; i < parser->configurations->len; ++i) { GsdRRConfig *config = parser->configurations->pdata[i]; g_object_unref (config); } g_ptr_array_free (parser->configurations, TRUE); for (list = parser->stack->head; list; list = list->next) g_free (list->data); g_queue_free (parser->stack); g_free (parser); } static GsdRRConfig ** configurations_read_from_file (const gchar *filename, GError **error) { Parser *parser = g_new0 (Parser, 1); GsdRRConfig **result; GMarkupParser callbacks = { handle_start_element, handle_end_element, handle_text, NULL, /* passthrough */ NULL, /* error */ }; parser->config_file_version = 0; parser->configurations = g_ptr_array_new (); parser->outputs = g_ptr_array_new (); parser->stack = g_queue_new (); if (!parse_file_gmarkup (filename, &callbacks, parser, error)) { result = NULL; g_assert (parser->outputs); goto out; } g_assert (parser->outputs); g_ptr_array_add (parser->configurations, NULL); result = (GsdRRConfig **)g_ptr_array_free (parser->configurations, FALSE); parser->configurations = g_ptr_array_new (); g_assert (parser->outputs); out: parser_free (parser); return result; } static void gsd_rr_config_init (GsdRRConfig *self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GSD_TYPE_RR_CONFIG, GsdRRConfigPrivate); self->priv->clone = FALSE; self->priv->screen = NULL; self->priv->outputs = NULL; } static void gsd_rr_config_set_property (GObject *gobject, guint property_id, const GValue *value, GParamSpec *property) { GsdRRConfig *self = GSD_RR_CONFIG (gobject); switch (property_id) { case PROP_SCREEN: self->priv->screen = g_value_dup_object (value); return; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, property); } } static void gsd_rr_config_finalize (GObject *gobject) { GsdRRConfig *self = GSD_RR_CONFIG (gobject); if (self->priv->screen) g_object_unref (self->priv->screen); if (self->priv->outputs) { int i; for (i = 0; self->priv->outputs[i] != NULL; i++) { GsdRROutputInfo *output = self->priv->outputs[i]; g_object_unref (output); } g_free (self->priv->outputs); } G_OBJECT_CLASS (gsd_rr_config_parent_class)->finalize (gobject); } gboolean gsd_rr_config_load_current (GsdRRConfig *config, GError **error) { GPtrArray *a; GsdRROutput **rr_outputs; int i; int clone_width = -1; int clone_height = -1; int last_x; g_return_val_if_fail (GSD_IS_RR_CONFIG (config), FALSE); a = g_ptr_array_new (); rr_outputs = gsd_rr_screen_list_outputs (config->priv->screen); config->priv->clone = FALSE; for (i = 0; rr_outputs[i] != NULL; ++i) { GsdRROutput *rr_output = rr_outputs[i]; GsdRROutputInfo *output = g_object_new (GSD_TYPE_RR_OUTPUT_INFO, NULL); GsdRRMode *mode = NULL; const guint8 *edid_data = gsd_rr_output_get_edid_data (rr_output, NULL); GsdRRCrtc *crtc; output->priv->name = g_strdup (gsd_rr_output_get_name (rr_output)); output->priv->connected = gsd_rr_output_is_connected (rr_output); output->priv->display_name = g_strdup (gsd_rr_output_get_display_name (rr_output)); if (!output->priv->connected) { output->priv->x = -1; output->priv->y = -1; output->priv->width = -1; output->priv->height = -1; output->priv->rate = -1; output->priv->rotation = GSD_RR_ROTATION_0; } else { MonitorInfo *info = NULL; if (edid_data) info = decode_edid (edid_data); if (info) { memcpy (output->priv->vendor, info->manufacturer_code, sizeof (output->priv->vendor)); output->priv->product = info->product_code; output->priv->serial = info->serial_number; output->priv->aspect = info->aspect_ratio; } else { strcpy (output->priv->vendor, "???"); output->priv->product = 0; output->priv->serial = 0; } g_free (info); crtc = gsd_rr_output_get_crtc (rr_output); mode = crtc? gsd_rr_crtc_get_current_mode (crtc) : NULL; if (crtc && mode) { output->priv->on = TRUE; gsd_rr_crtc_get_position (crtc, &output->priv->x, &output->priv->y); output->priv->width = gsd_rr_mode_get_width (mode); output->priv->height = gsd_rr_mode_get_height (mode); output->priv->rate = gsd_rr_mode_get_freq (mode); output->priv->rotation = gsd_rr_crtc_get_current_rotation (crtc); if (output->priv->x == 0 && output->priv->y == 0) { if (clone_width == -1) { clone_width = output->priv->width; clone_height = output->priv->height; } else if (clone_width == output->priv->width && clone_height == output->priv->height) { config->priv->clone = TRUE; } } } else { output->priv->on = FALSE; config->priv->clone = FALSE; } /* Get preferred size for the monitor */ mode = gsd_rr_output_get_preferred_mode (rr_output); if (!mode) { GsdRRMode **modes = gsd_rr_output_list_modes (rr_output); /* FIXME: we should pick the "best" mode here, where best is * sorted wrt * * - closest aspect ratio * - mode area * - refresh rate * - We may want to extend randrwrap so that get_preferred * returns that - although that could also depend on * the crtc. */ if (modes[0]) mode = modes[0]; } if (mode) { output->priv->pref_width = gsd_rr_mode_get_width (mode); output->priv->pref_height = gsd_rr_mode_get_height (mode); } else { /* Pick some random numbers. This should basically never happen */ output->priv->pref_width = 1024; output->priv->pref_height = 768; } } output->priv->primary = gsd_rr_output_get_is_primary (rr_output); g_ptr_array_add (a, output); } g_ptr_array_add (a, NULL); config->priv->outputs = (GsdRROutputInfo **)g_ptr_array_free (a, FALSE); /* Walk the outputs computing the right-most edge of all * lit-up displays */ last_x = 0; for (i = 0; config->priv->outputs[i] != NULL; ++i) { GsdRROutputInfo *output = config->priv->outputs[i]; if (output->priv->on) { last_x = MAX (last_x, output->priv->x + output->priv->width); } } /* Now position all off displays to the right of the * on displays */ for (i = 0; config->priv->outputs[i] != NULL; ++i) { GsdRROutputInfo *output = config->priv->outputs[i]; if (output->priv->connected && !output->priv->on) { output->priv->x = last_x; last_x = output->priv->x + output->priv->width; } } g_assert (gsd_rr_config_match (config, config)); return TRUE; } gboolean gsd_rr_config_load_filename (GsdRRConfig *result, const char *filename, GError **error) { GsdRRConfig *current; GsdRRConfig **configs; gboolean found = FALSE; g_return_val_if_fail (GSD_IS_RR_CONFIG (result), FALSE); g_return_val_if_fail (filename != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); current = gsd_rr_config_new_current (result->priv->screen, error); configs = configurations_read_from_file (filename, error); if (configs) { int i; for (i = 0; configs[i] != NULL; ++i) { if (gsd_rr_config_match (configs[i], current)) { int j; GPtrArray *array; result->priv->clone = configs[i]->priv->clone; array = g_ptr_array_new (); for (j = 0; configs[i]->priv->outputs[j] != NULL; j++) { g_object_ref (configs[i]->priv->outputs[j]); g_ptr_array_add (array, configs[i]->priv->outputs[j]); } g_ptr_array_add (array, NULL); result->priv->outputs = (GsdRROutputInfo **) g_ptr_array_free (array, FALSE); found = TRUE; break; } g_object_unref (configs[i]); } g_free (configs); if (!found) g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_NO_MATCHING_CONFIG, _("none of the saved display configurations matched the active configuration")); } g_object_unref (current); return found; } static void gsd_rr_config_class_init (GsdRRConfigClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (GsdRROutputInfoPrivate)); gobject_class->set_property = gsd_rr_config_set_property; gobject_class->finalize = gsd_rr_config_finalize; g_object_class_install_property (gobject_class, PROP_SCREEN, g_param_spec_object ("screen", "Screen", "The GsdRRScreen this config applies to", GSD_TYPE_RR_SCREEN, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); } GsdRRConfig * gsd_rr_config_new_current (GsdRRScreen *screen, GError **error) { GsdRRConfig *self = g_object_new (GSD_TYPE_RR_CONFIG, "screen", screen, NULL); if (gsd_rr_config_load_current (self, error)) return self; else { g_object_unref (self); return NULL; } } GsdRRConfig * gsd_rr_config_new_stored (GsdRRScreen *screen, GError **error) { GsdRRConfig *self = g_object_new (GSD_TYPE_RR_CONFIG, "screen", screen, NULL); char *filename; gboolean success; filename = gsd_rr_config_get_intended_filename (); success = gsd_rr_config_load_filename (self, filename, error); g_free (filename); if (success) return self; else { g_object_unref (self); return NULL; } } static gboolean parse_file_gmarkup (const gchar *filename, const GMarkupParser *parser, gpointer data, GError **err) { GMarkupParseContext *context = NULL; gchar *contents = NULL; gboolean result = TRUE; gsize len; if (!g_file_get_contents (filename, &contents, &len, err)) { result = FALSE; goto out; } context = g_markup_parse_context_new (parser, 0, data, NULL); if (!g_markup_parse_context_parse (context, contents, len, err)) { result = FALSE; goto out; } if (!g_markup_parse_context_end_parse (context, err)) { result = FALSE; goto out; } out: if (contents) g_free (contents); if (context) g_markup_parse_context_free (context); return result; } static gboolean output_match (GsdRROutputInfo *output1, GsdRROutputInfo *output2) { g_assert (GSD_IS_RR_OUTPUT_INFO (output1)); g_assert (GSD_IS_RR_OUTPUT_INFO (output2)); if (strcmp (output1->priv->name, output2->priv->name) != 0) return FALSE; if (strcmp (output1->priv->vendor, output2->priv->vendor) != 0) return FALSE; if (output1->priv->product != output2->priv->product) return FALSE; if (output1->priv->serial != output2->priv->serial) return FALSE; if (output1->priv->connected != output2->priv->connected) return FALSE; return TRUE; } static gboolean output_equal (GsdRROutputInfo *output1, GsdRROutputInfo *output2) { g_assert (GSD_IS_RR_OUTPUT_INFO (output1)); g_assert (GSD_IS_RR_OUTPUT_INFO (output2)); if (!output_match (output1, output2)) return FALSE; if (output1->priv->on != output2->priv->on) return FALSE; if (output1->priv->on) { if (output1->priv->width != output2->priv->width) return FALSE; if (output1->priv->height != output2->priv->height) return FALSE; if (output1->priv->rate != output2->priv->rate) return FALSE; if (output1->priv->x != output2->priv->x) return FALSE; if (output1->priv->y != output2->priv->y) return FALSE; if (output1->priv->rotation != output2->priv->rotation) return FALSE; } return TRUE; } static GsdRROutputInfo * find_output (GsdRRConfig *config, const char *name) { int i; for (i = 0; config->priv->outputs[i] != NULL; ++i) { GsdRROutputInfo *output = config->priv->outputs[i]; if (strcmp (name, output->priv->name) == 0) return output; } return NULL; } /* Match means "these configurations apply to the same hardware * setups" */ gboolean gsd_rr_config_match (GsdRRConfig *c1, GsdRRConfig *c2) { int i; g_return_val_if_fail (GSD_IS_RR_CONFIG (c1), FALSE); g_return_val_if_fail (GSD_IS_RR_CONFIG (c2), FALSE); for (i = 0; c1->priv->outputs[i] != NULL; ++i) { GsdRROutputInfo *output1 = c1->priv->outputs[i]; GsdRROutputInfo *output2; output2 = find_output (c2, output1->priv->name); if (!output2 || !output_match (output1, output2)) return FALSE; } return TRUE; } /* Equal means "the configurations will result in the same * modes being set on the outputs" */ gboolean gsd_rr_config_equal (GsdRRConfig *c1, GsdRRConfig *c2) { int i; g_return_val_if_fail (GSD_IS_RR_CONFIG (c1), FALSE); g_return_val_if_fail (GSD_IS_RR_CONFIG (c2), FALSE); for (i = 0; c1->priv->outputs[i] != NULL; ++i) { GsdRROutputInfo *output1 = c1->priv->outputs[i]; GsdRROutputInfo *output2; output2 = find_output (c2, output1->priv->name); if (!output2 || !output_equal (output1, output2)) return FALSE; } return TRUE; } static GsdRROutputInfo ** make_outputs (GsdRRConfig *config) { GPtrArray *outputs; GsdRROutputInfo *first_on; int i; outputs = g_ptr_array_new (); first_on = NULL; for (i = 0; config->priv->outputs[i] != NULL; ++i) { GsdRROutputInfo *old = config->priv->outputs[i]; GsdRROutputInfo *new = g_object_new (GSD_TYPE_RR_OUTPUT_INFO, NULL); *(new->priv) = *(old->priv); if (old->priv->name) new->priv->name = g_strdup (old->priv->name); if (old->priv->display_name) new->priv->display_name = g_strdup (old->priv->display_name); if (old->priv->on && !first_on) first_on = old; if (config->priv->clone && new->priv->on) { g_assert (first_on); new->priv->width = first_on->priv->width; new->priv->height = first_on->priv->height; new->priv->rotation = first_on->priv->rotation; new->priv->x = 0; new->priv->y = 0; } g_ptr_array_add (outputs, new); } g_ptr_array_add (outputs, NULL); return (GsdRROutputInfo **)g_ptr_array_free (outputs, FALSE); } gboolean gsd_rr_config_applicable (GsdRRConfig *configuration, GsdRRScreen *screen, GError **error) { GsdRROutputInfo **outputs; CrtcAssignment *assign; gboolean result; int i; g_return_val_if_fail (GSD_IS_RR_CONFIG (configuration), FALSE); g_return_val_if_fail (GSD_IS_RR_SCREEN (screen), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); outputs = make_outputs (configuration); assign = crtc_assignment_new (screen, outputs, error); if (assign) { result = TRUE; crtc_assignment_free (assign); } else { result = FALSE; } for (i = 0; outputs[i] != NULL; i++) { g_object_unref (outputs[i]); } return result; } /* Database management */ static void ensure_config_directory (void) { g_mkdir_with_parents (g_get_user_config_dir (), 0700); } char * gsd_rr_config_get_backup_filename (void) { ensure_config_directory (); return g_build_filename (g_get_user_config_dir (), CONFIG_BACKUP_BASENAME, NULL); } char * gsd_rr_config_get_intended_filename (void) { ensure_config_directory (); return g_build_filename (g_get_user_config_dir (), CONFIG_INTENDED_BASENAME, NULL); } static const char * get_rotation_name (GsdRRRotation r) { if (r & GSD_RR_ROTATION_0) return "normal"; if (r & GSD_RR_ROTATION_90) return "left"; if (r & GSD_RR_ROTATION_180) return "upside_down"; if (r & GSD_RR_ROTATION_270) return "right"; return "normal"; } static const char * yes_no (int x) { return x? "yes" : "no"; } static const char * get_reflect_x (GsdRRRotation r) { return yes_no (r & GSD_RR_REFLECT_X); } static const char * get_reflect_y (GsdRRRotation r) { return yes_no (r & GSD_RR_REFLECT_Y); } static void emit_configuration (GsdRRConfig *config, GString *string) { int j; g_string_append_printf (string, " \n"); g_string_append_printf (string, " %s\n", yes_no (config->priv->clone)); for (j = 0; config->priv->outputs[j] != NULL; ++j) { GsdRROutputInfo *output = config->priv->outputs[j]; g_string_append_printf ( string, " \n", output->priv->name); if (output->priv->connected && *output->priv->vendor != '\0') { g_string_append_printf ( string, " %s\n", output->priv->vendor); g_string_append_printf ( string, " 0x%04x\n", output->priv->product); g_string_append_printf ( string, " 0x%08x\n", output->priv->serial); } /* An unconnected output which is on does not make sense */ if (output->priv->connected && output->priv->on) { g_string_append_printf ( string, " %d\n", output->priv->width); g_string_append_printf ( string, " %d\n", output->priv->height); g_string_append_printf ( string, " %d\n", output->priv->rate); g_string_append_printf ( string, " %d\n", output->priv->x); g_string_append_printf ( string, " %d\n", output->priv->y); g_string_append_printf ( string, " %s\n", get_rotation_name (output->priv->rotation)); g_string_append_printf ( string, " %s\n", get_reflect_x (output->priv->rotation)); g_string_append_printf ( string, " %s\n", get_reflect_y (output->priv->rotation)); g_string_append_printf ( string, " %s\n", yes_no (output->priv->primary)); } g_string_append_printf (string, " \n"); } g_string_append_printf (string, " \n"); } void gsd_rr_config_sanitize (GsdRRConfig *config) { int i; int x_offset, y_offset; gboolean found; /* Offset everything by the top/left-most coordinate to * make sure the configuration starts at (0, 0) */ x_offset = y_offset = G_MAXINT; for (i = 0; config->priv->outputs[i]; ++i) { GsdRROutputInfo *output = config->priv->outputs[i]; if (output->priv->on) { x_offset = MIN (x_offset, output->priv->x); y_offset = MIN (y_offset, output->priv->y); } } for (i = 0; config->priv->outputs[i]; ++i) { GsdRROutputInfo *output = config->priv->outputs[i]; if (output->priv->on) { output->priv->x -= x_offset; output->priv->y -= y_offset; } } /* Only one primary, please */ found = FALSE; for (i = 0; config->priv->outputs[i]; ++i) { if (config->priv->outputs[i]->priv->primary) { if (found) { config->priv->outputs[i]->priv->primary = FALSE; } else { found = TRUE; } } } } gboolean gsd_rr_config_ensure_primary (GsdRRConfig *configuration) { int i; GsdRROutputInfo *laptop; GsdRROutputInfo *top_left; gboolean found; GsdRRConfigPrivate *priv; g_return_val_if_fail (GSD_IS_RR_CONFIG (configuration), FALSE); laptop = NULL; top_left = NULL; found = FALSE; priv = configuration->priv; for (i = 0; priv->outputs[i] != NULL; ++i) { GsdRROutputInfo *info = priv->outputs[i]; if (!info->priv->on) { info->priv->primary = FALSE; continue; } /* ensure only one */ if (info->priv->primary) { if (found) { info->priv->primary = FALSE; } else { found = TRUE; } } if (top_left == NULL || (info->priv->x < top_left->priv->x && info->priv->y < top_left->priv->y)) { top_left = info; } if (laptop == NULL && _gsd_rr_output_name_is_laptop (info->priv->name)) { /* shame we can't find the connector type as with gsd_rr_output_is_laptop */ laptop = info; } } if (!found) { if (laptop != NULL) { laptop->priv->primary = TRUE; } else if (top_left != NULL) { /* Note: top_left can be NULL if all outputs are off */ top_left->priv->primary = TRUE; } } return !found; } gboolean gsd_rr_config_save (GsdRRConfig *configuration, GError **error) { GsdRRConfig **configurations; GString *output; int i; gchar *intended_filename; gchar *backup_filename; gboolean result; g_return_val_if_fail (GSD_IS_RR_CONFIG (configuration), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); output = g_string_new (""); backup_filename = gsd_rr_config_get_backup_filename (); intended_filename = gsd_rr_config_get_intended_filename (); configurations = configurations_read_from_file (intended_filename, NULL); /* NULL-GError */ g_string_append_printf (output, "\n"); if (configurations) { for (i = 0; configurations[i] != NULL; ++i) { if (!gsd_rr_config_match (configurations[i], configuration)) emit_configuration (configurations[i], output); g_object_unref (configurations[i]); } g_free (configurations); } emit_configuration (configuration, output); g_string_append_printf (output, "\n"); /* backup the file first */ rename (intended_filename, backup_filename); /* no error checking because the intended file may not even exist */ result = g_file_set_contents (intended_filename, output->str, -1, error); if (!result) rename (backup_filename, intended_filename); /* no error checking because the backup may not even exist */ g_free (backup_filename); g_free (intended_filename); return result; } gboolean gsd_rr_config_apply_with_time (GsdRRConfig *config, GsdRRScreen *screen, guint32 timestamp, GError **error) { CrtcAssignment *assignment; GsdRROutputInfo **outputs; gboolean result = FALSE; int i; g_return_val_if_fail (GSD_IS_RR_CONFIG (config), FALSE); g_return_val_if_fail (GSD_IS_RR_SCREEN (screen), FALSE); outputs = make_outputs (config); assignment = crtc_assignment_new (screen, outputs, error); for (i = 0; outputs[i] != NULL; i++) g_object_unref (outputs[i]); g_free (outputs); if (assignment) { if (crtc_assignment_apply (assignment, timestamp, error)) result = TRUE; crtc_assignment_free (assignment); gdk_flush (); } return result; } /* gsd_rr_config_apply_from_filename_with_time: * @screen: A #GsdRRScreen * @filename: Path of the file to look in for stored RANDR configurations. * @timestamp: X server timestamp from the event that causes the screen configuration to change (a user's button press, for example) * @error: Location to store error, or %NULL * * Loads the file in @filename and looks for suitable matching RANDR * configurations in the file; if one is found, that configuration will be * applied to the current set of RANDR outputs. * * Typically, @filename is the result of gsd_rr_config_get_intended_filename() or * gsd_rr_config_get_backup_filename(). * * Returns: TRUE if the RANDR configuration was loaded and applied from * the specified file, or FALSE otherwise: * * If the file in question is loaded successfully but the configuration cannot * be applied, the @error will have a domain of #GSD_RR_ERROR. Note that an * error code of #GSD_RR_ERROR_NO_MATCHING_CONFIG is not a real error; it * simply means that there were no stored configurations that match the current * set of RANDR outputs. * * If the file in question cannot be loaded, the @error will have a domain of * #G_FILE_ERROR. Note that an error code of G_FILE_ERROR_NOENT is not really * an error, either; it means that there was no stored configuration file and so * nothing is changed. */ gboolean gsd_rr_config_apply_from_filename_with_time (GsdRRScreen *screen, const char *filename, guint32 timestamp, GError **error) { GsdRRConfig *stored; g_return_val_if_fail (GSD_IS_RR_SCREEN (screen), FALSE); g_return_val_if_fail (filename != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); stored = g_object_new (GSD_TYPE_RR_CONFIG, "screen", screen, NULL); if (gsd_rr_config_load_filename (stored, filename, error)) { gboolean result; gsd_rr_config_ensure_primary (stored); result = gsd_rr_config_apply_with_time (stored, screen, timestamp, error); g_object_unref (stored); return result; } else { g_object_unref (stored); return FALSE; } } /** * gsd_rr_config_get_outputs: * * Returns: (array zero-terminated=1) (element-type GnomeDesktop.RROutputInfo) (transfer none): the output configuration for this #GsdRRConfig */ GsdRROutputInfo ** gsd_rr_config_get_outputs (GsdRRConfig *self) { g_return_val_if_fail (GSD_IS_RR_CONFIG (self), NULL); return self->priv->outputs; } /** * gsd_rr_config_get_clone: * * Returns: whether at least two outputs are at (0, 0) offset and they * have the same width/height. Those outputs are of course connected and on * (i.e. they have a CRTC assigned). */ gboolean gsd_rr_config_get_clone (GsdRRConfig *self) { g_return_val_if_fail (GSD_IS_RR_CONFIG (self), FALSE); return self->priv->clone; } void gsd_rr_config_set_clone (GsdRRConfig *self, gboolean clone) { g_return_if_fail (GSD_IS_RR_CONFIG (self)); self->priv->clone = clone; } /* * CRTC assignment */ typedef struct CrtcInfo CrtcInfo; struct CrtcInfo { GsdRRMode *mode; int x; int y; GsdRRRotation rotation; GPtrArray *outputs; }; struct CrtcAssignment { GsdRRScreen *screen; GHashTable *info; GsdRROutput *primary; }; static gboolean can_clone (CrtcInfo *info, GsdRROutput *output) { int i; for (i = 0; i < info->outputs->len; ++i) { GsdRROutput *clone = info->outputs->pdata[i]; if (!gsd_rr_output_can_clone (clone, output)) return FALSE; } return TRUE; } static gboolean crtc_assignment_assign (CrtcAssignment *assign, GsdRRCrtc *crtc, GsdRRMode *mode, int x, int y, GsdRRRotation rotation, gboolean primary, GsdRROutput *output, GError **error) { CrtcInfo *info = g_hash_table_lookup (assign->info, crtc); guint32 crtc_id; const char *output_name; crtc_id = gsd_rr_crtc_get_id (crtc); output_name = gsd_rr_output_get_name (output); if (!gsd_rr_crtc_can_drive_output (crtc, output)) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_CRTC_ASSIGNMENT, _("CRTC %d cannot drive output %s"), crtc_id, output_name); return FALSE; } if (!gsd_rr_output_supports_mode (output, mode)) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_CRTC_ASSIGNMENT, _("output %s does not support mode %dx%d@%dHz"), output_name, gsd_rr_mode_get_width (mode), gsd_rr_mode_get_height (mode), gsd_rr_mode_get_freq (mode)); return FALSE; } if (!gsd_rr_crtc_supports_rotation (crtc, rotation)) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_CRTC_ASSIGNMENT, _("CRTC %d does not support rotation=%s"), crtc_id, get_rotation_name (rotation)); return FALSE; } if (info) { if (!(info->mode == mode && info->x == x && info->y == y && info->rotation == rotation)) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_CRTC_ASSIGNMENT, _("output %s does not have the same parameters as another cloned output:\n" "existing mode = %d, new mode = %d\n" "existing coordinates = (%d, %d), new coordinates = (%d, %d)\n" "existing rotation = %s, new rotation = %s"), output_name, gsd_rr_mode_get_id (info->mode), gsd_rr_mode_get_id (mode), info->x, info->y, x, y, get_rotation_name (info->rotation), get_rotation_name (rotation)); return FALSE; } if (!can_clone (info, output)) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_CRTC_ASSIGNMENT, _("cannot clone to output %s"), output_name); return FALSE; } g_ptr_array_add (info->outputs, output); if (primary && !assign->primary) { assign->primary = output; } return TRUE; } else { CrtcInfo *info = g_new0 (CrtcInfo, 1); info->mode = mode; info->x = x; info->y = y; info->rotation = rotation; info->outputs = g_ptr_array_new (); g_ptr_array_add (info->outputs, output); g_hash_table_insert (assign->info, crtc, info); if (primary && !assign->primary) { assign->primary = output; } return TRUE; } } static void crtc_assignment_unassign (CrtcAssignment *assign, GsdRRCrtc *crtc, GsdRROutput *output) { CrtcInfo *info = g_hash_table_lookup (assign->info, crtc); if (info) { g_ptr_array_remove (info->outputs, output); if (assign->primary == output) { assign->primary = NULL; } if (info->outputs->len == 0) g_hash_table_remove (assign->info, crtc); } } static void crtc_assignment_free (CrtcAssignment *assign) { g_hash_table_destroy (assign->info); g_free (assign); } typedef struct { guint32 timestamp; gboolean has_error; GError **error; } ConfigureCrtcState; static void configure_crtc (gpointer key, gpointer value, gpointer data) { GsdRRCrtc *crtc = key; CrtcInfo *info = value; ConfigureCrtcState *state = data; if (state->has_error) return; if (!gsd_rr_crtc_set_config_with_time (crtc, state->timestamp, info->x, info->y, info->mode, info->rotation, (GsdRROutput **)info->outputs->pdata, info->outputs->len, state->error)) state->has_error = TRUE; } static gboolean mode_is_rotated (CrtcInfo *info) { if ((info->rotation & GSD_RR_ROTATION_270) || (info->rotation & GSD_RR_ROTATION_90)) { return TRUE; } return FALSE; } static gboolean crtc_is_rotated (GsdRRCrtc *crtc) { GsdRRRotation r = gsd_rr_crtc_get_current_rotation (crtc); if ((r & GSD_RR_ROTATION_270) || (r & GSD_RR_ROTATION_90)) { return TRUE; } return FALSE; } static void accumulate_error (GString *accumulated_error, GError *error) { g_string_append_printf (accumulated_error, " %s\n", error->message); g_error_free (error); } /* Check whether the given set of settings can be used * at the same time -- ie. whether there is an assignment * of CRTC's to outputs. * * Brute force - the number of objects involved is small * enough that it doesn't matter. */ static gboolean real_assign_crtcs (GsdRRScreen *screen, GsdRROutputInfo **outputs, CrtcAssignment *assignment, GError **error) { GsdRRCrtc **crtcs = gsd_rr_screen_list_crtcs (screen); GsdRROutputInfo *output; int i; gboolean tried_mode; GError *my_error; GString *accumulated_error; gboolean success; output = *outputs; if (!output) return TRUE; /* It is always allowed for an output to be turned off */ if (!output->priv->on) { return real_assign_crtcs (screen, outputs + 1, assignment, error); } success = FALSE; tried_mode = FALSE; accumulated_error = g_string_new (NULL); for (i = 0; crtcs[i] != NULL; ++i) { GsdRRCrtc *crtc = crtcs[i]; int crtc_id = gsd_rr_crtc_get_id (crtc); int pass; g_string_append_printf (accumulated_error, _("Trying modes for CRTC %d\n"), crtc_id); /* Make two passes, one where frequencies must match, then * one where they don't have to */ for (pass = 0; pass < 2; ++pass) { GsdRROutput *gsd_rr_output = gsd_rr_screen_get_output_by_name (screen, output->priv->name); GsdRRMode **modes = gsd_rr_output_list_modes (gsd_rr_output); int j; for (j = 0; modes[j] != NULL; ++j) { GsdRRMode *mode = modes[j]; int mode_width; int mode_height; int mode_freq; mode_width = gsd_rr_mode_get_width (mode); mode_height = gsd_rr_mode_get_height (mode); mode_freq = gsd_rr_mode_get_freq (mode); g_string_append_printf (accumulated_error, _("CRTC %d: trying mode %dx%d@%dHz with output at %dx%d@%dHz (pass %d)\n"), crtc_id, mode_width, mode_height, mode_freq, output->priv->width, output->priv->height, output->priv->rate, pass); if (mode_width == output->priv->width && mode_height == output->priv->height && (pass == 1 || mode_freq == output->priv->rate)) { tried_mode = TRUE; my_error = NULL; if (crtc_assignment_assign ( assignment, crtc, modes[j], output->priv->x, output->priv->y, output->priv->rotation, output->priv->primary, gsd_rr_output, &my_error)) { my_error = NULL; if (real_assign_crtcs (screen, outputs + 1, assignment, &my_error)) { success = TRUE; goto out; } else accumulate_error (accumulated_error, my_error); crtc_assignment_unassign (assignment, crtc, gsd_rr_output); } else accumulate_error (accumulated_error, my_error); } } } } out: if (success) g_string_free (accumulated_error, TRUE); else { char *str; str = g_string_free (accumulated_error, FALSE); if (tried_mode) g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_CRTC_ASSIGNMENT, _("could not assign CRTCs to outputs:\n%s"), str); else g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_CRTC_ASSIGNMENT, _("none of the selected modes were compatible with the possible modes:\n%s"), str); g_free (str); } return success; } static void crtc_info_free (CrtcInfo *info) { g_ptr_array_free (info->outputs, TRUE); g_free (info); } static void get_required_virtual_size (CrtcAssignment *assign, int *width, int *height) { GList *active_crtcs = g_hash_table_get_keys (assign->info); GList *list; int d; if (!width) width = &d; if (!height) height = &d; /* Compute size of the screen */ *width = *height = 1; for (list = active_crtcs; list != NULL; list = list->next) { GsdRRCrtc *crtc = list->data; CrtcInfo *info = g_hash_table_lookup (assign->info, crtc); int w, h; w = gsd_rr_mode_get_width (info->mode); h = gsd_rr_mode_get_height (info->mode); if (mode_is_rotated (info)) { int tmp = h; h = w; w = tmp; } *width = MAX (*width, info->x + w); *height = MAX (*height, info->y + h); } g_list_free (active_crtcs); } static gboolean unity_running (void) { const gchar *desktop_environment = g_getenv ("DESKTOP_SESSION"); return !g_strcmp0 (desktop_environment, "ubuntu"); } static gint _max_texture_size_cache = -1; static gint get_max_texture_size (GsdRRScreen *screen) { if (_max_texture_size_cache != -1) { return _max_texture_size_cache; } else { /* * Spawn a second process to check the GL texture limits * We do this across a process boundary to ensure that crashes * in the GL driver (which are unfortunately common) don't take * down the app. */ int pipe_fd[2]; pid_t canary_pid; char * const canary_argv[] = { LIBEXECDIR "/check_gl_texture_size", NULL }; char *canary_env[2]; char display_env[80]; snprintf (display_env, sizeof (display_env), "DISPLAY=%s", DisplayString (screen->priv->xdisplay)); canary_env[0] = display_env; canary_env[1] = NULL; if (pipe (pipe_fd) == -1) { _max_texture_size_cache = 0; return 0; } canary_pid = fork (); if (canary_pid == -1) { _max_texture_size_cache = 0; return 0; } if (canary_pid == 0) { close (pipe_fd[0]); dup2 (pipe_fd[1], 1); close (pipe_fd[1]); execve (canary_argv[0], canary_argv, canary_env); } else { char buffer[10]; gint max_texture_size; int child_status; int num_char; struct timespec fifty_msec = {0, 50000000}; int wait_count = 0; close (pipe_fd[1]); /* Empirical testing suggests this check takes < 150msec on my * crappy Atom netbook with slow rotating HDD. A 500msec timeout * should be generous while not being *too* long if it triggers. * * Do a sleep/poll dance because we're a library and there's no * guarantee that waiting on SIGCHLD won't stomp over a client's * set up. */ while (waitpid (canary_pid, &child_status, WNOHANG) == 0 && wait_count < 10) { g_debug ("Waiting for GL_MAX_TEXTURE_SIZE helper..."); nanosleep (&fifty_msec, NULL); wait_count++; } if (WIFEXITED (child_status) && WEXITSTATUS (child_status) == EXIT_SUCCESS) { if ((num_char = read (pipe_fd[0], buffer, sizeof(buffer) - 1)) <= 0) { g_warning ("Failed to read GL_MAX_TEXTURE_SIZE from helper."); max_texture_size = 0; } else { buffer[num_char] = '\0'; sscanf (buffer, "%u", &max_texture_size); /* * Sanity check the numbers. No hardware I know of has a * GL_MAX_TEXTURE_SIZE smaller than 1024. */ if (max_texture_size < 1024) max_texture_size = 0; } } else { if (wait_count == 10) { g_warning ("Timed out waiting for GL_MAX_TEXTURE_SIZE helper"); /* Ensure we don't leave processes sitting around. Who knows what they're doing? */ kill (canary_pid, SIGTERM); waitpid (canary_pid, &child_status, 0); } else { g_warning ("GL_MAX_TEXTURE_SIZE helper quit unexpectedly"); } max_texture_size = 0; } close (pipe_fd[0]); g_debug ("Found GL_MAX_TEXTURE_SIZE of %u", max_texture_size); _max_texture_size_cache = max_texture_size; return _max_texture_size_cache; } } } static CrtcAssignment * crtc_assignment_new (GsdRRScreen *screen, GsdRROutputInfo **outputs, GError **error) { CrtcAssignment *assignment = g_new0 (CrtcAssignment, 1); assignment->info = g_hash_table_new_full ( g_direct_hash, g_direct_equal, NULL, (GFreeFunc)crtc_info_free); if (real_assign_crtcs (screen, outputs, assignment, error)) { int width, height; int min_width, max_width, min_height, max_height; int max_texture_size; get_required_virtual_size (assignment, &width, &height); gsd_rr_screen_get_ranges ( screen, &min_width, &max_width, &min_height, &max_height); if (width < min_width || width > max_width || height < min_height || height > max_height) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_BOUNDS_ERROR, /* Translators: the "requested", "minimum", and * "maximum" words here are not keywords; please * translate them as usual. */ _("required virtual size does not fit available size: " "requested=(%d, %d), minimum=(%d, %d), maximum=(%d, %d)"), width, height, min_width, min_height, max_width, max_height); goto fail; } /* Hack: * This should either be solved by * (a) Allowing the compositor to veto RandR changes * (b) Fixing the compositor * * Nethier of these are feasible at this point, so just fix Unity. */ if (unity_running ()) { max_texture_size = get_max_texture_size (screen); if (max_texture_size > 0 && (width > max_texture_size || height > max_texture_size)) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_BOUNDS_ERROR, _("Requested size (%d, %d) exceeds 3D hardware limit (%d, %d).\n" "You must either rearrange the displays so that they fit within a (%d, %d) square."), width, height, max_texture_size, max_texture_size, max_texture_size, max_texture_size); goto fail; } } assignment->screen = screen; return assignment; } fail: crtc_assignment_free (assignment); return NULL; } static gboolean crtc_assignment_apply (CrtcAssignment *assign, guint32 timestamp, GError **error) { GsdRRCrtc **all_crtcs = gsd_rr_screen_list_crtcs (assign->screen); int width, height; int i; int min_width, max_width, min_height, max_height; int width_mm, height_mm; gboolean success = TRUE; /* Compute size of the screen */ get_required_virtual_size (assign, &width, &height); gsd_rr_screen_get_ranges ( assign->screen, &min_width, &max_width, &min_height, &max_height); /* We should never get here if the dimensions don't fit in the virtual size, * but just in case we do, fix it up. */ width = MAX (min_width, width); width = MIN (max_width, width); height = MAX (min_height, height); height = MIN (max_height, height); /* FMQ: do we need to check the sizes instead of clamping them? */ /* Grab the server while we fiddle with the CRTCs and the screen, so that * apps that listen for RANDR notifications will only receive the final * status. */ gdk_x11_display_grab (gdk_screen_get_display (assign->screen->priv->gdk_screen)); /* Turn off all crtcs that are currently displaying outside the new screen, * or are not used in the new setup */ for (i = 0; all_crtcs[i] != NULL; ++i) { GsdRRCrtc *crtc = all_crtcs[i]; GsdRRMode *mode = gsd_rr_crtc_get_current_mode (crtc); int x, y; if (mode) { int w, h; gsd_rr_crtc_get_position (crtc, &x, &y); w = gsd_rr_mode_get_width (mode); h = gsd_rr_mode_get_height (mode); if (crtc_is_rotated (crtc)) { int tmp = h; h = w; w = tmp; } if (x + w > width || y + h > height || !g_hash_table_lookup (assign->info, crtc)) { if (!gsd_rr_crtc_set_config_with_time (crtc, timestamp, 0, 0, NULL, GSD_RR_ROTATION_0, NULL, 0, error)) { success = FALSE; break; } } } } /* The 'physical size' of an X screen is meaningless if that screen * can consist of many monitors. So just pick a size that make the * dpi 96. * * Firefox and Evince apparently believe what X tells them. */ width_mm = (width / DPI_FALLBACK) * 25.4 + 0.5; height_mm = (height / DPI_FALLBACK) * 25.4 + 0.5; if (success) { ConfigureCrtcState state; gsd_rr_screen_set_size (assign->screen, width, height, width_mm, height_mm); state.timestamp = timestamp; state.has_error = FALSE; state.error = error; g_hash_table_foreach (assign->info, configure_crtc, &state); success = !state.has_error; } gsd_rr_screen_set_primary_output (assign->screen, assign->primary); gdk_x11_display_ungrab (gdk_screen_get_display (assign->screen->priv->gdk_screen)); return success; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-rr-config.h0000664000175000017500000001446200000000000026063 0ustar00jeremyjeremy/* gnome-rr-config.h * -*- c-basic-offset: 4 -*- * * Copyright 2007, 2008, Red Hat, Inc. * Copyright 2010 Giovanni Campagna * * This file is part of the Gnome Library. * * The Gnome Library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * The Gnome 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with the Gnome Library; see the file COPYING.LIB. If not, * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * Author: Soren Sandmann */ #ifndef GSD_RR_CONFIG_H #define GSD_RR_CONFIG_H #include #include #include "gsd-rr.h" typedef struct _GsdRROutputInfo GsdRROutputInfo; typedef struct _GsdRROutputInfoClass GsdRROutputInfoClass; typedef struct _GsdRROutputInfoPrivate GsdRROutputInfoPrivate; struct _GsdRROutputInfo { GObject parent; /*< private >*/ GsdRROutputInfoPrivate *priv; }; struct _GsdRROutputInfoClass { GObjectClass parent_class; }; #define GSD_TYPE_RR_OUTPUT_INFO (gsd_rr_output_info_get_type()) #define GSD_RR_OUTPUT_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_RR_OUTPUT_INFO, GsdRROutputInfo)) #define GSD_IS_RR_OUTPUT_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_RR_OUTPUT_INFO)) #define GSD_RR_OUTPUT_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_RR_OUTPUT_INFO, GsdRROutputInfoClass)) #define GSD_IS_RR_OUTPUT_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_RR_OUTPUT_INFO)) #define GSD_RR_OUTPUT_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_RR_OUTPUT_INFO, GsdRROutputInfoClass)) GType gsd_rr_output_info_get_type (void); char *gsd_rr_output_info_get_name (GsdRROutputInfo *self); gboolean gsd_rr_output_info_is_active (GsdRROutputInfo *self); void gsd_rr_output_info_set_active (GsdRROutputInfo *self, gboolean active); void gsd_rr_output_info_get_geometry (GsdRROutputInfo *self, int *x, int *y, int *width, int *height); void gsd_rr_output_info_set_geometry (GsdRROutputInfo *self, int x, int y, int width, int height); int gsd_rr_output_info_get_refresh_rate (GsdRROutputInfo *self); void gsd_rr_output_info_set_refresh_rate (GsdRROutputInfo *self, int rate); GsdRRRotation gsd_rr_output_info_get_rotation (GsdRROutputInfo *self); void gsd_rr_output_info_set_rotation (GsdRROutputInfo *self, GsdRRRotation rotation); gboolean gsd_rr_output_info_is_connected (GsdRROutputInfo *self); void gsd_rr_output_info_get_vendor (GsdRROutputInfo *self, gchar* vendor); guint gsd_rr_output_info_get_product (GsdRROutputInfo *self); guint gsd_rr_output_info_get_serial (GsdRROutputInfo *self); double gsd_rr_output_info_get_aspect_ratio (GsdRROutputInfo *self); char *gsd_rr_output_info_get_display_name (GsdRROutputInfo *self); gboolean gsd_rr_output_info_get_primary (GsdRROutputInfo *self); void gsd_rr_output_info_set_primary (GsdRROutputInfo *self, gboolean primary); int gsd_rr_output_info_get_preferred_width (GsdRROutputInfo *self); int gsd_rr_output_info_get_preferred_height (GsdRROutputInfo *self); typedef struct _GsdRRConfig GsdRRConfig; typedef struct _GsdRRConfigClass GsdRRConfigClass; typedef struct _GsdRRConfigPrivate GsdRRConfigPrivate; struct _GsdRRConfig { GObject parent; /*< private >*/ GsdRRConfigPrivate *priv; }; struct _GsdRRConfigClass { GObjectClass parent_class; }; #define GSD_TYPE_RR_CONFIG (gsd_rr_config_get_type()) #define GSD_RR_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_RR_CONFIG, GsdRRConfig)) #define GSD_IS_RR_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_RR_CONFIG)) #define GSD_RR_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_RR_CONFIG, GsdRRConfigClass)) #define GSD_IS_RR_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_RR_CONFIG)) #define GSD_RR_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_RR_CONFIG, GsdRRConfigClass)) GType gsd_rr_config_get_type (void); GsdRRConfig *gsd_rr_config_new_current (GsdRRScreen *screen, GError **error); GsdRRConfig *gsd_rr_config_new_stored (GsdRRScreen *screen, GError **error); gboolean gsd_rr_config_load_current (GsdRRConfig *self, GError **error); gboolean gsd_rr_config_load_filename (GsdRRConfig *self, const gchar *filename, GError **error); gboolean gsd_rr_config_match (GsdRRConfig *config1, GsdRRConfig *config2); gboolean gsd_rr_config_equal (GsdRRConfig *config1, GsdRRConfig *config2); gboolean gsd_rr_config_save (GsdRRConfig *configuration, GError **error); void gsd_rr_config_sanitize (GsdRRConfig *configuration); gboolean gsd_rr_config_ensure_primary (GsdRRConfig *configuration); gboolean gsd_rr_config_apply_with_time (GsdRRConfig *configuration, GsdRRScreen *screen, guint32 timestamp, GError **error); gboolean gsd_rr_config_apply_from_filename_with_time (GsdRRScreen *screen, const char *filename, guint32 timestamp, GError **error); gboolean gsd_rr_config_applicable (GsdRRConfig *configuration, GsdRRScreen *screen, GError **error); gboolean gsd_rr_config_get_clone (GsdRRConfig *configuration); void gsd_rr_config_set_clone (GsdRRConfig *configuration, gboolean clone); GsdRROutputInfo **gsd_rr_config_get_outputs (GsdRRConfig *configuration); char *gsd_rr_config_get_backup_filename (void); char *gsd_rr_config_get_intended_filename (void); #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-rr-output-info.c0000664000175000017500000001417700000000000027105 0ustar00jeremyjeremy/* gnome-rr-output-info.c * -*- c-basic-offset: 4 -*- * * Copyright 2010 Giovanni Campagna * * This file is part of the Gnome Desktop Library. * * The Gnome Desktop Library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * The Gnome 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with the Gnome Desktop Library; see the file COPYING.LIB. If not, * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include "gsd-rr-config.h" #include "edid.h" #include "gsd-rr-private.h" G_DEFINE_TYPE (GsdRROutputInfo, gsd_rr_output_info, G_TYPE_OBJECT) static void gsd_rr_output_info_init (GsdRROutputInfo *self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GSD_TYPE_RR_OUTPUT_INFO, GsdRROutputInfoPrivate); self->priv->name = NULL; self->priv->on = FALSE; self->priv->display_name = NULL; } static void gsd_rr_output_info_finalize (GObject *gobject) { GsdRROutputInfo *self = GSD_RR_OUTPUT_INFO (gobject); g_free (self->priv->name); g_free (self->priv->display_name); G_OBJECT_CLASS (gsd_rr_output_info_parent_class)->finalize (gobject); } static void gsd_rr_output_info_class_init (GsdRROutputInfoClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (GsdRROutputInfoPrivate)); gobject_class->finalize = gsd_rr_output_info_finalize; } /** * gsd_rr_output_info_get_name: * * Returns: (transfer none): the output name */ char *gsd_rr_output_info_get_name (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), NULL); return self->priv->name; } /** * gsd_rr_output_info_is_active: * * Returns: whether there is a CRTC assigned to this output (i.e. a signal is being sent to it) */ gboolean gsd_rr_output_info_is_active (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), FALSE); return self->priv->on; } void gsd_rr_output_info_set_active (GsdRROutputInfo *self, gboolean active) { g_return_if_fail (GSD_IS_RR_OUTPUT_INFO (self)); self->priv->on = active; } /** * gsd_rr_output_info_get_geometry: * @self: a #GsdRROutputInfo * @x: (out) (allow-none): * @y: (out) (allow-none): * @width: (out) (allow-none): * @height: (out) (allow-none): */ void gsd_rr_output_info_get_geometry (GsdRROutputInfo *self, int *x, int *y, int *width, int *height) { g_return_if_fail (GSD_IS_RR_OUTPUT_INFO (self)); if (x) *x = self->priv->x; if (y) *y = self->priv->y; if (width) *width = self->priv->width; if (height) *height = self->priv->height; } void gsd_rr_output_info_set_geometry (GsdRROutputInfo *self, int x, int y, int width, int height) { g_return_if_fail (GSD_IS_RR_OUTPUT_INFO (self)); self->priv->x = x; self->priv->y = y; self->priv->width = width; self->priv->height = height; } int gsd_rr_output_info_get_refresh_rate (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), 0); return self->priv->rate; } void gsd_rr_output_info_set_refresh_rate (GsdRROutputInfo *self, int rate) { g_return_if_fail (GSD_IS_RR_OUTPUT_INFO (self)); self->priv->rate = rate; } GsdRRRotation gsd_rr_output_info_get_rotation (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), GSD_RR_ROTATION_0); return self->priv->rotation; } void gsd_rr_output_info_set_rotation (GsdRROutputInfo *self, GsdRRRotation rotation) { g_return_if_fail (GSD_IS_RR_OUTPUT_INFO (self)); self->priv->rotation = rotation; } /** * gsd_rr_output_info_is_connected: * * Returns: whether the output is physically connected to a monitor */ gboolean gsd_rr_output_info_is_connected (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), FALSE); return self->priv->connected; } /** * gsd_rr_output_info_get_vendor: * @self: a #GsdRROutputInfo * @vendor: (out caller-allocates) (array fixed-size=4): */ void gsd_rr_output_info_get_vendor (GsdRROutputInfo *self, gchar* vendor) { g_return_if_fail (GSD_IS_RR_OUTPUT_INFO (self)); g_return_if_fail (vendor != NULL); vendor[0] = self->priv->vendor[0]; vendor[1] = self->priv->vendor[1]; vendor[2] = self->priv->vendor[2]; vendor[3] = self->priv->vendor[3]; } guint gsd_rr_output_info_get_product (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), 0); return self->priv->product; } guint gsd_rr_output_info_get_serial (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), 0); return self->priv->serial; } double gsd_rr_output_info_get_aspect_ratio (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), 0); return self->priv->aspect; } /** * gsd_rr_output_info_get_display_name: * * Returns: (transfer none): the display name of this output */ char *gsd_rr_output_info_get_display_name (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), NULL); return self->priv->display_name; } gboolean gsd_rr_output_info_get_primary (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), FALSE); return self->priv->primary; } void gsd_rr_output_info_set_primary (GsdRROutputInfo *self, gboolean primary) { g_return_if_fail (GSD_IS_RR_OUTPUT_INFO (self)); self->priv->primary = primary; } int gsd_rr_output_info_get_preferred_width (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), 0); return self->priv->pref_width; } int gsd_rr_output_info_get_preferred_height (GsdRROutputInfo *self) { g_return_val_if_fail (GSD_IS_RR_OUTPUT_INFO (self), 0); return self->priv->pref_height; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-rr-private.h0000664000175000017500000000260400000000000026263 0ustar00jeremyjeremy#ifndef GSD_RR_PRIVATE_H #define GSD_RR_PRIVATE_H #include #include typedef struct ScreenInfo ScreenInfo; struct ScreenInfo { int min_width; int max_width; int min_height; int max_height; XRRScreenResources *resources; GsdRROutput ** outputs; GsdRRCrtc ** crtcs; GsdRRMode ** modes; GsdRRScreen * screen; GsdRRMode ** clone_modes; RROutput primary; }; struct GsdRRScreenPrivate { GdkScreen * gdk_screen; GdkWindow * gdk_root; Display * xdisplay; Screen * xscreen; Window xroot; ScreenInfo * info; int randr_event_base; int rr_major_version; int rr_minor_version; Atom connector_type_atom; gboolean dpms_capable; }; struct _GsdRROutputInfoPrivate { char * name; gboolean on; int width; int height; int rate; int x; int y; GsdRRRotation rotation; gboolean connected; gchar vendor[4]; guint product; guint serial; double aspect; int pref_width; int pref_height; char * display_name; gboolean primary; }; struct _GsdRRConfigPrivate { gboolean clone; GsdRRScreen *screen; GsdRROutputInfo **outputs; }; gboolean _gsd_rr_output_name_is_laptop (const char *name); #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-rr.c0000664000175000017500000020434400000000000024613 0ustar00jeremyjeremy/* gnome-rr.c * * Copyright 2007, 2008, Red Hat, Inc. * * This file is part of the Gnome Library. * * The Gnome Library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * The Gnome 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with the Gnome Library; see the file COPYING.LIB. If not, * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * Author: Soren Sandmann */ #include #include #include #include #include #include #include #include #include #undef GNOME_DISABLE_DEPRECATED #include "gsd-rr.h" #include "gsd-rr-config.h" #include "edid.h" #include "gsd-rr-private.h" #define DISPLAY(o) ((o)->info->screen->priv->xdisplay) #define SERVERS_RANDR_IS_AT_LEAST_1_3(priv) (priv->rr_major_version > 1 || (priv->rr_major_version == 1 && priv->rr_minor_version >= 3)) enum { SCREEN_PROP_0, SCREEN_PROP_GDK_SCREEN, SCREEN_PROP_LAST, }; enum { SCREEN_CHANGED, SCREEN_OUTPUT_CONNECTED, SCREEN_OUTPUT_DISCONNECTED, SCREEN_SIGNAL_LAST, }; gint screen_signals[SCREEN_SIGNAL_LAST]; struct GsdRROutput { ScreenInfo * info; RROutput id; char * name; char * display_name; GsdRRCrtc * current_crtc; gboolean connected; gulong width_mm; gulong height_mm; GsdRRCrtc ** possible_crtcs; GsdRROutput ** clones; GsdRRMode ** modes; int n_preferred; guint8 * edid_data; gsize edid_size; char * connector_type; gint backlight_min; gint backlight_max; }; struct GsdRROutputWrap { RROutput id; }; struct GsdRRCrtc { ScreenInfo * info; RRCrtc id; GsdRRMode * current_mode; GsdRROutput ** current_outputs; GsdRROutput ** possible_outputs; int x; int y; GsdRRRotation current_rotation; GsdRRRotation rotations; int gamma_size; }; struct GsdRRMode { ScreenInfo * info; RRMode id; char * name; int width; int height; int freq; /* in mHz */ }; /* GsdRRCrtc */ static GsdRRCrtc * crtc_new (ScreenInfo *info, RRCrtc id); static GsdRRCrtc * crtc_copy (const GsdRRCrtc *from); static void crtc_free (GsdRRCrtc *crtc); static gboolean crtc_initialize (GsdRRCrtc *crtc, XRRScreenResources *res, GError **error); /* GsdRROutput */ static GsdRROutput *output_new (ScreenInfo *info, RROutput id); static gboolean output_initialize (GsdRROutput *output, XRRScreenResources *res, GError **error); static gboolean output_initialize_clones (GsdRROutput *output, XRRScreenResources *res, GError **error); static GsdRROutput *output_copy (const GsdRROutput *from); static void output_free (GsdRROutput *output); /* GsdRRMode */ static GsdRRMode * mode_new (ScreenInfo *info, RRMode id); static void mode_initialize (GsdRRMode *mode, XRRModeInfo *info); static GsdRRMode * mode_copy (const GsdRRMode *from); static void mode_free (GsdRRMode *mode); static void gsd_rr_screen_finalize (GObject*); static void gsd_rr_screen_set_property (GObject*, guint, const GValue*, GParamSpec*); static void gsd_rr_screen_get_property (GObject*, guint, GValue*, GParamSpec*); static gboolean gsd_rr_screen_initable_init (GInitable*, GCancellable*, GError**); static void gsd_rr_screen_initable_iface_init (GInitableIface *iface); G_DEFINE_TYPE_WITH_CODE (GsdRRScreen, gsd_rr_screen, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, gsd_rr_screen_initable_iface_init)) G_DEFINE_BOXED_TYPE (GsdRRCrtc, gsd_rr_crtc, crtc_copy, crtc_free) G_DEFINE_BOXED_TYPE (GsdRROutput, gsd_rr_output, output_copy, output_free) G_DEFINE_BOXED_TYPE (GsdRRMode, gsd_rr_mode, mode_copy, mode_free) /* Errors */ /** * gsd_rr_error_quark: * * Returns the #GQuark that will be used for #GError values returned by the * GsdRR API. * * Return value: a #GQuark used to identify errors coming from the GsdRR API. */ GQuark gsd_rr_error_quark (void) { return g_quark_from_static_string ("gsd-rr-error-quark"); } /* Screen */ static GsdRROutput * gsd_rr_output_by_id (ScreenInfo *info, RROutput id) { GsdRROutput **output; g_assert (info != NULL); for (output = info->outputs; *output; ++output) { if ((*output)->id == id) return *output; } return NULL; } static GsdRRCrtc * crtc_by_id (ScreenInfo *info, RRCrtc id) { GsdRRCrtc **crtc; if (!info) return NULL; for (crtc = info->crtcs; *crtc; ++crtc) { if ((*crtc)->id == id) return *crtc; } return NULL; } static GsdRRMode * mode_by_id (ScreenInfo *info, RRMode id) { GsdRRMode **mode; g_assert (info != NULL); for (mode = info->modes; *mode; ++mode) { if ((*mode)->id == id) return *mode; } return NULL; } static void screen_info_free (ScreenInfo *info) { GsdRROutput **output; GsdRRCrtc **crtc; GsdRRMode **mode; g_assert (info != NULL); if (info->resources) { XRRFreeScreenResources (info->resources); info->resources = NULL; } if (info->outputs) { for (output = info->outputs; *output; ++output) output_free (*output); g_free (info->outputs); } if (info->crtcs) { for (crtc = info->crtcs; *crtc; ++crtc) crtc_free (*crtc); g_free (info->crtcs); } if (info->modes) { for (mode = info->modes; *mode; ++mode) mode_free (*mode); g_free (info->modes); } if (info->clone_modes) { /* The modes themselves were freed above */ g_free (info->clone_modes); } g_free (info); } static gboolean has_similar_mode (GsdRROutput *output, GsdRRMode *mode) { int i; GsdRRMode **modes = gsd_rr_output_list_modes (output); int width = gsd_rr_mode_get_width (mode); int height = gsd_rr_mode_get_height (mode); for (i = 0; modes[i] != NULL; ++i) { GsdRRMode *m = modes[i]; if (gsd_rr_mode_get_width (m) == width && gsd_rr_mode_get_height (m) == height) { return TRUE; } } return FALSE; } static void gather_clone_modes (ScreenInfo *info) { int i; GPtrArray *result = g_ptr_array_new (); for (i = 0; info->outputs[i] != NULL; ++i) { int j; GsdRROutput *output1, *output2; output1 = info->outputs[i]; if (!output1->connected) continue; for (j = 0; output1->modes[j] != NULL; ++j) { GsdRRMode *mode = output1->modes[j]; gboolean valid; int k; valid = TRUE; for (k = 0; info->outputs[k] != NULL; ++k) { output2 = info->outputs[k]; if (!output2->connected) continue; if (!has_similar_mode (output2, mode)) { valid = FALSE; break; } } if (valid) g_ptr_array_add (result, mode); } } g_ptr_array_add (result, NULL); info->clone_modes = (GsdRRMode **)g_ptr_array_free (result, FALSE); } static gboolean fill_screen_info_from_resources (ScreenInfo *info, XRRScreenResources *resources, GError **error) { int i; GPtrArray *a; GsdRRCrtc **crtc; GsdRROutput **output; info->resources = resources; /* We create all the structures before initializing them, so * that they can refer to each other. */ a = g_ptr_array_new (); for (i = 0; i < resources->ncrtc; ++i) { GsdRRCrtc *crtc = crtc_new (info, resources->crtcs[i]); g_ptr_array_add (a, crtc); } g_ptr_array_add (a, NULL); info->crtcs = (GsdRRCrtc **)g_ptr_array_free (a, FALSE); a = g_ptr_array_new (); for (i = 0; i < resources->nmode; ++i) { GsdRRMode *mode = mode_new (info, resources->modes[i].id); g_ptr_array_add (a, mode); } g_ptr_array_add (a, NULL); info->modes = (GsdRRMode **)g_ptr_array_free (a, FALSE); /* We create and partially initialize the outputs in one pass to make it * easier to filter out ones that don't have any valid modes or CRTCs */ a = g_ptr_array_new (); for (i = 0; i < resources->noutput; ++i) { GsdRROutput *output = output_new (info, resources->outputs[i]); if (!output_initialize (output, resources, error)) { output_free(output); g_ptr_array_foreach (a, (GFunc) output_free, NULL); g_ptr_array_free (a, FALSE); return FALSE; } if (!output->possible_crtcs[0] || !output->modes[0]) { output_free(output); continue; } g_ptr_array_add (a, output); } g_ptr_array_add (a, NULL); info->outputs = (GsdRROutput **)g_ptr_array_free (a, FALSE); /* Initialize everything else */ for (crtc = info->crtcs; *crtc; ++crtc) { if (!crtc_initialize (*crtc, resources, error)) return FALSE; } for (output = info->outputs; *output; ++output) { if (!output_initialize_clones (*output, resources, error)) return FALSE; } for (i = 0; i < resources->nmode; ++i) { GsdRRMode *mode = mode_by_id (info, resources->modes[i].id); mode_initialize (mode, &(resources->modes[i])); } gather_clone_modes (info); return TRUE; } static gboolean fill_out_screen_info (Display *xdisplay, Window xroot, ScreenInfo *info, gboolean needs_reprobe, GError **error) { XRRScreenResources *resources; GsdRRScreenPrivate *priv; g_assert (xdisplay != NULL); g_assert (info != NULL); priv = info->screen->priv; /* First update the screen resources */ if (needs_reprobe) resources = XRRGetScreenResources (xdisplay, xroot); else { /* XRRGetScreenResourcesCurrent is less expensive than * XRRGetScreenResources, however it is available only * in RandR 1.3 or higher */ if (SERVERS_RANDR_IS_AT_LEAST_1_3 (priv)) resources = XRRGetScreenResourcesCurrent (xdisplay, xroot); else resources = XRRGetScreenResources (xdisplay, xroot); } if (resources) { if (!fill_screen_info_from_resources (info, resources, error)) return FALSE; } else { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_RANDR_ERROR, /* Translators: a CRTC is a CRT Controller (this is X terminology). */ _("could not get the screen resources (CRTCs, outputs, modes)")); return FALSE; } /* Then update the screen size range. We do this after XRRGetScreenResources() so that * the X server will already have an updated view of the outputs. */ if (needs_reprobe) { gboolean success; gdk_error_trap_push (); success = XRRGetScreenSizeRange (xdisplay, xroot, &(info->min_width), &(info->min_height), &(info->max_width), &(info->max_height)); gdk_flush (); if (gdk_error_trap_pop ()) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_UNKNOWN, _("unhandled X error while getting the range of screen sizes")); return FALSE; } if (!success) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_RANDR_ERROR, _("could not get the range of screen sizes")); return FALSE; } } else { gsd_rr_screen_get_ranges (info->screen, &(info->min_width), &(info->max_width), &(info->min_height), &(info->max_height)); } info->primary = None; if (SERVERS_RANDR_IS_AT_LEAST_1_3 (priv)) { gdk_error_trap_push (); info->primary = XRRGetOutputPrimary (xdisplay, xroot); gdk_error_trap_pop_ignored (); } /* can the screen do DPMS? */ gdk_error_trap_push (); priv->dpms_capable = DPMSCapable (priv->xdisplay); gdk_error_trap_pop_ignored (); return TRUE; } static ScreenInfo * screen_info_new (GsdRRScreen *screen, gboolean needs_reprobe, GError **error) { ScreenInfo *info = g_new0 (ScreenInfo, 1); GsdRRScreenPrivate *priv; g_assert (screen != NULL); priv = screen->priv; info->outputs = NULL; info->crtcs = NULL; info->modes = NULL; info->screen = screen; if (fill_out_screen_info (priv->xdisplay, priv->xroot, info, needs_reprobe, error)) { return info; } else { screen_info_free (info); return NULL; } } static GsdRROutput * find_output_by_id (GsdRROutput **haystack, guint32 id) { guint i; for (i = 0; haystack[i] != NULL; i++) { if (gsd_rr_output_get_id (haystack[i]) == id) return haystack[i]; } return NULL; } static void diff_outputs_and_emit_signals (ScreenInfo *old, ScreenInfo *new) { guint i; guint32 id_old, id_new; GsdRROutput *output_old; GsdRROutput *output_new; /* have any outputs been removed or disconnected */ for (i = 0; old->outputs[i] != NULL; i++) { id_old = gsd_rr_output_get_id (old->outputs[i]); output_new = find_output_by_id (new->outputs, id_old); if (output_new == NULL) { /* output removed (and disconnected) */ if (gsd_rr_output_is_connected (old->outputs[i])) { g_signal_emit (G_OBJECT (new->screen), screen_signals[SCREEN_OUTPUT_DISCONNECTED], 0, old->outputs[i]); } continue; } if (gsd_rr_output_is_connected (old->outputs[i]) && !gsd_rr_output_is_connected (output_new)) { /* output disconnected */ g_signal_emit (G_OBJECT (new->screen), screen_signals[SCREEN_OUTPUT_DISCONNECTED], 0, old->outputs[i]); } } /* have any outputs been created or connected */ for (i = 0; new->outputs[i] != NULL; i++) { id_new = gsd_rr_output_get_id (new->outputs[i]); output_old = find_output_by_id (old->outputs, id_new); if (output_old == NULL) { /* output created */ if (gsd_rr_output_is_connected (new->outputs[i])) { g_signal_emit (G_OBJECT (new->screen), screen_signals[SCREEN_OUTPUT_CONNECTED], 0, new->outputs[i]); } continue; } if (!gsd_rr_output_is_connected (output_old) && gsd_rr_output_is_connected (new->outputs[i])) { /* output connected */ g_signal_emit (G_OBJECT (new->screen), screen_signals[SCREEN_OUTPUT_CONNECTED], 0, new->outputs[i]); } } } static gboolean screen_update (GsdRRScreen *screen, gboolean force_callback, gboolean needs_reprobe, GError **error) { ScreenInfo *info; gboolean changed = FALSE; g_assert (screen != NULL); info = screen_info_new (screen, needs_reprobe, error); if (!info) return FALSE; if (info->resources->configTimestamp != screen->priv->info->resources->configTimestamp) changed = TRUE; /* work out if any outputs have changed connected state */ diff_outputs_and_emit_signals (screen->priv->info, info); screen_info_free (screen->priv->info); screen->priv->info = info; if (changed || force_callback) g_signal_emit (G_OBJECT (screen), screen_signals[SCREEN_CHANGED], 0); return changed; } static GdkFilterReturn screen_on_event (GdkXEvent *xevent, GdkEvent *event, gpointer data) { GsdRRScreen *screen = data; GsdRRScreenPrivate *priv = screen->priv; XEvent *e = xevent; int event_num; if (!e) return GDK_FILTER_CONTINUE; event_num = e->type - priv->randr_event_base; if (event_num == RRScreenChangeNotify) { /* We don't reprobe the hardware; we just fetch the X server's latest * state. The server already knows the new state of the outputs; that's * why it sent us an event! */ screen_update (screen, TRUE, FALSE, NULL); /* NULL-GError */ #if 0 /* Enable this code to get a dialog showing the RANDR timestamps, for debugging purposes */ { GtkWidget *dialog; XRRScreenChangeNotifyEvent *rr_event; static int dialog_num; rr_event = (XRRScreenChangeNotifyEvent *) e; dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "RRScreenChangeNotify timestamps (%d):\n" "event change: %u\n" "event config: %u\n" "event serial: %lu\n" "----------------------" "screen change: %u\n" "screen config: %u\n", dialog_num++, (guint32) rr_event->timestamp, (guint32) rr_event->config_timestamp, rr_event->serial, (guint32) priv->info->resources->timestamp, (guint32) priv->info->resources->configTimestamp); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_widget_show (dialog); } #endif } #if 0 /* WHY THIS CODE IS DISABLED: * * Note that in gsd_rr_screen_new(), we only select for * RRScreenChangeNotifyMask. We used to select for other values in * RR*NotifyMask, but we weren't really doing anything useful with those * events. We only care about "the screens changed in some way or another" * for now. * * If we ever run into a situtation that could benefit from processing more * detailed events, we can enable this code again. * * Note that the X server sends RRScreenChangeNotify in conjunction with the * more detailed events from RANDR 1.2 - see xserver/randr/randr.c:TellChanged(). */ else if (event_num == RRNotify) { /* Other RandR events */ XRRNotifyEvent *event = (XRRNotifyEvent *)e; /* Here we can distinguish between RRNotify events supported * since RandR 1.2 such as RRNotify_OutputProperty. For now, we * don't have anything special to do for particular subevent types, so * we leave this as an empty switch(). */ switch (event->subtype) { default: break; } /* No need to reprobe hardware here */ screen_update (screen, TRUE, FALSE, NULL); /* NULL-GError */ } #endif /* Pass the event on to GTK+ */ return GDK_FILTER_CONTINUE; } static gboolean gsd_rr_screen_initable_init (GInitable *initable, GCancellable *canc, GError **error) { GsdRRScreen *self = GSD_RR_SCREEN (initable); GsdRRScreenPrivate *priv = self->priv; Display *dpy = GDK_SCREEN_XDISPLAY (self->priv->gdk_screen); int event_base; int ignore; priv->connector_type_atom = XInternAtom (dpy, "ConnectorType", FALSE); if (XRRQueryExtension (dpy, &event_base, &ignore)) { priv->randr_event_base = event_base; XRRQueryVersion (dpy, &priv->rr_major_version, &priv->rr_minor_version); if (priv->rr_major_version < 1 || (priv->rr_major_version == 1 && priv->rr_minor_version < 2)) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_NO_RANDR_EXTENSION, "RANDR extension is too old (must be at least 1.2)"); return FALSE; } priv->info = screen_info_new (self, TRUE, error); if (!priv->info) { return FALSE; } XRRSelectInput (priv->xdisplay, priv->xroot, RRScreenChangeNotifyMask); gdk_x11_register_standard_event_type (gdk_screen_get_display (priv->gdk_screen), event_base, RRNotify + 1); gdk_window_add_filter (priv->gdk_root, screen_on_event, self); return TRUE; } else { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_NO_RANDR_EXTENSION, _("RANDR extension is not present")); return FALSE; } } void gsd_rr_screen_initable_iface_init (GInitableIface *iface) { iface->init = gsd_rr_screen_initable_init; } void gsd_rr_screen_finalize (GObject *gobject) { GsdRRScreen *screen = GSD_RR_SCREEN (gobject); gdk_window_remove_filter (screen->priv->gdk_root, screen_on_event, screen); if (screen->priv->info) screen_info_free (screen->priv->info); G_OBJECT_CLASS (gsd_rr_screen_parent_class)->finalize (gobject); } void gsd_rr_screen_set_property (GObject *gobject, guint property_id, const GValue *value, GParamSpec *property) { GsdRRScreen *self = GSD_RR_SCREEN (gobject); GsdRRScreenPrivate *priv = self->priv; switch (property_id) { case SCREEN_PROP_GDK_SCREEN: priv->gdk_screen = g_value_get_object (value); priv->gdk_root = gdk_screen_get_root_window (priv->gdk_screen); priv->xroot = gdk_x11_window_get_xid (priv->gdk_root); priv->xdisplay = GDK_SCREEN_XDISPLAY (priv->gdk_screen); priv->xscreen = gdk_x11_screen_get_xscreen (priv->gdk_screen); return; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, property); return; } } void gsd_rr_screen_get_property (GObject *gobject, guint property_id, GValue *value, GParamSpec *property) { GsdRRScreen *self = GSD_RR_SCREEN (gobject); GsdRRScreenPrivate *priv = self->priv; switch (property_id) { case SCREEN_PROP_GDK_SCREEN: g_value_set_object (value, priv->gdk_screen); return; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, property); return; } } void gsd_rr_screen_class_init (GsdRRScreenClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (GsdRRScreenPrivate)); bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); gobject_class->set_property = gsd_rr_screen_set_property; gobject_class->get_property = gsd_rr_screen_get_property; gobject_class->finalize = gsd_rr_screen_finalize; g_object_class_install_property( gobject_class, SCREEN_PROP_GDK_SCREEN, g_param_spec_object ( "gdk-screen", "GDK Screen", "The GDK Screen represented by this GsdRRScreen", GDK_TYPE_SCREEN, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS) ); screen_signals[SCREEN_CHANGED] = g_signal_new("changed", G_TYPE_FROM_CLASS (gobject_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, G_STRUCT_OFFSET (GsdRRScreenClass, changed), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); /** * GsdRRScreen::output-connected: * @screen: the #GsdRRScreen that emitted the signal * @output: the #GsdRROutput that was connected * * This signal is emitted when a display device is connected to a * port, or a port is hotplugged with an active output. The latter * can happen if a laptop is docked, and the dock provides a new * active output. * * The @output value is not a #GObject. The returned @output value can * only assume to be valid during the emission of the signal (i.e. within * your signal handler only), as it may change later when the @screen * is modified due to an event from the X server, or due to another * place in the application modifying the @screen and the @output. * Therefore, deal with changes to the @output right in your signal * handler, instead of keeping the @output reference for an async or * idle function. **/ screen_signals[SCREEN_OUTPUT_CONNECTED] = g_signal_new("output-connected", G_TYPE_FROM_CLASS (gobject_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, G_STRUCT_OFFSET (GsdRRScreenClass, output_connected), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); /** * GsdRRScreen::output-disconnected: * @screen: the #GsdRRScreen that emitted the signal * @output: the #GsdRROutput that was disconnected * * This signal is emitted when a display device is disconnected from * a port, or a port output is hot-unplugged. The latter can happen * if a laptop is undocked, and the dock provided the output. * * The @output value is not a #GObject. The returned @output value can * only assume to be valid during the emission of the signal (i.e. within * your signal handler only), as it may change later when the @screen * is modified due to an event from the X server, or due to another * place in the application modifying the @screen and the @output. * Therefore, deal with changes to the @output right in your signal * handler, instead of keeping the @output reference for an async or * idle function. **/ screen_signals[SCREEN_OUTPUT_DISCONNECTED] = g_signal_new("output-disconnected", G_TYPE_FROM_CLASS (gobject_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, G_STRUCT_OFFSET (GsdRRScreenClass, output_disconnected), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); } void gsd_rr_screen_init (GsdRRScreen *self) { GsdRRScreenPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GSD_TYPE_RR_SCREEN, GsdRRScreenPrivate); self->priv = priv; priv->gdk_screen = NULL; priv->gdk_root = NULL; priv->xdisplay = NULL; priv->xroot = None; priv->xscreen = NULL; priv->info = NULL; priv->rr_major_version = 0; priv->rr_minor_version = 0; } /* Weak reference callback set in gsd_rr_screen_new(); we remove the GObject data from the GdkScreen. */ static void rr_screen_weak_notify_cb (gpointer data, GObject *where_the_object_was) { GdkScreen *screen = GDK_SCREEN (data); g_object_set_data (G_OBJECT (screen), "GsdRRScreen", NULL); } /** * gsd_rr_screen_new: * @screen: the #GdkScreen on which to operate * @error: will be set if XRandR is not supported * * Creates a unique #GsdRRScreen instance for the specified @screen. * * Returns: a unique #GsdRRScreen instance, specific to the @screen, or NULL * if this could not be created, for instance if the driver does not support * Xrandr 1.2. Each #GdkScreen thus has a single instance of #GsdRRScreen. */ GsdRRScreen * gsd_rr_screen_new (GdkScreen *screen, GError **error) { GsdRRScreen *rr_screen; g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); rr_screen = g_object_get_data (G_OBJECT (screen), "GsdRRScreen"); if (rr_screen) g_object_ref (rr_screen); else { rr_screen = g_initable_new (GSD_TYPE_RR_SCREEN, NULL, error, "gdk-screen", screen, NULL); if (rr_screen) { g_object_set_data (G_OBJECT (screen), "GsdRRScreen", rr_screen); g_object_weak_ref (G_OBJECT (rr_screen), rr_screen_weak_notify_cb, screen); } } return rr_screen; } void gsd_rr_screen_set_size (GsdRRScreen *screen, int width, int height, int mm_width, int mm_height) { g_return_if_fail (GSD_IS_RR_SCREEN (screen)); gdk_error_trap_push (); XRRSetScreenSize (screen->priv->xdisplay, screen->priv->xroot, width, height, mm_width, mm_height); gdk_error_trap_pop_ignored (); } /** * gsd_rr_screen_get_ranges: * @screen: a #GsdRRScreen * @min_width: (out): the minimum width * @max_width: (out): the maximum width * @min_height: (out): the minimum height * @max_height: (out): the maximum height * * Get the ranges of the screen */ void gsd_rr_screen_get_ranges (GsdRRScreen *screen, int *min_width, int *max_width, int *min_height, int *max_height) { GsdRRScreenPrivate *priv; g_return_if_fail (GSD_IS_RR_SCREEN (screen)); priv = screen->priv; if (min_width) *min_width = priv->info->min_width; if (max_width) *max_width = priv->info->max_width; if (min_height) *min_height = priv->info->min_height; if (max_height) *max_height = priv->info->max_height; } /** * gsd_rr_screen_get_timestamps: * @screen: a #GsdRRScreen * @change_timestamp_ret: (out): Location in which to store the timestamp at which the RANDR configuration was last changed * @config_timestamp_ret: (out): Location in which to store the timestamp at which the RANDR configuration was last obtained * * Queries the two timestamps that the X RANDR extension maintains. The X * server will prevent change requests for stale configurations, those whose * timestamp is not equal to that of the latest request for configuration. The * X server will also prevent change requests that have an older timestamp to * the latest change request. */ void gsd_rr_screen_get_timestamps (GsdRRScreen *screen, guint32 *change_timestamp_ret, guint32 *config_timestamp_ret) { GsdRRScreenPrivate *priv; g_return_if_fail (GSD_IS_RR_SCREEN (screen)); priv = screen->priv; if (change_timestamp_ret) *change_timestamp_ret = priv->info->resources->timestamp; if (config_timestamp_ret) *config_timestamp_ret = priv->info->resources->configTimestamp; } static gboolean force_timestamp_update (GsdRRScreen *screen) { GsdRRScreenPrivate *priv = screen->priv; GsdRRCrtc *crtc; XRRCrtcInfo *current_info; Status status; gboolean timestamp_updated; timestamp_updated = FALSE; crtc = priv->info->crtcs[0]; if (crtc == NULL) goto out; current_info = XRRGetCrtcInfo (priv->xdisplay, priv->info->resources, crtc->id); if (current_info == NULL) goto out; gdk_error_trap_push (); status = XRRSetCrtcConfig (priv->xdisplay, priv->info->resources, crtc->id, current_info->timestamp, current_info->x, current_info->y, current_info->mode, current_info->rotation, current_info->outputs, current_info->noutput); XRRFreeCrtcInfo (current_info); gdk_flush (); if (gdk_error_trap_pop ()) goto out; if (status == RRSetConfigSuccess) timestamp_updated = TRUE; out: return timestamp_updated; } /** * gsd_rr_screen_refresh: * @screen: a #GsdRRScreen * @error: location to store error, or %NULL * * Refreshes the screen configuration, and calls the screen's callback if it * exists and if the screen's configuration changed. * * Return value: TRUE if the screen's configuration changed; otherwise, the * function returns FALSE and a NULL error if the configuration didn't change, * or FALSE and a non-NULL error if there was an error while refreshing the * configuration. */ gboolean gsd_rr_screen_refresh (GsdRRScreen *screen, GError **error) { gboolean refreshed; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); gdk_x11_display_grab (gdk_screen_get_display (screen->priv->gdk_screen)); refreshed = screen_update (screen, FALSE, TRUE, error); force_timestamp_update (screen); /* this is to keep other clients from thinking that the X server re-detected things by itself - bgo#621046 */ gdk_x11_display_ungrab (gdk_screen_get_display (screen->priv->gdk_screen)); return refreshed; } /** * gsd_rr_screen_get_dpms_mode: * @mode: (out): The current #GsdRRDpmsMode of this screen **/ gboolean gsd_rr_screen_get_dpms_mode (GsdRRScreen *screen, GsdRRDpmsMode *mode, GError **error) { BOOL enabled = FALSE; CARD16 state; gboolean ret = FALSE; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (mode != NULL, FALSE); if (!screen->priv->dpms_capable) { g_set_error_literal (error, GSD_RR_ERROR, GSD_RR_ERROR_NO_DPMS_EXTENSION, "Display is not DPMS capable"); goto out; } if (!DPMSInfo (screen->priv->xdisplay, &state, &enabled)) { g_set_error_literal (error, GSD_RR_ERROR, GSD_RR_ERROR_UNKNOWN, "Unable to get DPMS state"); goto out; } /* DPMS not enabled is a valid mode */ if (!enabled) { *mode = GSD_RR_DPMS_DISABLED; ret = TRUE; goto out; } switch (state) { case DPMSModeOn: *mode = GSD_RR_DPMS_ON; break; case DPMSModeStandby: *mode = GSD_RR_DPMS_STANDBY; break; case DPMSModeSuspend: *mode = GSD_RR_DPMS_SUSPEND; break; case DPMSModeOff: *mode = GSD_RR_DPMS_OFF; break; default: g_assert_not_reached (); break; } ret = TRUE; out: return ret; } /** * gsd_rr_screen_clear_dpms_timeouts: **/ static gboolean gsd_rr_screen_clear_dpms_timeouts (GsdRRScreen *screen, GError **error) { gdk_error_trap_push (); /* DPMSSetTimeouts() return value is often a lie, so ignore it */ DPMSSetTimeouts (screen->priv->xdisplay, 0, 0, 0); if (gdk_error_trap_pop ()) { g_set_error_literal (error, GSD_RR_ERROR, GSD_RR_ERROR_UNKNOWN, "Could not set DPMS timeouts"); return FALSE; } return TRUE; } /** * gsd_rr_screen_set_dpms_mode: * * This method also disables the DPMS timeouts. **/ gboolean gsd_rr_screen_set_dpms_mode (GsdRRScreen *screen, GsdRRDpmsMode mode, GError **error) { CARD16 state = 0; gboolean ret; GsdRRDpmsMode current_mode; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); /* set, if the new mode is different */ ret = gsd_rr_screen_get_dpms_mode (screen, ¤t_mode, error); if (!ret) goto out; if (current_mode == mode) { ret = gsd_rr_screen_clear_dpms_timeouts (screen, error); goto out; } switch (mode) { case GSD_RR_DPMS_ON: state = DPMSModeOn; break; case GSD_RR_DPMS_STANDBY: state = DPMSModeStandby; break; case GSD_RR_DPMS_SUSPEND: state = DPMSModeSuspend; break; case GSD_RR_DPMS_OFF: state = DPMSModeOff; break; default: g_assert_not_reached (); break; } gdk_error_trap_push (); /* DPMSForceLevel() return value is often a lie, so ignore it */ DPMSForceLevel (screen->priv->xdisplay, state); XSync (screen->priv->xdisplay, False); if (gdk_error_trap_pop ()) { ret = FALSE; g_set_error_literal (error, GSD_RR_ERROR, GSD_RR_ERROR_UNKNOWN, "Could not change DPMS mode"); goto out; } ret = gsd_rr_screen_clear_dpms_timeouts (screen, error); if (!ret) goto out; out: return ret; } /** * gsd_rr_screen_list_modes: * * List available XRandR modes * * Returns: (array zero-terminated=1) (transfer none): */ GsdRRMode ** gsd_rr_screen_list_modes (GsdRRScreen *screen) { g_return_val_if_fail (GSD_IS_RR_SCREEN (screen), NULL); g_return_val_if_fail (screen->priv->info != NULL, NULL); return screen->priv->info->modes; } /** * gsd_rr_screen_list_clone_modes: * * List available XRandR clone modes * * Returns: (array zero-terminated=1) (transfer none): */ GsdRRMode ** gsd_rr_screen_list_clone_modes (GsdRRScreen *screen) { g_return_val_if_fail (GSD_IS_RR_SCREEN (screen), NULL); g_return_val_if_fail (screen->priv->info != NULL, NULL); return screen->priv->info->clone_modes; } /** * gsd_rr_screen_list_crtcs: * * List all CRTCs * * Returns: (array zero-terminated=1) (transfer none): */ GsdRRCrtc ** gsd_rr_screen_list_crtcs (GsdRRScreen *screen) { g_return_val_if_fail (GSD_IS_RR_SCREEN (screen), NULL); g_return_val_if_fail (screen->priv->info != NULL, NULL); return screen->priv->info->crtcs; } /** * gsd_rr_screen_list_outputs: * * List all outputs * * Returns: (array zero-terminated=1) (transfer none): */ GsdRROutput ** gsd_rr_screen_list_outputs (GsdRRScreen *screen) { g_return_val_if_fail (GSD_IS_RR_SCREEN (screen), NULL); g_return_val_if_fail (screen->priv->info != NULL, NULL); return screen->priv->info->outputs; } /** * gsd_rr_screen_get_crtc_by_id: * * Returns: (transfer none): the CRTC identified by @id */ GsdRRCrtc * gsd_rr_screen_get_crtc_by_id (GsdRRScreen *screen, guint32 id) { GsdRRCrtc **crtcs; int i; g_return_val_if_fail (GSD_IS_RR_SCREEN (screen), NULL); g_return_val_if_fail (screen->priv->info != NULL, NULL); crtcs = screen->priv->info->crtcs; for (i = 0; crtcs[i] != NULL; ++i) { if (crtcs[i]->id == id) return crtcs[i]; } return NULL; } /** * gsd_rr_screen_get_output_by_id: * * Returns: (transfer none): the output identified by @id */ GsdRROutput * gsd_rr_screen_get_output_by_id (GsdRRScreen *screen, guint32 id) { GsdRROutput **outputs; int i; g_return_val_if_fail (GSD_IS_RR_SCREEN (screen), NULL); g_return_val_if_fail (screen->priv->info != NULL, NULL); outputs = screen->priv->info->outputs; for (i = 0; outputs[i] != NULL; ++i) { if (outputs[i]->id == id) return outputs[i]; } return NULL; } /* GsdRROutput */ static GsdRROutput * output_new (ScreenInfo *info, RROutput id) { GsdRROutput *output = g_slice_new0 (GsdRROutput); output->id = id; output->info = info; return output; } static guint8 * get_property (Display *dpy, RROutput output, Atom atom, gsize *len) { unsigned char *prop; int actual_format; unsigned long nitems, bytes_after; Atom actual_type; guint8 *result; XRRGetOutputProperty (dpy, output, atom, 0, 100, False, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &prop); if (actual_type == XA_INTEGER && actual_format == 8) { result = g_memdup (prop, nitems); if (len) *len = nitems; } else { result = NULL; } XFree (prop); return result; } static guint8 * read_edid_data (GsdRROutput *output, gsize *len) { Atom edid_atom; guint8 *result; edid_atom = XInternAtom (DISPLAY (output), "EDID", FALSE); result = get_property (DISPLAY (output), output->id, edid_atom, len); if (!result) { edid_atom = XInternAtom (DISPLAY (output), "EDID_DATA", FALSE); result = get_property (DISPLAY (output), output->id, edid_atom, len); } if (!result) { edid_atom = XInternAtom (DISPLAY (output), "XFree86_DDC_EDID1_RAWDATA", FALSE); result = get_property (DISPLAY (output), output->id, edid_atom, len); } if (result) { if (*len % 128 == 0) return result; else g_free (result); } return NULL; } static char * get_connector_type_string (GsdRROutput *output) { char *result; unsigned char *prop; int actual_format; unsigned long nitems, bytes_after; Atom actual_type; Atom connector_type; char *connector_type_str; result = NULL; if (XRRGetOutputProperty (DISPLAY (output), output->id, output->info->screen->priv->connector_type_atom, 0, 100, False, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &prop) != Success) return NULL; if (!(actual_type == XA_ATOM && actual_format == 32 && nitems == 1)) goto out; connector_type = *((Atom *) prop); connector_type_str = XGetAtomName (DISPLAY (output), connector_type); if (connector_type_str) { result = g_strdup (connector_type_str); /* so the caller can g_free() it */ XFree (connector_type_str); } out: XFree (prop); return result; } static void update_brightness_limits (GsdRROutput *output) { gint rc; Atom atom; XRRPropertyInfo *info; gdk_error_trap_push (); atom = XInternAtom (DISPLAY (output), "Backlight", FALSE); info = XRRQueryOutputProperty (DISPLAY (output), output->id, atom); rc = gdk_error_trap_pop (); if (rc != Success) { if (rc != BadName) g_warning ("could not get output property for %s, rc: %i", output->name, rc); goto out; } if (info == NULL) { g_warning ("could not get output property for %s", output->name); goto out; } if (!info->range || info->num_values != 2) { g_debug ("backlight %s was not range", output->name); goto out; } output->backlight_min = info->values[0]; output->backlight_max = info->values[1]; /* If the interface has more than 99 possible values, it's * likely that 0 turns the backlight off so we let 1 be * set in that case. */ if (output->backlight_max > 99 && output->backlight_min == 0) output->backlight_min = 1; out: if (info != NULL) { XFree (info); } } static gboolean output_initialize (GsdRROutput *output, XRRScreenResources *res, GError **error) { XRROutputInfo *info = XRRGetOutputInfo ( DISPLAY (output), res, output->id); GPtrArray *a; int i; #if 0 g_print ("Output %lx Timestamp: %u\n", output->id, (guint32)info->timestamp); #endif if (!info || !output->info) { /* FIXME: see the comment in crtc_initialize() */ /* Translators: here, an "output" is a video output */ g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_RANDR_ERROR, _("could not get information about output %d"), (int) output->id); return FALSE; } output->name = g_strdup (info->name); /* FIXME: what is nameLen used for? */ output->display_name = NULL; /* set first time the getter is used */ output->current_crtc = crtc_by_id (output->info, info->crtc); output->width_mm = info->mm_width; output->height_mm = info->mm_height; output->connected = (info->connection == RR_Connected); output->connector_type = get_connector_type_string (output); /* Possible crtcs */ a = g_ptr_array_new (); for (i = 0; i < info->ncrtc; ++i) { GsdRRCrtc *crtc = crtc_by_id (output->info, info->crtcs[i]); if (crtc) g_ptr_array_add (a, crtc); } g_ptr_array_add (a, NULL); output->possible_crtcs = (GsdRRCrtc **)g_ptr_array_free (a, FALSE); /* Modes */ a = g_ptr_array_new (); for (i = 0; i < info->nmode; ++i) { GsdRRMode *mode = mode_by_id (output->info, info->modes[i]); if (mode) g_ptr_array_add (a, mode); } g_ptr_array_add (a, NULL); output->modes = (GsdRRMode **)g_ptr_array_free (a, FALSE); output->n_preferred = info->npreferred; /* Edid data */ output->edid_data = read_edid_data (output, &output->edid_size); /* brightness data */ if (output->connected) update_brightness_limits (output); XRRFreeOutputInfo (info); return TRUE; } static gboolean output_initialize_clones (GsdRROutput *output, XRRScreenResources *res, GError **error) { XRROutputInfo *info = XRRGetOutputInfo (DISPLAY (output), res, output->id); GPtrArray *a; int i; if (!info || !output->info) { /* FIXME: see the comment in crtc_initialize() */ /* Translators: here, an "output" is a video output */ g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_RANDR_ERROR, _("could not get information about output %d"), (int) output->id); return FALSE; } a = g_ptr_array_new (); for (i = 0; i < info->nclone; ++i) { GsdRROutput *gsd_rr_output = gsd_rr_output_by_id (output->info, info->clones[i]); if (gsd_rr_output) g_ptr_array_add (a, gsd_rr_output); } g_ptr_array_add (a, NULL); output->clones = (GsdRROutput **)g_ptr_array_free (a, FALSE); XRRFreeOutputInfo (info); return TRUE; } static GsdRROutput* output_copy (const GsdRROutput *from) { GPtrArray *array; GsdRRCrtc **p_crtc; GsdRROutput **p_output; GsdRRMode **p_mode; GsdRROutput *output = g_slice_new0 (GsdRROutput); output->id = from->id; output->info = from->info; output->name = g_strdup (from->name); output->current_crtc = from->current_crtc; output->width_mm = from->width_mm; output->height_mm = from->height_mm; output->connected = from->connected; output->n_preferred = from->n_preferred; output->connector_type = g_strdup (from->connector_type); output->backlight_min = -1; output->backlight_max = -1; array = g_ptr_array_new (); for (p_crtc = from->possible_crtcs; *p_crtc != NULL; p_crtc++) { g_ptr_array_add (array, *p_crtc); } output->possible_crtcs = (GsdRRCrtc**) g_ptr_array_free (array, FALSE); array = g_ptr_array_new (); for (p_output = from->clones; *p_output != NULL; p_output++) { g_ptr_array_add (array, *p_output); } output->clones = (GsdRROutput**) g_ptr_array_free (array, FALSE); array = g_ptr_array_new (); for (p_mode = from->modes; *p_mode != NULL; p_mode++) { g_ptr_array_add (array, *p_mode); } output->modes = (GsdRRMode**) g_ptr_array_free (array, FALSE); output->edid_size = from->edid_size; output->edid_data = g_memdup (from->edid_data, from->edid_size); return output; } static void output_free (GsdRROutput *output) { g_free (output->clones); g_free (output->modes); g_free (output->possible_crtcs); g_free (output->edid_data); g_free (output->name); g_free (output->display_name); g_free (output->connector_type); g_slice_free (GsdRROutput, output); } guint32 gsd_rr_output_get_id (GsdRROutput *output) { g_assert(output != NULL); return output->id; } const guint8 * gsd_rr_output_get_edid_data (GsdRROutput *output, gsize *size) { g_return_val_if_fail (output != NULL, NULL); if (size) *size = output->edid_size; return output->edid_data; } /** * gsd_rr_output_get_ids_from_edid: * @output: a #GsdRROutput * @vendor: (out) (allow-none): * @product: (out) (allow-none): * @serial: (out) (allow-none): */ gboolean gsd_rr_output_get_ids_from_edid (GsdRROutput *output, char **vendor, int *product, int *serial) { MonitorInfo *info; g_return_val_if_fail (output != NULL, FALSE); if (!output->edid_data) return FALSE; info = decode_edid (output->edid_data); if (!info) return FALSE; if (vendor) *vendor = g_memdup (info->manufacturer_code, 4); if (product) *product = info->product_code; if (serial) *serial = info->serial_number; g_free (info); return TRUE; } static void ensure_display_name (GsdRROutput *output) { if (output->display_name != NULL) return; if (gsd_rr_output_is_laptop (output)) output->display_name = g_strdup (_("Built-in Display")); if (output->display_name == NULL && output->edid_data != NULL) { MonitorInfo *info; info = decode_edid (output->edid_data); if (info != NULL) output->display_name = make_display_name (info); g_free (info); } if (output->display_name == NULL) { char *inches; inches = make_display_size_string (output->width_mm, output->height_mm); if (inches != NULL) { /* Translators: %s is the size of the monitor in inches */ output->display_name = g_strdup_printf (_("%s Display"), inches); } g_free (inches); } /* last chance on the stairway */ if (output->display_name == NULL) { output->display_name = g_strdup (_("Unknown Display")); } } const char * gsd_rr_output_get_display_name (GsdRROutput *output) { g_return_val_if_fail (output != NULL, NULL); ensure_display_name (output); return output->display_name; } /** * gsd_rr_output_get_backlight_min: * * Returns: The mimimum backlight value, or -1 if not supported */ gint gsd_rr_output_get_backlight_min (GsdRROutput *output) { g_return_val_if_fail (output != NULL, -1); return output->backlight_min; } /** * gsd_rr_output_get_backlight_max: * * Returns: The maximum backlight value, or -1 if not supported */ gint gsd_rr_output_get_backlight_max (GsdRROutput *output) { g_return_val_if_fail (output != NULL, -1); return output->backlight_max; } /** * gsd_rr_output_get_backlight: * * Returns: The currently set backlight brightness */ gint gsd_rr_output_get_backlight (GsdRROutput *output, GError **error) { guint now = -1; unsigned long nitems; unsigned long bytes_after; guint *prop; Atom atom; Atom actual_type; int actual_format; gint retval; g_return_val_if_fail (output != NULL, -1); gdk_error_trap_push (); atom = XInternAtom (DISPLAY (output), "Backlight", FALSE); retval = XRRGetOutputProperty (DISPLAY (output), output->id, atom, 0, 4, False, False, None, &actual_type, &actual_format, &nitems, &bytes_after, ((unsigned char **)&prop)); gdk_flush (); if (gdk_error_trap_pop ()) { g_set_error_literal (error, GSD_RR_ERROR, GSD_RR_ERROR_UNKNOWN, "unhandled X error while getting the range of backlight values"); goto out; } if (retval != Success) { g_set_error_literal (error, GSD_RR_ERROR, GSD_RR_ERROR_RANDR_ERROR, "could not get the range of backlight values"); goto out; } if (actual_type == XA_INTEGER && nitems == 1 && actual_format == 32) { memcpy (&now, prop, sizeof (guint)); } else { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_RANDR_ERROR, "failed to get correct property type, got %lu,%i", nitems, actual_format); } out: XFree (prop); return now; } /** * gsd_rr_output_set_backlight: * @value: the absolute value which is min >= this <= max * * Returns: %TRUE for success */ gboolean gsd_rr_output_set_backlight (GsdRROutput *output, gint value, GError **error) { gboolean ret = FALSE; Atom atom; g_return_val_if_fail (output != NULL, FALSE); /* check this is sane */ if (value < output->backlight_min || value > output->backlight_max) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_BOUNDS_ERROR, "out of brightness range: %i, has to be %i -> %i", value, output->backlight_max, output->backlight_min); goto out; } /* don't abort on error */ gdk_error_trap_push (); atom = XInternAtom (DISPLAY (output), "Backlight", FALSE); XRRChangeOutputProperty (DISPLAY (output), output->id, atom, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &value, 1); if (gdk_error_trap_pop ()) { g_set_error_literal (error, GSD_RR_ERROR, GSD_RR_ERROR_UNKNOWN, "unhandled X error while setting the backlight values"); goto out; } /* we assume this succeeded as there's no return value */ ret = TRUE; out: return ret; } /** * gsd_rr_screen_get_output_by_name: * * Returns: (transfer none): the output identified by @name */ GsdRROutput * gsd_rr_screen_get_output_by_name (GsdRRScreen *screen, const char *name) { int i; g_return_val_if_fail (GSD_IS_RR_SCREEN (screen), NULL); g_return_val_if_fail (screen->priv->info != NULL, NULL); for (i = 0; screen->priv->info->outputs[i] != NULL; ++i) { GsdRROutput *output = screen->priv->info->outputs[i]; if (strcmp (output->name, name) == 0) return output; } return NULL; } GsdRRCrtc * gsd_rr_output_get_crtc (GsdRROutput *output) { g_return_val_if_fail (output != NULL, NULL); return output->current_crtc; } /* Returns NULL if the ConnectorType property is not available */ const char * gsd_rr_output_get_connector_type (GsdRROutput *output) { g_return_val_if_fail (output != NULL, NULL); return output->connector_type; } gboolean _gsd_rr_output_name_is_laptop (const char *name) { if (!name) return FALSE; if (strstr (name, "lvds") || /* Most drivers use an "LVDS" prefix... */ strstr (name, "LVDS") || strstr (name, "Lvds") || strstr (name, "LCD") || /* ... but fglrx uses "LCD" in some versions. Shoot me now, kthxbye. */ strstr (name, "eDP") || /* eDP is for internal laptop panel connections */ strstr (name, "default")) /* Finally, NVidia and all others that don't bother to do RANDR properly */ return TRUE; return FALSE; } gboolean gsd_rr_output_is_laptop (GsdRROutput *output) { g_return_val_if_fail (output != NULL, FALSE); if (!output->connected) return FALSE; /* The ConnectorType property is present in RANDR 1.3 and greater */ if (g_strcmp0 (output->connector_type, GSD_RR_CONNECTOR_TYPE_PANEL) == 0) return TRUE; /* Older versions of RANDR - this is a best guess, as @#$% RANDR doesn't have standard output names, * so drivers can use whatever they like. */ if (_gsd_rr_output_name_is_laptop (output->name)) return TRUE; return FALSE; } GsdRRMode * gsd_rr_output_get_current_mode (GsdRROutput *output) { GsdRRCrtc *crtc; g_return_val_if_fail (output != NULL, NULL); if ((crtc = gsd_rr_output_get_crtc (output))) return gsd_rr_crtc_get_current_mode (crtc); return NULL; } /** * gsd_rr_output_get_position: * @output: a #GsdRROutput * @x: (out) (allow-none): * @y: (out) (allow-none): */ void gsd_rr_output_get_position (GsdRROutput *output, int *x, int *y) { GsdRRCrtc *crtc; g_return_if_fail (output != NULL); if ((crtc = gsd_rr_output_get_crtc (output))) gsd_rr_crtc_get_position (crtc, x, y); } const char * gsd_rr_output_get_name (GsdRROutput *output) { g_assert (output != NULL); return output->name; } int gsd_rr_output_get_width_mm (GsdRROutput *output) { g_assert (output != NULL); return output->width_mm; } int gsd_rr_output_get_height_mm (GsdRROutput *output) { g_assert (output != NULL); return output->height_mm; } GsdRRMode * gsd_rr_output_get_preferred_mode (GsdRROutput *output) { g_return_val_if_fail (output != NULL, NULL); if (output->n_preferred) return output->modes[0]; return NULL; } GsdRRMode ** gsd_rr_output_list_modes (GsdRROutput *output) { g_return_val_if_fail (output != NULL, NULL); return output->modes; } gboolean gsd_rr_output_is_connected (GsdRROutput *output) { g_return_val_if_fail (output != NULL, FALSE); return output->connected; } gboolean gsd_rr_output_supports_mode (GsdRROutput *output, GsdRRMode *mode) { int i; g_return_val_if_fail (output != NULL, FALSE); g_return_val_if_fail (mode != NULL, FALSE); for (i = 0; output->modes[i] != NULL; ++i) { if (output->modes[i] == mode) return TRUE; } return FALSE; } gboolean gsd_rr_output_can_clone (GsdRROutput *output, GsdRROutput *clone) { int i; g_return_val_if_fail (output != NULL, FALSE); g_return_val_if_fail (clone != NULL, FALSE); for (i = 0; output->clones[i] != NULL; ++i) { if (output->clones[i] == clone) return TRUE; } return FALSE; } gboolean gsd_rr_output_get_is_primary (GsdRROutput *output) { return output->info->primary == output->id; } void gsd_rr_screen_set_primary_output (GsdRRScreen *screen, GsdRROutput *output) { GsdRRScreenPrivate *priv; RROutput id; g_return_if_fail (GSD_IS_RR_SCREEN (screen)); priv = screen->priv; if (output) id = output->id; else id = None; if (SERVERS_RANDR_IS_AT_LEAST_1_3 (priv)) { gdk_error_trap_push (); XRRSetOutputPrimary (priv->xdisplay, priv->xroot, id); gdk_error_trap_pop_ignored (); } } /* GsdRRCrtc */ typedef struct { Rotation xrot; GsdRRRotation rot; } RotationMap; static const RotationMap rotation_map[] = { { RR_Rotate_0, GSD_RR_ROTATION_0 }, { RR_Rotate_90, GSD_RR_ROTATION_90 }, { RR_Rotate_180, GSD_RR_ROTATION_180 }, { RR_Rotate_270, GSD_RR_ROTATION_270 }, { RR_Reflect_X, GSD_RR_REFLECT_X }, { RR_Reflect_Y, GSD_RR_REFLECT_Y }, }; static GsdRRRotation gsd_rr_rotation_from_xrotation (Rotation r) { int i; GsdRRRotation result = 0; for (i = 0; i < G_N_ELEMENTS (rotation_map); ++i) { if (r & rotation_map[i].xrot) result |= rotation_map[i].rot; } return result; } static Rotation xrotation_from_rotation (GsdRRRotation r) { int i; Rotation result = 0; for (i = 0; i < G_N_ELEMENTS (rotation_map); ++i) { if (r & rotation_map[i].rot) result |= rotation_map[i].xrot; } return result; } gboolean gsd_rr_crtc_set_config_with_time (GsdRRCrtc *crtc, guint32 timestamp, int x, int y, GsdRRMode *mode, GsdRRRotation rotation, GsdRROutput **outputs, int n_outputs, GError **error) { ScreenInfo *info; GArray *output_ids; Status status; gboolean result; int i; g_return_val_if_fail (crtc != NULL, FALSE); g_return_val_if_fail (mode != NULL || outputs == NULL || n_outputs == 0, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); info = crtc->info; if (mode) { if (x + mode->width > info->max_width || y + mode->height > info->max_height) { g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_BOUNDS_ERROR, /* Translators: the "position", "size", and "maximum" * words here are not keywords; please translate them * as usual. A CRTC is a CRT Controller (this is X terminology) */ _("requested position/size for CRTC %d is outside the allowed limit: " "position=(%d, %d), size=(%d, %d), maximum=(%d, %d)"), (int) crtc->id, x, y, mode->width, mode->height, info->max_width, info->max_height); return FALSE; } } output_ids = g_array_new (FALSE, FALSE, sizeof (RROutput)); if (outputs) { for (i = 0; i < n_outputs; ++i) g_array_append_val (output_ids, outputs[i]->id); } gdk_error_trap_push (); status = XRRSetCrtcConfig (DISPLAY (crtc), info->resources, crtc->id, timestamp, x, y, mode ? mode->id : None, xrotation_from_rotation (rotation), (RROutput *)output_ids->data, output_ids->len); g_array_free (output_ids, TRUE); if (gdk_error_trap_pop () || status != RRSetConfigSuccess) { /* Translators: CRTC is a CRT Controller (this is X terminology). * It is *very* unlikely that you'll ever get this error, so it is * only listed for completeness. */ g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_RANDR_ERROR, _("could not set the configuration for CRTC %d"), (int) crtc->id); return FALSE; } else { result = TRUE; } return result; } GsdRRMode * gsd_rr_crtc_get_current_mode (GsdRRCrtc *crtc) { g_return_val_if_fail (crtc != NULL, NULL); return crtc->current_mode; } guint32 gsd_rr_crtc_get_id (GsdRRCrtc *crtc) { g_return_val_if_fail (crtc != NULL, 0); return crtc->id; } gboolean gsd_rr_crtc_can_drive_output (GsdRRCrtc *crtc, GsdRROutput *output) { int i; g_return_val_if_fail (crtc != NULL, FALSE); g_return_val_if_fail (output != NULL, FALSE); for (i = 0; crtc->possible_outputs[i] != NULL; ++i) { if (crtc->possible_outputs[i] == output) return TRUE; } return FALSE; } /* FIXME: merge with get_mode()? */ /** * gsd_rr_crtc_get_position: * @crtc: a #GsdRRCrtc * @x: (out) (allow-none): * @y: (out) (allow-none): */ void gsd_rr_crtc_get_position (GsdRRCrtc *crtc, int *x, int *y) { g_return_if_fail (crtc != NULL); if (x) *x = crtc->x; if (y) *y = crtc->y; } /* FIXME: merge with get_mode()? */ GsdRRRotation gsd_rr_crtc_get_current_rotation (GsdRRCrtc *crtc) { g_assert(crtc != NULL); return crtc->current_rotation; } GsdRRRotation gsd_rr_crtc_get_rotations (GsdRRCrtc *crtc) { g_assert(crtc != NULL); return crtc->rotations; } gboolean gsd_rr_crtc_supports_rotation (GsdRRCrtc * crtc, GsdRRRotation rotation) { g_return_val_if_fail (crtc != NULL, FALSE); return (crtc->rotations & rotation); } static GsdRRCrtc * crtc_new (ScreenInfo *info, RROutput id) { GsdRRCrtc *crtc = g_slice_new0 (GsdRRCrtc); crtc->id = id; crtc->info = info; return crtc; } static GsdRRCrtc * crtc_copy (const GsdRRCrtc *from) { GsdRROutput **p_output; GPtrArray *array; GsdRRCrtc *to = g_slice_new0 (GsdRRCrtc); to->info = from->info; to->id = from->id; to->current_mode = from->current_mode; to->x = from->x; to->y = from->y; to->current_rotation = from->current_rotation; to->rotations = from->rotations; to->gamma_size = from->gamma_size; array = g_ptr_array_new (); for (p_output = from->current_outputs; *p_output != NULL; p_output++) { g_ptr_array_add (array, *p_output); } to->current_outputs = (GsdRROutput**) g_ptr_array_free (array, FALSE); array = g_ptr_array_new (); for (p_output = from->possible_outputs; *p_output != NULL; p_output++) { g_ptr_array_add (array, *p_output); } to->possible_outputs = (GsdRROutput**) g_ptr_array_free (array, FALSE); return to; } static gboolean crtc_initialize (GsdRRCrtc *crtc, XRRScreenResources *res, GError **error) { XRRCrtcInfo *info = XRRGetCrtcInfo (DISPLAY (crtc), res, crtc->id); GPtrArray *a; int i; #if 0 g_print ("CRTC %lx Timestamp: %u\n", crtc->id, (guint32)info->timestamp); #endif if (!info) { /* FIXME: We need to reaquire the screen resources */ /* FIXME: can we actually catch BadRRCrtc, and does it make sense to emit that? */ /* Translators: CRTC is a CRT Controller (this is X terminology). * It is *very* unlikely that you'll ever get this error, so it is * only listed for completeness. */ g_set_error (error, GSD_RR_ERROR, GSD_RR_ERROR_RANDR_ERROR, _("could not get information about CRTC %d"), (int) crtc->id); return FALSE; } /* GsdRRMode */ crtc->current_mode = mode_by_id (crtc->info, info->mode); crtc->x = info->x; crtc->y = info->y; /* Current outputs */ a = g_ptr_array_new (); for (i = 0; i < info->noutput; ++i) { GsdRROutput *output = gsd_rr_output_by_id (crtc->info, info->outputs[i]); if (output) g_ptr_array_add (a, output); } g_ptr_array_add (a, NULL); crtc->current_outputs = (GsdRROutput **)g_ptr_array_free (a, FALSE); /* Possible outputs */ a = g_ptr_array_new (); for (i = 0; i < info->npossible; ++i) { GsdRROutput *output = gsd_rr_output_by_id (crtc->info, info->possible[i]); if (output) g_ptr_array_add (a, output); } g_ptr_array_add (a, NULL); crtc->possible_outputs = (GsdRROutput **)g_ptr_array_free (a, FALSE); /* Rotations */ crtc->current_rotation = gsd_rr_rotation_from_xrotation (info->rotation); crtc->rotations = gsd_rr_rotation_from_xrotation (info->rotations); XRRFreeCrtcInfo (info); /* get an store gamma size */ crtc->gamma_size = XRRGetCrtcGammaSize (DISPLAY (crtc), crtc->id); return TRUE; } static void crtc_free (GsdRRCrtc *crtc) { g_free (crtc->current_outputs); g_free (crtc->possible_outputs); g_slice_free (GsdRRCrtc, crtc); } /* GsdRRMode */ static GsdRRMode * mode_new (ScreenInfo *info, RRMode id) { GsdRRMode *mode = g_slice_new0 (GsdRRMode); mode->id = id; mode->info = info; return mode; } guint32 gsd_rr_mode_get_id (GsdRRMode *mode) { g_return_val_if_fail (mode != NULL, 0); return mode->id; } guint gsd_rr_mode_get_width (GsdRRMode *mode) { g_return_val_if_fail (mode != NULL, 0); return mode->width; } int gsd_rr_mode_get_freq (GsdRRMode *mode) { g_return_val_if_fail (mode != NULL, 0); return (mode->freq) / 1000; } guint gsd_rr_mode_get_height (GsdRRMode *mode) { g_return_val_if_fail (mode != NULL, 0); return mode->height; } static void mode_initialize (GsdRRMode *mode, XRRModeInfo *info) { g_assert (mode != NULL); g_assert (info != NULL); mode->name = g_strdup (info->name); mode->width = info->width; mode->height = info->height; mode->freq = ((info->dotClock / (double)info->hTotal) / info->vTotal + 0.5) * 1000; } static GsdRRMode * mode_copy (const GsdRRMode *from) { GsdRRMode *to = g_slice_new0 (GsdRRMode); to->id = from->id; to->info = from->info; to->name = g_strdup (from->name); to->width = from->width; to->height = from->height; to->freq = from->freq; return to; } static void mode_free (GsdRRMode *mode) { g_free (mode->name); g_slice_free (GsdRRMode, mode); } void gsd_rr_crtc_set_gamma (GsdRRCrtc *crtc, int size, unsigned short *red, unsigned short *green, unsigned short *blue) { int copy_size; XRRCrtcGamma *gamma; g_return_if_fail (crtc != NULL); g_return_if_fail (red != NULL); g_return_if_fail (green != NULL); g_return_if_fail (blue != NULL); if (size != crtc->gamma_size) return; gamma = XRRAllocGamma (crtc->gamma_size); copy_size = crtc->gamma_size * sizeof (unsigned short); memcpy (gamma->red, red, copy_size); memcpy (gamma->green, green, copy_size); memcpy (gamma->blue, blue, copy_size); XRRSetCrtcGamma (DISPLAY (crtc), crtc->id, gamma); XRRFreeGamma (gamma); } gboolean gsd_rr_crtc_get_gamma (GsdRRCrtc *crtc, int *size, unsigned short **red, unsigned short **green, unsigned short **blue) { int copy_size; unsigned short *r, *g, *b; XRRCrtcGamma *gamma; g_return_val_if_fail (crtc != NULL, FALSE); gamma = XRRGetCrtcGamma (DISPLAY (crtc), crtc->id); if (!gamma) return FALSE; copy_size = crtc->gamma_size * sizeof (unsigned short); if (red) { r = g_new0 (unsigned short, crtc->gamma_size); memcpy (r, gamma->red, copy_size); *red = r; } if (green) { g = g_new0 (unsigned short, crtc->gamma_size); memcpy (g, gamma->green, copy_size); *green = g; } if (blue) { b = g_new0 (unsigned short, crtc->gamma_size); memcpy (b, gamma->blue, copy_size); *blue = b; } XRRFreeGamma (gamma); if (size) *size = crtc->gamma_size; return TRUE; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/gsd-rr.h0000664000175000017500000002454600000000000024624 0ustar00jeremyjeremy/* gnome-rr.h * * Copyright 2007, 2008, Red Hat, Inc. * * This file is part of the Gnome Library. * * The Gnome Library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * The Gnome 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with the Gnome Library; see the file COPYING.LIB. If not, * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * Author: Soren Sandmann */ #ifndef GSD_RR_H #define GSD_RR_H #include #include typedef struct GsdRRScreenPrivate GsdRRScreenPrivate; typedef struct GsdRROutput GsdRROutput; typedef struct GsdRRCrtc GsdRRCrtc; typedef struct GsdRRMode GsdRRMode; typedef struct { GObject parent; GsdRRScreenPrivate* priv; } GsdRRScreen; typedef struct { GObjectClass parent_class; void (*changed) (GsdRRScreen *screen); void (*output_connected) (GsdRRScreen *screen, GsdRROutput *output); void (*output_disconnected) (GsdRRScreen *screen, GsdRROutput *output); } GsdRRScreenClass; typedef enum { GSD_RR_ROTATION_NEXT = 0, GSD_RR_ROTATION_0 = (1 << 0), GSD_RR_ROTATION_90 = (1 << 1), GSD_RR_ROTATION_180 = (1 << 2), GSD_RR_ROTATION_270 = (1 << 3), GSD_RR_REFLECT_X = (1 << 4), GSD_RR_REFLECT_Y = (1 << 5) } GsdRRRotation; typedef enum { GSD_RR_DPMS_ON, GSD_RR_DPMS_STANDBY, GSD_RR_DPMS_SUSPEND, GSD_RR_DPMS_OFF, GSD_RR_DPMS_DISABLED, GSD_RR_DPMS_UNKNOWN } GsdRRDpmsMode; /* Error codes */ #define GSD_RR_ERROR (gsd_rr_error_quark ()) GQuark gsd_rr_error_quark (void); typedef enum { GSD_RR_ERROR_UNKNOWN, /* generic "fail" */ GSD_RR_ERROR_NO_RANDR_EXTENSION, /* RANDR extension is not present */ GSD_RR_ERROR_RANDR_ERROR, /* generic/undescribed error from the underlying XRR API */ GSD_RR_ERROR_BOUNDS_ERROR, /* requested bounds of a CRTC are outside the maximum size */ GSD_RR_ERROR_CRTC_ASSIGNMENT, /* could not assign CRTCs to outputs */ GSD_RR_ERROR_NO_MATCHING_CONFIG, /* none of the saved configurations matched the current configuration */ GSD_RR_ERROR_NO_DPMS_EXTENSION, /* DPMS extension is not present */ } GsdRRError; #define GSD_RR_CONNECTOR_TYPE_PANEL "Panel" /* This is a laptop's built-in LCD */ #define GSD_TYPE_RR_SCREEN (gsd_rr_screen_get_type()) #define GSD_RR_SCREEN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_RR_SCREEN, GsdRRScreen)) #define GSD_IS_RR_SCREEN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_RR_SCREEN)) #define GSD_RR_SCREEN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_RR_SCREEN, GsdRRScreenClass)) #define GSD_IS_RR_SCREEN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_RR_SCREEN)) #define GSD_RR_SCREEN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_RR_SCREEN, GsdRRScreenClass)) #define GSD_TYPE_RR_OUTPUT (gsd_rr_output_get_type()) #define GSD_TYPE_RR_CRTC (gsd_rr_crtc_get_type()) #define GSD_TYPE_RR_MODE (gsd_rr_mode_get_type()) GType gsd_rr_screen_get_type (void); GType gsd_rr_output_get_type (void); GType gsd_rr_crtc_get_type (void); GType gsd_rr_mode_get_type (void); /* GsdRRScreen */ GsdRRScreen * gsd_rr_screen_new (GdkScreen *screen, GError **error); GsdRROutput **gsd_rr_screen_list_outputs (GsdRRScreen *screen); GsdRRCrtc ** gsd_rr_screen_list_crtcs (GsdRRScreen *screen); GsdRRMode ** gsd_rr_screen_list_modes (GsdRRScreen *screen); GsdRRMode ** gsd_rr_screen_list_clone_modes (GsdRRScreen *screen); void gsd_rr_screen_set_size (GsdRRScreen *screen, int width, int height, int mm_width, int mm_height); GsdRRCrtc * gsd_rr_screen_get_crtc_by_id (GsdRRScreen *screen, guint32 id); gboolean gsd_rr_screen_refresh (GsdRRScreen *screen, GError **error); GsdRROutput * gsd_rr_screen_get_output_by_id (GsdRRScreen *screen, guint32 id); GsdRROutput * gsd_rr_screen_get_output_by_name (GsdRRScreen *screen, const char *name); void gsd_rr_screen_get_ranges (GsdRRScreen *screen, int *min_width, int *max_width, int *min_height, int *max_height); void gsd_rr_screen_get_timestamps (GsdRRScreen *screen, guint32 *change_timestamp_ret, guint32 *config_timestamp_ret); void gsd_rr_screen_set_primary_output (GsdRRScreen *screen, GsdRROutput *output); GsdRRMode **gsd_rr_screen_create_clone_modes (GsdRRScreen *screen); gboolean gsd_rr_screen_get_dpms_mode (GsdRRScreen *screen, GsdRRDpmsMode *mode, GError **error); gboolean gsd_rr_screen_set_dpms_mode (GsdRRScreen *screen, GsdRRDpmsMode mode, GError **error); /* GsdRROutput */ guint32 gsd_rr_output_get_id (GsdRROutput *output); const char * gsd_rr_output_get_name (GsdRROutput *output); const char * gsd_rr_output_get_display_name (GsdRROutput *output); gboolean gsd_rr_output_is_connected (GsdRROutput *output); int gsd_rr_output_get_size_inches (GsdRROutput *output); int gsd_rr_output_get_width_mm (GsdRROutput *outout); int gsd_rr_output_get_height_mm (GsdRROutput *output); const guint8 * gsd_rr_output_get_edid_data (GsdRROutput *output, gsize *size); gboolean gsd_rr_output_get_ids_from_edid (GsdRROutput *output, char **vendor, int *product, int *serial); gint gsd_rr_output_get_backlight_min (GsdRROutput *output); gint gsd_rr_output_get_backlight_max (GsdRROutput *output); gint gsd_rr_output_get_backlight (GsdRROutput *output, GError **error); gboolean gsd_rr_output_set_backlight (GsdRROutput *output, gint value, GError **error); GsdRRCrtc ** gsd_rr_output_get_possible_crtcs (GsdRROutput *output); GsdRRMode * gsd_rr_output_get_current_mode (GsdRROutput *output); GsdRRCrtc * gsd_rr_output_get_crtc (GsdRROutput *output); const char * gsd_rr_output_get_connector_type (GsdRROutput *output); gboolean gsd_rr_output_is_laptop (GsdRROutput *output); void gsd_rr_output_get_position (GsdRROutput *output, int *x, int *y); gboolean gsd_rr_output_can_clone (GsdRROutput *output, GsdRROutput *clone); GsdRRMode ** gsd_rr_output_list_modes (GsdRROutput *output); GsdRRMode * gsd_rr_output_get_preferred_mode (GsdRROutput *output); gboolean gsd_rr_output_supports_mode (GsdRROutput *output, GsdRRMode *mode); gboolean gsd_rr_output_get_is_primary (GsdRROutput *output); /* GsdRRMode */ guint32 gsd_rr_mode_get_id (GsdRRMode *mode); guint gsd_rr_mode_get_width (GsdRRMode *mode); guint gsd_rr_mode_get_height (GsdRRMode *mode); int gsd_rr_mode_get_freq (GsdRRMode *mode); /* GsdRRCrtc */ guint32 gsd_rr_crtc_get_id (GsdRRCrtc *crtc); gboolean gsd_rr_crtc_set_config_with_time (GsdRRCrtc *crtc, guint32 timestamp, int x, int y, GsdRRMode *mode, GsdRRRotation rotation, GsdRROutput **outputs, int n_outputs, GError **error); gboolean gsd_rr_crtc_can_drive_output (GsdRRCrtc *crtc, GsdRROutput *output); GsdRRMode * gsd_rr_crtc_get_current_mode (GsdRRCrtc *crtc); void gsd_rr_crtc_get_position (GsdRRCrtc *crtc, int *x, int *y); GsdRRRotation gsd_rr_crtc_get_current_rotation (GsdRRCrtc *crtc); GsdRRRotation gsd_rr_crtc_get_rotations (GsdRRCrtc *crtc); gboolean gsd_rr_crtc_supports_rotation (GsdRRCrtc *crtc, GsdRRRotation rotation); gboolean gsd_rr_crtc_get_gamma (GsdRRCrtc *crtc, int *size, unsigned short **red, unsigned short **green, unsigned short **blue); void gsd_rr_crtc_set_gamma (GsdRRCrtc *crtc, int size, unsigned short *red, unsigned short *green, unsigned short *blue); #endif /* GSD_RR_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/idle-monitor.xml0000664000175000017500000000167600000000000026400 0ustar00jeremyjeremy ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/main.c0000664000175000017500000003532500000000000024342 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "gnome-settings-manager.h" #include "gnome-settings-plugin.h" #include "gnome-settings-profile.h" #include "gnome-settings-bus.h" #include "gsd-idle-monitor-private.h" #define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager" #define GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate" static gboolean replace = FALSE; static gboolean debug = FALSE; static gboolean do_timed_exit = FALSE; static int term_signal_pipe_fds[2]; static guint name_id = 0; static GnomeSettingsManager *manager = NULL; static GOptionEntry entries[] = { {"debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL }, { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, N_("Replace existing daemon"), NULL }, { "timed-exit", 0, 0, G_OPTION_ARG_NONE, &do_timed_exit, N_("Exit after a time (for debugging)"), NULL }, {NULL} }; static gboolean timed_exit_cb (void) { g_debug ("Doing timed exit"); gtk_main_quit (); return FALSE; } static void stop_manager (GnomeSettingsManager *manager) { gnome_settings_manager_stop (manager); gtk_main_quit (); } static void on_session_over (GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) { if (g_strcmp0 (signal_name, "SessionOver") == 0) { g_debug ("Got a SessionOver signal - stopping"); stop_manager (manager); } } static void respond_to_end_session (GDBusProxy *proxy) { /* we must answer with "EndSessionResponse" */ g_dbus_proxy_call (proxy, "EndSessionResponse", g_variant_new ("(bs)", TRUE, ""), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); } static void client_proxy_signal_cb (GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) { if (g_strcmp0 (signal_name, "QueryEndSession") == 0) { g_debug ("Got QueryEndSession signal"); respond_to_end_session (proxy); } else if (g_strcmp0 (signal_name, "EndSession") == 0) { g_debug ("Got EndSession signal"); respond_to_end_session (proxy); } else if (g_strcmp0 (signal_name, "Stop") == 0) { g_debug ("Got Stop signal"); stop_manager (manager); } } static void got_client_proxy (GObject *object, GAsyncResult *res, gpointer user_data) { GDBusProxy *client_proxy; GError *error = NULL; client_proxy = g_dbus_proxy_new_for_bus_finish (res, &error); if (error != NULL) { g_debug ("Unable to get the session client proxy: %s", error->message); g_error_free (error); return; } g_signal_connect (client_proxy, "g-signal", G_CALLBACK (client_proxy_signal_cb), manager); } static void start_settings_manager (void) { gboolean res; GError *error; gnome_settings_profile_start ("gnome_settings_manager_new"); manager = gnome_settings_manager_new (); gnome_settings_profile_end ("gnome_settings_manager_new"); if (manager == NULL) { g_warning ("Unable to register object"); gtk_main_quit (); } error = NULL; res = gnome_settings_manager_start (manager, &error); if (! res) { g_warning ("Unable to start: %s", error->message); g_error_free (error); gtk_main_quit (); } } static void on_client_registered (GObject *source_object, GAsyncResult *res, gpointer user_data) { GVariant *variant; GError *error = NULL; gchar *object_path = NULL; variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); if (error != NULL) { g_warning ("Unable to register client: %s", error->message); g_error_free (error); } else { g_variant_get (variant, "(o)", &object_path); g_debug ("Registered client at path %s", object_path); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, 0, NULL, GNOME_SESSION_DBUS_NAME, object_path, GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE, NULL, got_client_proxy, manager); g_free (object_path); g_variant_unref (variant); } } static void session_env_done (GObject *source_object, GAsyncResult *res, gpointer user_data) { GVariant *result; GError *error = NULL; result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); if (result == NULL) { g_debug ("Failed to set the environment: %s", error->message); g_error_free (error); return; } g_variant_unref (result); } static void set_session_env (GDBusProxy *proxy, const gchar *name, const gchar *value) { g_dbus_proxy_call (proxy, "Setenv", g_variant_new ("(ss)", name, value), G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback) session_env_done, NULL); } static void set_locale (GDBusProxy *proxy) { GSettings *locale_settings; gchar *region; /* Set locale environment */ locale_settings = g_settings_new ("org.gnome.system.locale"); region = g_settings_get_string (locale_settings, "region"); if (region[0]) { /* Only set the locale settings if the user has ever customized them */ set_session_env (proxy, "LC_TIME", region); set_session_env (proxy, "LC_NUMERIC", region); set_session_env (proxy, "LC_MONETARY", region); set_session_env (proxy, "LC_MEASUREMENT", region); set_session_env (proxy, "LC_PAPER", region); } g_free (region); g_object_unref (locale_settings); } #ifdef HAVE_IBUS static gboolean is_program_in_path (const char *binary) { char *path; path = g_find_program_in_path (binary); if (path == NULL) return FALSE; g_free (path); return TRUE; } static gboolean keyboard_plugin_is_enabled (void) { GSettings *settings; gboolean enabled; settings = g_settings_new ("com.canonical.unity.settings-daemon.plugins.keyboard"); enabled = g_settings_get_boolean (settings, "active"); g_object_unref (settings); return enabled; } static void set_legacy_ibus_env_vars (GDBusProxy *proxy) { if (is_program_in_path ("ibus-daemon") && keyboard_plugin_is_enabled ()) { set_session_env (proxy, "QT_IM_MODULE", "ibus"); set_session_env (proxy, "XMODIFIERS", "@im=ibus"); } } #endif static void register_with_gnome_session (GDBusProxy *proxy) { const char *startup_id; g_signal_connect (G_OBJECT (proxy), "g-signal", G_CALLBACK (on_session_over), NULL); startup_id = g_getenv ("DESKTOP_AUTOSTART_ID"); g_dbus_proxy_call (proxy, "RegisterClient", g_variant_new ("(ss)", "gnome-settings-daemon", startup_id ? startup_id : ""), G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback) on_client_registered, manager); } static gboolean on_term_signal_pipe_closed (GIOChannel *source, GIOCondition condition, gpointer data) { term_signal_pipe_fds[0] = -1; g_debug ("Received SIGTERM - shutting down"); /* Got SIGTERM, time to clean up and get out */ gtk_main_quit (); return FALSE; } static void on_term_signal (int signal) { /* Wake up main loop to tell it to shutdown */ close (term_signal_pipe_fds[1]); term_signal_pipe_fds[1] = -1; } static void watch_for_term_signal (GnomeSettingsManager *manager) { GIOChannel *channel; if (-1 == pipe (term_signal_pipe_fds) || -1 == fcntl (term_signal_pipe_fds[0], F_SETFD, FD_CLOEXEC) || -1 == fcntl (term_signal_pipe_fds[1], F_SETFD, FD_CLOEXEC)) { g_error ("Could not create pipe: %s", g_strerror (errno)); exit (EXIT_FAILURE); } channel = g_io_channel_unix_new (term_signal_pipe_fds[0]); g_io_channel_set_encoding (channel, NULL, NULL); g_io_channel_set_buffered (channel, FALSE); g_io_add_watch (channel, G_IO_HUP, on_term_signal_pipe_closed, manager); g_io_channel_unref (channel); signal (SIGTERM, on_term_signal); } static void name_acquired_handler (GDBusConnection *connection, const gchar *name, gpointer user_data) { GDBusProxy *proxy; proxy = G_DBUS_PROXY (gnome_settings_bus_get_session_proxy ()); #ifdef HAVE_IBUS set_legacy_ibus_env_vars (proxy); #endif start_settings_manager (); register_with_gnome_session (proxy); watch_for_term_signal (manager); } static void name_lost_handler (GDBusConnection *connection, const gchar *name, gpointer user_data) { /* Name was already taken, or the bus went away */ g_warning ("Name taken or bus went away - shutting down"); if (manager != NULL) stop_manager (manager); gtk_main_quit (); } static void bus_register (void) { GBusNameOwnerFlags flags; flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; if (replace) flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; name_id = g_bus_own_name (G_BUS_TYPE_SESSION, GSD_DBUS_NAME, flags, NULL, (GBusNameAcquiredCallback) name_acquired_handler, (GBusNameLostCallback) name_lost_handler, NULL, NULL); } static void gsd_log_default_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data) { /* filter out DEBUG messages if debug isn't set */ if ((log_level & G_LOG_LEVEL_MASK) == G_LOG_LEVEL_DEBUG && ! debug) { return; } g_log_default_handler (log_domain, log_level, message, unused_data); } static void parse_args (int *argc, char ***argv) { GError *error; GOptionContext *context; gnome_settings_profile_start (NULL); context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gtk_get_option_group (FALSE)); error = NULL; if (!g_option_context_parse (context, argc, argv, &error)) { if (error != NULL) { g_warning ("%s", error->message); g_error_free (error); } else { g_warning ("Unable to initialize GTK+"); } exit (EXIT_FAILURE); } g_option_context_free (context); gnome_settings_profile_end (NULL); if (debug) g_setenv ("G_MESSAGES_DEBUG", "all", FALSE); } int main (int argc, char *argv[]) { gnome_settings_profile_start (NULL); bindtextdomain (GETTEXT_PACKAGE, GNOME_SETTINGS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); setlocale (LC_ALL, ""); parse_args (&argc, &argv); gnome_settings_profile_start ("opening gtk display"); if (! gtk_init_check (NULL, NULL)) { g_warning ("Unable to initialize GTK+"); exit (EXIT_FAILURE); } gnome_settings_profile_end ("opening gtk display"); g_log_set_default_handler (gsd_log_default_handler, NULL); notify_init ("gnome-settings-daemon"); bus_register (); if (do_timed_exit) { g_timeout_add_seconds (30, (GSourceFunc) timed_exit_cb, NULL); } gsd_idle_monitor_init_dbus (replace); gtk_main (); g_debug ("Shutting down"); if (name_id > 0) { g_bus_unown_name (name_id); name_id = 0; } if (manager != NULL) { g_object_unref (manager); } g_debug ("SettingsDaemon finished"); gnome_settings_profile_end (NULL); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/org.gnome.ScreenSaver.xml0000664000175000017500000000335500000000000030104 0ustar00jeremyjeremy ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/org.gnome.SessionManager.xml0000664000175000017500000003735000000000000030604 0ustar00jeremyjeremy The variable name The value Adds the variable name to the application launch environment with the specified value. May only be used during the Session Manager initialization phase. The locale category The value Reads the current state of the specific locale category. The error message Whether the error should be treated as fatal May be used by applications launched during the Session Manager initialization phase to indicate there was a problem. The application identifier Client startup identifier The object path of the newly registered client Register the caller as a Session Management client. The object path of the client Unregister the specified client from Session Management. The application identifier The toplevel X window identifier The reason for the inhibit Flags that specify what should be inhibited The cookie Proactively indicates that the calling application is performing an action that should not be interrupted and sets a reason to be displayed to the user when an interruption is about to take placea. Applications should invoke this method when they begin an operation that should not be interrupted, such as creating a CD or DVD. The types of actions that may be blocked are specified by the flags parameter. When the application completes the operation it should call Uninhibit() or disconnect from the session bus. Applications should not expect that they will always be able to block the action. In most cases, users will be given the option to force the action to take place. Reasons should be short and to the point. The flags parameter must include at least one of the following: 1 Inhibit logging out 2 Inhibit user switching 4 Inhibit suspending the session or computer 8 Inhibit the session being marked as idle 16 Inhibit auto-mounting removable media for the session Values for flags may be bitwise or'ed together. The returned cookie is used to uniquely identify this request. It should be used as an argument to Uninhibit() in order to remove the request. The cookie Cancel a previous call to Inhibit() identified by the cookie. Flags that spefify what should be inhibited Returns TRUE if any of the operations in the bitfield flags are inhibited Determine if operation(s) specified by the flags are currently inhibited. Flags are same as those accepted by the Inhibit() method. an array of client IDs This gets a list of all the Clients that are currently known to the session manager. Each Client ID is an D-Bus object path for the object that implements the Client interface. org.gnome.SessionManager.Client an array of inhibitor IDs This gets a list of all the Inhibitors that are currently known to the session manager. Each Inhibitor ID is an D-Bus object path for the object that implements the Inhibitor interface. org.gnome.SessionManager.Inhibitor The autostart condition string True if condition is handled, false otherwise Allows the caller to determine whether the session manager is handling changes to the specified autostart condition. Request a shutdown dialog. Request a reboot dialog. True if shutdown is available to the user, false otherwise Allows the caller to determine whether or not it's okay to show a shutdown option in the UI The type of logout that is being requested Request a logout dialog Allowed values for the mode parameter are: 0 Normal. 1 No confirmation inferface should be shown. 2 Forcefully logout. No confirmation will be shown and any inhibitors will be ignored. Values for flags may be bitwise or'ed together. True if the session has entered the Running phase, false otherwise Allows the caller to determine whether the session manager has entered the Running phase, in case the client missed the SessionRunning signal. The object path for the added client Emitted when a client has been added to the session manager. The object path for the removed client Emitted when a client has been removed from the session manager. The object path for the added inhibitor Emitted when an inhibitor has been added to the session manager. The object path for the removed inhibitor Emitted when an inhibitor has been removed from the session manager. Indicates the session has entered the Running phase. Indicates the session is about to end. The name of the session that has been loaded. If true, the session is currently in the foreground and available for user input. A bitmask of flags to indicate which actions are inhibited. See the Inhibit() function's description for a list of possible values. ././@PaxHeader0000000000000000000000000000021400000000000010212 xustar00112 path=unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/unity-settings-daemon-localeexec.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon/unity-settings-daemon-localeexec.0000775000175000017500000000064400000000000031623 0ustar00jeremyjeremy#!/bin/sh SETTING=$(gsettings get org.gnome.system.locale region) REGION=${SETTING#\'} REGION=${REGION%\'} if [ -n "$REGION" ]; then export LC_TIME=$REGION export LC_NUMERIC=$REGION export LC_MONETARY=$REGION export LC_MEASUREMENT=$REGION export LC_PAPER=$REGION fi if [ -x @prefix@/bin/ibus-daemon ]; then export QT_IM_MODULE=ibus export XMODIFIERS=@im=ibus fi exec @libexecdir@/unity-settings-daemon ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/gnome-settings-daemon.doap0000664000175000017500000000321400000000000024107 0ustar00jeremyjeremy GNOME Settings Daemon GNOME Settings Daemon Rui Matos rtcm Bastien Nocera hadess Richard Hughes rhughes Olivier Fourdan ofourdan ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5717669 unity-settings-daemon-15.04.1+21.10.20220207/man/0000775000175000017500000000000000000000000017611 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/man/Makefile.am0000664000175000017500000000103700000000000021646 0ustar00jeremyjeremyXSLTPROC_FLAGS = \ --nonet \ --stringparam man.output.quietly 1 \ --stringparam funcsynopsis.style ansi \ --stringparam man.th.extra1.suppress 1 \ --stringparam man.authors.section.enabled 0 \ --stringparam man.copyright.section.enabled 0 .xml.1: $(AM_V_GEN) $(XSLTPROC) $(XSLTPROC_FLAGS) http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $< man_MANS = \ unity-settings-daemon.1 xml_files = $(man_MANS:.1=.xml) EXTRA_DIST = $(xml_files) DISTCLEANFILES = $(man_MANS) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/man/unity-settings-daemon.xml0000664000175000017500000001403500000000000024605 0ustar00jeremyjeremy unity-settings-daemon Unity Maintainer Bastien Nocera hadess@hadess.net unity-settings-daemon 1 User Commands unity-settings-daemon Unity settings daemon unity-settings-daemon OPTION Description unity-settings-daemon provides many session-wide services and functions that require a long-running process. Among the services implemented by unity-settings-daemon are an XSettings manager, which provides theming, font and other settings to GTK+ applications, and a clipboard manager, which preserves clipboard contents when an application exits. Many user interface elements of unity and unity-control-center rely on unity-settings-daemon for their functionality. The internal architecture of unity-settings-daemon consists of a number of plugins, which provide functionality such as printer notifications, software update monitoring, background changing, etc. For debugging purposes, these plugins can be individually disabled by changing the gsettings key org.gnome.settings-daemon.plugins.plugin-name.active, where plugin-name is the name of the plugin. To see a list of all plugins, use the command gsettings list-children org.gnome.settings-daemon.plugins unity-settings-daemon takes the name org.gnome.SettingsDaemon on the session bus to ensure that only one instance is running. Some plugins export objects under this name to make their functionality available to other applications. The interfaces of these objects should generally be considered private and unstable. unity-settings-daemon is a required component of the Unity desktop, i.e. it is listed in the RequiredComponents field of /usr/share/gnome-session/sessions/gnome.session. It is started in the initialization phase of the session, and gnome-session will restart it if it crashes. Options , Prints a short help text and exits. Enables debugging code. Exits after a timeout (30 seconds) for debugging. Files /usr/share/gnome-session/sessions/ubuntu.session Unity session definition file where unity-settings-daemon is listed as a required component. /etc/xdg/autostart/unity-settings-daemon.desktop Autostart file for unity-settings-daemon, where its autostart phase is set. See Also unity1, unity-control-center1, gnome-session1 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5717669 unity-settings-daemon-15.04.1+21.10.20220207/plugins/0000775000175000017500000000000000000000000020517 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/Makefile.am0000664000175000017500000000151000000000000022550 0ustar00jeremyjeremyNULL = enabled_plugins = \ a11y-keyboard \ a11y-settings \ automount \ background \ clipboard \ color \ cursor \ dummy \ power \ housekeeping \ keyboard \ media-keys \ mouse \ remote-display \ screensaver-proxy \ sharing \ sound \ xrandr \ xsettings \ $(NULL) disabled_plugins = $(NULL) if HAVE_PACKAGEKIT enabled_plugins += updates else disabled_plugins += updates endif if SMARTCARD_SUPPORT enabled_plugins += smartcard else disabled_plugins += smartcard endif if HAVE_GUDEV enabled_plugins += orientation else disabled_plugins += orientation endif if HAVE_WACOM enabled_plugins += wacom else disabled_plugins += wacom endif if BUILD_RFKILL enabled_plugins += rfkill else disabled_plugins += rfkill endif SUBDIRS = common $(enabled_plugins) DIST_SUBDIRS = $(SUBDIRS) $(disabled_plugins) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5717669 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-keyboard/0000775000175000017500000000000000000000000023070 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-keyboard/Makefile.am0000664000175000017500000000335300000000000025130 0ustar00jeremyjeremyNULL = plugin_name = a11y-keyboard libexec_PROGRAMS = usd-test-a11y-keyboard usd_test_a11y_keyboard_SOURCES = \ gsd-a11y-keyboard-manager.h \ gsd-a11y-keyboard-manager.c \ test-a11y-keyboard.c usd_test_a11y_keyboard_CFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DGTKBUILDERDIR=\""$(pkgdatadir)"\" \ $(PLUGIN_CFLAGS) \ $(LIBNOTIFY_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) usd_test_a11y_keyboard_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(LIBNOTIFY_LIBS) \ $(SETTINGS_PLUGIN_LIBS) plugin_LTLIBRARIES = \ liba11y-keyboard.la \ $(NULL) liba11y_keyboard_la_SOURCES = \ gsd-a11y-keyboard-plugin.c \ gsd-a11y-keyboard-manager.h \ gsd-a11y-keyboard-manager.c \ $(NULL) liba11y_keyboard_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DGTKBUILDERDIR=\""$(gtkbuilderdir)"\" \ $(AM_CPPFLAGS) liba11y_keyboard_la_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(LIBNOTIFY_CFLAGS) \ $(AM_CFLAGS) liba11y_keyboard_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) \ $(NULL) liba11y_keyboard_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(SETTINGS_PLUGIN_LIBS) \ $(XF86MISC_LIBS) \ $(LIBNOTIFY_LIBS) \ $(NULL) plugin_in_files = \ a11y-keyboard.gnome-settings-plugin.in \ $(NULL) plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = \ $(plugin_in_files) \ $(gtkbuilder_DATA) \ $(NULL) CLEANFILES = \ $(plugin_DATA) \ $(NULL) DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000021700000000000010215 xustar00115 path=unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-keyboard/a11y-keyboard.gnome-settings-plugin.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-keyboard/a11y-keyboard.gnome-settings-plug0000664000175000017500000000031700000000000031274 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=a11y-keyboard IAge=0 Priority=7 _Name=Accessibility Keyboard _Description=Accessibility keyboard plugin Authors=Jody Goldberg Copyright=Copyright © 2001 Ximian, Inc. Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c0000664000175000017500000010142100000000000027767 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright © 2001 Ximian, Inc. * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "gnome-settings-profile.h" #include "gsd-a11y-keyboard-manager.h" #define KEYBOARD_A11Y_SCHEMA "org.gnome.desktop.a11y.keyboard" #define NOTIFICATION_TIMEOUT 30 #define GSD_A11Y_KEYBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_A11Y_KEYBOARD_MANAGER, GsdA11yKeyboardManagerPrivate)) struct GsdA11yKeyboardManagerPrivate { guint start_idle_id; int xkbEventBase; GdkDeviceManager *device_manager; guint device_added_id; gboolean stickykeys_shortcut_val; gboolean slowkeys_shortcut_val; XkbDescRec *desc; GSettings *settings; NotifyNotification *notification; }; #define DEFAULT_XKB_SET_CONTROLS_MASK XkbSlowKeysMask | \ XkbBounceKeysMask | \ XkbStickyKeysMask | \ XkbMouseKeysMask | \ XkbMouseKeysAccelMask | \ XkbAccessXKeysMask | \ XkbAccessXTimeoutMask | \ XkbAccessXFeedbackMask | \ XkbControlsEnabledMask static void gsd_a11y_keyboard_manager_class_init (GsdA11yKeyboardManagerClass *klass); static void gsd_a11y_keyboard_manager_init (GsdA11yKeyboardManager *a11y_keyboard_manager); static void gsd_a11y_keyboard_manager_finalize (GObject *object); static void set_server_from_gsettings (GsdA11yKeyboardManager *manager); G_DEFINE_TYPE (GsdA11yKeyboardManager, gsd_a11y_keyboard_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static void device_added_cb (GdkDeviceManager *device_manager, GdkDevice *device, GsdA11yKeyboardManager *manager) { if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) set_server_from_gsettings (manager); } static void set_devicepresence_handler (GsdA11yKeyboardManager *manager) { GdkDeviceManager *device_manager; device_manager = gdk_display_get_device_manager (gdk_display_get_default ()); if (device_manager == NULL) return; manager->priv->device_manager = device_manager; manager->priv->device_added_id = g_signal_connect (G_OBJECT (device_manager), "device-added", G_CALLBACK (device_added_cb), manager); } static gboolean xkb_enabled (GsdA11yKeyboardManager *manager) { int opcode, errorBase, major, minor; if (!XkbQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &opcode, &manager->priv->xkbEventBase, &errorBase, &major, &minor)) return FALSE; if (!XkbUseExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor)) return FALSE; return TRUE; } static XkbDescRec * get_xkb_desc_rec (GsdA11yKeyboardManager *manager) { XkbDescRec *desc; Status status = Success; gdk_error_trap_push (); desc = XkbGetMap (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XkbAllMapComponentsMask, XkbUseCoreKbd); if (desc != NULL) { desc->ctrls = NULL; status = XkbGetControls (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XkbAllControlsMask, desc); } gdk_error_trap_pop_ignored (); g_return_val_if_fail (desc != NULL, NULL); g_return_val_if_fail (desc->ctrls != NULL, NULL); g_return_val_if_fail (status == Success, NULL); return desc; } static int get_int (GSettings *settings, char const *key) { int res = g_settings_get_int (settings, key); if (res <= 0) { res = 1; } return res; } static gboolean set_int (GSettings *settings, char const *key, int val) { int prev_val; prev_val = g_settings_get_int (settings, key); g_settings_set_int (settings, key, val); if (val != prev_val) { g_debug ("%s changed", key); } return val != prev_val; } static gboolean set_bool (GSettings *settings, char const *key, int val) { gboolean bval = (val != 0); gboolean prev_val; prev_val = g_settings_get_boolean (settings, key); g_settings_set_boolean (settings, key, bval ? TRUE : FALSE); if (bval != prev_val) { g_debug ("%s changed", key); return TRUE; } return (bval != prev_val); } static unsigned long set_clear (gboolean flag, unsigned long value, unsigned long mask) { if (flag) { return value | mask; } return value & ~mask; } static gboolean set_ctrl_from_gsettings (XkbDescRec *desc, GSettings *settings, char const *key, unsigned long mask) { gboolean result = g_settings_get_boolean (settings, key); desc->ctrls->enabled_ctrls = set_clear (result, desc->ctrls->enabled_ctrls, mask); return result; } static void set_server_from_gsettings (GsdA11yKeyboardManager *manager) { XkbDescRec *desc; gboolean enable_accessX; GSettings *settings; gnome_settings_profile_start (NULL); desc = get_xkb_desc_rec (manager); if (!desc) { return; } settings = manager->priv->settings; /* general */ enable_accessX = g_settings_get_boolean (settings, "enable"); desc->ctrls->enabled_ctrls = set_clear (enable_accessX, desc->ctrls->enabled_ctrls, XkbAccessXKeysMask); if (set_ctrl_from_gsettings (desc, settings, "timeout-enable", XkbAccessXTimeoutMask)) { desc->ctrls->ax_timeout = get_int (settings, "disable-timeout"); /* disable only the master flag via the server we will disable * the rest on the rebound without affecting GSettings state * don't change the option flags at all. */ desc->ctrls->axt_ctrls_mask = XkbAccessXKeysMask | XkbAccessXFeedbackMask; desc->ctrls->axt_ctrls_values = 0; desc->ctrls->axt_opts_mask = 0; } desc->ctrls->ax_options = set_clear (g_settings_get_boolean (settings, "feature-state-change-beep"), desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_FeatureFBMask | XkbAX_SlowWarnFBMask); /* bounce keys */ if (set_ctrl_from_gsettings (desc, settings, "bouncekeys-enable", XkbBounceKeysMask)) { desc->ctrls->debounce_delay = get_int (settings, "bouncekeys-delay"); desc->ctrls->ax_options = set_clear (g_settings_get_boolean (settings, "bouncekeys-beep-reject"), desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_BKRejectFBMask); } /* mouse keys */ if (set_ctrl_from_gsettings (desc, settings, "mousekeys-enable", XkbMouseKeysMask | XkbMouseKeysAccelMask)) { desc->ctrls->mk_interval = 100; /* msec between mousekey events */ desc->ctrls->mk_curve = 50; /* We store pixels / sec, XKB wants pixels / event */ desc->ctrls->mk_max_speed = get_int (settings, "mousekeys-max-speed") / (1000 / desc->ctrls->mk_interval); if (desc->ctrls->mk_max_speed <= 0) desc->ctrls->mk_max_speed = 1; desc->ctrls->mk_time_to_max = get_int (settings, /* events before max */ "mousekeys-accel-time") / desc->ctrls->mk_interval; if (desc->ctrls->mk_time_to_max <= 0) desc->ctrls->mk_time_to_max = 1; desc->ctrls->mk_delay = get_int (settings, /* ms before 1st event */ "mousekeys-init-delay"); } /* slow keys */ if (set_ctrl_from_gsettings (desc, settings, "slowkeys-enable", XkbSlowKeysMask)) { desc->ctrls->ax_options = set_clear (g_settings_get_boolean (settings, "slowkeys-beep-press"), desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_SKPressFBMask); desc->ctrls->ax_options = set_clear (g_settings_get_boolean (settings, "slowkeys-beep-accept"), desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_SKAcceptFBMask); desc->ctrls->ax_options = set_clear (g_settings_get_boolean (settings, "slowkeys-beep-reject"), desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_SKRejectFBMask); desc->ctrls->slow_keys_delay = get_int (settings, "slowkeys-delay"); /* anything larger than 500 seems to loose all keyboard input */ if (desc->ctrls->slow_keys_delay > 500) desc->ctrls->slow_keys_delay = 500; } /* sticky keys */ if (set_ctrl_from_gsettings (desc, settings, "stickykeys-enable", XkbStickyKeysMask)) { desc->ctrls->ax_options |= XkbAX_LatchToLockMask; desc->ctrls->ax_options = set_clear (g_settings_get_boolean (settings, "stickykeys-two-key-off"), desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_TwoKeysMask); desc->ctrls->ax_options = set_clear (g_settings_get_boolean (settings, "stickykeys-modifier-beep"), desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_StickyKeysFBMask); } /* toggle keys */ desc->ctrls->ax_options = set_clear (g_settings_get_boolean (settings, "togglekeys-enable"), desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_IndicatorFBMask); /* g_debug ("CHANGE to : 0x%x", desc->ctrls->enabled_ctrls); g_debug ("CHANGE to : 0x%x (2)", desc->ctrls->ax_options); */ gdk_error_trap_push (); XkbSetControls (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), DEFAULT_XKB_SET_CONTROLS_MASK, desc); XkbFreeKeyboard (desc, XkbAllComponentsMask, True); XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), FALSE); gdk_error_trap_pop_ignored (); gnome_settings_profile_end (NULL); } static void ax_response_callback (GsdA11yKeyboardManager *manager, const char *action, guint revert_controls_mask, gboolean enabled) { if (g_strcmp0 (action, "reject") == 0) { /* we're reverting, so we invert sense of 'enabled' flag */ g_debug ("cancelling AccessX request"); if (revert_controls_mask == XkbStickyKeysMask) { g_settings_set_boolean (manager->priv->settings, "stickykeys-enable", !enabled); } else if (revert_controls_mask == XkbSlowKeysMask) { g_settings_set_boolean (manager->priv->settings, "slowkeys-enable", !enabled); } set_server_from_gsettings (manager); } } static void on_notification_closed (NotifyNotification *notification, GsdA11yKeyboardManager *manager) { g_object_unref (manager->priv->notification); manager->priv->notification = NULL; } static void on_slow_keys_action (NotifyNotification *notification, const char *action, GsdA11yKeyboardManager *manager) { g_assert (action != NULL); ax_response_callback (manager, action, XkbSlowKeysMask, manager->priv->slowkeys_shortcut_val); notify_notification_close (manager->priv->notification, NULL); } static void on_sticky_keys_action (NotifyNotification *notification, const char *action, GsdA11yKeyboardManager *manager) { g_assert (action != NULL); ax_response_callback (manager, action, XkbStickyKeysMask, manager->priv->stickykeys_shortcut_val); notify_notification_close (manager->priv->notification, NULL); } static gboolean ax_slowkeys_warning_post_bubble (GsdA11yKeyboardManager *manager, gboolean enabled) { gboolean res; const char *title; const char *message; GError *error; title = enabled ? _("Slow Keys Turned On") : _("Slow Keys Turned Off"); message = _("You just held down the Shift key for 8 seconds. This is the shortcut " "for the Slow Keys feature, which affects the way your keyboard works."); if (manager->priv->notification != NULL) { notify_notification_close (manager->priv->notification, NULL); } manager->priv->notification = notify_notification_new (title, message, "preferences-desktop-accessibility-symbolic"); notify_notification_set_app_name (manager->priv->notification, _("Universal Access")); notify_notification_set_timeout (manager->priv->notification, NOTIFICATION_TIMEOUT * 1000); notify_notification_set_hint (manager->priv->notification, "transient", g_variant_new_boolean (TRUE)); notify_notification_add_action (manager->priv->notification, "reject", enabled ? _("Turn Off") : _("Turn On"), (NotifyActionCallback) on_slow_keys_action, manager, NULL); notify_notification_add_action (manager->priv->notification, "accept", enabled ? _("Leave On") : _("Leave Off"), (NotifyActionCallback) on_slow_keys_action, manager, NULL); g_signal_connect (manager->priv->notification, "closed", G_CALLBACK (on_notification_closed), manager); error = NULL; res = notify_notification_show (manager->priv->notification, &error); if (! res) { g_warning ("GsdA11yKeyboardManager: unable to show notification: %s", error->message); g_error_free (error); notify_notification_close (manager->priv->notification, NULL); } return res; } static void ax_slowkeys_warning_post (GsdA11yKeyboardManager *manager, gboolean enabled) { manager->priv->slowkeys_shortcut_val = enabled; ax_slowkeys_warning_post_bubble (manager, enabled); } static gboolean ax_stickykeys_warning_post_bubble (GsdA11yKeyboardManager *manager, gboolean enabled) { gboolean res; const char *title; const char *message; GError *error; title = enabled ? _("Sticky Keys Turned On") : _("Sticky Keys Turned Off"); message = enabled ? _("You just pressed the Shift key 5 times in a row. This is the shortcut " "for the Sticky Keys feature, which affects the way your keyboard works.") : _("You just pressed two keys at once, or pressed the Shift key 5 times in a row. " "This turns off the Sticky Keys feature, which affects the way your keyboard works."); if (manager->priv->notification != NULL) { notify_notification_close (manager->priv->notification, NULL); } manager->priv->notification = notify_notification_new (title, message, "preferences-desktop-accessibility-symbolic"); notify_notification_set_app_name (manager->priv->notification, _("Universal Access")); notify_notification_set_timeout (manager->priv->notification, NOTIFICATION_TIMEOUT * 1000); notify_notification_set_hint (manager->priv->notification, "transient", g_variant_new_boolean (TRUE)); notify_notification_add_action (manager->priv->notification, "reject", enabled ? _("Turn Off") : _("Turn On"), (NotifyActionCallback) on_sticky_keys_action, manager, NULL); notify_notification_add_action (manager->priv->notification, "accept", enabled ? _("Leave On") : _("Leave Off"), (NotifyActionCallback) on_sticky_keys_action, manager, NULL); g_signal_connect (manager->priv->notification, "closed", G_CALLBACK (on_notification_closed), manager); error = NULL; res = notify_notification_show (manager->priv->notification, &error); if (! res) { g_warning ("GsdA11yKeyboardManager: unable to show notification: %s", error->message); g_error_free (error); notify_notification_close (manager->priv->notification, NULL); } return res; } static void ax_stickykeys_warning_post (GsdA11yKeyboardManager *manager, gboolean enabled) { manager->priv->stickykeys_shortcut_val = enabled; ax_stickykeys_warning_post_bubble (manager, enabled); } static void set_gsettings_from_server (GsdA11yKeyboardManager *manager) { XkbDescRec *desc; gboolean changed = FALSE; gboolean slowkeys_changed; gboolean stickykeys_changed; GSettings *settings; desc = get_xkb_desc_rec (manager); if (! desc) { return; } /* Create a new one, so that only those settings * are delayed */ settings = g_settings_new (KEYBOARD_A11Y_SCHEMA); g_settings_delay (settings); /* fprintf (stderr, "changed to : 0x%x\n", desc->ctrls->enabled_ctrls); fprintf (stderr, "changed to : 0x%x (2)\n", desc->ctrls->ax_options); */ changed |= set_bool (settings, "enable", desc->ctrls->enabled_ctrls & XkbAccessXKeysMask); changed |= set_bool (settings, "feature-state-change-beep", desc->ctrls->ax_options & (XkbAX_FeatureFBMask | XkbAX_SlowWarnFBMask)); changed |= set_bool (settings, "timeout-enable", desc->ctrls->enabled_ctrls & XkbAccessXTimeoutMask); changed |= set_int (settings, "disable-timeout", desc->ctrls->ax_timeout); changed |= set_bool (settings, "bouncekeys-enable", desc->ctrls->enabled_ctrls & XkbBounceKeysMask); changed |= set_int (settings, "bouncekeys-delay", desc->ctrls->debounce_delay); changed |= set_bool (settings, "bouncekeys-beep-reject", desc->ctrls->ax_options & XkbAX_BKRejectFBMask); changed |= set_bool (settings, "mousekeys-enable", desc->ctrls->enabled_ctrls & XkbMouseKeysMask); changed |= set_int (settings, "mousekeys-max-speed", desc->ctrls->mk_max_speed * (1000 / desc->ctrls->mk_interval)); /* NOTE : mk_time_to_max is measured in events not time */ changed |= set_int (settings, "mousekeys-accel-time", desc->ctrls->mk_time_to_max * desc->ctrls->mk_interval); changed |= set_int (settings, "mousekeys-init-delay", desc->ctrls->mk_delay); slowkeys_changed = set_bool (settings, "slowkeys-enable", desc->ctrls->enabled_ctrls & XkbSlowKeysMask); changed |= set_bool (settings, "slowkeys-beep-press", desc->ctrls->ax_options & XkbAX_SKPressFBMask); changed |= set_bool (settings, "slowkeys-beep-accept", desc->ctrls->ax_options & XkbAX_SKAcceptFBMask); changed |= set_bool (settings, "slowkeys-beep-reject", desc->ctrls->ax_options & XkbAX_SKRejectFBMask); changed |= set_int (settings, "slowkeys-delay", desc->ctrls->slow_keys_delay); stickykeys_changed = set_bool (settings, "stickykeys-enable", desc->ctrls->enabled_ctrls & XkbStickyKeysMask); changed |= set_bool (settings, "stickykeys-two-key-off", desc->ctrls->ax_options & XkbAX_TwoKeysMask); changed |= set_bool (settings, "stickykeys-modifier-beep", desc->ctrls->ax_options & XkbAX_StickyKeysFBMask); changed |= set_bool (settings, "togglekeys-enable", desc->ctrls->ax_options & XkbAX_IndicatorFBMask); if (!changed && stickykeys_changed ^ slowkeys_changed) { /* * sticky or slowkeys has changed, singly, without our intervention. * 99% chance this is due to a keyboard shortcut being used. * we need to detect via this hack until we get * XkbAXN_AXKWarning notifications working (probable XKB bug), * at which time we can directly intercept such shortcuts instead. * See cb_xkb_event_filter () below. */ /* sanity check: are keyboard shortcuts available? */ if (desc->ctrls->enabled_ctrls & XkbAccessXKeysMask) { if (slowkeys_changed) { ax_slowkeys_warning_post (manager, desc->ctrls->enabled_ctrls & XkbSlowKeysMask); } else { ax_stickykeys_warning_post (manager, desc->ctrls->enabled_ctrls & XkbStickyKeysMask); } } } XkbFreeKeyboard (desc, XkbAllComponentsMask, True); g_settings_apply (settings); g_object_unref (settings); } static GdkFilterReturn cb_xkb_event_filter (GdkXEvent *xevent, GdkEvent *ignored1, GsdA11yKeyboardManager *manager) { XEvent *xev = (XEvent *) xevent; XkbEvent *xkbEv = (XkbEvent *) xevent; /* 'event_type' is set to zero on notifying us of updates in * response to client requests (including our own) and non-zero * to notify us of key/mouse events causing changes (like * pressing shift 5 times to enable sticky keys). * * We only want to update GSettings when it's in response to an * explicit user input event, so require a non-zero event_type. */ if (xev->xany.type == (manager->priv->xkbEventBase + XkbEventCode) && xkbEv->any.xkb_type == XkbControlsNotify && xkbEv->ctrls.event_type != 0) { g_debug ("XKB state changed"); set_gsettings_from_server (manager); } else if (xev->xany.type == (manager->priv->xkbEventBase + XkbEventCode) && xkbEv->any.xkb_type == XkbAccessXNotify) { if (xkbEv->accessx.detail == XkbAXN_AXKWarning) { g_debug ("About to turn on an AccessX feature from the keyboard!"); /* * TODO: when XkbAXN_AXKWarnings start working, we need to * invoke ax_keys_warning_dialog_run here instead of in * set_gsettings_from_server(). */ } } return GDK_FILTER_CONTINUE; } static void keyboard_callback (GSettings *settings, const char *key, GsdA11yKeyboardManager *manager) { set_server_from_gsettings (manager); } static gboolean start_a11y_keyboard_idle_cb (GsdA11yKeyboardManager *manager) { guint event_mask; g_debug ("Starting a11y_keyboard manager"); gnome_settings_profile_start (NULL); if (!xkb_enabled (manager)) goto out; manager->priv->settings = g_settings_new (KEYBOARD_A11Y_SCHEMA); g_signal_connect (G_OBJECT (manager->priv->settings), "changed", G_CALLBACK (keyboard_callback), manager); set_devicepresence_handler (manager); /* Get the original configuration from the server */ manager->priv->desc = get_xkb_desc_rec (manager); event_mask = XkbControlsNotifyMask; event_mask |= XkbAccessXNotifyMask; /* make default when AXN_AXKWarning works */ /* be sure to init before starting to monitor the server */ set_server_from_gsettings (manager); XkbSelectEvents (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XkbUseCoreKbd, event_mask, event_mask); gdk_window_add_filter (NULL, (GdkFilterFunc) cb_xkb_event_filter, manager); out: gnome_settings_profile_end (NULL); manager->priv->start_idle_id = 0; return FALSE; } gboolean gsd_a11y_keyboard_manager_start (GsdA11yKeyboardManager *manager, GError **error) { gnome_settings_profile_start (NULL); manager->priv->start_idle_id = g_idle_add ((GSourceFunc) start_a11y_keyboard_idle_cb, manager); gnome_settings_profile_end (NULL); return TRUE; } void gsd_a11y_keyboard_manager_stop (GsdA11yKeyboardManager *manager) { GsdA11yKeyboardManagerPrivate *p = manager->priv; g_debug ("Stopping a11y_keyboard manager"); if (p->desc != NULL) { XkbDescRec *desc; desc = get_xkb_desc_rec (manager); if (desc != NULL) { if (p->desc->ctrls->enabled_ctrls != desc->ctrls->enabled_ctrls) { gdk_error_trap_push (); XkbSetControls (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), DEFAULT_XKB_SET_CONTROLS_MASK, p->desc); XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), FALSE); gdk_error_trap_pop_ignored (); } XkbFreeKeyboard (desc, XkbAllComponentsMask, True); } XkbFreeKeyboard (p->desc, XkbAllComponentsMask, True); p->desc = NULL; } if (p->start_idle_id != 0) { g_source_remove (p->start_idle_id); p->start_idle_id = 0; } if (p->device_manager != NULL) { g_signal_handler_disconnect (p->device_manager, p->device_added_id); p->device_manager = NULL; } if (p->settings != NULL) { g_signal_handlers_disconnect_by_func (p->settings, keyboard_callback, manager); g_object_unref (p->settings); p->settings = NULL; } gdk_window_remove_filter (NULL, (GdkFilterFunc) cb_xkb_event_filter, manager); p->slowkeys_shortcut_val = FALSE; p->stickykeys_shortcut_val = FALSE; } static void gsd_a11y_keyboard_manager_class_init (GsdA11yKeyboardManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_a11y_keyboard_manager_finalize; g_type_class_add_private (klass, sizeof (GsdA11yKeyboardManagerPrivate)); } static void gsd_a11y_keyboard_manager_init (GsdA11yKeyboardManager *manager) { manager->priv = GSD_A11Y_KEYBOARD_MANAGER_GET_PRIVATE (manager); } static void gsd_a11y_keyboard_manager_finalize (GObject *object) { GsdA11yKeyboardManager *a11y_keyboard_manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_A11Y_KEYBOARD_MANAGER (object)); a11y_keyboard_manager = GSD_A11Y_KEYBOARD_MANAGER (object); g_return_if_fail (a11y_keyboard_manager->priv != NULL); gsd_a11y_keyboard_manager_stop (a11y_keyboard_manager); G_OBJECT_CLASS (gsd_a11y_keyboard_manager_parent_class)->finalize (object); } GsdA11yKeyboardManager * gsd_a11y_keyboard_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_A11Y_KEYBOARD_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_A11Y_KEYBOARD_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h0000664000175000017500000000474500000000000030007 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_A11Y_KEYBOARD_MANAGER_H #define __GSD_A11Y_KEYBOARD_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_A11Y_KEYBOARD_MANAGER (gsd_a11y_keyboard_manager_get_type ()) #define GSD_A11Y_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_A11Y_KEYBOARD_MANAGER, GsdA11yKeyboardManager)) #define GSD_A11Y_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_A11Y_KEYBOARD_MANAGER, GsdA11yKeyboardManagerClass)) #define GSD_IS_A11Y_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_A11Y_KEYBOARD_MANAGER)) #define GSD_IS_A11Y_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_A11Y_KEYBOARD_MANAGER)) #define GSD_A11Y_KEYBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_A11Y_KEYBOARD_MANAGER, GsdA11yKeyboardManagerClass)) typedef struct GsdA11yKeyboardManagerPrivate GsdA11yKeyboardManagerPrivate; typedef struct { GObject parent; GsdA11yKeyboardManagerPrivate *priv; } GsdA11yKeyboardManager; typedef struct { GObjectClass parent_class; } GsdA11yKeyboardManagerClass; GType gsd_a11y_keyboard_manager_get_type (void); GsdA11yKeyboardManager *gsd_a11y_keyboard_manager_new (void); gboolean gsd_a11y_keyboard_manager_start (GsdA11yKeyboardManager *manager, GError **error); void gsd_a11y_keyboard_manager_stop (GsdA11yKeyboardManager *manager); G_END_DECLS #endif /* __GSD_A11Y_KEYBOARD_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c0000664000175000017500000000204400000000000027654 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-a11y-keyboard-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdA11yKeyboard, gsd_a11y_keyboard) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-keyboard/test-a11y-keyboard.c0000664000175000017500000000035400000000000026564 0ustar00jeremyjeremy#define NEW gsd_a11y_keyboard_manager_new #define START gsd_a11y_keyboard_manager_start #define STOP gsd_a11y_keyboard_manager_stop #define MANAGER GsdA11yKeyboardManager #include "gsd-a11y-keyboard-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5717669 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-settings/0000775000175000017500000000000000000000000023130 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-settings/Makefile.am0000664000175000017500000000270300000000000025166 0ustar00jeremyjeremyplugin_name = a11y-settings libexec_PROGRAMS = usd-test-a11y-settings usd_test_a11y_settings_SOURCES = \ gsd-a11y-settings-manager.h \ gsd-a11y-settings-manager.c \ test-a11y-settings.c usd_test_a11y_settings_CFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) usd_test_a11y_settings_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(SETTINGS_PLUGIN_LIBS) plugin_LTLIBRARIES = \ liba11y-settings.la liba11y_settings_la_SOURCES = \ gsd-a11y-settings-manager.c \ gsd-a11y-settings-manager.h \ gsd-a11y-settings-plugin.c liba11y_settings_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) liba11y_settings_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) liba11y_settings_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) liba11y_settings_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(SETTINGS_PLUGIN_LIBS) \ $(NULL) plugin_in_files = \ a11y-settings.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = \ $(plugin_in_files) CLEANFILES = \ $(plugin_DATA) DISTCLEANFILES = \ $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000021700000000000010215 xustar00115 path=unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-settings/a11y-settings.gnome-settings-plugin.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-settings/a11y-settings.gnome-settings-plug0000664000175000017500000000034400000000000031374 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=a11y-settings IAge=0 Priority=7 _Name=Accessibility settings _Description=Accessibility settings plugin Authors=Bastien Nocera Copyright=Copyright © 2011 Red Hat Inc. Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-settings/gsd-a11y-settings-manager.c0000664000175000017500000001541200000000000030073 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include "gnome-settings-profile.h" #include "gsd-a11y-settings-manager.h" #define GSD_A11Y_SETTINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_A11Y_SETTINGS_MANAGER, GsdA11ySettingsManagerPrivate)) struct GsdA11ySettingsManagerPrivate { GSettings *interface_settings; GSettings *a11y_apps_settings; }; enum { PROP_0, }; static void gsd_a11y_settings_manager_class_init (GsdA11ySettingsManagerClass *klass); static void gsd_a11y_settings_manager_init (GsdA11ySettingsManager *a11y_settings_manager); static void gsd_a11y_settings_manager_finalize (GObject *object); G_DEFINE_TYPE (GsdA11ySettingsManager, gsd_a11y_settings_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static void apps_settings_changed (GSettings *settings, const char *key, GsdA11ySettingsManager *manager) { gboolean screen_reader, keyboard; if (g_str_equal (key, "screen-reader-enabled") == FALSE && g_str_equal (key, "screen-keyboard-enabled") == FALSE) return; g_debug ("screen reader or OSK enablement changed"); screen_reader = g_settings_get_boolean (manager->priv->a11y_apps_settings, "screen-reader-enabled"); keyboard = g_settings_get_boolean (manager->priv->a11y_apps_settings, "screen-keyboard-enabled"); if (screen_reader || keyboard) { g_debug ("Enabling toolkit-accessibility, screen reader or OSK enabled"); g_settings_set_boolean (manager->priv->interface_settings, "toolkit-accessibility", TRUE); } else if (screen_reader == FALSE && keyboard == FALSE) { g_debug ("Disabling toolkit-accessibility, screen reader and OSK disabled"); g_settings_set_boolean (manager->priv->interface_settings, "toolkit-accessibility", FALSE); } } gboolean gsd_a11y_settings_manager_start (GsdA11ySettingsManager *manager, GError **error) { g_debug ("Starting a11y_settings manager"); gnome_settings_profile_start (NULL); manager->priv->interface_settings = g_settings_new ("org.gnome.desktop.interface"); manager->priv->a11y_apps_settings = g_settings_new ("org.gnome.desktop.a11y.applications"); g_signal_connect (G_OBJECT (manager->priv->a11y_apps_settings), "changed", G_CALLBACK (apps_settings_changed), manager); /* If any of the screen reader or on-screen keyboard are enabled, * make sure a11y is enabled for the toolkits. * We don't do the same thing for the reverse so it's possible to * enable AT-SPI for the toolkits without using an a11y app */ if (g_settings_get_boolean (manager->priv->a11y_apps_settings, "screen-keyboard-enabled") || g_settings_get_boolean (manager->priv->a11y_apps_settings, "screen-reader-enabled")) g_settings_set_boolean (manager->priv->interface_settings, "toolkit-accessibility", TRUE); gnome_settings_profile_end (NULL); return TRUE; } void gsd_a11y_settings_manager_stop (GsdA11ySettingsManager *manager) { if (manager->priv->interface_settings) { g_object_unref (manager->priv->interface_settings); manager->priv->interface_settings = NULL; } if (manager->priv->a11y_apps_settings) { g_object_unref (manager->priv->a11y_apps_settings); manager->priv->a11y_apps_settings = NULL; } g_debug ("Stopping a11y_settings manager"); } static GObject * gsd_a11y_settings_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { GsdA11ySettingsManager *a11y_settings_manager; a11y_settings_manager = GSD_A11Y_SETTINGS_MANAGER (G_OBJECT_CLASS (gsd_a11y_settings_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); return G_OBJECT (a11y_settings_manager); } static void gsd_a11y_settings_manager_dispose (GObject *object) { G_OBJECT_CLASS (gsd_a11y_settings_manager_parent_class)->dispose (object); } static void gsd_a11y_settings_manager_class_init (GsdA11ySettingsManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructor = gsd_a11y_settings_manager_constructor; object_class->dispose = gsd_a11y_settings_manager_dispose; object_class->finalize = gsd_a11y_settings_manager_finalize; g_type_class_add_private (klass, sizeof (GsdA11ySettingsManagerPrivate)); } static void gsd_a11y_settings_manager_init (GsdA11ySettingsManager *manager) { manager->priv = GSD_A11Y_SETTINGS_MANAGER_GET_PRIVATE (manager); } static void gsd_a11y_settings_manager_finalize (GObject *object) { GsdA11ySettingsManager *a11y_settings_manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_A11Y_SETTINGS_MANAGER (object)); a11y_settings_manager = GSD_A11Y_SETTINGS_MANAGER (object); g_return_if_fail (a11y_settings_manager->priv != NULL); G_OBJECT_CLASS (gsd_a11y_settings_manager_parent_class)->finalize (object); } GsdA11ySettingsManager * gsd_a11y_settings_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_A11Y_SETTINGS_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_A11Y_SETTINGS_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-settings/gsd-a11y-settings-manager.h0000664000175000017500000000474100000000000030103 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_A11Y_SETTINGS_MANAGER_H #define __GSD_A11Y_SETTINGS_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_A11Y_SETTINGS_MANAGER (gsd_a11y_settings_manager_get_type ()) #define GSD_A11Y_SETTINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_A11Y_SETTINGS_MANAGER, GsdA11ySettingsManager)) #define GSD_A11Y_SETTINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_A11Y_SETTINGS_MANAGER, GsdA11ySettingsManagerClass)) #define GSD_IS_A11Y_SETTINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_A11Y_SETTINGS_MANAGER)) #define GSD_IS_A11Y_SETTINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_A11Y_SETTINGS_MANAGER)) #define GSD_A11Y_SETTINGS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_A11Y_SETTINGS_MANAGER, GsdA11ySettingsManagerClass)) typedef struct GsdA11ySettingsManagerPrivate GsdA11ySettingsManagerPrivate; typedef struct { GObject parent; GsdA11ySettingsManagerPrivate *priv; } GsdA11ySettingsManager; typedef struct { GObjectClass parent_class; } GsdA11ySettingsManagerClass; GType gsd_a11y_settings_manager_get_type (void); GsdA11ySettingsManager *gsd_a11y_settings_manager_new (void); gboolean gsd_a11y_settings_manager_start (GsdA11ySettingsManager *manager, GError **error); void gsd_a11y_settings_manager_stop (GsdA11ySettingsManager *manager); G_END_DECLS #endif /* __GSD_A11Y_SETTINGS_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-settings/gsd-a11y-settings-plugin.c0000664000175000017500000000204400000000000027754 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-a11y-settings-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdA11ySettings, gsd_a11y_settings) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/a11y-settings/test-a11y-settings.c0000664000175000017500000000035400000000000026664 0ustar00jeremyjeremy#define NEW gsd_a11y_settings_manager_new #define START gsd_a11y_settings_manager_start #define STOP gsd_a11y_settings_manager_stop #define MANAGER GsdA11ySettingsManager #include "gsd-a11y-settings-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5757668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/automount/0000775000175000017500000000000000000000000022552 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/automount/Makefile.am0000664000175000017500000000201500000000000024604 0ustar00jeremyjeremylibexec_PROGRAMS = unity-fallback-mount-helper unity_fallback_mount_helper_SOURCES = \ gnome-fallback-mount-helper.c \ gsd-automount-manager.c \ gsd-automount-manager.h \ gsd-autorun.c \ gsd-autorun.h unity_fallback_mount_helper_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) unity_fallback_mount_helper_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AUTOMOUNT_CFLAGS) unity_fallback_mount_helper_LDADD = \ $(SETTINGS_PLUGIN_LIBS) \ $(AUTOMOUNT_LIBS) \ $(top_builddir)/gnome-settings-daemon/libgsd.la autostartdir = $(sysconfdir)/xdg/autostart autostart_in_files = unity-fallback-mount-helper.desktop.in autostart_in_in_files = unity-fallback-mount-helper.desktop.in.in autostart_DATA = $(autostart_in_files:.desktop.in=.desktop) $(autostart_in_files): $(autostart_in_in_files) @sed -e "s|\@LIBEXECDIR\@|$(libexecdir)|" $< > $@ @INTLTOOL_DESKTOP_RULE@ EXTRA_DIST = $(autostart_in_in_files) CLEANFILES = $(autostart_DATA) $(autostart_in_files) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/automount/gnome-fallback-mount-helper.c0000664000175000017500000000351100000000000030175 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2010 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Tomas Bzatek */ #include "config.h" #include #include #include #include #include "gsd-automount-manager.h" int main (int argc, char **argv) { GMainLoop *loop; GsdAutomountManager *manager; GError *error = NULL; gtk_init (&argc, &argv); bindtextdomain (GETTEXT_PACKAGE, GNOME_SETTINGS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); loop = g_main_loop_new (NULL, FALSE); manager = gsd_automount_manager_new (); gsd_automount_manager_start (manager, &error); if (error != NULL) { g_printerr ("Unable to start the mount manager: %s", error->message); g_error_free (error); _exit (1); } g_main_loop_run (loop); gsd_automount_manager_stop (manager); g_main_loop_unref (loop); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/automount/gsd-automount-manager.c0000664000175000017500000005214400000000000027142 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2010 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Tomas Bzatek */ #include "config.h" #include #include #include #include #include #include "gnome-settings-profile.h" #include "gnome-settings-bus.h" #include "gsd-automount-manager.h" #include "gsd-autorun.h" #define GSD_AUTOMOUNT_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_AUTOMOUNT_MANAGER, GsdAutomountManagerPrivate)) struct GsdAutomountManagerPrivate { GSettings *settings; GVolumeMonitor *volume_monitor; unsigned int automount_idle_id; GDBusProxy *session; gboolean session_is_active; gboolean screensaver_active; gboolean lockscreen_active; guint ss_watch_id; guint us_watch_id; GDBusProxy *ss_proxy; GDBusProxy *us_proxy; GList *volume_queue; }; static void gsd_automount_manager_class_init (GsdAutomountManagerClass *klass); static void gsd_automount_manager_init (GsdAutomountManager *gsd_automount_manager); G_DEFINE_TYPE (GsdAutomountManager, gsd_automount_manager, G_TYPE_OBJECT) static GtkDialog * show_error_dialog (const char *primary_text, const char *secondary_text) { GtkWidget *dialog; dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", ""); g_object_set (dialog, "text", primary_text, "secondary-text", secondary_text, NULL); gtk_widget_show (GTK_WIDGET (dialog)); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); return GTK_DIALOG (dialog); } static void startup_volume_mount_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { g_volume_mount_finish (G_VOLUME (source_object), res, NULL); } static void automount_all_volumes (GsdAutomountManager *manager) { GList *volumes, *l; GMount *mount; GVolume *volume; if (g_settings_get_boolean (manager->priv->settings, "automount")) { /* automount all mountable volumes at start-up */ volumes = g_volume_monitor_get_volumes (manager->priv->volume_monitor); for (l = volumes; l != NULL; l = l->next) { volume = l->data; if (!g_volume_should_automount (volume) || !g_volume_can_mount (volume)) { continue; } mount = g_volume_get_mount (volume); if (mount != NULL) { g_object_unref (mount); continue; } /* pass NULL as GMountOperation to avoid user interaction */ g_volume_mount (volume, 0, NULL, NULL, startup_volume_mount_cb, NULL); } g_list_free_full (volumes, g_object_unref); } } static gboolean automount_all_volumes_idle_cb (gpointer data) { GsdAutomountManager *manager = GSD_AUTOMOUNT_MANAGER (data); automount_all_volumes (manager); manager->priv->automount_idle_id = 0; return FALSE; } static void volume_mount_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GMountOperation *mount_op = user_data; GError *error; char *primary; char *name; error = NULL; gsd_allow_autorun_for_volume_finish (G_VOLUME (source_object)); if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error)) { if (error->code != G_IO_ERROR_FAILED_HANDLED) { name = g_volume_get_name (G_VOLUME (source_object)); primary = g_strdup_printf (_("Unable to mount %s"), name); g_free (name); show_error_dialog (primary, error->message); g_free (primary); } g_error_free (error); } g_object_unref (mount_op); } static void do_mount_volume (GVolume *volume) { GMountOperation *mount_op; mount_op = gtk_mount_operation_new (NULL); g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION); gsd_allow_autorun_for_volume (volume); g_volume_mount (volume, 0, mount_op, NULL, volume_mount_cb, mount_op); } static void check_volume_queue (GsdAutomountManager *manager) { GList *l; GVolume *volume; if (manager->priv->screensaver_active || manager->priv->lockscreen_active) return; l = manager->priv->volume_queue; while (l != NULL) { volume = l->data; do_mount_volume (volume); manager->priv->volume_queue = g_list_remove (manager->priv->volume_queue, volume); g_object_unref (volume); l = l->next; } manager->priv->volume_queue = NULL; } static void clear_volume_queue (GsdAutomountManager *manager) { if (!manager->priv->volume_queue) return; g_list_free_full (manager->priv->volume_queue, g_object_unref); manager->priv->volume_queue = NULL; } static void check_screen_lock_and_mount (GsdAutomountManager *manager, GVolume *volume) { if (!manager->priv->session_is_active) return; if (manager->priv->screensaver_active || manager->priv->lockscreen_active) { /* queue the volume, to mount it after the screensaver state changed */ g_debug ("Queuing volume %p", volume); manager->priv->volume_queue = g_list_prepend (manager->priv->volume_queue, g_object_ref (volume)); } else { /* mount it immediately */ do_mount_volume (volume); } } static void volume_removed_callback (GVolumeMonitor *monitor, GVolume *volume, GsdAutomountManager *manager) { g_debug ("Volume %p removed, removing from the queue", volume); /* clear it from the queue, if present */ manager->priv->volume_queue = g_list_remove (manager->priv->volume_queue, volume); } static void volume_added_callback (GVolumeMonitor *monitor, GVolume *volume, GsdAutomountManager *manager) { if (g_settings_get_boolean (manager->priv->settings, "automount") && g_volume_should_automount (volume) && g_volume_can_mount (volume)) { check_screen_lock_and_mount (manager, volume); } else { /* Allow gsd_autorun() to run. When the mount is later * added programmatically (i.e. for a blank CD), * gsd_autorun() will be called by mount_added_callback(). */ gsd_allow_autorun_for_volume (volume); gsd_allow_autorun_for_volume_finish (volume); } } static void autorun_show_window (GMount *mount, gpointer user_data) { GFile *location; char *uri; GError *error; char *primary; char *name; location = g_mount_get_root (mount); uri = g_file_get_uri (location); error = NULL; /* use default folder handler */ if (! gtk_show_uri (NULL, uri, GDK_CURRENT_TIME, &error)) { name = g_mount_get_name (mount); primary = g_strdup_printf (_("Unable to open a folder for %s"), name); g_free (name); show_error_dialog (primary, error->message); g_free (primary); g_error_free (error); } g_free (uri); g_object_unref (location); } static void mount_added_callback (GVolumeMonitor *monitor, GMount *mount, GsdAutomountManager *manager) { /* don't autorun if the session is not active */ if (!manager->priv->session_is_active) { return; } gsd_autorun (mount, manager->priv->settings, autorun_show_window, manager); } static void session_state_changed (GDBusProxy *session, GVariant *changed, char **invalidated, GsdAutomountManager *manager) { GsdAutomountManagerPrivate *p = manager->priv; GVariant *v; v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN); if (v) { gboolean active; active = g_variant_get_boolean (v); g_debug ("Received session is active change: now %s", active ? "active" : "inactive"); /* when doing the fast-user-switch into a new account, * ensure the new account is undimmed and with the backlight on */ if (active) p->session_is_active = TRUE; else p->session_is_active = FALSE; g_variant_unref (v); } if (!p->session_is_active) { if (p->volume_queue != NULL) { g_list_free_full (p->volume_queue, g_object_unref); p->volume_queue = NULL; } } } static gboolean is_session_active (GsdAutomountManager *manager) { GVariant *variant; gboolean is_session_active = FALSE; variant = g_dbus_proxy_get_cached_property (manager->priv->session, "SessionIsActive"); if (variant) { is_session_active = g_variant_get_boolean (variant); g_variant_unref (variant); } return is_session_active; } static void do_initialize_session (GsdAutomountManager *manager) { manager->priv->session = G_DBUS_PROXY (gnome_settings_bus_get_session_proxy ()); g_signal_connect (manager->priv->session, "g-properties-changed", G_CALLBACK (session_state_changed), manager); manager->priv->session_is_active = is_session_active (manager); } #define SCREENSAVER_NAME "org.gnome.ScreenSaver" static void screensaver_signal_callback (GDBusProxy *proxy, const gchar *sender_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { GsdAutomountManager *manager = user_data; if (g_strcmp0 (signal_name, "ActiveChanged") == 0) { g_variant_get (parameters, "(b)", &manager->priv->screensaver_active); g_debug ("Screensaver active changed to %d", manager->priv->screensaver_active); check_volume_queue (manager); } } static void screensaver_get_active_ready_cb (GObject *source, GAsyncResult *res, gpointer user_data) { GsdAutomountManager *manager = user_data; GDBusProxy *proxy = manager->priv->ss_proxy; GVariant *result; GError *error = NULL; result = g_dbus_proxy_call_finish (proxy, res, &error); if (error != NULL) { g_warning ("Can't call GetActive() on the ScreenSaver object: %s", error->message); g_error_free (error); return; } g_variant_get (result, "(b)", &manager->priv->screensaver_active); g_variant_unref (result); g_debug ("Screensaver GetActive() returned %d", manager->priv->screensaver_active); } static void screensaver_appeared_callback (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data) { GsdAutomountManager *manager = user_data; g_debug ("ScreenSaver name appeared"); manager->priv->ss_proxy = G_DBUS_PROXY (gnome_settings_bus_get_screen_saver_proxy ()); if (manager->priv->ss_proxy == NULL) { g_warning ("Can't get proxy for the ScreenSaver object"); return; } g_debug ("ScreenSaver proxy ready"); g_signal_connect (manager->priv->ss_proxy, "g-signal", G_CALLBACK (screensaver_signal_callback), manager); g_dbus_proxy_call (manager->priv->ss_proxy, "GetActive", NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, screensaver_get_active_ready_cb, manager); } static void screensaver_vanished_callback (GDBusConnection *connection, const gchar *name, gpointer user_data) { GsdAutomountManager *manager = user_data; g_debug ("ScreenSaver name vanished"); manager->priv->screensaver_active = FALSE; g_clear_object (&manager->priv->ss_proxy); if (!manager->priv->ss_proxy && !manager->priv->us_proxy) { /* in this case force a clear of the volume queue, without * mounting them. */ clear_volume_queue (manager); } } static void do_initialize_screensaver (GsdAutomountManager *manager) { GsdAutomountManagerPrivate *p = manager->priv; p->ss_watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION, SCREENSAVER_NAME, G_BUS_NAME_WATCHER_FLAGS_NONE, screensaver_appeared_callback, screensaver_vanished_callback, manager, NULL); } #define UNITY_NAME "com.canonical.Unity" #define UNITY_SESSION_PATH "/com/canonical/Unity/Session" #define UNITY_SESSION_INTERFACE "com.canonical.Unity.Session" static void unity_session_signal_callback (GDBusProxy *proxy, const gchar *sender_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { GsdAutomountManager *manager = user_data; if (g_strcmp0 (signal_name, "Locked") == 0) { manager->priv->lockscreen_active = TRUE; check_volume_queue (manager); g_debug ("Unity.Session Locked"); } else if (g_strcmp0 (signal_name, "Unlocked") == 0) { manager->priv->lockscreen_active = FALSE; check_volume_queue (manager); g_debug ("Unity.Session Unlocked"); } } static void unity_session_is_locked_cb (GObject *source, GAsyncResult *res, gpointer user_data) { GsdAutomountManager *manager = user_data; GDBusProxy *proxy = manager->priv->us_proxy; GVariant *result; GError *error = NULL; result = g_dbus_proxy_call_finish (proxy, res, &error); if (error != NULL) { g_warning ("Can't call IsLocked() on the Unity.Session object: %s", error->message); g_error_free (error); return; } g_variant_get (result, "(b)", &manager->priv->lockscreen_active); g_variant_unref (result); g_debug ("Unity Session IsLocked() returned %d", manager->priv->lockscreen_active); } static void unity_session_proxy_ready_cb (GObject *source, GAsyncResult *res, gpointer user_data) { GsdAutomountManager *manager = user_data; GError *error = NULL; GDBusProxy *us_proxy; us_proxy = g_dbus_proxy_new_finish (res, &error); if (error != NULL) { g_warning ("Can't get proxy for the Unity Session object: %s", error->message); g_error_free (error); return; } g_debug ("Unity Session proxy ready"); manager->priv->us_proxy = us_proxy; g_signal_connect (us_proxy, "g-signal", G_CALLBACK (unity_session_signal_callback), manager); g_dbus_proxy_call (us_proxy, "IsLocked", NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, unity_session_is_locked_cb, manager); } static void unity_appeared_callback (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data) { GsdAutomountManager *manager = user_data; g_debug ("Unity name appeared"); manager->priv->lockscreen_active = FALSE; g_dbus_proxy_new (connection, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, name, UNITY_SESSION_PATH, UNITY_SESSION_INTERFACE, NULL, unity_session_proxy_ready_cb, manager); } static void unity_vanished_callback (GDBusConnection *connection, const gchar *name, gpointer user_data) { GsdAutomountManager *manager = user_data; g_debug ("Unity name vanished"); manager->priv->lockscreen_active = FALSE; g_clear_object (&manager->priv->us_proxy); if (!manager->priv->ss_proxy && !manager->priv->us_proxy) { /* in this case force a clear of the volume queue, without * mounting them. */ clear_volume_queue (manager); } } static void do_initialize_lockscreen (GsdAutomountManager *manager) { GsdAutomountManagerPrivate *p = manager->priv; p->us_watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION, UNITY_NAME, G_BUS_NAME_WATCHER_FLAGS_NONE, unity_appeared_callback, unity_vanished_callback, manager, NULL); } static void setup_automounter (GsdAutomountManager *manager) { do_initialize_session (manager); do_initialize_screensaver (manager); do_initialize_lockscreen (manager); manager->priv->volume_monitor = g_volume_monitor_get (); g_signal_connect_object (manager->priv->volume_monitor, "mount-added", G_CALLBACK (mount_added_callback), manager, 0); g_signal_connect_object (manager->priv->volume_monitor, "volume-added", G_CALLBACK (volume_added_callback), manager, 0); g_signal_connect_object (manager->priv->volume_monitor, "volume-removed", G_CALLBACK (volume_removed_callback), manager, 0); manager->priv->automount_idle_id = g_idle_add_full (G_PRIORITY_LOW, automount_all_volumes_idle_cb, manager, NULL); } gboolean gsd_automount_manager_start (GsdAutomountManager *manager, GError **error) { g_debug ("Starting automounting manager"); gnome_settings_profile_start (NULL); manager->priv->settings = g_settings_new ("org.gnome.desktop.media-handling"); setup_automounter (manager); gnome_settings_profile_end (NULL); return TRUE; } void gsd_automount_manager_stop (GsdAutomountManager *manager) { GsdAutomountManagerPrivate *p = manager->priv; g_debug ("Stopping automounting manager"); if (p->ss_proxy) { g_signal_handlers_disconnect_by_data (p->ss_proxy, manager); } g_clear_object (&p->session); g_clear_object (&p->volume_monitor); g_clear_object (&p->settings); g_clear_object (&p->ss_proxy); g_clear_object (&p->us_proxy); g_bus_unwatch_name (p->ss_watch_id); g_bus_unwatch_name (p->us_watch_id); if (p->volume_queue != NULL) { g_list_free_full (p->volume_queue, g_object_unref); p->volume_queue = NULL; } if (p->automount_idle_id != 0) { g_source_remove (p->automount_idle_id); p->automount_idle_id = 0; } } static void gsd_automount_manager_class_init (GsdAutomountManagerClass *klass) { g_type_class_add_private (klass, sizeof (GsdAutomountManagerPrivate)); } static void gsd_automount_manager_init (GsdAutomountManager *manager) { manager->priv = GSD_AUTOMOUNT_MANAGER_GET_PRIVATE (manager); } GsdAutomountManager * gsd_automount_manager_new (void) { return GSD_AUTOMOUNT_MANAGER (g_object_new (GSD_TYPE_AUTOMOUNT_MANAGER, NULL)); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/automount/gsd-automount-manager.h0000664000175000017500000000461300000000000027145 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2010 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Tomas Bzatek */ #ifndef __GSD_AUTOMOUNT_MANAGER_H #define __GSD_AUTOMOUNT_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_AUTOMOUNT_MANAGER (gsd_automount_manager_get_type ()) #define GSD_AUTOMOUNT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_AUTOMOUNT_MANAGER, GsdAutomountManager)) #define GSD_AUTOMOUNT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_AUTOMOUNT_MANAGER, GsdAutomountManagerClass)) #define GSD_IS_AUTOMOUNT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_AUTOMOUNT_MANAGER)) #define GSD_IS_AUTOMOUNT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_AUTOMOUNT_MANAGER)) #define GSD_AUTOMOUNT_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_AUTOMOUNT_MANAGER, GsdAutomountManagerClass)) typedef struct GsdAutomountManagerPrivate GsdAutomountManagerPrivate; typedef struct { GObject parent; GsdAutomountManagerPrivate *priv; } GsdAutomountManager; typedef struct { GObjectClass parent_class; } GsdAutomountManagerClass; GType gsd_automount_manager_get_type (void); GsdAutomountManager * gsd_automount_manager_new (void); gboolean gsd_automount_manager_start (GsdAutomountManager *manager, GError **error); void gsd_automount_manager_stop (GsdAutomountManager *manager); G_END_DECLS #endif /* __GSD_AUTOMOUNT_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/automount/gsd-autorun.c0000664000175000017500000007057200000000000025201 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* * gsd-automount.c: helpers for automounting hotplugged volumes * * Copyright (C) 2008, 2010 Red Hat, Inc. * * Nautilus is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Authors: David Zeuthen * Cosimo Cecchi */ #include #include #include #include #include #include #include #include #include "gsd-autorun.h" static gboolean should_autorun_mount (GMount *mount); #define CUSTOM_ITEM_ASK "gsd-item-ask" #define CUSTOM_ITEM_DO_NOTHING "gsd-item-do-nothing" #define CUSTOM_ITEM_OPEN_FOLDER "gsd-item-open-folder" typedef struct { GtkWidget *dialog; GMount *mount; gboolean should_eject; gboolean selected_ignore; gboolean selected_open_folder; GAppInfo *selected_app; gboolean remember; char *x_content_type; GsdAutorunOpenWindow open_window_func; gpointer user_data; } AutorunDialogData; static int gsd_autorun_g_strv_find (char **strv, const char *find_me) { guint index; g_return_val_if_fail (find_me != NULL, -1); for (index = 0; strv[index] != NULL; ++index) { if (strcmp (strv[index], find_me) == 0) { return index; } } return -1; } #define ICON_SIZE_STANDARD 48 static gint get_icon_size_for_stock_size (GtkIconSize size) { gint w, h; if (gtk_icon_size_lookup (size, &w, &h)) { return MAX (w, h); } return ICON_SIZE_STANDARD; } static GdkPixbuf * render_icon (GIcon *icon, gint icon_size) { GdkPixbuf *pixbuf; GtkIconInfo *info; pixbuf = NULL; if (G_IS_THEMED_ICON (icon)) { gchar const * const *names; info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), icon, icon_size, 0); if (info) { pixbuf = gtk_icon_info_load_icon (info, NULL); g_object_unref (info); } if (pixbuf == NULL) { names = g_themed_icon_get_names (G_THEMED_ICON (icon)); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), *names, icon_size, 0, NULL); } } else if (G_IS_FILE_ICON (icon)) { GFile *icon_file; gchar *path; icon_file = g_file_icon_get_file (G_FILE_ICON (icon)); path = g_file_get_path (icon_file); pixbuf = gdk_pixbuf_new_from_file_at_size (path, icon_size, icon_size, NULL); g_free (path); g_object_unref (G_OBJECT (icon_file)); } return pixbuf; } static void gsd_autorun_get_preferences (const char *x_content_type, gboolean *pref_start_app, gboolean *pref_ignore, gboolean *pref_open_folder) { GSettings *settings; char **x_content_start_app; char **x_content_ignore; char **x_content_open_folder; g_return_if_fail (pref_start_app != NULL); g_return_if_fail (pref_ignore != NULL); g_return_if_fail (pref_open_folder != NULL); settings = g_settings_new ("org.gnome.desktop.media-handling"); *pref_start_app = FALSE; *pref_ignore = FALSE; *pref_open_folder = FALSE; x_content_start_app = g_settings_get_strv (settings, "autorun-x-content-start-app"); x_content_ignore = g_settings_get_strv (settings, "autorun-x-content-ignore"); x_content_open_folder = g_settings_get_strv (settings, "autorun-x-content-open-folder"); if (x_content_start_app != NULL) { *pref_start_app = gsd_autorun_g_strv_find (x_content_start_app, x_content_type) != -1; } if (x_content_ignore != NULL) { *pref_ignore = gsd_autorun_g_strv_find (x_content_ignore, x_content_type) != -1; } if (x_content_open_folder != NULL) { *pref_open_folder = gsd_autorun_g_strv_find (x_content_open_folder, x_content_type) != -1; } g_strfreev (x_content_ignore); g_strfreev (x_content_start_app); g_strfreev (x_content_open_folder); g_object_unref (settings); } static char ** remove_elem_from_str_array (char **v, const char *s) { GPtrArray *array; guint idx; array = g_ptr_array_new (); for (idx = 0; v[idx] != NULL; idx++) { if (g_strcmp0 (v[idx], s) == 0) { continue; } g_ptr_array_add (array, v[idx]); } g_ptr_array_add (array, NULL); g_free (v); return (char **) g_ptr_array_free (array, FALSE); } static char ** add_elem_to_str_array (char **v, const char *s) { GPtrArray *array; guint idx; array = g_ptr_array_new (); for (idx = 0; v[idx] != NULL; idx++) { g_ptr_array_add (array, v[idx]); } g_ptr_array_add (array, g_strdup (s)); g_ptr_array_add (array, NULL); g_free (v); return (char **) g_ptr_array_free (array, FALSE); } static void gsd_autorun_set_preferences (const char *x_content_type, gboolean pref_start_app, gboolean pref_ignore, gboolean pref_open_folder) { GSettings *settings; char **x_content_start_app; char **x_content_ignore; char **x_content_open_folder; g_assert (x_content_type != NULL); settings = g_settings_new ("org.gnome.desktop.media-handling"); x_content_start_app = g_settings_get_strv (settings, "autorun-x-content-start-app"); x_content_ignore = g_settings_get_strv (settings, "autorun-x-content-ignore"); x_content_open_folder = g_settings_get_strv (settings, "autorun-x-content-open-folder"); x_content_start_app = remove_elem_from_str_array (x_content_start_app, x_content_type); if (pref_start_app) { x_content_start_app = add_elem_to_str_array (x_content_start_app, x_content_type); } g_settings_set_strv (settings, "autorun-x-content-start-app", (const gchar * const*) x_content_start_app); x_content_ignore = remove_elem_from_str_array (x_content_ignore, x_content_type); if (pref_ignore) { x_content_ignore = add_elem_to_str_array (x_content_ignore, x_content_type); } g_settings_set_strv (settings, "autorun-x-content-ignore", (const gchar * const*) x_content_ignore); x_content_open_folder = remove_elem_from_str_array (x_content_open_folder, x_content_type); if (pref_open_folder) { x_content_open_folder = add_elem_to_str_array (x_content_open_folder, x_content_type); } g_settings_set_strv (settings, "autorun-x-content-open-folder", (const gchar * const*) x_content_open_folder); g_strfreev (x_content_open_folder); g_strfreev (x_content_ignore); g_strfreev (x_content_start_app); g_object_unref (settings); } static void custom_item_activated_cb (GtkAppChooserButton *button, const gchar *item, gpointer user_data) { gchar *content_type; AutorunDialogData *data = user_data; content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (button)); if (g_strcmp0 (item, CUSTOM_ITEM_ASK) == 0) { gsd_autorun_set_preferences (content_type, FALSE, FALSE, FALSE); data->selected_open_folder = FALSE; data->selected_ignore = FALSE; } else if (g_strcmp0 (item, CUSTOM_ITEM_OPEN_FOLDER) == 0) { gsd_autorun_set_preferences (content_type, FALSE, FALSE, TRUE); data->selected_open_folder = TRUE; data->selected_ignore = FALSE; } else if (g_strcmp0 (item, CUSTOM_ITEM_DO_NOTHING) == 0) { gsd_autorun_set_preferences (content_type, FALSE, TRUE, FALSE); data->selected_open_folder = FALSE; data->selected_ignore = TRUE; } g_free (content_type); } static void combo_box_changed_cb (GtkComboBox *combo_box, gpointer user_data) { GAppInfo *info; AutorunDialogData *data = user_data; info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box)); if (info == NULL) return; g_clear_object (&data->selected_app); data->selected_app = info; } static void prepare_combo_box (GtkWidget *combo_box, AutorunDialogData *data) { GtkAppChooserButton *app_chooser = GTK_APP_CHOOSER_BUTTON (combo_box); GIcon *icon; gboolean pref_ask; gboolean pref_start_app; gboolean pref_ignore; gboolean pref_open_folder; GAppInfo *info; gchar *content_type; content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (app_chooser)); /* fetch preferences for this content type */ gsd_autorun_get_preferences (content_type, &pref_start_app, &pref_ignore, &pref_open_folder); pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder; info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box)); /* append the separator only if we have >= 1 apps in the chooser */ if (info != NULL) { gtk_app_chooser_button_append_separator (app_chooser); g_object_unref (info); } icon = g_themed_icon_new (GTK_STOCK_DIALOG_QUESTION); gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_ASK, _("Ask what to do"), icon); g_object_unref (icon); icon = g_themed_icon_new (GTK_STOCK_CLOSE); gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_DO_NOTHING, _("Do Nothing"), icon); g_object_unref (icon); icon = g_themed_icon_new ("folder-open"); gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_OPEN_FOLDER, _("Open Folder"), icon); g_object_unref (icon); gtk_app_chooser_button_set_show_dialog_item (app_chooser, TRUE); if (pref_ask) { gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_ASK); } else if (pref_ignore) { gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_DO_NOTHING); } else if (pref_open_folder) { gtk_app_chooser_button_set_active_custom_item (app_chooser, CUSTOM_ITEM_OPEN_FOLDER); } g_signal_connect (app_chooser, "changed", G_CALLBACK (combo_box_changed_cb), data); g_signal_connect (app_chooser, "custom-item-activated", G_CALLBACK (custom_item_activated_cb), data); g_free (content_type); } static gboolean is_shift_pressed (void) { gboolean ret; XkbStateRec state; Bool status; ret = FALSE; gdk_error_trap_push (); status = XkbGetState (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XkbUseCoreKbd, &state); gdk_error_trap_pop_ignored (); if (status == Success) { ret = state.mods & ShiftMask; } return ret; } enum { AUTORUN_DIALOG_RESPONSE_EJECT = 0 }; static void gsd_autorun_launch_for_mount (GMount *mount, GAppInfo *app_info) { GFile *root; GdkAppLaunchContext *launch_context; GError *error; gboolean result; GList *list; gchar *uri_scheme; gchar *uri; root = g_mount_get_root (mount); list = g_list_append (NULL, root); launch_context = gdk_app_launch_context_new (); error = NULL; result = g_app_info_launch (app_info, list, G_APP_LAUNCH_CONTEXT (launch_context), &error); g_object_unref (launch_context); if (!result) { if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_SUPPORTED) { uri = g_file_get_uri (root); uri_scheme = g_uri_parse_scheme (uri); /* FIXME: Present user a dialog to choose another app when the last one failed to handle a file */ g_warning ("Cannot open location: %s\n", error->message); g_free (uri_scheme); g_free (uri); } else { g_warning ("Cannot open app: %s\n", error->message); } g_error_free (error); } g_list_free (list); g_object_unref (root); } static void autorun_dialog_mount_unmounted (GMount *mount, AutorunDialogData *data); static void autorun_dialog_destroy (AutorunDialogData *data) { g_signal_handlers_disconnect_by_func (G_OBJECT (data->mount), G_CALLBACK (autorun_dialog_mount_unmounted), data); gtk_widget_destroy (GTK_WIDGET (data->dialog)); if (data->selected_app != NULL) { g_object_unref (data->selected_app); } g_object_unref (data->mount); g_free (data->x_content_type); g_free (data); } static void autorun_dialog_mount_unmounted (GMount *mount, AutorunDialogData *data) { /* remove the dialog if the media is unmounted */ autorun_dialog_destroy (data); } static void unmount_mount_callback (GObject *source_object, GAsyncResult *res, gpointer user_data) { GError *error; char *primary; gboolean unmounted; gboolean should_eject; GtkWidget *dialog; should_eject = user_data != NULL; error = NULL; if (should_eject) { unmounted = g_mount_eject_with_operation_finish (G_MOUNT (source_object), res, &error); } else { unmounted = g_mount_unmount_with_operation_finish (G_MOUNT (source_object), res, &error); } if (! unmounted) { if (error->code != G_IO_ERROR_FAILED_HANDLED) { if (should_eject) { primary = g_strdup_printf (_("Unable to eject %p"), source_object); } else { primary = g_strdup_printf (_("Unable to unmount %p"), source_object); } dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", primary); gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog), "%s", error->message); gtk_widget_show (GTK_WIDGET (dialog)); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); g_free (primary); } } if (error != NULL) { g_error_free (error); } } static void do_unmount (GMount *mount, gboolean should_eject, GtkWindow *window) { GMountOperation *mount_op; mount_op = gtk_mount_operation_new (window); if (should_eject) { g_mount_eject_with_operation (mount, 0, mount_op, NULL, unmount_mount_callback, (gpointer) 1); } else { g_mount_unmount_with_operation (mount, 0, mount_op, NULL, unmount_mount_callback, (gpointer) 0); } g_object_unref (mount_op); } static void autorun_dialog_response (GtkDialog *dialog, gint response, AutorunDialogData *data) { switch (response) { case AUTORUN_DIALOG_RESPONSE_EJECT: do_unmount (data->mount, data->should_eject, GTK_WINDOW (dialog)); break; case GTK_RESPONSE_NONE: /* window was closed */ break; case GTK_RESPONSE_CANCEL: break; case GTK_RESPONSE_OK: /* do the selected action */ if (data->remember) { /* make sure we don't ask again */ gsd_autorun_set_preferences (data->x_content_type, TRUE, data->selected_ignore, data->selected_open_folder); if (!data->selected_ignore && !data->selected_open_folder && data->selected_app != NULL) { g_app_info_set_as_default_for_type (data->selected_app, data->x_content_type, NULL); } } else { /* make sure we do ask again */ gsd_autorun_set_preferences (data->x_content_type, FALSE, FALSE, FALSE); } if (!data->selected_ignore && !data->selected_open_folder && data->selected_app != NULL) { gsd_autorun_launch_for_mount (data->mount, data->selected_app); } else if (!data->selected_ignore && data->selected_open_folder) { if (data->open_window_func != NULL) data->open_window_func (data->mount, data->user_data); } break; } autorun_dialog_destroy (data); } static void autorun_always_toggled (GtkToggleButton *togglebutton, AutorunDialogData *data) { data->remember = gtk_toggle_button_get_active (togglebutton); } static gboolean combo_box_enter_ok (GtkWidget *togglebutton, GdkEventKey *event, GtkDialog *dialog) { if (event->keyval == GDK_KEY_KP_Enter || event->keyval == GDK_KEY_Return) { gtk_dialog_response (dialog, GTK_RESPONSE_OK); return TRUE; } return FALSE; } /* returns TRUE if a folder window should be opened */ static gboolean do_autorun_for_content_type (GMount *mount, const char *x_content_type, GsdAutorunOpenWindow open_window_func, gpointer user_data) { AutorunDialogData *data; GtkWidget *dialog; GtkWidget *hbox; GtkWidget *vbox; GtkWidget *label; GtkWidget *combo_box; GtkWidget *always_check_button; GtkWidget *eject_button; GtkWidget *image; char *markup; char *content_description; char *mount_name; GIcon *icon; GdkPixbuf *pixbuf; int icon_size; gboolean user_forced_dialog; gboolean pref_ask; gboolean pref_start_app; gboolean pref_ignore; gboolean pref_open_folder; char *media_greeting; gboolean ret; ret = FALSE; mount_name = NULL; if (g_content_type_is_a (x_content_type, "x-content/win32-software")) { /* don't pop up the dialog anyway if the content type says * windows software. */ goto out; } user_forced_dialog = is_shift_pressed (); gsd_autorun_get_preferences (x_content_type, &pref_start_app, &pref_ignore, &pref_open_folder); pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder; if (user_forced_dialog) { goto show_dialog; } if (!pref_ask && !pref_ignore && !pref_open_folder) { GAppInfo *app_info; app_info = g_app_info_get_default_for_type (x_content_type, FALSE); if (app_info != NULL) { gsd_autorun_launch_for_mount (mount, app_info); } goto out; } if (pref_open_folder) { ret = TRUE; goto out; } if (pref_ignore) { goto out; } show_dialog: mount_name = g_mount_get_name (mount); dialog = gtk_dialog_new (); hbox = gtk_hbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox, TRUE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (hbox), 12); icon = g_mount_get_icon (mount); icon_size = get_icon_size_for_stock_size (GTK_ICON_SIZE_DIALOG); image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG); pixbuf = render_icon (icon, icon_size); gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0); /* also use the icon on the dialog */ gtk_window_set_title (GTK_WINDOW (dialog), mount_name); gtk_window_set_icon (GTK_WINDOW (dialog), pixbuf); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); g_object_unref (icon); if (pixbuf) { g_object_unref (pixbuf); } vbox = gtk_vbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); label = gtk_label_new (NULL); /* Customize greeting for well-known x-content types */ if (strcmp (x_content_type, "x-content/audio-cdda") == 0) { media_greeting = _("You have just inserted an Audio CD."); } else if (strcmp (x_content_type, "x-content/audio-dvd") == 0) { media_greeting = _("You have just inserted an Audio DVD."); } else if (strcmp (x_content_type, "x-content/video-dvd") == 0) { media_greeting = _("You have just inserted a Video DVD."); } else if (strcmp (x_content_type, "x-content/video-vcd") == 0) { media_greeting = _("You have just inserted a Video CD."); } else if (strcmp (x_content_type, "x-content/video-svcd") == 0) { media_greeting = _("You have just inserted a Super Video CD."); } else if (strcmp (x_content_type, "x-content/blank-cd") == 0) { media_greeting = _("You have just inserted a blank CD."); } else if (strcmp (x_content_type, "x-content/blank-dvd") == 0) { media_greeting = _("You have just inserted a blank DVD."); } else if (strcmp (x_content_type, "x-content/blank-cd") == 0) { media_greeting = _("You have just inserted a blank Blu-Ray disc."); } else if (strcmp (x_content_type, "x-content/blank-cd") == 0) { media_greeting = _("You have just inserted a blank HD DVD."); } else if (strcmp (x_content_type, "x-content/image-photocd") == 0) { media_greeting = _("You have just inserted a Photo CD."); } else if (strcmp (x_content_type, "x-content/image-picturecd") == 0) { media_greeting = _("You have just inserted a Picture CD."); } else if (strcmp (x_content_type, "x-content/image-dcf") == 0) { media_greeting = _("You have just inserted a medium with digital photos."); } else if (strcmp (x_content_type, "x-content/audio-player") == 0) { media_greeting = _("You have just inserted a digital audio player."); } else if (g_content_type_is_a (x_content_type, "x-content/software")) { media_greeting = _("You have just inserted a medium with software intended to be automatically started."); } else { /* fallback to generic greeting */ media_greeting = _("You have just inserted a medium."); } markup = g_strdup_printf ("%s %s", media_greeting, _("Choose what application to launch.")); gtk_label_set_markup (GTK_LABEL (label), markup); g_free (markup); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_label_set_max_width_chars (GTK_LABEL (label), 72); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); label = gtk_label_new (NULL); content_description = g_content_type_get_description (x_content_type); markup = g_strdup_printf (_("Select how to open \"%s\" and whether to perform this action in the future for other media of type \"%s\"."), mount_name, content_description); g_free (content_description); gtk_label_set_markup (GTK_LABEL (label), markup); g_free (markup); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_label_set_max_width_chars (GTK_LABEL (label), 72); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); data = g_new0 (AutorunDialogData, 1); data->dialog = dialog; data->mount = g_object_ref (mount); data->remember = !pref_ask; data->selected_ignore = pref_ignore; data->x_content_type = g_strdup (x_content_type); data->selected_app = g_app_info_get_default_for_type (x_content_type, FALSE); data->open_window_func = open_window_func; data->user_data = user_data; combo_box = gtk_app_chooser_button_new (x_content_type); prepare_combo_box (combo_box, data); g_signal_connect (G_OBJECT (combo_box), "key-press-event", G_CALLBACK (combo_box_enter_ok), dialog); gtk_box_pack_start (GTK_BOX (vbox), combo_box, TRUE, TRUE, 0); always_check_button = gtk_check_button_new_with_mnemonic (_("_Always perform this action")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (always_check_button), data->remember); g_signal_connect (G_OBJECT (always_check_button), "toggled", G_CALLBACK (autorun_always_toggled), data); gtk_box_pack_start (GTK_BOX (vbox), always_check_button, TRUE, TRUE, 0); gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); if (g_mount_can_eject (mount)) { GtkWidget *eject_image; eject_button = gtk_button_new_with_mnemonic (_("_Eject")); eject_image = gtk_image_new_from_icon_name ("media-eject", GTK_ICON_SIZE_BUTTON); gtk_button_set_image (GTK_BUTTON (eject_button), eject_image); data->should_eject = TRUE; } else { eject_button = gtk_button_new_with_mnemonic (_("_Unmount")); data->should_eject = FALSE; } gtk_dialog_add_action_widget (GTK_DIALOG (dialog), eject_button, AUTORUN_DIALOG_RESPONSE_EJECT); gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), eject_button, TRUE); /* show the dialog */ gtk_widget_show_all (dialog); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (autorun_dialog_response), data); g_signal_connect (G_OBJECT (data->mount), "unmounted", G_CALLBACK (autorun_dialog_mount_unmounted), data); out: g_free (mount_name); return ret; } typedef struct { GMount *mount; GsdAutorunOpenWindow open_window_func; gpointer user_data; GSettings *settings; } AutorunData; static void autorun_guessed_content_type_callback (GObject *source_object, GAsyncResult *res, gpointer user_data) { GError *error; char **guessed_content_type; AutorunData *data = user_data; gboolean open_folder; open_folder = FALSE; error = NULL; guessed_content_type = g_mount_guess_content_type_finish (G_MOUNT (source_object), res, &error); g_object_set_data_full (source_object, "gsd-content-type-cache", g_strdupv (guessed_content_type), (GDestroyNotify)g_strfreev); if (error != NULL) { g_warning ("Unable to guess content type for mount: %s", error->message); g_error_free (error); } else { if (guessed_content_type != NULL && g_strv_length (guessed_content_type) > 0) { int n; for (n = 0; guessed_content_type[n] != NULL; n++) { if (do_autorun_for_content_type (data->mount, guessed_content_type[n], data->open_window_func, data->user_data)) { open_folder = TRUE; } } g_strfreev (guessed_content_type); } else { if (g_settings_get_boolean (data->settings, "automount-open")) { open_folder = TRUE; } } } /* only open the folder once.. */ if (open_folder && data->open_window_func != NULL) { data->open_window_func (data->mount, data->user_data); } g_object_unref (data->mount); g_object_unref (data->settings); g_free (data); } void gsd_autorun (GMount *mount, GSettings *settings, GsdAutorunOpenWindow open_window_func, gpointer user_data) { AutorunData *data; if (!should_autorun_mount (mount) || g_settings_get_boolean (settings, "autorun-never")) { return; } data = g_new0 (AutorunData, 1); data->mount = g_object_ref (mount); data->open_window_func = open_window_func; data->user_data = user_data; data->settings = g_object_ref (settings); g_mount_guess_content_type (mount, FALSE, NULL, autorun_guessed_content_type_callback, data); } static gboolean remove_allow_volume (gpointer data) { GVolume *volume = data; g_object_set_data (G_OBJECT (volume), "gsd-allow-autorun", NULL); return FALSE; } void gsd_allow_autorun_for_volume (GVolume *volume) { g_object_set_data (G_OBJECT (volume), "gsd-allow-autorun", GINT_TO_POINTER (1)); } #define INHIBIT_AUTORUN_SECONDS 10 void gsd_allow_autorun_for_volume_finish (GVolume *volume) { if (g_object_get_data (G_OBJECT (volume), "gsd-allow-autorun") != NULL) { g_timeout_add_seconds_full (0, INHIBIT_AUTORUN_SECONDS, remove_allow_volume, g_object_ref (volume), g_object_unref); } } static gboolean should_skip_native_mount_root (GFile *root) { char *path; gboolean should_skip; /* skip any mounts in hidden directory hierarchies */ path = g_file_get_path (root); should_skip = strstr (path, "/.") != NULL; g_free (path); return should_skip; } static gboolean should_autorun_mount (GMount *mount) { GFile *root; GVolume *enclosing_volume; gboolean ignore_autorun; ignore_autorun = TRUE; enclosing_volume = g_mount_get_volume (mount); if (enclosing_volume != NULL) { if (g_object_get_data (G_OBJECT (enclosing_volume), "gsd-allow-autorun") != NULL) { ignore_autorun = FALSE; g_object_set_data (G_OBJECT (enclosing_volume), "gsd-allow-autorun", NULL); } } if (ignore_autorun) { if (enclosing_volume != NULL) { g_object_unref (enclosing_volume); } return FALSE; } root = g_mount_get_root (mount); /* only do autorun on local files or files where g_volume_should_automount() returns TRUE */ ignore_autorun = TRUE; if ((g_file_is_native (root) && !should_skip_native_mount_root (root)) || (enclosing_volume != NULL && g_volume_should_automount (enclosing_volume))) { ignore_autorun = FALSE; } if (enclosing_volume != NULL) { g_object_unref (enclosing_volume); } g_object_unref (root); return !ignore_autorun; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/automount/gsd-autorun.h0000664000175000017500000000316100000000000025174 0ustar00jeremyjeremy/* * gsd-automount.h:helpers for automounting hotplugged volumes * * Copyright (C) 2008 Red Hat, Inc. * * Nautilus is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Authors: David Zeuthen * Cosimo Cecchi */ /* TODO: * * - unmount all the media we've automounted on shutdown * - finish x-content / * types * - finalize the semi-spec * - add probing/sniffing code * - implement missing features * - "Open Folder when mounted" * - Autorun spec (e.g. $ROOT/.autostart) * */ #ifndef __GSD_AUTORUN_H__ #define __GSD_AUTORUN_H__ #include #include typedef void (*GsdAutorunOpenWindow) (GMount *mount, gpointer user_data); void gsd_autorun (GMount *mount, GSettings *settings, GsdAutorunOpenWindow open_window_func, gpointer user_data); void gsd_allow_autorun_for_volume (GVolume *volume); void gsd_allow_autorun_for_volume_finish (GVolume *volume); #endif /* __GSD_AUTORUN_H__ */ ././@PaxHeader0000000000000000000000000000021600000000000010214 xustar00114 path=unity-settings-daemon-15.04.1+21.10.20220207/plugins/automount/unity-fallback-mount-helper.desktop.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/automount/unity-fallback-mount-helper.desktop.i0000664000175000017500000000045500000000000031722 0ustar00jeremyjeremy[Desktop Entry] _Name=Mount Helper _Comment=Automount and autorun plugged devices Exec=@LIBEXECDIR@/unity-fallback-mount-helper Icon=drive-optical Terminal=false Type=Application Categories= NoDisplay=true OnlyShowIn=Unity; X-GNOME-Autostart-Notify=true AutostartCondition=GNOME3 unless-session gnome ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5757668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/background/0000775000175000017500000000000000000000000022636 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/background/Makefile.am0000664000175000017500000000456600000000000024705 0ustar00jeremyjeremyNULL = plugin_name = background libexec_PROGRAMS = usd-test-background usd_test_background_SOURCES = \ test-background.c \ gsd-background-manager.h \ gsd-background-manager.c \ $(NULL) usd_test_background_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) usd_test_background_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(BACKGROUND_CFLAGS) \ $(AM_CFLAGS) usd_test_background_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(SETTINGS_PLUGIN_LIBS) \ $(BACKGROUND_LIBS) \ $(NULL) libexec_PROGRAMS += gnome-update-wallpaper-cache gnome_update_wallpaper_cache_SOURCES = \ gnome-update-wallpaper-cache.c \ $(NULL) gnome_update_wallpaper_cache_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) gnome_update_wallpaper_cache_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(BACKGROUND_CFLAGS) \ $(AM_CFLAGS) gnome_update_wallpaper_cache_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(SETTINGS_PLUGIN_LIBS) \ $(BACKGROUND_LIBS) \ $(NULL) plugin_LTLIBRARIES = \ libbackground.la \ $(NULL) libbackground_la_SOURCES = \ gsd-background-plugin.c \ gsd-background-manager.h \ gsd-background-manager.c \ $(NULL) libbackground_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/background/libbackground \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) libbackground_la_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(BACKGROUND_CFLAGS) \ $(AM_CFLAGS) libbackground_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) \ $(NULL) libbackground_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(SETTINGS_PLUGIN_LIBS) \ $(BACKGROUND_LIBS) \ $(NULL) plugin_in_files = \ background.gnome-settings-plugin.in \ $(NULL) plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = \ $(plugin_in_files) \ $(NULL) CLEANFILES = \ $(plugin_DATA) \ $(NULL) DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/background/background.gnome-settings-plugin.in0000664000175000017500000000021700000000000031543 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=background IAge=0 _Name=Background _Description=Background plugin Authors= Copyright=Copyright © 2007 Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/background/gnome-update-wallpaper-cache.c0000664000175000017500000000401300000000000030413 0ustar00jeremyjeremy/* * Copyright (C) 2010 Canonical, Ltd. * * 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 version 3.0 for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Authored by Didier Roche * * Bug: https://bugs.launchpad.net/bugs/530024 */ #include "config.h" #include #include #include "gsd-bg.h" static GOptionEntry entries[] = { { NULL } }; main (int argc, char *argv[]) { GOptionContext *context = NULL; GError *error = NULL; GdkScreen *screen; GdkRectangle rect; GsdBG *bg; GSettings *settings; GdkPixbuf *pixbuf; gdk_init (&argc, &argv); context = g_option_context_new ("- refresh wallpaper cache"); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s\n", error->message); g_option_context_free(context); g_error_free (error); return (1); } if (context) g_option_context_free (context); /* cache only the first monitor */ screen = gdk_screen_get_default (); gdk_screen_get_monitor_geometry (screen, 0, &rect); bg = gsd_bg_new (); settings = g_settings_new ("org.gnome.desktop.background"); gsd_bg_load_from_preferences (bg, settings); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, rect.width, rect.height); gsd_bg_draw (bg, pixbuf, screen, FALSE); g_object_unref (settings); return (0); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/background/gsd-background-manager.c0000664000175000017500000005136300000000000027314 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright © 2001 Ximian, Inc. * Copyright (C) 2007 William Jon McCann * Copyright 2007 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "gsd-bg.h" #include "gnome-settings-bus.h" #include "gnome-settings-profile.h" #include "gsd-background-manager.h" #define GSD_BACKGROUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_BACKGROUND_MANAGER, GsdBackgroundManagerPrivate)) struct GsdBackgroundManagerPrivate { GSettings *settings; GSettings *usettings; GsdBG *bg; GsdBGCrossfade *fade; GDBusProxy *proxy; guint proxy_signal_id; }; static void gsd_background_manager_class_init (GsdBackgroundManagerClass *klass); static void gsd_background_manager_init (GsdBackgroundManager *background_manager); static void gsd_background_manager_finalize (GObject *object); static void setup_bg (GsdBackgroundManager *manager); static void connect_screen_signals (GsdBackgroundManager *manager); G_DEFINE_TYPE (GsdBackgroundManager, gsd_background_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static gboolean dont_draw_background (GsdBackgroundManager *manager) { return !g_settings_get_boolean (manager->priv->usettings, "draw-background"); } static gboolean nautilus_is_drawing_background (GsdBackgroundManager *manager) { Atom window_id_atom; Window nautilus_xid; Atom actual_type; int actual_format; unsigned long nitems; unsigned long bytes_after; unsigned char *data; Atom wmclass_atom; gboolean running; gint error; gboolean show_desktop_icons; show_desktop_icons = g_settings_get_boolean (manager->priv->settings, "show-desktop-icons"); if (! show_desktop_icons) { return FALSE; } window_id_atom = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "NAUTILUS_DESKTOP_WINDOW_ID", True); if (window_id_atom == None) { return FALSE; } XGetWindowProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_ROOT_WINDOW (), window_id_atom, 0, 1, False, XA_WINDOW, &actual_type, &actual_format, &nitems, &bytes_after, &data); if (data != NULL) { nautilus_xid = *(Window *) data; XFree (data); } else { return FALSE; } if (actual_type != XA_WINDOW) { return FALSE; } if (actual_format != 32) { return FALSE; } wmclass_atom = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "WM_CLASS", False); gdk_error_trap_push (); XGetWindowProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), nautilus_xid, wmclass_atom, 0, 24, False, XA_STRING, &actual_type, &actual_format, &nitems, &bytes_after, &data); error = gdk_error_trap_pop (); if (error == BadWindow) { return FALSE; } if (actual_type == XA_STRING && nitems == 24 && bytes_after == 0 && actual_format == 8 && data != NULL && !strcmp ((char *)data, "desktop_window") && !strcmp ((char *)data + strlen ((char *)data) + 1, "Nautilus")) { running = TRUE; } else { running = FALSE; } if (data != NULL) { XFree (data); } return running; } static void on_crossfade_finished (GsdBackgroundManager *manager) { g_object_unref (manager->priv->fade); manager->priv->fade = NULL; } static void draw_background (GsdBackgroundManager *manager, gboolean use_crossfade) { GdkDisplay *display; int n_screens; int i; if (nautilus_is_drawing_background (manager) || dont_draw_background (manager)) { return; } gnome_settings_profile_start (NULL); display = gdk_display_get_default (); n_screens = gdk_display_get_n_screens (display); for (i = 0; i < n_screens; ++i) { GdkScreen *screen; GdkWindow *root_window; cairo_surface_t *surface; screen = gdk_display_get_screen (display, i); root_window = gdk_screen_get_root_window (screen); surface = gsd_bg_create_surface (manager->priv->bg, root_window, gdk_screen_get_width (screen), gdk_screen_get_height (screen), TRUE); if (use_crossfade) { if (manager->priv->fade != NULL) { g_object_unref (manager->priv->fade); } manager->priv->fade = gsd_bg_set_surface_as_root_with_crossfade (screen, surface); g_signal_connect_swapped (manager->priv->fade, "finished", G_CALLBACK (on_crossfade_finished), manager); } else { gsd_bg_set_surface_as_root (screen, surface); } cairo_surface_destroy (surface); } gnome_settings_profile_end (NULL); } static void on_bg_transitioned (GsdBG *bg, GsdBackgroundManager *manager) { draw_background (manager, FALSE); } static gboolean settings_change_event_cb (GSettings *settings, gpointer keys, gint n_keys, GsdBackgroundManager *manager) { gsd_bg_load_from_preferences (manager->priv->bg, manager->priv->settings); return FALSE; } static void on_screen_size_changed (GdkScreen *screen, GsdBackgroundManager *manager) { draw_background (manager, FALSE); } static void watch_bg_preferences (GsdBackgroundManager *manager) { g_signal_connect (manager->priv->settings, "change-event", G_CALLBACK (settings_change_event_cb), manager); } static void on_bg_changed (GsdBG *bg, GsdBackgroundManager *manager) { draw_background (manager, TRUE); } static void setup_bg (GsdBackgroundManager *manager) { g_return_if_fail (manager->priv->bg == NULL); manager->priv->bg = gsd_bg_new (); g_signal_connect (manager->priv->bg, "changed", G_CALLBACK (on_bg_changed), manager); g_signal_connect (manager->priv->bg, "transitioned", G_CALLBACK (on_bg_transitioned), manager); connect_screen_signals (manager); watch_bg_preferences (manager); gsd_bg_load_from_preferences (manager->priv->bg, manager->priv->settings); } static void setup_bg_and_draw_background (GsdBackgroundManager *manager) { setup_bg (manager); draw_background (manager, FALSE); } static void disconnect_session_manager_listener (GsdBackgroundManager *manager) { if (manager->priv->proxy && manager->priv->proxy_signal_id) { g_signal_handler_disconnect (manager->priv->proxy, manager->priv->proxy_signal_id); manager->priv->proxy_signal_id = 0; } } static void on_session_manager_signal (GDBusProxy *proxy, const gchar *sender_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { GsdBackgroundManager *manager = GSD_BACKGROUND_MANAGER (user_data); if (g_strcmp0 (signal_name, "SessionRunning") == 0) { setup_bg_and_draw_background (manager); disconnect_session_manager_listener (manager); } } static void draw_background_after_session_loads (GsdBackgroundManager *manager) { manager->priv->proxy = G_DBUS_PROXY (gnome_settings_bus_get_session_proxy ()); manager->priv->proxy_signal_id = g_signal_connect (manager->priv->proxy, "g-signal", G_CALLBACK (on_session_manager_signal), manager); } static void disconnect_screen_signals (GsdBackgroundManager *manager) { GdkDisplay *display; int i; int n_screens; display = gdk_display_get_default (); n_screens = gdk_display_get_n_screens (display); for (i = 0; i < n_screens; ++i) { GdkScreen *screen; screen = gdk_display_get_screen (display, i); g_signal_handlers_disconnect_by_func (screen, G_CALLBACK (on_screen_size_changed), manager); } } static void connect_screen_signals (GsdBackgroundManager *manager) { GdkDisplay *display; int i; int n_screens; display = gdk_display_get_default (); n_screens = gdk_display_get_n_screens (display); for (i = 0; i < n_screens; ++i) { GdkScreen *screen; screen = gdk_display_get_screen (display, i); g_signal_connect (screen, "monitors-changed", G_CALLBACK (on_screen_size_changed), manager); g_signal_connect (screen, "size-changed", G_CALLBACK (on_screen_size_changed), manager); } } static void draw_background_changed (GSettings *settings, const char *key, GsdBackgroundManager *manager) { if (dont_draw_background (manager) == FALSE) setup_bg_and_draw_background (manager); } static void set_accountsservice_background (const gchar *background) { GDBusConnection *bus; GVariant *variant; GError *error = NULL; gchar *object_path = NULL; bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (bus == NULL) { g_warning ("Failed to get system bus: %s", error->message); g_error_free (error); return; } variant = g_dbus_connection_call_sync (bus, "org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts", "FindUserByName", g_variant_new ("(s)", g_get_user_name ()), G_VARIANT_TYPE ("(o)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (variant == NULL) { g_warning ("Could not contact accounts service to look up '%s': %s", g_get_user_name (), error->message); g_error_free (error); g_object_unref (bus); return; } g_variant_get (variant, "(o)", &object_path); g_variant_unref (variant); variant = g_dbus_connection_call_sync (bus, "org.freedesktop.Accounts", object_path, "org.freedesktop.DBus.Properties", "Set", g_variant_new ("(ssv)", "org.freedesktop.DisplayManager.AccountsService", "BackgroundFile", g_variant_new_string (background ? background : "")), G_VARIANT_TYPE ("()"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (variant != NULL) g_variant_unref (variant); else { g_warning ("Failed to set the background '%s': %s", background, error->message); g_clear_error (&error); } /* Also attempt the old method (patch not upstreamed into AccountsService */ variant = g_dbus_connection_call_sync (bus, "org.freedesktop.Accounts", object_path, "org.freedesktop.Accounts.User", "SetBackgroundFile", g_variant_new ("(s)", background ? background : ""), G_VARIANT_TYPE ("()"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (variant != NULL) g_variant_unref (variant); else { g_warning ("Failed to set the background '%s': %s", background, error->message); g_clear_error (&error); } g_object_unref (bus); } static void picture_uri_changed (GSettings *settings, const char *key, GsdBackgroundManager *manager) { const char *picture_uri = g_settings_get_string (settings, key); GFile *picture_file = g_file_new_for_uri (picture_uri); char *picture_path = g_file_get_path (picture_file); set_accountsservice_background (picture_path); g_free (picture_path); g_object_unref (picture_file); } gboolean gsd_background_manager_start (GsdBackgroundManager *manager, GError **error) { gboolean show_desktop_icons; g_debug ("Starting background manager"); gnome_settings_profile_start (NULL); manager->priv->settings = g_settings_new ("org.gnome.desktop.background"); manager->priv->usettings = g_settings_new ("com.canonical.unity.desktop.background"); g_signal_connect (manager->priv->usettings, "changed::draw-background", G_CALLBACK (draw_background_changed), manager); g_signal_connect (manager->priv->settings, "changed::picture-uri", G_CALLBACK (picture_uri_changed), manager); /* If this is set, nautilus will draw the background and is * almost definitely in our session. however, it may not be * running yet (so is_nautilus_running() will fail). so, on * startup, just don't do anything if this key is set so we * don't waste time setting the background only to have * nautilus overwrite it. */ show_desktop_icons = g_settings_get_boolean (manager->priv->settings, "show-desktop-icons"); if (!show_desktop_icons) { setup_bg (manager); } else { draw_background_after_session_loads (manager); } gnome_settings_profile_end (NULL); return TRUE; } void gsd_background_manager_stop (GsdBackgroundManager *manager) { GsdBackgroundManagerPrivate *p = manager->priv; g_debug ("Stopping background manager"); disconnect_screen_signals (manager); if (manager->priv->proxy) { disconnect_session_manager_listener (manager); g_clear_object (&manager->priv->proxy); } g_signal_handlers_disconnect_by_func (manager->priv->settings, settings_change_event_cb, manager); g_signal_handlers_disconnect_by_func (manager->priv->usettings, settings_change_event_cb, manager); if (p->settings != NULL) { g_object_unref (p->settings); p->settings = NULL; } if (p->usettings != NULL) { g_object_unref (p->usettings); p->usettings = NULL; } if (p->bg != NULL) { g_object_unref (p->bg); p->bg = NULL; } } static GObject * gsd_background_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { GsdBackgroundManager *background_manager; background_manager = GSD_BACKGROUND_MANAGER (G_OBJECT_CLASS (gsd_background_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); return G_OBJECT (background_manager); } static void gsd_background_manager_class_init (GsdBackgroundManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructor = gsd_background_manager_constructor; object_class->finalize = gsd_background_manager_finalize; g_type_class_add_private (klass, sizeof (GsdBackgroundManagerPrivate)); } static void gsd_background_manager_init (GsdBackgroundManager *manager) { manager->priv = GSD_BACKGROUND_MANAGER_GET_PRIVATE (manager); } static void gsd_background_manager_finalize (GObject *object) { GsdBackgroundManager *background_manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_BACKGROUND_MANAGER (object)); background_manager = GSD_BACKGROUND_MANAGER (object); g_return_if_fail (background_manager->priv != NULL); G_OBJECT_CLASS (gsd_background_manager_parent_class)->finalize (object); } GsdBackgroundManager * gsd_background_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_BACKGROUND_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_BACKGROUND_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/background/gsd-background-manager.h0000664000175000017500000000462300000000000027316 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_BACKGROUND_MANAGER_H #define __GSD_BACKGROUND_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_BACKGROUND_MANAGER (gsd_background_manager_get_type ()) #define GSD_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_BACKGROUND_MANAGER, GsdBackgroundManager)) #define GSD_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_BACKGROUND_MANAGER, GsdBackgroundManagerClass)) #define GSD_IS_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_BACKGROUND_MANAGER)) #define GSD_IS_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_BACKGROUND_MANAGER)) #define GSD_BACKGROUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_BACKGROUND_MANAGER, GsdBackgroundManagerClass)) typedef struct GsdBackgroundManagerPrivate GsdBackgroundManagerPrivate; typedef struct { GObject parent; GsdBackgroundManagerPrivate *priv; } GsdBackgroundManager; typedef struct { GObjectClass parent_class; } GsdBackgroundManagerClass; GType gsd_background_manager_get_type (void); GsdBackgroundManager * gsd_background_manager_new (void); gboolean gsd_background_manager_start (GsdBackgroundManager *manager, GError **error); void gsd_background_manager_stop (GsdBackgroundManager *manager); G_END_DECLS #endif /* __GSD_BACKGROUND_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/background/gsd-background-plugin.c0000664000175000017500000000203400000000000027167 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-background-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdBackground, gsd_background) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/background/test-background.c0000664000175000017500000000033600000000000026100 0ustar00jeremyjeremy#define NEW gsd_background_manager_new #define START gsd_background_manager_start #define STOP gsd_background_manager_stop #define MANAGER GsdBackgroundManager #include "gsd-background-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5757668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/clipboard/0000775000175000017500000000000000000000000022456 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/clipboard/Makefile.am0000664000175000017500000000174400000000000024520 0ustar00jeremyjeremyNULL = plugin_name = clipboard plugin_LTLIBRARIES = \ libclipboard.la \ $(NULL) libclipboard_la_SOURCES = \ gsd-clipboard-plugin.c \ gsd-clipboard-manager.h \ gsd-clipboard-manager.c \ xutils.h \ xutils.c \ list.h \ list.c \ $(NULL) libclipboard_la_CPPFLAGS = \ $(PLUGIN_CFLAGS) \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) libclipboard_la_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) libclipboard_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) \ $(NULL) libclipboard_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(SETTINGS_PLUGIN_LIBS) \ $(NULL) plugin_in_files = \ clipboard.gnome-settings-plugin.in \ $(NULL) plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = \ $(plugin_in_files) \ $(NULL) CLEANFILES = \ $(plugin_DATA) \ $(NULL) DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/clipboard/clipboard.gnome-settings-plugin.in0000664000175000017500000000031500000000000031202 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=clipboard IAge=0 # Default Priority # Priority=100 _Name=Clipboard _Description=Clipboard plugin Authors=Matthias Clasen Copyright=Copyright © 2007 Matthias Clasen Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/clipboard/gsd-clipboard-manager.c0000664000175000017500000011642600000000000026756 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 Matthias Clasen * Copyright (C) 2007 Anders Carlsson * Copyright (C) 2007 Rodrigo Moya * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "xutils.h" #include "list.h" #include "gnome-settings-profile.h" #include "gsd-clipboard-manager.h" #define GSD_CLIPBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManagerPrivate)) struct GsdClipboardManagerPrivate { guint start_idle_id; Display *display; Window window; Time timestamp; List *contents; List *conversions; Window requestor; Atom property; Time time; }; typedef struct { unsigned char *data; int length; Atom target; Atom type; int format; int refcount; } TargetData; typedef struct { Atom target; TargetData *data; Atom property; Window requestor; int offset; } IncrConversion; static void gsd_clipboard_manager_class_init (GsdClipboardManagerClass *klass); static void gsd_clipboard_manager_init (GsdClipboardManager *clipboard_manager); static void gsd_clipboard_manager_finalize (GObject *object); static void clipboard_manager_watch_cb (GsdClipboardManager *manager, Window window, Bool is_start, long mask, void *cb_data); G_DEFINE_TYPE (GsdClipboardManager, gsd_clipboard_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; /* We need to use reference counting for the target data, since we may * need to keep the data around after loosing the CLIPBOARD ownership * to complete incremental transfers. */ static TargetData * target_data_ref (TargetData *data) { data->refcount++; return data; } static void target_data_unref (TargetData *data) { data->refcount--; if (data->refcount == 0) { free (data->data); free (data); } } static void conversion_free (IncrConversion *rdata) { if (rdata->data) { target_data_unref (rdata->data); } free (rdata); } static void send_selection_notify (GsdClipboardManager *manager, Bool success) { XSelectionEvent notify; notify.type = SelectionNotify; notify.serial = 0; notify.send_event = True; notify.display = manager->priv->display; notify.requestor = manager->priv->requestor; notify.selection = XA_CLIPBOARD_MANAGER; notify.target = XA_SAVE_TARGETS; notify.property = success ? manager->priv->property : None; notify.time = manager->priv->time; gdk_error_trap_push (); XSendEvent (manager->priv->display, manager->priv->requestor, False, NoEventMask, (XEvent *)¬ify); XSync (manager->priv->display, False); gdk_error_trap_pop_ignored (); } static void finish_selection_request (GsdClipboardManager *manager, XEvent *xev, Bool success) { XSelectionEvent notify; notify.type = SelectionNotify; notify.serial = 0; notify.send_event = True; notify.display = xev->xselectionrequest.display; notify.requestor = xev->xselectionrequest.requestor; notify.selection = xev->xselectionrequest.selection; notify.target = xev->xselectionrequest.target; notify.property = success ? xev->xselectionrequest.property : None; notify.time = xev->xselectionrequest.time; gdk_error_trap_push (); XSendEvent (xev->xselectionrequest.display, xev->xselectionrequest.requestor, False, NoEventMask, (XEvent *) ¬ify); XSync (manager->priv->display, False); gdk_error_trap_pop_ignored (); } static int clipboard_bytes_per_item (int format) { switch (format) { case 8: return sizeof (char); case 16: return sizeof (short); case 32: return sizeof (long); default: ; } return 0; } static void save_targets (GsdClipboardManager *manager, Atom *save_targets, int nitems) { int nout, i; Atom *multiple; TargetData *tdata; multiple = (Atom *) malloc (2 * nitems * sizeof (Atom)); nout = 0; for (i = 0; i < nitems; i++) { if (save_targets[i] != XA_TARGETS && save_targets[i] != XA_MULTIPLE && save_targets[i] != XA_DELETE && save_targets[i] != XA_INSERT_PROPERTY && save_targets[i] != XA_INSERT_SELECTION && save_targets[i] != XA_PIXMAP) { tdata = (TargetData *) malloc (sizeof (TargetData)); tdata->data = NULL; tdata->length = 0; tdata->target = save_targets[i]; tdata->type = None; tdata->format = 0; tdata->refcount = 1; manager->priv->contents = list_prepend (manager->priv->contents, tdata); multiple[nout++] = save_targets[i]; multiple[nout++] = save_targets[i]; } } XFree (save_targets); XChangeProperty (manager->priv->display, manager->priv->window, XA_MULTIPLE, XA_ATOM_PAIR, 32, PropModeReplace, (const unsigned char *) multiple, nout); free (multiple); XConvertSelection (manager->priv->display, XA_CLIPBOARD, XA_MULTIPLE, XA_MULTIPLE, manager->priv->window, manager->priv->time); } static int find_content_target (TargetData *tdata, Atom target) { return tdata->target == target; } static int find_content_type (TargetData *tdata, Atom type) { return tdata->type == type; } static int find_conversion_requestor (IncrConversion *rdata, XEvent *xev) { return (rdata->requestor == xev->xproperty.window && rdata->property == xev->xproperty.atom); } static void get_property (TargetData *tdata, GsdClipboardManager *manager) { Atom type; int format; unsigned long length; unsigned long remaining; unsigned char *data; XGetWindowProperty (manager->priv->display, manager->priv->window, tdata->target, 0, 0x1FFFFFFF, True, AnyPropertyType, &type, &format, &length, &remaining, &data); if (type == None) { manager->priv->contents = list_remove (manager->priv->contents, tdata); free (tdata); } else if (type == XA_INCR) { tdata->type = type; tdata->length = 0; XFree (data); } else { tdata->type = type; tdata->data = data; tdata->length = length * clipboard_bytes_per_item (format); tdata->format = format; } } static Bool receive_incrementally (GsdClipboardManager *manager, XEvent *xev) { List *list; TargetData *tdata; Atom type; int format; unsigned long length, nitems, remaining; unsigned char *data; if (xev->xproperty.window != manager->priv->window) return False; list = list_find (manager->priv->contents, (ListFindFunc) find_content_target, (void *) xev->xproperty.atom); if (!list) return False; tdata = (TargetData *) list->data; if (tdata->type != XA_INCR) return False; XGetWindowProperty (xev->xproperty.display, xev->xproperty.window, xev->xproperty.atom, 0, 0x1FFFFFFF, True, AnyPropertyType, &type, &format, &nitems, &remaining, &data); length = nitems * clipboard_bytes_per_item (format); if (length == 0) { tdata->type = type; tdata->format = format; if (!list_find (manager->priv->contents, (ListFindFunc) find_content_type, (void *)XA_INCR)) { /* all incremental transfers done */ send_selection_notify (manager, True); manager->priv->requestor = None; } XFree (data); } else { if (!tdata->data) { tdata->data = data; tdata->length = length; } else { tdata->data = realloc (tdata->data, tdata->length + length + 1); memcpy (tdata->data + tdata->length, data, length + 1); tdata->length += length; XFree (data); } } return True; } static Bool send_incrementally (GsdClipboardManager *manager, XEvent *xev) { List *list; IncrConversion *rdata; unsigned long length; unsigned long items; unsigned char *data; list = list_find (manager->priv->conversions, (ListFindFunc) find_conversion_requestor, xev); if (list == NULL) return False; rdata = (IncrConversion *) list->data; data = rdata->data->data + rdata->offset; length = rdata->data->length - rdata->offset; if (length > SELECTION_MAX_SIZE) length = SELECTION_MAX_SIZE; rdata->offset += length; items = length / clipboard_bytes_per_item (rdata->data->format); XChangeProperty (manager->priv->display, rdata->requestor, rdata->property, rdata->data->type, rdata->data->format, PropModeAppend, data, items); if (length == 0) { clipboard_manager_watch_cb (manager, rdata->requestor, False, PropertyChangeMask, NULL); manager->priv->conversions = list_remove (manager->priv->conversions, rdata); conversion_free (rdata); } return True; } static void convert_clipboard_manager (GsdClipboardManager *manager, XEvent *xev) { Atom type = None; int format; unsigned long nitems; unsigned long remaining; Atom *targets = NULL; if (xev->xselectionrequest.target == XA_SAVE_TARGETS) { if (manager->priv->requestor != None || manager->priv->contents != NULL) { /* We're in the middle of a conversion request, or own * the CLIPBOARD already */ finish_selection_request (manager, xev, False); } else { gdk_error_trap_push (); clipboard_manager_watch_cb (manager, xev->xselectionrequest.requestor, True, StructureNotifyMask, NULL); XSelectInput (manager->priv->display, xev->xselectionrequest.requestor, StructureNotifyMask); XSync (manager->priv->display, False); if (gdk_error_trap_pop () != Success) return; gdk_error_trap_push (); if (xev->xselectionrequest.property != None) { XGetWindowProperty (manager->priv->display, xev->xselectionrequest.requestor, xev->xselectionrequest.property, 0, 0x1FFFFFFF, False, XA_ATOM, &type, &format, &nitems, &remaining, (unsigned char **) &targets); if (gdk_error_trap_pop () != Success) { if (targets) XFree (targets); return; } } manager->priv->requestor = xev->xselectionrequest.requestor; manager->priv->property = xev->xselectionrequest.property; manager->priv->time = xev->xselectionrequest.time; if (type == None) XConvertSelection (manager->priv->display, XA_CLIPBOARD, XA_TARGETS, XA_TARGETS, manager->priv->window, manager->priv->time); else save_targets (manager, targets, nitems); } } else if (xev->xselectionrequest.target == XA_TIMESTAMP) { XChangeProperty (manager->priv->display, xev->xselectionrequest.requestor, xev->xselectionrequest.property, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &manager->priv->timestamp, 1); finish_selection_request (manager, xev, True); } else if (xev->xselectionrequest.target == XA_TARGETS) { int n_targets = 0; Atom targets[3]; targets[n_targets++] = XA_TARGETS; targets[n_targets++] = XA_TIMESTAMP; targets[n_targets++] = XA_SAVE_TARGETS; XChangeProperty (manager->priv->display, xev->xselectionrequest.requestor, xev->xselectionrequest.property, XA_ATOM, 32, PropModeReplace, (unsigned char *) targets, n_targets); finish_selection_request (manager, xev, True); } else finish_selection_request (manager, xev, False); } static void convert_clipboard_target (IncrConversion *rdata, GsdClipboardManager *manager) { TargetData *tdata; Atom *targets; int n_targets; List *list; unsigned long items; XWindowAttributes atts; if (rdata->target == XA_TARGETS) { n_targets = list_length (manager->priv->contents) + 2; targets = (Atom *) malloc (n_targets * sizeof (Atom)); n_targets = 0; targets[n_targets++] = XA_TARGETS; targets[n_targets++] = XA_MULTIPLE; for (list = manager->priv->contents; list; list = list->next) { tdata = (TargetData *) list->data; targets[n_targets++] = tdata->target; } XChangeProperty (manager->priv->display, rdata->requestor, rdata->property, XA_ATOM, 32, PropModeReplace, (unsigned char *) targets, n_targets); free (targets); } else { /* Convert from stored CLIPBOARD data */ list = list_find (manager->priv->contents, (ListFindFunc) find_content_target, (void *) rdata->target); /* We got a target that we don't support */ if (!list) return; tdata = (TargetData *)list->data; if (tdata->type == XA_INCR) { /* we haven't completely received this target yet */ rdata->property = None; return; } rdata->data = target_data_ref (tdata); items = tdata->length / clipboard_bytes_per_item (tdata->format); if (tdata->length <= SELECTION_MAX_SIZE) XChangeProperty (manager->priv->display, rdata->requestor, rdata->property, tdata->type, tdata->format, PropModeReplace, tdata->data, items); else { /* start incremental transfer */ rdata->offset = 0; gdk_error_trap_push (); XGetWindowAttributes (manager->priv->display, rdata->requestor, &atts); clipboard_manager_watch_cb (manager, rdata->requestor, True, PropertyChangeMask, NULL); XSelectInput (manager->priv->display, rdata->requestor, atts.your_event_mask | PropertyChangeMask); XChangeProperty (manager->priv->display, rdata->requestor, rdata->property, XA_INCR, 32, PropModeReplace, (unsigned char *) &items, 1); XSync (manager->priv->display, False); gdk_error_trap_pop_ignored (); } } } static void collect_incremental (IncrConversion *rdata, GsdClipboardManager *manager) { if (rdata->offset >= 0) manager->priv->conversions = list_prepend (manager->priv->conversions, rdata); else { if (rdata->data) { target_data_unref (rdata->data); rdata->data = NULL; } free (rdata); } } static void convert_clipboard (GsdClipboardManager *manager, XEvent *xev) { List *list; List *conversions; IncrConversion *rdata; Atom type; int i; int format; unsigned long nitems; unsigned long remaining; Atom *multiple; conversions = NULL; type = None; if (xev->xselectionrequest.target == XA_MULTIPLE) { XGetWindowProperty (xev->xselectionrequest.display, xev->xselectionrequest.requestor, xev->xselectionrequest.property, 0, 0x1FFFFFFF, False, XA_ATOM_PAIR, &type, &format, &nitems, &remaining, (unsigned char **) &multiple); if (type != XA_ATOM_PAIR || nitems == 0) { if (multiple) free (multiple); return; } for (i = 0; i < nitems; i += 2) { rdata = (IncrConversion *) malloc (sizeof (IncrConversion)); rdata->requestor = xev->xselectionrequest.requestor; rdata->target = multiple[i]; rdata->property = multiple[i+1]; rdata->data = NULL; rdata->offset = -1; conversions = list_prepend (conversions, rdata); } } else { multiple = NULL; rdata = (IncrConversion *) malloc (sizeof (IncrConversion)); rdata->requestor = xev->xselectionrequest.requestor; rdata->target = xev->xselectionrequest.target; rdata->property = xev->xselectionrequest.property; rdata->data = NULL; rdata->offset = -1; conversions = list_prepend (conversions, rdata); } list_foreach (conversions, (Callback) convert_clipboard_target, manager); if (conversions->next == NULL && ((IncrConversion *) conversions->data)->property == None) { finish_selection_request (manager, xev, False); } else { if (multiple) { i = 0; for (list = conversions; list; list = list->next) { rdata = (IncrConversion *)list->data; multiple[i++] = rdata->target; multiple[i++] = rdata->property; } XChangeProperty (xev->xselectionrequest.display, xev->xselectionrequest.requestor, xev->xselectionrequest.property, XA_ATOM_PAIR, 32, PropModeReplace, (unsigned char *) multiple, nitems); } finish_selection_request (manager, xev, True); } list_foreach (conversions, (Callback) collect_incremental, manager); list_free (conversions); if (multiple) free (multiple); } static Bool clipboard_manager_process_event (GsdClipboardManager *manager, XEvent *xev) { Atom type; int format; unsigned long nitems; unsigned long remaining; Atom *targets; targets = NULL; switch (xev->xany.type) { case DestroyNotify: if (xev->xdestroywindow.window == manager->priv->requestor) { list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); list_free (manager->priv->contents); manager->priv->contents = NULL; clipboard_manager_watch_cb (manager, manager->priv->requestor, False, 0, NULL); manager->priv->requestor = None; } break; case PropertyNotify: if (xev->xproperty.state == PropertyNewValue) { return receive_incrementally (manager, xev); } else { return send_incrementally (manager, xev); } case SelectionClear: if (xev->xany.window != manager->priv->window) return False; if (xev->xselectionclear.selection == XA_CLIPBOARD_MANAGER) { /* We lost the manager selection */ if (manager->priv->contents) { list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); list_free (manager->priv->contents); manager->priv->contents = NULL; XSetSelectionOwner (manager->priv->display, XA_CLIPBOARD, None, manager->priv->time); } return True; } if (xev->xselectionclear.selection == XA_CLIPBOARD) { /* We lost the clipboard selection */ list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); list_free (manager->priv->contents); manager->priv->contents = NULL; clipboard_manager_watch_cb (manager, manager->priv->requestor, False, 0, NULL); manager->priv->requestor = None; return True; } break; case SelectionNotify: if (xev->xany.window != manager->priv->window) return False; if (xev->xselection.selection == XA_CLIPBOARD) { /* a CLIPBOARD conversion is done */ if (xev->xselection.property == XA_TARGETS) { XGetWindowProperty (xev->xselection.display, xev->xselection.requestor, xev->xselection.property, 0, 0x1FFFFFFF, True, XA_ATOM, &type, &format, &nitems, &remaining, (unsigned char **) &targets); save_targets (manager, targets, nitems); } else if (xev->xselection.property == XA_MULTIPLE) { List *tmp; tmp = list_copy (manager->priv->contents); list_foreach (tmp, (Callback) get_property, manager); list_free (tmp); manager->priv->time = xev->xselection.time; XSetSelectionOwner (manager->priv->display, XA_CLIPBOARD, manager->priv->window, manager->priv->time); if (manager->priv->property != None) XChangeProperty (manager->priv->display, manager->priv->requestor, manager->priv->property, XA_ATOM, 32, PropModeReplace, (unsigned char *)&XA_NULL, 1); if (!list_find (manager->priv->contents, (ListFindFunc)find_content_type, (void *)XA_INCR)) { /* all transfers done */ send_selection_notify (manager, True); clipboard_manager_watch_cb (manager, manager->priv->requestor, False, 0, NULL); manager->priv->requestor = None; } } else if (xev->xselection.property == None) { send_selection_notify (manager, False); clipboard_manager_watch_cb (manager, manager->priv->requestor, False, 0, NULL); manager->priv->requestor = None; } return True; } break; case SelectionRequest: if (xev->xany.window != manager->priv->window) { return False; } if (xev->xselectionrequest.selection == XA_CLIPBOARD_MANAGER) { convert_clipboard_manager (manager, xev); return True; } else if (xev->xselectionrequest.selection == XA_CLIPBOARD) { convert_clipboard (manager, xev); return True; } break; default: ; } return False; } static GdkFilterReturn clipboard_manager_event_filter (GdkXEvent *xevent, GdkEvent *event, GsdClipboardManager *manager) { if (clipboard_manager_process_event (manager, (XEvent *)xevent)) { return GDK_FILTER_REMOVE; } else { return GDK_FILTER_CONTINUE; } } static void clipboard_manager_watch_cb (GsdClipboardManager *manager, Window window, Bool is_start, long mask, void *cb_data) { GdkWindow *gdkwin; GdkDisplay *display; display = gdk_display_get_default (); gdkwin = gdk_x11_window_lookup_for_display (display, window); if (is_start) { if (gdkwin == NULL) { gdkwin = gdk_x11_window_foreign_new_for_display (display, window); } else { g_object_ref (gdkwin); } gdk_window_add_filter (gdkwin, (GdkFilterFunc)clipboard_manager_event_filter, manager); } else { if (gdkwin == NULL) { return; } gdk_window_remove_filter (gdkwin, (GdkFilterFunc)clipboard_manager_event_filter, manager); g_object_unref (gdkwin); } } static gboolean start_clipboard_idle_cb (GsdClipboardManager *manager) { XClientMessageEvent xev; gnome_settings_profile_start (NULL); init_atoms (manager->priv->display); /* check if there is a clipboard manager running */ if (XGetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER)) { g_warning ("Clipboard manager is already running."); return FALSE; } manager->priv->contents = NULL; manager->priv->conversions = NULL; manager->priv->requestor = None; manager->priv->window = XCreateSimpleWindow (manager->priv->display, DefaultRootWindow (manager->priv->display), 0, 0, 10, 10, 0, WhitePixel (manager->priv->display, DefaultScreen (manager->priv->display)), WhitePixel (manager->priv->display, DefaultScreen (manager->priv->display))); clipboard_manager_watch_cb (manager, manager->priv->window, True, PropertyChangeMask, NULL); XSelectInput (manager->priv->display, manager->priv->window, PropertyChangeMask); manager->priv->timestamp = get_server_time (manager->priv->display, manager->priv->window); XSetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER, manager->priv->window, manager->priv->timestamp); /* Check to see if we managed to claim the selection. If not, * we treat it as if we got it then immediately lost it */ if (XGetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER) == manager->priv->window) { xev.type = ClientMessage; xev.window = DefaultRootWindow (manager->priv->display); xev.message_type = XA_MANAGER; xev.format = 32; xev.data.l[0] = manager->priv->timestamp; xev.data.l[1] = XA_CLIPBOARD_MANAGER; xev.data.l[2] = manager->priv->window; xev.data.l[3] = 0; /* manager specific data */ xev.data.l[4] = 0; /* manager specific data */ XSendEvent (manager->priv->display, DefaultRootWindow (manager->priv->display), False, StructureNotifyMask, (XEvent *)&xev); } else { clipboard_manager_watch_cb (manager, manager->priv->window, False, 0, NULL); /* FIXME: manager->priv->terminate (manager->priv->cb_data); */ } gnome_settings_profile_end (NULL); manager->priv->start_idle_id = 0; return FALSE; } gboolean gsd_clipboard_manager_start (GsdClipboardManager *manager, GError **error) { gnome_settings_profile_start (NULL); manager->priv->start_idle_id = g_idle_add ((GSourceFunc) start_clipboard_idle_cb, manager); gnome_settings_profile_end (NULL); return TRUE; } void gsd_clipboard_manager_stop (GsdClipboardManager *manager) { g_debug ("Stopping clipboard manager"); if (manager->priv->window != None) { clipboard_manager_watch_cb (manager, manager->priv->window, FALSE, 0, NULL); XDestroyWindow (manager->priv->display, manager->priv->window); manager->priv->window = None; } if (manager->priv->conversions != NULL) { list_foreach (manager->priv->conversions, (Callback) conversion_free, NULL); list_free (manager->priv->conversions); manager->priv->conversions = NULL; } if (manager->priv->contents != NULL) { list_foreach (manager->priv->contents, (Callback) target_data_unref, NULL); list_free (manager->priv->contents); manager->priv->contents = NULL; } } static GObject * gsd_clipboard_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { GsdClipboardManager *clipboard_manager; clipboard_manager = GSD_CLIPBOARD_MANAGER (G_OBJECT_CLASS (gsd_clipboard_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); return G_OBJECT (clipboard_manager); } static void gsd_clipboard_manager_class_init (GsdClipboardManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructor = gsd_clipboard_manager_constructor; object_class->finalize = gsd_clipboard_manager_finalize; g_type_class_add_private (klass, sizeof (GsdClipboardManagerPrivate)); } static void gsd_clipboard_manager_init (GsdClipboardManager *manager) { manager->priv = GSD_CLIPBOARD_MANAGER_GET_PRIVATE (manager); manager->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); } static void gsd_clipboard_manager_finalize (GObject *object) { GsdClipboardManager *clipboard_manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_CLIPBOARD_MANAGER (object)); clipboard_manager = GSD_CLIPBOARD_MANAGER (object); g_return_if_fail (clipboard_manager->priv != NULL); if (clipboard_manager->priv->start_idle_id !=0) g_source_remove (clipboard_manager->priv->start_idle_id); G_OBJECT_CLASS (gsd_clipboard_manager_parent_class)->finalize (object); } GsdClipboardManager * gsd_clipboard_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_CLIPBOARD_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_CLIPBOARD_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/clipboard/gsd-clipboard-manager.h0000664000175000017500000000456000000000000026756 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_CLIPBOARD_MANAGER_H #define __GSD_CLIPBOARD_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_CLIPBOARD_MANAGER (gsd_clipboard_manager_get_type ()) #define GSD_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManager)) #define GSD_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManagerClass)) #define GSD_IS_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_CLIPBOARD_MANAGER)) #define GSD_IS_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_CLIPBOARD_MANAGER)) #define GSD_CLIPBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManagerClass)) typedef struct GsdClipboardManagerPrivate GsdClipboardManagerPrivate; typedef struct { GObject parent; GsdClipboardManagerPrivate *priv; } GsdClipboardManager; typedef struct { GObjectClass parent_class; } GsdClipboardManagerClass; GType gsd_clipboard_manager_get_type (void); GsdClipboardManager * gsd_clipboard_manager_new (void); gboolean gsd_clipboard_manager_start (GsdClipboardManager *manager, GError **error); void gsd_clipboard_manager_stop (GsdClipboardManager *manager); G_END_DECLS #endif /* __GSD_CLIPBOARD_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/clipboard/gsd-clipboard-plugin.c0000664000175000017500000000203100000000000026624 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-clipboard-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdClipboard, gsd_clipboard) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/clipboard/list.c0000664000175000017500000000550400000000000023601 0ustar00jeremyjeremy/* * Copyright © 2004 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of Red Hat not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. Red Hat makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Author: Matthias Clasen, Red Hat, Inc. */ #include #include void list_foreach (List *list, Callback func, void *user_data) { while (list) { func (list->data, user_data); list = list->next; } } List * list_prepend (List *list, void *data) { List *link; link = (List *) malloc (sizeof (List)); link->next = list; link->data = data; return link; } void list_free (List *list) { while (list) { List *next = list->next; free (list); list = next; } } List * list_find (List *list, ListFindFunc func, void *user_data) { List *tmp; for (tmp = list; tmp; tmp = tmp->next) { if ((*func) (tmp->data, user_data)) break; } return tmp; } List * list_remove (List *list, void *data) { List *tmp, *prev; prev = NULL; for (tmp = list; tmp; tmp = tmp->next) { if (tmp->data == data) { if (prev) prev->next = tmp->next; else list = tmp->next; free (tmp); break; } prev = tmp; } return list; } int list_length (List *list) { List *tmp; int length; length = 0; for (tmp = list; tmp; tmp = tmp->next) length++; return length; } List * list_copy (List *list) { List *new_list = NULL; if (list) { List *last; new_list = (List *) malloc (sizeof (List)); new_list->data = list->data; new_list->next = NULL; last = new_list; list = list->next; while (list) { last->next = (List *) malloc (sizeof (List)); last = last->next; last->data = list->data; list = list->next; } last->next = NULL; } return new_list; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/clipboard/list.h0000664000175000017500000000356600000000000023614 0ustar00jeremyjeremy/* * Copyright © 2004 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of Red Hat not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. Red Hat makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Author: Matthias Clasen, Red Hat, Inc. */ #ifndef LIST_H #define LIST_H typedef struct _List List; typedef void (*Callback) (void *data, void *user_data); struct _List { void *data; List *next; }; typedef int (*ListFindFunc) (void *data, void *user_data); void list_foreach (List *list, Callback func, void *user_data); List *list_prepend (List *list, void *data); void list_free (List *list); List *list_find (List *list, ListFindFunc func, void *user_data); List *list_remove (List *list, void *data); int list_length (List *list); List *list_copy (List *list); #endif /* LIST_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/clipboard/xutils.c0000664000175000017500000000675600000000000024170 0ustar00jeremyjeremy/* * Copyright © 2004 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of Red Hat not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. Red Hat makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Author: Matthias Clasen, Red Hat, Inc. */ #include #include "xutils.h" Atom XA_ATOM_PAIR; Atom XA_CLIPBOARD_MANAGER; Atom XA_CLIPBOARD; Atom XA_DELETE; Atom XA_INCR; Atom XA_INSERT_PROPERTY; Atom XA_INSERT_SELECTION; Atom XA_MANAGER; Atom XA_MULTIPLE; Atom XA_NULL; Atom XA_SAVE_TARGETS; Atom XA_TARGETS; Atom XA_TIMESTAMP; unsigned long SELECTION_MAX_SIZE = 0; void init_atoms (Display *display) { unsigned long max_request_size; if (SELECTION_MAX_SIZE > 0) return; XA_ATOM_PAIR = XInternAtom (display, "ATOM_PAIR", False); XA_CLIPBOARD_MANAGER = XInternAtom (display, "CLIPBOARD_MANAGER", False); XA_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False); XA_DELETE = XInternAtom (display, "DELETE", False); XA_INCR = XInternAtom (display, "INCR", False); XA_INSERT_PROPERTY = XInternAtom (display, "INSERT_PROPERTY", False); XA_INSERT_SELECTION = XInternAtom (display, "INSERT_SELECTION", False); XA_MANAGER = XInternAtom (display, "MANAGER", False); XA_MULTIPLE = XInternAtom (display, "MULTIPLE", False); XA_NULL = XInternAtom (display, "NULL", False); XA_SAVE_TARGETS = XInternAtom (display, "SAVE_TARGETS", False); XA_TARGETS = XInternAtom (display, "TARGETS", False); XA_TIMESTAMP = XInternAtom (display, "TIMESTAMP", False); max_request_size = XExtendedMaxRequestSize (display); if (max_request_size == 0) max_request_size = XMaxRequestSize (display); SELECTION_MAX_SIZE = max_request_size - 100; if (SELECTION_MAX_SIZE > 262144) SELECTION_MAX_SIZE = 262144; } typedef struct { Window window; Atom timestamp_prop_atom; } TimeStampInfo; static Bool timestamp_predicate (Display *display, XEvent *xevent, XPointer arg) { TimeStampInfo *info = (TimeStampInfo *)arg; if (xevent->type == PropertyNotify && xevent->xproperty.window == info->window && xevent->xproperty.atom == info->timestamp_prop_atom) return True; return False; } Time get_server_time (Display *display, Window window) { unsigned char c = 'a'; XEvent xevent; TimeStampInfo info; info.timestamp_prop_atom = XInternAtom (display, "_TIMESTAMP_PROP", False); info.window = window; XChangeProperty (display, window, info.timestamp_prop_atom, info.timestamp_prop_atom, 8, PropModeReplace, &c, 1); XIfEvent (display, &xevent, timestamp_predicate, (XPointer)&info); return xevent.xproperty.time; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/clipboard/xutils.h0000664000175000017500000000334000000000000024157 0ustar00jeremyjeremy/* * Copyright © 2004 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of Red Hat not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. Red Hat makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Author: Matthias Clasen, Red Hat, Inc. */ #ifndef X_UTILS_H #define X_UTILS_H #include extern Atom XA_ATOM_PAIR; extern Atom XA_CLIPBOARD_MANAGER; extern Atom XA_CLIPBOARD; extern Atom XA_DELETE; extern Atom XA_INCR; extern Atom XA_INSERT_PROPERTY; extern Atom XA_INSERT_SELECTION; extern Atom XA_MANAGER; extern Atom XA_MULTIPLE; extern Atom XA_NULL; extern Atom XA_SAVE_TARGETS; extern Atom XA_TARGETS; extern Atom XA_TIMESTAMP; extern unsigned long SELECTION_MAX_SIZE; void init_atoms (Display *display); Time get_server_time (Display *display, Window window); #endif /* X_UTILS_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5757668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/0000775000175000017500000000000000000000000021635 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/Makefile.am0000664000175000017500000000331300000000000023671 0ustar00jeremyjeremyplugin_name = color plugin_LTLIBRARIES = \ libcolor.la libcolor_la_SOURCES = \ gcm-profile-store.c \ gcm-profile-store.h \ gcm-dmi.c \ gcm-dmi.h \ gcm-edid.c \ gcm-edid.h \ gsd-color-manager.c \ gsd-color-manager.h \ gsd-color-plugin.c libcolor_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DBINDIR=\"$(bindir)\" \ $(AM_CPPFLAGS) libcolor_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(COLOR_CFLAGS) \ $(LCMS_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(LIBNOTIFY_CFLAGS) \ $(AM_CFLAGS) libcolor_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) libcolor_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(COLOR_LIBS) \ $(LCMS_LIBS) \ $(SETTINGS_PLUGIN_LIBS) \ $(LIBNOTIFY_LIBS) check_PROGRAMS = \ gcm-self-test gcm_self_test_CPPFLAGS = \ -DTESTDATADIR=\""$(top_srcdir)/plugins/color/test-data"\" \ $(AM_CPPFLAGS) gcm_self_test_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(COLOR_CFLAGS) \ $(PLUGIN_CFLAGS) \ $(AM_CFLAGS) gcm_self_test_SOURCES = \ gcm-dmi.c \ gcm-dmi.h \ gcm-edid.c \ gcm-edid.h \ gcm-self-test.c gcm_self_test_LDADD = \ $(COLOR_LIBS) \ $(LCMS_LIBS) \ $(SETTINGS_PLUGIN_LIBS) \ -lm TESTS = gcm-self-test plugin_in_files = \ color.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = \ $(plugin_in_files) \ test-data/Lenovo-T61-Internal.bin \ test-data/LG-L225W-External.bin CLEANFILES = \ $(plugin_DATA) DISTCLEANFILES = \ $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/color.gnome-settings-plugin.in0000664000175000017500000000027700000000000027547 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=color IAge=0 Priority=10 _Name=Color _Description=Color plugin Authors=Richard Hughes Copyright=Copyright © 2011 Richard Hughes Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/gcm-dmi.c0000664000175000017500000001206300000000000023320 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2009-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #include #include #include #include "gcm-dmi.h" static void gcm_dmi_finalize (GObject *object); #define GCM_DMI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_DMI, GcmDmiPrivate)) struct _GcmDmiPrivate { gchar *name; gchar *version; gchar *vendor; }; static gpointer gcm_dmi_object = NULL; G_DEFINE_TYPE (GcmDmi, gcm_dmi, G_TYPE_OBJECT) static gchar * gcm_dmi_get_from_filename (const gchar *filename) { gboolean ret; GError *error = NULL; gchar *data = NULL; /* get the contents */ ret = g_file_get_contents (filename, &data, NULL, &error); if (!ret) { if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) g_warning ("failed to get contents of %s: %s", filename, error->message); g_error_free (error); } /* process the random chars and trailing spaces */ if (data != NULL) { g_strdelimit (data, "\t_", ' '); g_strdelimit (data, "\n\r", '\0'); g_strchomp (data); } /* don't return an empty string */ if (data != NULL && data[0] == '\0') { g_free (data); data = NULL; } return data; } static gchar * gcm_dmi_get_from_filenames (const gchar * const * filenames) { guint i; gchar *tmp = NULL; /* try each one in preference order */ for (i = 0; filenames[i] != NULL; i++) { tmp = gcm_dmi_get_from_filename (filenames[i]); if (tmp != NULL) break; } return tmp; } const gchar * gcm_dmi_get_name (GcmDmi *dmi) { g_return_val_if_fail (GCM_IS_DMI (dmi), NULL); return dmi->priv->name; } const gchar * gcm_dmi_get_version (GcmDmi *dmi) { g_return_val_if_fail (GCM_IS_DMI (dmi), NULL); return dmi->priv->version; } const gchar * gcm_dmi_get_vendor (GcmDmi *dmi) { g_return_val_if_fail (GCM_IS_DMI (dmi), NULL); return dmi->priv->vendor; } static void gcm_dmi_class_init (GcmDmiClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gcm_dmi_finalize; g_type_class_add_private (klass, sizeof (GcmDmiPrivate)); } static void gcm_dmi_init (GcmDmi *dmi) { #if defined(__linux__) const gchar *sysfs_name[] = { "/sys/class/dmi/id/product_name", "/sys/class/dmi/id/board_name", NULL}; const gchar *sysfs_version[] = { "/sys/class/dmi/id/product_version", "/sys/class/dmi/id/chassis_version", "/sys/class/dmi/id/board_version", NULL}; const gchar *sysfs_vendor[] = { "/sys/class/dmi/id/sys_vendor", "/sys/class/dmi/id/chassis_vendor", "/sys/class/dmi/id/board_vendor", NULL}; #else #warning Please add dmi support for your OS const gchar *sysfs_name[] = { NULL }; const gchar *sysfs_version[] = { NULL }; const gchar *sysfs_vendor[] = { NULL }; #endif dmi->priv = GCM_DMI_GET_PRIVATE (dmi); /* get all the possible data now */ dmi->priv->name = gcm_dmi_get_from_filenames (sysfs_name); dmi->priv->version = gcm_dmi_get_from_filenames (sysfs_version); dmi->priv->vendor = gcm_dmi_get_from_filenames (sysfs_vendor); } static void gcm_dmi_finalize (GObject *object) { GcmDmi *dmi = GCM_DMI (object); g_free (dmi->priv->name); g_free (dmi->priv->version); g_free (dmi->priv->vendor); G_OBJECT_CLASS (gcm_dmi_parent_class)->finalize (object); } GcmDmi * gcm_dmi_new (void) { if (gcm_dmi_object != NULL) { g_object_ref (gcm_dmi_object); } else { gcm_dmi_object = g_object_new (GCM_TYPE_DMI, NULL); g_object_add_weak_pointer (gcm_dmi_object, &gcm_dmi_object); } return GCM_DMI (gcm_dmi_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/gcm-dmi.h0000664000175000017500000000422600000000000023327 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2009-2010 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __GCM_DMI_H #define __GCM_DMI_H #include G_BEGIN_DECLS #define GCM_TYPE_DMI (gcm_dmi_get_type ()) #define GCM_DMI(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_DMI, GcmDmi)) #define GCM_DMI_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_DMI, GcmDmiClass)) #define GCM_IS_DMI(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_DMI)) #define GCM_IS_DMI_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_DMI)) #define GCM_DMI_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_DMI, GcmDmiClass)) typedef struct _GcmDmiPrivate GcmDmiPrivate; typedef struct _GcmDmi GcmDmi; typedef struct _GcmDmiClass GcmDmiClass; struct _GcmDmi { GObject parent; GcmDmiPrivate *priv; }; struct _GcmDmiClass { GObjectClass parent_class; }; GType gcm_dmi_get_type (void); GcmDmi *gcm_dmi_new (void); const gchar *gcm_dmi_get_name (GcmDmi *dmi); const gchar *gcm_dmi_get_version (GcmDmi *dmi); const gchar *gcm_dmi_get_vendor (GcmDmi *dmi); G_END_DECLS #endif /* __GCM_DMI_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/gcm-edid.c0000664000175000017500000003427300000000000023463 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2008 Soren Sandmann * Copyright (C) 2009-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #include #include #include #include "gcm-edid.h" #include "gsd-pnp-ids.h" static void gcm_edid_finalize (GObject *object); #define GCM_EDID_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_EDID, GcmEdidPrivate)) struct _GcmEdidPrivate { gchar *monitor_name; gchar *vendor_name; gchar *serial_number; gchar *eisa_id; gchar *checksum; gchar *pnp_id; guint width; guint height; gfloat gamma; CdColorYxy *red; CdColorYxy *green; CdColorYxy *blue; CdColorYxy *white; GsdPnpIds *pnp_ids; }; G_DEFINE_TYPE (GcmEdid, gcm_edid, G_TYPE_OBJECT) #define GCM_EDID_OFFSET_PNPID 0x08 #define GCM_EDID_OFFSET_SERIAL 0x0c #define GCM_EDID_OFFSET_SIZE 0x15 #define GCM_EDID_OFFSET_GAMMA 0x17 #define GCM_EDID_OFFSET_DATA_BLOCKS 0x36 #define GCM_EDID_OFFSET_LAST_BLOCK 0x6c #define GCM_EDID_OFFSET_EXTENSION_BLOCK_COUNT 0x7e #define GCM_DESCRIPTOR_DISPLAY_PRODUCT_NAME 0xfc #define GCM_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER 0xff #define GCM_DESCRIPTOR_COLOR_MANAGEMENT_DATA 0xf9 #define GCM_DESCRIPTOR_ALPHANUMERIC_DATA_STRING 0xfe #define GCM_DESCRIPTOR_COLOR_POINT 0xfb GQuark gcm_edid_error_quark (void) { static GQuark quark = 0; if (!quark) quark = g_quark_from_static_string ("gcm_edid_error"); return quark; } const gchar * gcm_edid_get_monitor_name (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), NULL); return edid->priv->monitor_name; } const gchar * gcm_edid_get_vendor_name (GcmEdid *edid) { GcmEdidPrivate *priv = edid->priv; g_return_val_if_fail (GCM_IS_EDID (edid), NULL); if (priv->vendor_name == NULL) priv->vendor_name = gsd_pnp_ids_get_pnp_id (priv->pnp_ids, priv->pnp_id); return priv->vendor_name; } const gchar * gcm_edid_get_serial_number (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), NULL); return edid->priv->serial_number; } const gchar * gcm_edid_get_eisa_id (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), NULL); return edid->priv->eisa_id; } const gchar * gcm_edid_get_checksum (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), NULL); return edid->priv->checksum; } const gchar * gcm_edid_get_pnp_id (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), NULL); return edid->priv->pnp_id; } guint gcm_edid_get_width (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), 0); return edid->priv->width; } guint gcm_edid_get_height (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), 0); return edid->priv->height; } gfloat gcm_edid_get_gamma (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), 0.0f); return edid->priv->gamma; } const CdColorYxy * gcm_edid_get_red (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), NULL); return edid->priv->red; } const CdColorYxy * gcm_edid_get_green (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), NULL); return edid->priv->green; } const CdColorYxy * gcm_edid_get_blue (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), NULL); return edid->priv->blue; } const CdColorYxy * gcm_edid_get_white (GcmEdid *edid) { g_return_val_if_fail (GCM_IS_EDID (edid), NULL); return edid->priv->white; } void gcm_edid_reset (GcmEdid *edid) { GcmEdidPrivate *priv = edid->priv; g_return_if_fail (GCM_IS_EDID (edid)); /* free old data */ g_free (priv->monitor_name); g_free (priv->vendor_name); g_free (priv->serial_number); g_free (priv->eisa_id); g_free (priv->checksum); /* do not deallocate, just blank */ priv->pnp_id[0] = '\0'; /* set to default values */ priv->monitor_name = NULL; priv->vendor_name = NULL; priv->serial_number = NULL; priv->eisa_id = NULL; priv->checksum = NULL; priv->width = 0; priv->height = 0; priv->gamma = 0.0f; } static gint gcm_edid_get_bit (gint in, gint bit) { return (in & (1 << bit)) >> bit; } /** * gcm_edid_get_bits: **/ static gint gcm_edid_get_bits (gint in, gint begin, gint end) { gint mask = (1 << (end - begin + 1)) - 1; return (in >> begin) & mask; } /** * gcm_edid_decode_fraction: **/ static gdouble gcm_edid_decode_fraction (gint high, gint low) { gdouble result = 0.0; gint i; high = (high << 2) | low; for (i = 0; i < 10; ++i) result += gcm_edid_get_bit (high, i) * pow (2, i - 10); return result; } static gchar * gcm_edid_parse_string (const guint8 *data) { gchar *text; guint i; guint replaced = 0; /* this is always 12 bytes, but we can't guarantee it's null * terminated or not junk. */ text = g_strndup ((const gchar *) data, 12); /* remove insane newline chars */ g_strdelimit (text, "\n\r", '\0'); /* remove spaces */ g_strchomp (text); /* nothing left? */ if (text[0] == '\0') { g_free (text); text = NULL; goto out; } /* ensure string is printable */ for (i = 0; text[i] != '\0'; i++) { if (!g_ascii_isprint (text[i])) { text[i] = '-'; replaced++; } } /* if the string is junk, ignore the string */ if (replaced > 4) { g_free (text); text = NULL; goto out; } out: return text; } gboolean gcm_edid_parse (GcmEdid *edid, const guint8 *data, gsize length, GError **error) { gboolean ret = TRUE; guint i; GcmEdidPrivate *priv = edid->priv; guint32 serial; gchar *tmp; /* check header */ if (length < 128) { g_set_error_literal (error, GCM_EDID_ERROR, GCM_EDID_ERROR_FAILED_TO_PARSE, "EDID length is too small"); ret = FALSE; goto out; } if (data[0] != 0x00 || data[1] != 0xff) { g_set_error_literal (error, GCM_EDID_ERROR, GCM_EDID_ERROR_FAILED_TO_PARSE, "Failed to parse EDID header"); ret = FALSE; goto out; } /* free old data */ gcm_edid_reset (edid); /* decode the PNP ID from three 5 bit words packed into 2 bytes * /--08--\/--09--\ * 7654321076543210 * |\---/\---/\---/ * R C1 C2 C3 */ priv->pnp_id[0] = 'A' + ((data[GCM_EDID_OFFSET_PNPID+0] & 0x7c) / 4) - 1; priv->pnp_id[1] = 'A' + ((data[GCM_EDID_OFFSET_PNPID+0] & 0x3) * 8) + ((data[GCM_EDID_OFFSET_PNPID+1] & 0xe0) / 32) - 1; priv->pnp_id[2] = 'A' + (data[GCM_EDID_OFFSET_PNPID+1] & 0x1f) - 1; /* maybe there isn't a ASCII serial number descriptor, so use this instead */ serial = (guint32) data[GCM_EDID_OFFSET_SERIAL+0]; serial += (guint32) data[GCM_EDID_OFFSET_SERIAL+1] * 0x100; serial += (guint32) data[GCM_EDID_OFFSET_SERIAL+2] * 0x10000; serial += (guint32) data[GCM_EDID_OFFSET_SERIAL+3] * 0x1000000; if (serial > 0) priv->serial_number = g_strdup_printf ("%" G_GUINT32_FORMAT, serial); /* get the size */ priv->width = data[GCM_EDID_OFFSET_SIZE+0]; priv->height = data[GCM_EDID_OFFSET_SIZE+1]; /* we don't care about aspect */ if (priv->width == 0 || priv->height == 0) { priv->width = 0; priv->height = 0; } /* get gamma */ if (data[GCM_EDID_OFFSET_GAMMA] == 0xff) { priv->gamma = 1.0f; } else { priv->gamma = ((gfloat) data[GCM_EDID_OFFSET_GAMMA] / 100) + 1; } /* get color red */ priv->red->x = gcm_edid_decode_fraction (data[0x1b], gcm_edid_get_bits (data[0x19], 6, 7)); priv->red->y = gcm_edid_decode_fraction (data[0x1c], gcm_edid_get_bits (data[0x19], 5, 4)); /* get color green */ priv->green->x = gcm_edid_decode_fraction (data[0x1d], gcm_edid_get_bits (data[0x19], 2, 3)); priv->green->y = gcm_edid_decode_fraction (data[0x1e], gcm_edid_get_bits (data[0x19], 0, 1)); /* get color blue */ priv->blue->x = gcm_edid_decode_fraction (data[0x1f], gcm_edid_get_bits (data[0x1a], 6, 7)); priv->blue->y = gcm_edid_decode_fraction (data[0x20], gcm_edid_get_bits (data[0x1a], 4, 5)); /* get color white */ priv->white->x = gcm_edid_decode_fraction (data[0x21], gcm_edid_get_bits (data[0x1a], 2, 3)); priv->white->y = gcm_edid_decode_fraction (data[0x22], gcm_edid_get_bits (data[0x1a], 0, 1)); /* parse EDID data */ for (i = GCM_EDID_OFFSET_DATA_BLOCKS; i <= GCM_EDID_OFFSET_LAST_BLOCK; i += 18) { /* ignore pixel clock data */ if (data[i] != 0) continue; if (data[i+2] != 0) continue; /* any useful blocks? */ if (data[i+3] == GCM_DESCRIPTOR_DISPLAY_PRODUCT_NAME) { tmp = gcm_edid_parse_string (&data[i+5]); if (tmp != NULL) { g_free (priv->monitor_name); priv->monitor_name = tmp; } } else if (data[i+3] == GCM_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER) { tmp = gcm_edid_parse_string (&data[i+5]); if (tmp != NULL) { g_free (priv->serial_number); priv->serial_number = tmp; } } else if (data[i+3] == GCM_DESCRIPTOR_COLOR_MANAGEMENT_DATA) { g_warning ("failing to parse color management data"); } else if (data[i+3] == GCM_DESCRIPTOR_ALPHANUMERIC_DATA_STRING) { tmp = gcm_edid_parse_string (&data[i+5]); if (tmp != NULL) { g_free (priv->eisa_id); priv->eisa_id = tmp; } } else if (data[i+3] == GCM_DESCRIPTOR_COLOR_POINT) { if (data[i+3+9] != 0xff) { /* extended EDID block(1) which contains * a better gamma value */ priv->gamma = ((gfloat) data[i+3+9] / 100) + 1; } if (data[i+3+14] != 0xff) { /* extended EDID block(2) which contains * a better gamma value */ priv->gamma = ((gfloat) data[i+3+9] / 100) + 1; } } } /* calculate checksum */ priv->checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5, data, length); out: return ret; } static void gcm_edid_class_init (GcmEdidClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gcm_edid_finalize; g_type_class_add_private (klass, sizeof (GcmEdidPrivate)); } static void gcm_edid_init (GcmEdid *edid) { edid->priv = GCM_EDID_GET_PRIVATE (edid); edid->priv->pnp_ids = gsd_pnp_ids_new (); edid->priv->pnp_id = g_new0 (gchar, 4); edid->priv->red = cd_color_yxy_new (); edid->priv->green = cd_color_yxy_new (); edid->priv->blue = cd_color_yxy_new (); edid->priv->white = cd_color_yxy_new (); } static void gcm_edid_finalize (GObject *object) { GcmEdid *edid = GCM_EDID (object); GcmEdidPrivate *priv = edid->priv; g_free (priv->monitor_name); g_free (priv->vendor_name); g_free (priv->serial_number); g_free (priv->eisa_id); g_free (priv->checksum); g_free (priv->pnp_id); cd_color_yxy_free (priv->white); cd_color_yxy_free (priv->red); cd_color_yxy_free (priv->green); cd_color_yxy_free (priv->blue); g_object_unref (priv->pnp_ids); G_OBJECT_CLASS (gcm_edid_parent_class)->finalize (object); } GcmEdid * gcm_edid_new (void) { GcmEdid *edid; edid = g_object_new (GCM_TYPE_EDID, NULL); return GCM_EDID (edid); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/gcm-edid.h0000664000175000017500000000725300000000000023466 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2009-2010 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __GCM_EDID_H #define __GCM_EDID_H #include #include G_BEGIN_DECLS #define GCM_TYPE_EDID (gcm_edid_get_type ()) #define GCM_EDID(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_EDID, GcmEdid)) #define GCM_EDID_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_EDID, GcmEdidClass)) #define GCM_IS_EDID(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_EDID)) #define GCM_IS_EDID_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_EDID)) #define GCM_EDID_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_EDID, GcmEdidClass)) #define GCM_EDID_ERROR (gcm_edid_error_quark ()) typedef struct _GcmEdidPrivate GcmEdidPrivate; typedef struct _GcmEdid GcmEdid; typedef struct _GcmEdidClass GcmEdidClass; struct _GcmEdid { GObject parent; GcmEdidPrivate *priv; }; struct _GcmEdidClass { GObjectClass parent_class; }; enum { GCM_EDID_ERROR_FAILED_TO_PARSE }; GType gcm_edid_get_type (void); GQuark gcm_edid_error_quark (void); GcmEdid *gcm_edid_new (void); void gcm_edid_reset (GcmEdid *edid); gboolean gcm_edid_parse (GcmEdid *edid, const guint8 *data, gsize length, GError **error); const gchar *gcm_edid_get_monitor_name (GcmEdid *edid); const gchar *gcm_edid_get_vendor_name (GcmEdid *edid); const gchar *gcm_edid_get_serial_number (GcmEdid *edid); const gchar *gcm_edid_get_eisa_id (GcmEdid *edid); const gchar *gcm_edid_get_checksum (GcmEdid *edid); const gchar *gcm_edid_get_pnp_id (GcmEdid *edid); guint gcm_edid_get_width (GcmEdid *edid); guint gcm_edid_get_height (GcmEdid *edid); gfloat gcm_edid_get_gamma (GcmEdid *edid); const CdColorYxy *gcm_edid_get_red (GcmEdid *edid); const CdColorYxy *gcm_edid_get_green (GcmEdid *edid); const CdColorYxy *gcm_edid_get_blue (GcmEdid *edid); const CdColorYxy *gcm_edid_get_white (GcmEdid *edid); G_END_DECLS #endif /* __GCM_EDID_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/gcm-profile-store.c0000664000175000017500000004570700000000000025354 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2009-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #include "gcm-profile-store.h" static void gcm_profile_store_finalize (GObject *object); #define GCM_PROFILE_STORE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_PROFILE_STORE, GcmProfileStorePrivate)) struct _GcmProfileStorePrivate { GPtrArray *filename_array; GPtrArray *directory_array; GCancellable *cancellable; }; enum { SIGNAL_ADDED, SIGNAL_REMOVED, SIGNAL_CHANGED, SIGNAL_LAST }; static guint signals[SIGNAL_LAST] = { 0 }; G_DEFINE_TYPE (GcmProfileStore, gcm_profile_store, G_TYPE_OBJECT) static void gcm_profile_store_search_path (GcmProfileStore *profile_store, const gchar *path, guint depth); static void gcm_profile_store_process_child (GcmProfileStore *profile_store, const gchar *path, GFileInfo *info); #define GCM_PROFILE_STORE_MAX_RECURSION_LEVELS 2 typedef struct { gchar *path; GFileMonitor *monitor; guint depth; } GcmProfileStoreDirHelper; static void gcm_profile_store_helper_free (GcmProfileStoreDirHelper *helper) { g_free (helper->path); if (helper->monitor != NULL) g_object_unref (helper->monitor); g_free (helper); } static const gchar * gcm_profile_store_find_filename (GcmProfileStore *profile_store, const gchar *filename) { const gchar *tmp; guint i; GPtrArray *array = profile_store->priv->filename_array; for (i=0; ilen; i++) { tmp = g_ptr_array_index (array, i); if (g_strcmp0 (filename, tmp) == 0) return tmp; } return NULL; } static GcmProfileStoreDirHelper * gcm_profile_store_find_directory (GcmProfileStore *profile_store, const gchar *path) { GcmProfileStoreDirHelper *tmp; guint i; GPtrArray *array = profile_store->priv->directory_array; for (i=0; ilen; i++) { tmp = g_ptr_array_index (array, i); if (g_strcmp0 (path, tmp->path) == 0) return tmp; } return NULL; } static gboolean gcm_profile_store_remove_profile (GcmProfileStore *profile_store, const gchar *filename) { gboolean ret = FALSE; const gchar *tmp; gchar *filename_dup = NULL; GcmProfileStorePrivate *priv = profile_store->priv; /* find exact pointer */ tmp = gcm_profile_store_find_filename (profile_store, filename); if (tmp == NULL) goto out; /* dup so we can emit the signal */ filename_dup = g_strdup (tmp); ret = g_ptr_array_remove (priv->filename_array, (gpointer)tmp); if (!ret) { g_warning ("failed to remove %s", filename); goto out; } /* emit a signal */ g_debug ("emit removed: %s", filename_dup); g_signal_emit (profile_store, signals[SIGNAL_REMOVED], 0, filename_dup); out: g_free (filename_dup); return ret; } static void gcm_profile_store_add_profile (GcmProfileStore *profile_store, const gchar *filename) { GcmProfileStorePrivate *priv = profile_store->priv; /* add to list */ g_ptr_array_add (priv->filename_array, g_strdup (filename)); /* emit a signal */ g_debug ("emit add: %s", filename); g_signal_emit (profile_store, signals[SIGNAL_ADDED], 0, filename); } static void gcm_profile_store_created_query_info_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GFileInfo *info; GError *error = NULL; gchar *path; GFile *file = G_FILE (source_object); GFile *parent; GcmProfileStore *profile_store = GCM_PROFILE_STORE (user_data); info = g_file_query_info_finish (file, res, &error); if (info == NULL) { g_warning ("failed to get info about deleted file: %s", error->message); g_error_free (error); return; } parent = g_file_get_parent (file); path = g_file_get_path (parent); gcm_profile_store_process_child (profile_store, path, info); g_free (path); g_object_unref (info); g_object_unref (parent); } static void gcm_profile_store_remove_from_prefix (GcmProfileStore *profile_store, const gchar *prefix) { guint i; const gchar *path; GcmProfileStorePrivate *priv = profile_store->priv; for (i = 0; i < priv->filename_array->len; i++) { path = g_ptr_array_index (priv->filename_array, i); if (g_str_has_prefix (path, prefix)) { g_debug ("auto-removed %s as path removed", path); gcm_profile_store_remove_profile (profile_store, path); } } } static void gcm_profile_store_file_monitor_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, GcmProfileStore *profile_store) { gchar *path = NULL; gchar *parent_path = NULL; const gchar *tmp; GcmProfileStoreDirHelper *helper; /* profile was deleted */ if (event_type == G_FILE_MONITOR_EVENT_DELETED) { /* we can either have two things here, a directory or a * file. We can't call g_file_query_info_async() as the * inode doesn't exist anymore */ path = g_file_get_path (file); tmp = gcm_profile_store_find_filename (profile_store, path); if (tmp != NULL) { /* is a file */ gcm_profile_store_remove_profile (profile_store, path); goto out; } /* is a directory, urgh. Remove all profiles there. */ gcm_profile_store_remove_from_prefix (profile_store, path); helper = gcm_profile_store_find_directory (profile_store, path); if (helper != NULL) { g_ptr_array_remove (profile_store->priv->directory_array, helper); } goto out; } /* ignore temp files */ path = g_file_get_path (file); if (g_strrstr (path, ".goutputstream") != NULL) { g_debug ("ignoring gvfs temporary file"); goto out; } /* only care about created objects */ if (event_type == G_FILE_MONITOR_EVENT_CREATED) { g_file_query_info_async (file, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, G_PRIORITY_LOW, NULL, gcm_profile_store_created_query_info_cb, profile_store); goto out; } out: g_free (path); g_free (parent_path); } static void gcm_profile_store_process_child (GcmProfileStore *profile_store, const gchar *path, GFileInfo *info) { gchar *full_path = NULL; const gchar *name; GcmProfileStoreDirHelper *helper; /* check we're not in a loop */ helper = gcm_profile_store_find_directory (profile_store, path); if (helper == NULL) goto out; if (helper->depth > GCM_PROFILE_STORE_MAX_RECURSION_LEVELS) { g_warning ("recursing more than %i levels deep is insane", GCM_PROFILE_STORE_MAX_RECURSION_LEVELS); goto out; } /* make the compete path */ name = g_file_info_get_name (info); full_path = g_build_filename (path, name, NULL); /* if a directory */ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { gcm_profile_store_search_path (profile_store, full_path, helper->depth + 1); goto out; } /* ignore temp files */ if (g_strrstr (full_path, ".goutputstream") != NULL) { g_debug ("ignoring gvfs temporary file"); goto out; } /* is a file */ gcm_profile_store_add_profile (profile_store, full_path); out: g_free (full_path); } static void gcm_profile_store_next_files_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GList *files; GList *f; GError *error = NULL; GFileInfo *info; GFile *file; gchar *path; GFileEnumerator *enumerator = G_FILE_ENUMERATOR (source_object); GcmProfileStore *profile_store = GCM_PROFILE_STORE (user_data); files = g_file_enumerator_next_files_finish (enumerator, res, &error); if (files == NULL) { /* special value, meaning "no more files to process" */ return; } if (error != NULL) { g_warning ("failed to get data about enumerated directory: %s", error->message); g_error_free (error); return; } /* get each file */ file = g_file_enumerator_get_container (enumerator); path = g_file_get_path (file); for (f = files; f != NULL; f = f->next) { info = G_FILE_INFO (f->data); gcm_profile_store_process_child (profile_store, path, info); } /* continue to get the rest of the data in chunks */ g_file_enumerator_next_files_async (enumerator, 5, G_PRIORITY_LOW, profile_store->priv->cancellable, gcm_profile_store_next_files_cb, user_data); g_free (path); g_list_foreach (files, (GFunc) g_object_unref, NULL); g_list_free (files); } static void gcm_profile_store_enumerate_children_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GError *error = NULL; GFileEnumerator *enumerator; GcmProfileStore *profile_store = GCM_PROFILE_STORE (user_data); enumerator = g_file_enumerate_children_finish (G_FILE (source_object), res, &error); if (enumerator == NULL) { GcmProfileStoreDirHelper *helper; gchar *path = NULL; path = g_file_get_path (G_FILE (source_object)); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) g_debug ("failed to enumerate directory %s: %s", path, error->message); else g_warning ("failed to enumerate directory %s: %s", path, error->message); helper = gcm_profile_store_find_directory (profile_store, path); if (helper) g_ptr_array_remove (profile_store->priv->directory_array, helper); g_error_free (error); g_free (path); return; } /* get the first chunk of data */ g_file_enumerator_next_files_async (enumerator, 5, G_PRIORITY_LOW, profile_store->priv->cancellable, gcm_profile_store_next_files_cb, user_data); g_object_unref (enumerator); } static void gcm_profile_store_search_path (GcmProfileStore *profile_store, const gchar *path, guint depth) { GFile *file = NULL; GError *error = NULL; GcmProfileStoreDirHelper *helper; file = g_file_new_for_path (path); /* add an inotify watch if not already added */ helper = gcm_profile_store_find_directory (profile_store, path); if (helper == NULL) { helper = g_new0 (GcmProfileStoreDirHelper, 1); helper->depth = depth; helper->path = g_strdup (path); helper->monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, &error); if (helper->monitor == NULL) { g_debug ("failed to monitor path: %s", error->message); g_error_free (error); gcm_profile_store_helper_free (helper); goto out; } g_signal_connect (helper->monitor, "changed", G_CALLBACK(gcm_profile_store_file_monitor_changed_cb), profile_store); g_ptr_array_add (profile_store->priv->directory_array, helper); } /* get contents of directory */ g_file_enumerate_children_async (file, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, G_PRIORITY_LOW, profile_store->priv->cancellable, gcm_profile_store_enumerate_children_cb, profile_store); out: g_object_unref (file); } static gboolean gcm_profile_store_mkdir_with_parents (const gchar *filename, GCancellable *cancellable, GError **error) { gboolean ret; GFile *file; /* ensure destination exists */ file = g_file_new_for_path (filename); ret = g_file_make_directory_with_parents (file, cancellable, error); g_object_unref (file); return ret; } gboolean gcm_profile_store_search (GcmProfileStore *profile_store) { gchar *path; gboolean ret; GError *error = NULL; /* get Linux per-user profiles */ path = g_build_filename (g_get_user_data_dir (), "icc", NULL); ret = gcm_profile_store_mkdir_with_parents (path, profile_store->priv->cancellable, &error); if (!ret && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) { g_warning ("failed to create directory on startup: %s", error->message); } else { gcm_profile_store_search_path (profile_store, path, 0); } g_free (path); g_clear_error (&error); /* get per-user profiles from obsolete location */ path = g_build_filename (g_get_home_dir (), ".color", "icc", NULL); gcm_profile_store_search_path (profile_store, path, 0); g_free (path); return TRUE; } static void gcm_profile_store_class_init (GcmProfileStoreClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gcm_profile_store_finalize; signals[SIGNAL_ADDED] = g_signal_new ("added", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GcmProfileStoreClass, added), NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); signals[SIGNAL_REMOVED] = g_signal_new ("removed", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GcmProfileStoreClass, removed), NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); g_type_class_add_private (klass, sizeof (GcmProfileStorePrivate)); } static void gcm_profile_store_init (GcmProfileStore *profile_store) { profile_store->priv = GCM_PROFILE_STORE_GET_PRIVATE (profile_store); profile_store->priv->cancellable = g_cancellable_new (); profile_store->priv->filename_array = g_ptr_array_new_with_free_func (g_free); profile_store->priv->directory_array = g_ptr_array_new_with_free_func ((GDestroyNotify) gcm_profile_store_helper_free); } static void gcm_profile_store_finalize (GObject *object) { GcmProfileStore *profile_store = GCM_PROFILE_STORE (object); GcmProfileStorePrivate *priv = profile_store->priv; g_cancellable_cancel (profile_store->priv->cancellable); g_object_unref (profile_store->priv->cancellable); g_ptr_array_unref (priv->filename_array); g_ptr_array_unref (priv->directory_array); G_OBJECT_CLASS (gcm_profile_store_parent_class)->finalize (object); } GcmProfileStore * gcm_profile_store_new (void) { GcmProfileStore *profile_store; profile_store = g_object_new (GCM_TYPE_PROFILE_STORE, NULL); return GCM_PROFILE_STORE (profile_store); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/gcm-profile-store.h0000664000175000017500000000467300000000000025356 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2009-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __GCM_PROFILE_STORE_H #define __GCM_PROFILE_STORE_H #include G_BEGIN_DECLS #define GCM_TYPE_PROFILE_STORE (gcm_profile_store_get_type ()) #define GCM_PROFILE_STORE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_PROFILE_STORE, GcmProfileStore)) #define GCM_PROFILE_STORE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_PROFILE_STORE, GcmProfileStoreClass)) #define GCM_IS_PROFILE_STORE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_PROFILE_STORE)) #define GCM_IS_PROFILE_STORE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_PROFILE_STORE)) #define GCM_PROFILE_STORE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_PROFILE_STORE, GcmProfileStoreClass)) typedef struct _GcmProfileStorePrivate GcmProfileStorePrivate; typedef struct _GcmProfileStore GcmProfileStore; typedef struct _GcmProfileStoreClass GcmProfileStoreClass; struct _GcmProfileStore { GObject parent; GcmProfileStorePrivate *priv; }; struct _GcmProfileStoreClass { GObjectClass parent_class; void (* added) (const gchar *filename); void (* removed) (const gchar *filename); }; GType gcm_profile_store_get_type (void); GcmProfileStore *gcm_profile_store_new (void); gboolean gcm_profile_store_search (GcmProfileStore *profile_store); G_END_DECLS #endif /* __GCM_PROFILE_STORE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/gcm-self-test.c0000664000175000017500000000774600000000000024471 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2007-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #include #include "gcm-edid.h" #include "gcm-dmi.h" static void gcm_test_dmi_func (void) { GcmDmi *dmi; dmi = gcm_dmi_new (); g_assert (dmi != NULL); g_assert (gcm_dmi_get_name (dmi) != NULL); g_assert (gcm_dmi_get_vendor (dmi) != NULL); g_object_unref (dmi); } static void gcm_test_edid_func (void) { GcmEdid *edid; gchar *data; gboolean ret; GError *error = NULL; gsize length = 0; edid = gcm_edid_new (); g_assert (edid != NULL); /* LG 21" LCD panel */ ret = g_file_get_contents (TESTDATADIR "/LG-L225W-External.bin", &data, &length, &error); g_assert_no_error (error); g_assert (ret); ret = gcm_edid_parse (edid, (const guint8 *) data, length, &error); g_assert_no_error (error); g_assert (ret); g_assert_cmpstr (gcm_edid_get_monitor_name (edid), ==, "L225W"); g_assert_cmpstr (gcm_edid_get_vendor_name (edid), ==, "Goldstar Company Ltd"); g_assert_cmpstr (gcm_edid_get_serial_number (edid), ==, "34398"); g_assert_cmpstr (gcm_edid_get_eisa_id (edid), ==, NULL); g_assert_cmpstr (gcm_edid_get_checksum (edid), ==, "0bb44865bb29984a4bae620656c31368"); g_assert_cmpstr (gcm_edid_get_pnp_id (edid), ==, "GSM"); g_assert_cmpint (gcm_edid_get_height (edid), ==, 30); g_assert_cmpint (gcm_edid_get_width (edid), ==, 47); g_assert_cmpfloat (gcm_edid_get_gamma (edid), >=, 2.2f - 0.01); g_assert_cmpfloat (gcm_edid_get_gamma (edid), <, 2.2f + 0.01); g_free (data); /* Lenovo T61 internal Panel */ ret = g_file_get_contents (TESTDATADIR "/Lenovo-T61-Internal.bin", &data, &length, &error); g_assert_no_error (error); g_assert (ret); ret = gcm_edid_parse (edid, (const guint8 *) data, length, &error); g_assert_no_error (error); g_assert (ret); g_assert_cmpstr (gcm_edid_get_monitor_name (edid), ==, NULL); g_assert_cmpstr (gcm_edid_get_vendor_name (edid), ==, "IBM France"); g_assert_cmpstr (gcm_edid_get_serial_number (edid), ==, NULL); g_assert_cmpstr (gcm_edid_get_eisa_id (edid), ==, "LTN154P2-L05"); g_assert_cmpstr (gcm_edid_get_checksum (edid), ==, "e1865128c7cd5e5ed49ecfc8102f6f9c"); g_assert_cmpstr (gcm_edid_get_pnp_id (edid), ==, "IBM"); g_assert_cmpint (gcm_edid_get_height (edid), ==, 21); g_assert_cmpint (gcm_edid_get_width (edid), ==, 33); g_assert_cmpfloat (gcm_edid_get_gamma (edid), >=, 2.2f - 0.01); g_assert_cmpfloat (gcm_edid_get_gamma (edid), <, 2.2f + 0.01); g_free (data); g_object_unref (edid); } int main (int argc, char **argv) { gtk_init (&argc, &argv); g_test_init (&argc, &argv, NULL); g_test_add_func ("/color/dmi", gcm_test_dmi_func); g_test_add_func ("/color/edid", gcm_test_edid_func); return g_test_run (); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/gsd-color-manager.c0000664000175000017500000024013100000000000025303 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * Copyright (C) 2011 Richard Hughes * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include "gnome-settings-plugin.h" #include "gnome-settings-profile.h" #include "gnome-settings-bus.h" #include "gsd-color-manager.h" #include "gcm-profile-store.h" #include "gcm-dmi.h" #include "gcm-edid.h" #include "gsd-rr.h" #define GSD_COLOR_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_COLOR_MANAGER, GsdColorManagerPrivate)) #define GCM_SESSION_NOTIFY_TIMEOUT 30000 /* ms */ #define GCM_SETTINGS_RECALIBRATE_PRINTER_THRESHOLD "recalibrate-printer-threshold" #define GCM_SETTINGS_RECALIBRATE_DISPLAY_THRESHOLD "recalibrate-display-threshold" struct GsdColorManagerPrivate { GsdSessionManager *session; CdClient *client; GSettings *settings; GcmProfileStore *profile_store; GcmDmi *dmi; GsdRRScreen *x11_screen; GHashTable *edid_cache; GdkWindow *gdk_window; gboolean session_is_active; GHashTable *device_assign_hash; }; enum { PROP_0, }; static void gsd_color_manager_class_init (GsdColorManagerClass *klass); static void gsd_color_manager_init (GsdColorManager *color_manager); static void gsd_color_manager_finalize (GObject *object); G_DEFINE_TYPE (GsdColorManager, gsd_color_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; /* see http://www.oyranos.org/wiki/index.php?title=ICC_Profiles_in_X_Specification_0.3 */ #define GCM_ICC_PROFILE_IN_X_VERSION_MAJOR 0 #define GCM_ICC_PROFILE_IN_X_VERSION_MINOR 3 typedef struct { guint32 red; guint32 green; guint32 blue; } GsdRROutputClutItem; GQuark gsd_color_manager_error_quark (void) { static GQuark quark = 0; if (!quark) quark = g_quark_from_static_string ("gsd_color_manager_error"); return quark; } static GcmEdid * gcm_session_get_output_edid (GsdColorManager *manager, GsdRROutput *output, GError **error) { const guint8 *data; gsize size; GcmEdid *edid = NULL; gboolean ret; /* can we find it in the cache */ edid = g_hash_table_lookup (manager->priv->edid_cache, gsd_rr_output_get_name (output)); if (edid != NULL) { g_object_ref (edid); goto out; } /* parse edid */ data = gsd_rr_output_get_edid_data (output, &size); if (data == NULL || size == 0) { g_set_error_literal (error, GSD_RR_ERROR, GSD_RR_ERROR_UNKNOWN, "unable to get EDID for output"); goto out; } edid = gcm_edid_new (); ret = gcm_edid_parse (edid, data, size, error); if (!ret) { g_object_unref (edid); edid = NULL; goto out; } /* add to cache */ g_hash_table_insert (manager->priv->edid_cache, g_strdup (gsd_rr_output_get_name (output)), g_object_ref (edid)); out: return edid; } static gboolean gcm_session_screen_set_icc_profile (GsdColorManager *manager, const gchar *filename, GError **error) { gboolean ret; gchar *data = NULL; gsize length; guint version_data; GsdColorManagerPrivate *priv = manager->priv; g_return_val_if_fail (filename != NULL, FALSE); g_debug ("setting root window ICC profile atom from %s", filename); /* get contents of file */ ret = g_file_get_contents (filename, &data, &length, error); if (!ret) goto out; /* set profile property */ gdk_property_change (priv->gdk_window, gdk_atom_intern_static_string ("_ICC_PROFILE"), gdk_atom_intern_static_string ("CARDINAL"), 8, GDK_PROP_MODE_REPLACE, (const guchar *) data, length); /* set version property */ version_data = GCM_ICC_PROFILE_IN_X_VERSION_MAJOR * 100 + GCM_ICC_PROFILE_IN_X_VERSION_MINOR * 1; gdk_property_change (priv->gdk_window, gdk_atom_intern_static_string ("_ICC_PROFILE_IN_X_VERSION"), gdk_atom_intern_static_string ("CARDINAL"), 8, GDK_PROP_MODE_REPLACE, (const guchar *) &version_data, 1); out: g_free (data); return ret; } static gchar * gcm_session_get_output_id (GsdColorManager *manager, GsdRROutput *output) { const gchar *name; const gchar *serial; const gchar *vendor; GcmEdid *edid = NULL; GString *device_id; GError *error = NULL; /* all output devices are prefixed with this */ device_id = g_string_new ("xrandr"); /* get the output EDID if possible */ edid = gcm_session_get_output_edid (manager, output, &error); if (edid == NULL) { g_debug ("no edid for %s [%s], falling back to connection name", gsd_rr_output_get_name (output), error->message); g_error_free (error); g_string_append_printf (device_id, "-%s", gsd_rr_output_get_name (output)); goto out; } /* check EDID data is okay to use */ vendor = gcm_edid_get_vendor_name (edid); name = gcm_edid_get_monitor_name (edid); serial = gcm_edid_get_serial_number (edid); if (vendor == NULL && name == NULL && serial == NULL) { g_debug ("edid invalid for %s, falling back to connection name", gsd_rr_output_get_name (output)); g_string_append_printf (device_id, "-%s", gsd_rr_output_get_name (output)); goto out; } /* use EDID data */ if (vendor != NULL) g_string_append_printf (device_id, "-%s", vendor); if (name != NULL) g_string_append_printf (device_id, "-%s", name); if (serial != NULL) g_string_append_printf (device_id, "-%s", serial); out: if (edid != NULL) g_object_unref (edid); return g_string_free (device_id, FALSE); } typedef struct { GsdColorManager *manager; CdProfile *profile; CdDevice *device; guint32 output_id; } GcmSessionAsyncHelper; static void gcm_session_async_helper_free (GcmSessionAsyncHelper *helper) { if (helper->manager != NULL) g_object_unref (helper->manager); if (helper->profile != NULL) g_object_unref (helper->profile); if (helper->device != NULL) g_object_unref (helper->device); g_free (helper); } static cmsBool _cmsWriteTagTextAscii (cmsHPROFILE lcms_profile, cmsTagSignature sig, const gchar *text) { cmsBool ret; cmsMLU *mlu = cmsMLUalloc (0, 1); cmsMLUsetASCII (mlu, "en", "US", text); ret = cmsWriteTag (lcms_profile, sig, mlu); cmsMLUfree (mlu); return ret; } static gboolean gcm_utils_mkdir_for_filename (const gchar *filename, GError **error) { gboolean ret = FALSE; GFile *file; GFile *parent_dir = NULL; /* get parent directory */ file = g_file_new_for_path (filename); parent_dir = g_file_get_parent (file); if (parent_dir == NULL) { g_set_error (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "could not get parent dir %s", filename); goto out; } /* ensure desination does not already exist */ ret = g_file_query_exists (parent_dir, NULL); if (ret) goto out; ret = g_file_make_directory_with_parents (parent_dir, NULL, error); if (!ret) goto out; out: if (file != NULL) g_object_unref (file); if (parent_dir != NULL) g_object_unref (parent_dir); return ret; } #ifdef HAVE_NEW_LCMS static wchar_t * utf8_to_wchar_t (const char *src) { size_t len; size_t converted; wchar_t *buf = NULL; len = mbstowcs (NULL, src, 0); if (len == (size_t) -1) { g_warning ("Invalid UTF-8 in string %s", src); goto out; } len += 1; buf = g_malloc (sizeof (wchar_t) * len); converted = mbstowcs (buf, src, len - 1); g_assert (converted != -1); buf[converted] = '\0'; out: return buf; } static cmsBool _cmsDictAddEntryAscii (cmsHANDLE dict, const gchar *key, const gchar *value) { cmsBool ret = FALSE; wchar_t *mb_key = NULL; wchar_t *mb_value = NULL; mb_key = utf8_to_wchar_t (key); if (mb_key == NULL) goto out; mb_value = utf8_to_wchar_t (value); if (mb_value == NULL) goto out; ret = cmsDictAddEntry (dict, mb_key, mb_value, NULL, NULL); out: g_free (mb_key); g_free (mb_value); return ret; } #endif /* HAVE_NEW_LCMS */ static gboolean gcm_apply_create_icc_profile_for_edid (GsdColorManager *manager, CdDevice *device, GcmEdid *edid, const gchar *filename, GError **error) { const CdColorYxy *tmp; cmsCIExyYTRIPLE chroma; cmsCIExyY white_point; cmsHPROFILE lcms_profile = NULL; cmsToneCurve *transfer_curve[3] = { NULL, NULL, NULL }; const gchar *data; gboolean ret = FALSE; gchar *str; gfloat edid_gamma; gfloat localgamma; #ifdef HAVE_NEW_LCMS cmsHANDLE dict = NULL; #endif GsdColorManagerPrivate *priv = manager->priv; /* ensure the per-user directory exists */ ret = gcm_utils_mkdir_for_filename (filename, error); if (!ret) goto out; /* copy color data from our structures */ tmp = gcm_edid_get_red (edid); chroma.Red.x = tmp->x; chroma.Red.y = tmp->y; tmp = gcm_edid_get_green (edid); chroma.Green.x = tmp->x; chroma.Green.y = tmp->y; tmp = gcm_edid_get_blue (edid); chroma.Blue.x = tmp->x; chroma.Blue.y = tmp->y; tmp = gcm_edid_get_white (edid); white_point.x = tmp->x; white_point.y = tmp->y; white_point.Y = 1.0; /* estimate the transfer function for the gamma */ localgamma = gcm_edid_get_gamma (edid); transfer_curve[0] = transfer_curve[1] = transfer_curve[2] = cmsBuildGamma (NULL, localgamma); /* create our generated profile */ lcms_profile = cmsCreateRGBProfile (&white_point, &chroma, transfer_curve); if (lcms_profile == NULL) { g_set_error (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "failed to create profile"); goto out; } cmsSetColorSpace (lcms_profile, cmsSigRgbData); cmsSetPCS (lcms_profile, cmsSigXYZData); cmsSetHeaderRenderingIntent (lcms_profile, INTENT_PERCEPTUAL); cmsSetDeviceClass (lcms_profile, cmsSigDisplayClass); /* copyright */ ret = _cmsWriteTagTextAscii (lcms_profile, cmsSigCopyrightTag, /* deliberately not translated */ "This profile is free of known copyright restrictions."); if (!ret) { g_set_error_literal (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "failed to write copyright"); goto out; } /* set model */ data = gcm_edid_get_monitor_name (edid); if (data == NULL) data = gcm_dmi_get_name (priv->dmi); if (data == NULL) data = "Unknown monitor"; ret = _cmsWriteTagTextAscii (lcms_profile, cmsSigDeviceModelDescTag, data); if (!ret) { g_set_error_literal (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "failed to write model"); goto out; } /* write title */ ret = _cmsWriteTagTextAscii (lcms_profile, cmsSigProfileDescriptionTag, data); if (!ret) { g_set_error_literal (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "failed to write description"); goto out; } /* get manufacturer */ data = gcm_edid_get_vendor_name (edid); if (data == NULL) data = gcm_dmi_get_vendor (priv->dmi); if (data == NULL) data = "Unknown vendor"; ret = _cmsWriteTagTextAscii (lcms_profile, cmsSigDeviceMfgDescTag, data); if (!ret) { g_set_error_literal (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "failed to write manufacturer"); goto out; } #ifdef HAVE_NEW_LCMS /* just create a new dict */ dict = cmsDictAlloc (NULL); /* set the framework creator metadata */ _cmsDictAddEntryAscii (dict, CD_PROFILE_METADATA_CMF_PRODUCT, PACKAGE_NAME); _cmsDictAddEntryAscii (dict, CD_PROFILE_METADATA_CMF_BINARY, PACKAGE_NAME); _cmsDictAddEntryAscii (dict, CD_PROFILE_METADATA_CMF_VERSION, PACKAGE_VERSION); _cmsDictAddEntryAscii (dict, CD_PROFILE_METADATA_MAPPING_DEVICE_ID, cd_device_get_id (device)); /* set the data source so we don't ever prompt the user to * recalibrate (as the EDID data won't have changed) */ _cmsDictAddEntryAscii (dict, CD_PROFILE_METADATA_DATA_SOURCE, CD_PROFILE_METADATA_DATA_SOURCE_EDID); /* set 'ICC meta Tag for Monitor Profiles' data */ _cmsDictAddEntryAscii (dict, "EDID_md5", gcm_edid_get_checksum (edid)); data = gcm_edid_get_monitor_name (edid); if (data != NULL) _cmsDictAddEntryAscii (dict, "EDID_model", data); data = gcm_edid_get_serial_number (edid); if (data != NULL) _cmsDictAddEntryAscii (dict, "EDID_serial", data); data = gcm_edid_get_pnp_id (edid); if (data != NULL) _cmsDictAddEntryAscii (dict, "EDID_mnft", data); data = gcm_edid_get_vendor_name (edid); if (data != NULL) _cmsDictAddEntryAscii (dict, "EDID_manufacturer", data); edid_gamma = gcm_edid_get_gamma (edid); if (edid_gamma > 0.0 && edid_gamma < 10.0) { str = g_strdup_printf ("%f", edid_gamma); _cmsDictAddEntryAscii (dict, "EDID_gamma", str); g_free (str); } /* also add the primaries */ str = g_strdup_printf ("%f", chroma.Red.x); _cmsDictAddEntryAscii (dict, "EDID_red_x", str); g_free (str); str = g_strdup_printf ("%f", chroma.Red.y); _cmsDictAddEntryAscii (dict, "EDID_red_y", str); g_free (str); str = g_strdup_printf ("%f", chroma.Green.x); _cmsDictAddEntryAscii (dict, "EDID_green_x", str); g_free (str); str = g_strdup_printf ("%f", chroma.Green.y); _cmsDictAddEntryAscii (dict, "EDID_green_y", str); g_free (str); str = g_strdup_printf ("%f", chroma.Blue.x); _cmsDictAddEntryAscii (dict, "EDID_blue_x", str); g_free (str); str = g_strdup_printf ("%f", chroma.Blue.y); _cmsDictAddEntryAscii (dict, "EDID_blue_y", str); g_free (str); /* write new tag */ ret = cmsWriteTag (lcms_profile, cmsSigMetaTag, dict); if (!ret) { g_set_error_literal (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "failed to write profile metadata"); goto out; } #endif /* HAVE_NEW_LCMS */ /* write profile id */ ret = cmsMD5computeID (lcms_profile); if (!ret) { g_set_error_literal (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "failed to write profile id"); goto out; } /* save, TODO: get error */ cmsSaveProfileToFile (lcms_profile, filename); ret = TRUE; out: #ifdef HAVE_NEW_LCMS if (dict != NULL) cmsDictFree (dict); #endif if (*transfer_curve != NULL) cmsFreeToneCurve (*transfer_curve); return ret; } static GPtrArray * gcm_session_generate_vcgt (CdProfile *profile, guint size) { GsdRROutputClutItem *tmp; GPtrArray *array = NULL; const cmsToneCurve **vcgt; cmsFloat32Number in; guint i; const gchar *filename; cmsHPROFILE lcms_profile = NULL; /* invalid size */ if (size == 0) goto out; /* not an actual profile */ filename = cd_profile_get_filename (profile); if (filename == NULL) goto out; /* open file */ lcms_profile = cmsOpenProfileFromFile (filename, "r"); if (lcms_profile == NULL) goto out; /* get tone curves from profile */ vcgt = cmsReadTag (lcms_profile, cmsSigVcgtTag); if (vcgt == NULL || vcgt[0] == NULL) { g_debug ("profile does not have any VCGT data"); goto out; } /* create array */ array = g_ptr_array_new_with_free_func (g_free); for (i = 0; i < size; i++) { in = (gdouble) i / (gdouble) (size - 1); tmp = g_new0 (GsdRROutputClutItem, 1); tmp->red = cmsEvalToneCurveFloat(vcgt[0], in) * (gdouble) 0xffff; tmp->green = cmsEvalToneCurveFloat(vcgt[1], in) * (gdouble) 0xffff; tmp->blue = cmsEvalToneCurveFloat(vcgt[2], in) * (gdouble) 0xffff; g_ptr_array_add (array, tmp); } out: if (lcms_profile != NULL) cmsCloseProfile (lcms_profile); return array; } static guint gsd_rr_output_get_gamma_size (GsdRROutput *output) { GsdRRCrtc *crtc; gint len = 0; crtc = gsd_rr_output_get_crtc (output); if (crtc == NULL) return 0; gsd_rr_crtc_get_gamma (crtc, &len, NULL, NULL, NULL); return (guint) len; } static gboolean gcm_session_output_set_gamma (GsdRROutput *output, GPtrArray *array, GError **error) { gboolean ret = TRUE; guint16 *red = NULL; guint16 *green = NULL; guint16 *blue = NULL; guint i; GsdRROutputClutItem *data; GsdRRCrtc *crtc; /* no length? */ if (array->len == 0) { ret = FALSE; g_set_error_literal (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "no data in the CLUT array"); goto out; } /* convert to a type X understands */ red = g_new (guint16, array->len); green = g_new (guint16, array->len); blue = g_new (guint16, array->len); for (i = 0; i < array->len; i++) { data = g_ptr_array_index (array, i); red[i] = data->red; green[i] = data->green; blue[i] = data->blue; } /* send to LUT */ crtc = gsd_rr_output_get_crtc (output); if (crtc == NULL) { ret = FALSE; g_set_error (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "failed to get ctrc for %s", gsd_rr_output_get_name (output)); goto out; } gsd_rr_crtc_set_gamma (crtc, array->len, red, green, blue); out: g_free (red); g_free (green); g_free (blue); return ret; } static gboolean gcm_session_device_set_gamma (GsdRROutput *output, CdProfile *profile, GError **error) { gboolean ret = FALSE; guint size; GPtrArray *clut = NULL; /* create a lookup table */ size = gsd_rr_output_get_gamma_size (output); if (size == 0) { ret = TRUE; goto out; } clut = gcm_session_generate_vcgt (profile, size); if (clut == NULL) { g_set_error_literal (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "failed to generate vcgt"); goto out; } /* apply the vcgt to this output */ ret = gcm_session_output_set_gamma (output, clut, error); if (!ret) goto out; out: if (clut != NULL) g_ptr_array_unref (clut); return ret; } static gboolean gcm_session_device_reset_gamma (GsdRROutput *output, GError **error) { gboolean ret; guint i; guint size; guint32 value; GPtrArray *clut; GsdRROutputClutItem *data; /* create a linear ramp */ g_debug ("falling back to dummy ramp"); clut = g_ptr_array_new_with_free_func (g_free); size = gsd_rr_output_get_gamma_size (output); if (size == 0) { ret = TRUE; goto out; } for (i = 0; i < size; i++) { value = (i * 0xffff) / (size - 1); data = g_new0 (GsdRROutputClutItem, 1); data->red = value; data->green = value; data->blue = value; g_ptr_array_add (clut, data); } /* apply the vcgt to this output */ ret = gcm_session_output_set_gamma (output, clut, error); if (!ret) goto out; out: g_ptr_array_unref (clut); return ret; } static GsdRROutput * gcm_session_get_x11_output_by_id (GsdColorManager *manager, const gchar *device_id, GError **error) { gchar *output_id; GsdRROutput *output = NULL; GsdRROutput **outputs = NULL; guint i; GsdColorManagerPrivate *priv = manager->priv; /* search all X11 outputs for the device id */ outputs = gsd_rr_screen_list_outputs (priv->x11_screen); if (outputs == NULL) { g_set_error_literal (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "Failed to get outputs"); goto out; } for (i = 0; outputs[i] != NULL && output == NULL; i++) { if (!gsd_rr_output_is_connected (outputs[i])) continue; output_id = gcm_session_get_output_id (manager, outputs[i]); if (g_strcmp0 (output_id, device_id) == 0) output = outputs[i]; g_free (output_id); } if (output == NULL) { g_set_error (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "Failed to find output %s", device_id); } out: return output; } /* this function is more complicated than it should be, due to the * fact that XOrg sometimes assigns no primary devices when using * "xrandr --auto" or when the version of RANDR is < 1.3 */ static gboolean gcm_session_use_output_profile_for_screen (GsdColorManager *manager, GsdRROutput *output) { gboolean has_laptop = FALSE; gboolean has_primary = FALSE; GsdRROutput **outputs; GsdRROutput *connected = NULL; guint i; /* do we have any screens marked as primary */ outputs = gsd_rr_screen_list_outputs (manager->priv->x11_screen); if (outputs == NULL || outputs[0] == NULL) { g_warning ("failed to get outputs"); return FALSE; } for (i = 0; outputs[i] != NULL; i++) { if (!gsd_rr_output_is_connected (outputs[i])) continue; if (connected == NULL) connected = outputs[i]; if (gsd_rr_output_get_is_primary (outputs[i])) has_primary = TRUE; if (gsd_rr_output_is_laptop (outputs[i])) has_laptop = TRUE; } /* we have an assigned primary device, are we that? */ if (has_primary) return gsd_rr_output_get_is_primary (output); /* choosing the internal panel is probably sane */ if (has_laptop) return gsd_rr_output_is_laptop (output); /* we have to choose one, so go for the first connected device */ if (connected != NULL) return gsd_rr_output_get_id (connected) == gsd_rr_output_get_id (output); return FALSE; } /* TODO: remove when we can dep on a released version of colord */ #ifndef CD_PROFILE_METADATA_SCREEN_BRIGHTNESS #define CD_PROFILE_METADATA_SCREEN_BRIGHTNESS "SCREEN_brightness" #endif #define GSD_DBUS_NAME_POWER GSD_DBUS_NAME ".Power" #define GSD_DBUS_INTERFACE_POWER_SCREEN GSD_DBUS_BASE_INTERFACE ".Power.Screen" #define GSD_DBUS_PATH_POWER GSD_DBUS_PATH "/Power" static void gcm_session_set_output_percentage_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GDBusConnection *connection = G_DBUS_CONNECTION (source_object); GError *error = NULL; GVariant *retval; retval = g_dbus_connection_call_finish (connection, res, &error); if (retval == NULL) { g_warning ("failed to set output brightness: %s", error->message); g_error_free (error); return; } g_variant_unref (retval); } static void gcm_session_set_output_percentage (guint percentage) { GDBusConnection *connection; /* get a ref to the existing bus connection */ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); if (connection == NULL) return; g_dbus_connection_call (connection, GSD_DBUS_NAME_POWER, GSD_DBUS_PATH_POWER, GSD_DBUS_INTERFACE_POWER_SCREEN, "SetPercentage", g_variant_new ("(u)", percentage), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, gcm_session_set_output_percentage_cb, NULL); g_object_unref (connection); } static void gcm_session_device_assign_profile_connect_cb (GObject *object, GAsyncResult *res, gpointer user_data) { CdProfile *profile = CD_PROFILE (object); const gchar *brightness_profile; const gchar *filename; gboolean ret; GError *error = NULL; GsdRROutput *output; guint brightness_percentage; GcmSessionAsyncHelper *helper = (GcmSessionAsyncHelper *) user_data; GsdColorManager *manager = GSD_COLOR_MANAGER (helper->manager); /* get properties */ ret = cd_profile_connect_finish (profile, res, &error); if (!ret) { g_warning ("failed to connect to profile: %s", error->message); g_error_free (error); goto out; } /* get the filename */ filename = cd_profile_get_filename (profile); g_assert (filename != NULL); /* get the output (can't save in helper as GsdRROutput isn't * a GObject, just a pointer */ output = gsd_rr_screen_get_output_by_id (manager->priv->x11_screen, helper->output_id); if (output == NULL) goto out; /* if output is a laptop screen and the profile has a * calibration brightness then set this new brightness */ brightness_profile = cd_profile_get_metadata_item (profile, CD_PROFILE_METADATA_SCREEN_BRIGHTNESS); if (gsd_rr_output_is_laptop (output) && brightness_profile != NULL) { /* the percentage is stored in the profile metadata as * a string, not ideal, but it's all we have... */ brightness_percentage = atoi (brightness_profile); gcm_session_set_output_percentage (brightness_percentage); } /* set the _ICC_PROFILE atom */ ret = gcm_session_use_output_profile_for_screen (manager, output); if (ret) { ret = gcm_session_screen_set_icc_profile (manager, filename, &error); if (!ret) { g_warning ("failed to set screen _ICC_PROFILE: %s", error->message); g_clear_error (&error); } } /* create a vcgt for this icc file */ ret = cd_profile_get_has_vcgt (profile); if (ret) { ret = gcm_session_device_set_gamma (output, profile, &error); if (!ret) { g_warning ("failed to set %s gamma tables: %s", cd_device_get_id (helper->device), error->message); g_error_free (error); goto out; } } else { ret = gcm_session_device_reset_gamma (output, &error); if (!ret) { g_warning ("failed to reset %s gamma tables: %s", cd_device_get_id (helper->device), error->message); g_error_free (error); goto out; } } out: gcm_session_async_helper_free (helper); } /* * Check to see if the on-disk profile has the MAPPING_device_id * metadata, and if not, we should delete the profile and re-create it * so that it gets mapped by the daemon. */ static gboolean gcm_session_check_profile_device_md (const gchar *filename) { cmsHANDLE dict; cmsHPROFILE lcms_profile; const cmsDICTentry *entry; gboolean ret = FALSE; gchar ascii_name[1024]; gsize len; /* parse the ICC file */ lcms_profile = cmsOpenProfileFromFile (filename, "r"); if (lcms_profile == NULL) goto out; /* does profile have metadata? */ dict = cmsReadTag (lcms_profile, cmsSigMetaTag); if (dict == NULL) { g_debug ("auto-edid profile is old, and contains no metadata"); goto out; } for (entry = cmsDictGetEntryList (dict); entry != NULL; entry = cmsDictNextEntry (entry)) { if (entry->Name == NULL) continue; len = wcstombs (ascii_name, entry->Name, sizeof (ascii_name)); if (len == (gsize) -1) continue; if (g_strcmp0 (ascii_name, CD_PROFILE_METADATA_MAPPING_DEVICE_ID) == 0) { ret = TRUE; goto out; } } g_debug ("auto-edid profile is old, and contains no %s data", CD_PROFILE_METADATA_MAPPING_DEVICE_ID); out: if (lcms_profile != NULL) cmsCloseProfile (lcms_profile); return ret; } static void gcm_session_device_assign_connect_cb (GObject *object, GAsyncResult *res, gpointer user_data) { CdDeviceKind kind; CdProfile *profile = NULL; gboolean ret; gchar *autogen_filename = NULL; gchar *autogen_path = NULL; GcmEdid *edid = NULL; GsdRROutput *output = NULL; GError *error = NULL; const gchar *xrandr_id; GcmSessionAsyncHelper *helper; CdDevice *device = CD_DEVICE (object); GsdColorManager *manager = GSD_COLOR_MANAGER (user_data); GsdColorManagerPrivate *priv = manager->priv; /* remove from assign array */ g_hash_table_remove (manager->priv->device_assign_hash, cd_device_get_object_path (device)); /* get properties */ ret = cd_device_connect_finish (device, res, &error); if (!ret) { g_warning ("failed to connect to device: %s", error->message); g_error_free (error); goto out; } /* check we care */ kind = cd_device_get_kind (device); if (kind != CD_DEVICE_KIND_DISPLAY) goto out; g_debug ("need to assign display device %s", cd_device_get_id (device)); /* get the GsdRROutput for the device id */ xrandr_id = cd_device_get_id (device); output = gcm_session_get_x11_output_by_id (manager, xrandr_id, &error); if (output == NULL) { g_warning ("no %s device found: %s", cd_device_get_id (device), error->message); g_error_free (error); goto out; } /* create profile from device edid if it exists */ edid = gcm_session_get_output_edid (manager, output, &error); if (edid == NULL) { g_warning ("unable to get EDID for %s: %s", cd_device_get_id (device), error->message); g_clear_error (&error); } else { autogen_filename = g_strdup_printf ("edid-%s.icc", gcm_edid_get_checksum (edid)); autogen_path = g_build_filename (g_get_user_data_dir (), "icc", autogen_filename, NULL); /* check if auto-profile has up-to-date metadata */ if (gcm_session_check_profile_device_md (autogen_path)) { g_debug ("auto-profile edid %s exists with md", autogen_path); } else { g_debug ("auto-profile edid does not exist, creating as %s", autogen_path); ret = gcm_apply_create_icc_profile_for_edid (manager, device, edid, autogen_path, &error); if (!ret) { g_warning ("failed to create profile from EDID data: %s", error->message); g_clear_error (&error); } } } /* get the default profile for the device */ profile = cd_device_get_default_profile (device); if (profile == NULL) { g_debug ("%s has no default profile to set", cd_device_get_id (device)); /* the default output? */ if (gsd_rr_output_get_is_primary (output)) { gdk_property_delete (priv->gdk_window, gdk_atom_intern_static_string ("_ICC_PROFILE")); gdk_property_delete (priv->gdk_window, gdk_atom_intern_static_string ("_ICC_PROFILE_IN_X_VERSION")); } /* reset, as we want linear profiles for profiling */ ret = gcm_session_device_reset_gamma (output, &error); if (!ret) { g_warning ("failed to reset %s gamma tables: %s", cd_device_get_id (device), error->message); g_error_free (error); goto out; } goto out; } /* get properties */ helper = g_new0 (GcmSessionAsyncHelper, 1); helper->output_id = gsd_rr_output_get_id (output); helper->manager = g_object_ref (manager); helper->device = g_object_ref (device); cd_profile_connect (profile, NULL, gcm_session_device_assign_profile_connect_cb, helper); out: g_free (autogen_filename); g_free (autogen_path); if (edid != NULL) g_object_unref (edid); if (profile != NULL) g_object_unref (profile); } static void gcm_session_device_assign (GsdColorManager *manager, CdDevice *device) { const gchar *key; gpointer found; /* are we already assigning this device */ key = cd_device_get_object_path (device); found = g_hash_table_lookup (manager->priv->device_assign_hash, key); if (found != NULL) { g_debug ("assign for %s already in progress", key); return; } g_hash_table_insert (manager->priv->device_assign_hash, g_strdup (key), GINT_TO_POINTER (TRUE)); cd_device_connect (device, NULL, gcm_session_device_assign_connect_cb, manager); } static void gcm_session_device_added_assign_cb (CdClient *client, CdDevice *device, GsdColorManager *manager) { gcm_session_device_assign (manager, device); } static void gcm_session_device_changed_assign_cb (CdClient *client, CdDevice *device, GsdColorManager *manager) { g_debug ("%s changed", cd_device_get_object_path (device)); gcm_session_device_assign (manager, device); } static void gcm_session_create_device_cb (GObject *object, GAsyncResult *res, gpointer user_data) { CdDevice *device; GError *error = NULL; device = cd_client_create_device_finish (CD_CLIENT (object), res, &error); if (device == NULL) { if (error->domain != CD_CLIENT_ERROR || error->code != CD_CLIENT_ERROR_ALREADY_EXISTS) { g_warning ("failed to create device: %s", error->message); } g_error_free (error); return; } g_object_unref (device); } static void gcm_session_add_x11_output (GsdColorManager *manager, GsdRROutput *output) { const gchar *edid_checksum = NULL; const gchar *model = NULL; const gchar *serial = NULL; const gchar *vendor = NULL; gboolean ret; gchar *device_id = NULL; GcmEdid *edid; GError *error = NULL; GHashTable *device_props = NULL; GsdColorManagerPrivate *priv = manager->priv; /* try to get edid */ edid = gcm_session_get_output_edid (manager, output, &error); if (edid == NULL) { g_warning ("failed to get edid: %s", error->message); g_clear_error (&error); } /* prefer DMI data for the internal output */ ret = gsd_rr_output_is_laptop (output); if (ret) { model = gcm_dmi_get_name (priv->dmi); vendor = gcm_dmi_get_vendor (priv->dmi); } /* use EDID data if we have it */ if (edid != NULL) { edid_checksum = gcm_edid_get_checksum (edid); if (model == NULL) model = gcm_edid_get_monitor_name (edid); if (vendor == NULL) vendor = gcm_edid_get_vendor_name (edid); if (serial == NULL) serial = gcm_edid_get_serial_number (edid); } /* ensure mandatory fields are set */ if (model == NULL) model = gsd_rr_output_get_name (output); if (vendor == NULL) vendor = "unknown"; if (serial == NULL) serial = "unknown"; device_id = gcm_session_get_output_id (manager, output); g_debug ("output %s added", device_id); device_props = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); g_hash_table_insert (device_props, (gpointer) CD_DEVICE_PROPERTY_KIND, (gpointer) cd_device_kind_to_string (CD_DEVICE_KIND_DISPLAY)); g_hash_table_insert (device_props, (gpointer) CD_DEVICE_PROPERTY_MODE, (gpointer) cd_device_mode_to_string (CD_DEVICE_MODE_PHYSICAL)); g_hash_table_insert (device_props, (gpointer) CD_DEVICE_PROPERTY_COLORSPACE, (gpointer) cd_colorspace_to_string (CD_COLORSPACE_RGB)); g_hash_table_insert (device_props, (gpointer) CD_DEVICE_PROPERTY_VENDOR, (gpointer) vendor); g_hash_table_insert (device_props, (gpointer) CD_DEVICE_PROPERTY_MODEL, (gpointer) model); g_hash_table_insert (device_props, (gpointer) CD_DEVICE_PROPERTY_SERIAL, (gpointer) serial); g_hash_table_insert (device_props, (gpointer) CD_DEVICE_METADATA_XRANDR_NAME, (gpointer) gsd_rr_output_get_name (output)); #if CD_CHECK_VERSION(0,1,25) g_hash_table_insert (device_props, (gpointer) CD_DEVICE_METADATA_OUTPUT_PRIORITY, gsd_rr_output_get_is_primary (output) ? (gpointer) CD_DEVICE_METADATA_OUTPUT_PRIORITY_PRIMARY : (gpointer) CD_DEVICE_METADATA_OUTPUT_PRIORITY_SECONDARY); #endif #if CD_CHECK_VERSION(0,1,34) if (edid_checksum != NULL) { g_hash_table_insert (device_props, (gpointer) CD_DEVICE_METADATA_OUTPUT_EDID_MD5, (gpointer) edid_checksum); } #endif #if CD_CHECK_VERSION(0,1,27) /* set this so we can call the device a 'Laptop Screen' in the * control center main panel */ if (gsd_rr_output_is_laptop (output)) { g_hash_table_insert (device_props, (gpointer) CD_DEVICE_PROPERTY_EMBEDDED, NULL); } #endif cd_client_create_device (priv->client, device_id, CD_OBJECT_SCOPE_TEMP, device_props, NULL, gcm_session_create_device_cb, manager); g_free (device_id); if (device_props != NULL) g_hash_table_unref (device_props); if (edid != NULL) g_object_unref (edid); } static void gsd_rr_screen_output_added_cb (GsdRRScreen *screen, GsdRROutput *output, GsdColorManager *manager) { gcm_session_add_x11_output (manager, output); } static void gcm_session_screen_removed_delete_device_cb (GObject *object, GAsyncResult *res, gpointer user_data) { gboolean ret; GError *error = NULL; /* deleted device */ ret = cd_client_delete_device_finish (CD_CLIENT (object), res, &error); if (!ret) { g_warning ("failed to delete device: %s", error->message); g_error_free (error); } } static void gcm_session_screen_removed_find_device_cb (GObject *object, GAsyncResult *res, gpointer user_data) { GError *error = NULL; CdDevice *device; GsdColorManager *manager = GSD_COLOR_MANAGER (user_data); device = cd_client_find_device_finish (manager->priv->client, res, &error); if (device == NULL) { g_warning ("failed to find device: %s", error->message); g_error_free (error); return; } g_debug ("output %s found, and will be removed", cd_device_get_object_path (device)); cd_client_delete_device (manager->priv->client, device, NULL, gcm_session_screen_removed_delete_device_cb, manager); g_object_unref (device); } static void gsd_rr_screen_output_removed_cb (GsdRRScreen *screen, GsdRROutput *output, GsdColorManager *manager) { g_debug ("output %s removed", gsd_rr_output_get_name (output)); g_hash_table_remove (manager->priv->edid_cache, gsd_rr_output_get_name (output)); cd_client_find_device_by_property (manager->priv->client, CD_DEVICE_METADATA_XRANDR_NAME, gsd_rr_output_get_name (output), NULL, gcm_session_screen_removed_find_device_cb, manager); } static void gcm_session_get_devices_cb (GObject *object, GAsyncResult *res, gpointer user_data) { CdDevice *device; GError *error = NULL; GPtrArray *array; guint i; GsdColorManager *manager = GSD_COLOR_MANAGER (user_data); array = cd_client_get_devices_finish (CD_CLIENT (object), res, &error); if (array == NULL) { g_warning ("failed to get devices: %s", error->message); g_error_free (error); goto out; } for (i = 0; i < array->len; i++) { device = g_ptr_array_index (array, i); gcm_session_device_assign (manager, device); } out: if (array != NULL) g_ptr_array_unref (array); } static void gcm_session_profile_gamma_find_device_cb (GObject *object, GAsyncResult *res, gpointer user_data) { CdClient *client = CD_CLIENT (object); CdDevice *device = NULL; GError *error = NULL; GsdColorManager *manager = GSD_COLOR_MANAGER (user_data); device = cd_client_find_device_by_property_finish (client, res, &error); if (device == NULL) { g_warning ("could not find device: %s", error->message); g_error_free (error); goto out; } /* get properties */ cd_device_connect (device, NULL, gcm_session_device_assign_connect_cb, manager); out: if (device != NULL) g_object_unref (device); } /* We have to reset the gamma tables each time as if the primary output * has changed then different crtcs are going to be used. * See https://bugzilla.gnome.org/show_bug.cgi?id=660164 for an example */ static void gsd_rr_screen_output_changed_cb (GsdRRScreen *screen, GsdColorManager *manager) { GsdRROutput **outputs; GsdColorManagerPrivate *priv = manager->priv; guint i; /* get X11 outputs */ outputs = gsd_rr_screen_list_outputs (priv->x11_screen); if (outputs == NULL) { g_warning ("failed to get outputs"); return; } for (i = 0; outputs[i] != NULL; i++) { if (!gsd_rr_output_is_connected (outputs[i])) continue; /* get CdDevice for this output */ cd_client_find_device_by_property (manager->priv->client, CD_DEVICE_METADATA_XRANDR_NAME, gsd_rr_output_get_name (outputs[i]), NULL, gcm_session_profile_gamma_find_device_cb, manager); } } static void gcm_session_client_connect_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { gboolean ret; GError *error = NULL; GsdRROutput **outputs; guint i; GsdColorManager *manager = GSD_COLOR_MANAGER (user_data); GsdColorManagerPrivate *priv = manager->priv; /* connected */ g_debug ("connected to colord"); ret = cd_client_connect_finish (manager->priv->client, res, &error); if (!ret) { g_warning ("failed to connect to colord: %s", error->message); g_error_free (error); return; } #if CD_CHECK_VERSION(0,1,12) /* is there an available colord instance? */ ret = cd_client_get_has_server (manager->priv->client); if (!ret) { g_warning ("There is no colord server available"); goto out; } #endif /* add profiles */ gcm_profile_store_search (priv->profile_store); /* add screens */ gsd_rr_screen_refresh (priv->x11_screen, &error); if (error != NULL) { g_warning ("failed to refresh: %s", error->message); g_error_free (error); goto out; } /* get X11 outputs */ outputs = gsd_rr_screen_list_outputs (priv->x11_screen); if (outputs == NULL) { g_warning ("failed to get outputs"); goto out; } for (i = 0; outputs[i] != NULL; i++) { if (gsd_rr_output_is_connected (outputs[i])) gcm_session_add_x11_output (manager, outputs[i]); } /* only connect when colord is awake */ g_signal_connect (priv->x11_screen, "output-connected", G_CALLBACK (gsd_rr_screen_output_added_cb), manager); g_signal_connect (priv->x11_screen, "output-disconnected", G_CALLBACK (gsd_rr_screen_output_removed_cb), manager); g_signal_connect (priv->x11_screen, "changed", G_CALLBACK (gsd_rr_screen_output_changed_cb), manager); g_signal_connect (priv->client, "device-added", G_CALLBACK (gcm_session_device_added_assign_cb), manager); g_signal_connect (priv->client, "device-changed", G_CALLBACK (gcm_session_device_changed_assign_cb), manager); /* set for each device that already exist */ cd_client_get_devices (priv->client, NULL, gcm_session_get_devices_cb, manager); out: return; } gboolean gsd_color_manager_start (GsdColorManager *manager, GError **error) { GsdColorManagerPrivate *priv = manager->priv; gboolean ret = FALSE; g_debug ("Starting color manager"); gnome_settings_profile_start (NULL); /* coldplug the list of screens */ priv->x11_screen = gsd_rr_screen_new (gdk_screen_get_default (), error); if (priv->x11_screen == NULL) goto out; cd_client_connect (priv->client, NULL, gcm_session_client_connect_cb, manager); /* success */ ret = TRUE; out: gnome_settings_profile_end (NULL); return ret; } void gsd_color_manager_stop (GsdColorManager *manager) { g_debug ("Stopping color manager"); g_clear_object (&manager->priv->settings); g_clear_object (&manager->priv->client); g_clear_object (&manager->priv->profile_store); g_clear_object (&manager->priv->dmi); g_clear_object (&manager->priv->session); g_clear_pointer (&manager->priv->edid_cache, g_hash_table_destroy); g_clear_pointer (&manager->priv->device_assign_hash, g_hash_table_destroy); g_clear_object (&manager->priv->x11_screen); } static void gcm_session_exec_control_center (GsdColorManager *manager) { gboolean ret; GError *error = NULL; GAppInfo *app_info; GdkAppLaunchContext *launch_context; /* setup the launch context so the startup notification is correct */ launch_context = gdk_display_get_app_launch_context (gdk_display_get_default ()); app_info = g_app_info_create_from_commandline (BINDIR "/gnome-control-center color", "gnome-control-center", G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION, &error); if (app_info == NULL) { g_warning ("failed to create application info: %s", error->message); g_error_free (error); goto out; } /* launch gnome-control-center */ ret = g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error); if (!ret) { g_warning ("failed to launch gnome-control-center: %s", error->message); g_error_free (error); goto out; } out: g_object_unref (launch_context); if (app_info != NULL) g_object_unref (app_info); } static void gcm_session_notify_cb (NotifyNotification *notification, gchar *action, gpointer user_data) { GsdColorManager *manager = GSD_COLOR_MANAGER (user_data); if (g_strcmp0 (action, "recalibrate") == 0) { notify_notification_close (notification, NULL); gcm_session_exec_control_center (manager); } } static void closed_cb (NotifyNotification *notification, gpointer data) { g_object_unref (notification); } static gboolean gcm_session_notify_recalibrate (GsdColorManager *manager, const gchar *title, const gchar *message, CdDeviceKind kind) { gboolean ret; GError *error = NULL; NotifyNotification *notification; GsdColorManagerPrivate *priv = manager->priv; /* show a bubble */ notification = notify_notification_new (title, message, "preferences-color"); notify_notification_set_timeout (notification, GCM_SESSION_NOTIFY_TIMEOUT); notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW); notify_notification_set_app_name (notification, _("Color")); /* TRANSLATORS: button: this is to open GCM */ notify_notification_add_action (notification, "recalibrate", _("Recalibrate now"), gcm_session_notify_cb, priv, NULL); g_signal_connect (notification, "closed", G_CALLBACK (closed_cb), NULL); ret = notify_notification_show (notification, &error); if (!ret) { g_warning ("failed to show notification: %s", error->message); g_error_free (error); } return ret; } static gchar * gcm_session_device_get_title (CdDevice *device) { const gchar *vendor; const gchar *model; model = cd_device_get_model (device); vendor = cd_device_get_vendor (device); if (model != NULL && vendor != NULL) return g_strdup_printf ("%s - %s", vendor, model); if (vendor != NULL) return g_strdup (vendor); if (model != NULL) return g_strdup (model); return g_strdup (cd_device_get_id (device)); } static void gcm_session_notify_device (GsdColorManager *manager, CdDevice *device) { CdDeviceKind kind; const gchar *title; gchar *device_title = NULL; gchar *message; guint threshold; glong since; GsdColorManagerPrivate *priv = manager->priv; /* TRANSLATORS: this is when the device has not been recalibrated in a while */ title = _("Recalibration required"); device_title = gcm_session_device_get_title (device); /* check we care */ kind = cd_device_get_kind (device); if (kind == CD_DEVICE_KIND_DISPLAY) { /* get from GSettings */ threshold = g_settings_get_uint (priv->settings, GCM_SETTINGS_RECALIBRATE_DISPLAY_THRESHOLD); /* TRANSLATORS: this is when the display has not been recalibrated in a while */ message = g_strdup_printf (_("The display '%s' should be recalibrated soon."), device_title); } else { /* get from GSettings */ threshold = g_settings_get_uint (priv->settings, GCM_SETTINGS_RECALIBRATE_PRINTER_THRESHOLD); /* TRANSLATORS: this is when the printer has not been recalibrated in a while */ message = g_strdup_printf (_("The printer '%s' should be recalibrated soon."), device_title); } /* check if we need to notify */ since = (g_get_real_time () - cd_device_get_modified (device)) / G_USEC_PER_SEC; if (threshold > since) gcm_session_notify_recalibrate (manager, title, message, kind); g_free (device_title); g_free (message); } static void gcm_session_profile_connect_cb (GObject *object, GAsyncResult *res, gpointer user_data) { const gchar *filename; gboolean ret; gchar *basename = NULL; const gchar *data_source; GError *error = NULL; CdProfile *profile = CD_PROFILE (object); GcmSessionAsyncHelper *helper = (GcmSessionAsyncHelper *) user_data; GsdColorManager *manager = GSD_COLOR_MANAGER (helper->manager); ret = cd_profile_connect_finish (profile, res, &error); if (!ret) { g_warning ("failed to connect to profile: %s", error->message); g_error_free (error); goto out; } /* ensure it's a profile generated by us */ data_source = cd_profile_get_metadata_item (profile, CD_PROFILE_METADATA_DATA_SOURCE); if (data_source == NULL) { /* existing profiles from gnome-color-manager < 3.1 * won't have the extra metadata values added */ filename = cd_profile_get_filename (profile); if (filename == NULL) goto out; basename = g_path_get_basename (filename); if (!g_str_has_prefix (basename, "GCM")) { g_debug ("not a GCM profile for %s: %s", cd_device_get_id (helper->device), filename); goto out; } /* ensure it's been created from a calibration, rather than from * auto-EDID */ } else if (g_strcmp0 (data_source, CD_PROFILE_METADATA_DATA_SOURCE_CALIB) != 0) { g_debug ("not a calib profile for %s", cd_device_get_id (helper->device)); goto out; } /* handle device */ gcm_session_notify_device (manager, helper->device); out: gcm_session_async_helper_free (helper); g_free (basename); } static void gcm_session_device_connect_cb (GObject *object, GAsyncResult *res, gpointer user_data) { gboolean ret; GError *error = NULL; CdDeviceKind kind; CdProfile *profile = NULL; CdDevice *device = CD_DEVICE (object); GsdColorManager *manager = GSD_COLOR_MANAGER (user_data); GcmSessionAsyncHelper *helper; ret = cd_device_connect_finish (device, res, &error); if (!ret) { g_warning ("failed to connect to device: %s", error->message); g_error_free (error); goto out; } /* check we care */ kind = cd_device_get_kind (device); if (kind != CD_DEVICE_KIND_DISPLAY && kind != CD_DEVICE_KIND_PRINTER) goto out; /* ensure we have a profile */ profile = cd_device_get_default_profile (device); if (profile == NULL) { g_debug ("no profile set for %s", cd_device_get_id (device)); goto out; } /* connect to the profile */ helper = g_new0 (GcmSessionAsyncHelper, 1); helper->manager = g_object_ref (manager); helper->device = g_object_ref (device); cd_profile_connect (profile, NULL, gcm_session_profile_connect_cb, helper); out: if (profile != NULL) g_object_unref (profile); } static void gcm_session_device_added_notify_cb (CdClient *client, CdDevice *device, GsdColorManager *manager) { /* connect to the device to get properties */ cd_device_connect (device, NULL, gcm_session_device_connect_cb, manager); } static gchar * gcm_session_get_precooked_md5 (cmsHPROFILE lcms_profile) { cmsUInt8Number profile_id[16]; gboolean md5_precooked = FALSE; guint i; gchar *md5 = NULL; /* check to see if we have a pre-cooked MD5 */ cmsGetHeaderProfileID (lcms_profile, profile_id); for (i = 0; i < 16; i++) { if (profile_id[i] != 0) { md5_precooked = TRUE; break; } } if (!md5_precooked) goto out; /* convert to a hex string */ md5 = g_new0 (gchar, 32 + 1); for (i = 0; i < 16; i++) g_snprintf (md5 + i*2, 3, "%02x", profile_id[i]); out: return md5; } static gchar * gcm_session_get_md5_for_filename (const gchar *filename, GError **error) { gboolean ret; gchar *checksum = NULL; gchar *data = NULL; gsize length; cmsHPROFILE lcms_profile = NULL; /* get the internal profile id, if it exists */ lcms_profile = cmsOpenProfileFromFile (filename, "r"); if (lcms_profile == NULL) { g_set_error_literal (error, GSD_COLOR_MANAGER_ERROR, GSD_COLOR_MANAGER_ERROR_FAILED, "failed to load: not an ICC profile"); goto out; } checksum = gcm_session_get_precooked_md5 (lcms_profile); if (checksum != NULL) goto out; /* generate checksum */ ret = g_file_get_contents (filename, &data, &length, error); if (!ret) goto out; checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5, (const guchar *) data, length); out: g_free (data); if (lcms_profile != NULL) cmsCloseProfile (lcms_profile); return checksum; } static void gcm_session_create_profile_cb (GObject *object, GAsyncResult *res, gpointer user_data) { CdProfile *profile; GError *error = NULL; CdClient *client = CD_CLIENT (object); profile = cd_client_create_profile_finish (client, res, &error); if (profile == NULL) { if (error->domain != CD_CLIENT_ERROR || error->code != CD_CLIENT_ERROR_ALREADY_EXISTS) g_warning ("%s", error->message); g_error_free (error); return; } g_object_unref (profile); } static void gcm_session_profile_store_added_cb (GcmProfileStore *profile_store, const gchar *filename, GsdColorManager *manager) { gchar *checksum = NULL; gchar *profile_id = NULL; GError *error = NULL; GHashTable *profile_props = NULL; GsdColorManagerPrivate *priv = manager->priv; g_debug ("profile %s added", filename); /* generate ID */ checksum = gcm_session_get_md5_for_filename (filename, &error); if (checksum == NULL) { g_debug ("failed to get profile checksum for %s: %s", filename, error->message); g_error_free (error); goto out; } profile_id = g_strdup_printf ("icc-%s", checksum); profile_props = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); g_hash_table_insert (profile_props, CD_PROFILE_PROPERTY_FILENAME, (gpointer) filename); g_hash_table_insert (profile_props, CD_PROFILE_METADATA_FILE_CHECKSUM, (gpointer) checksum); cd_client_create_profile (priv->client, profile_id, CD_OBJECT_SCOPE_TEMP, profile_props, NULL, gcm_session_create_profile_cb, manager); out: g_free (checksum); g_free (profile_id); if (profile_props != NULL) g_hash_table_unref (profile_props); } static void gcm_session_delete_profile_cb (GObject *object, GAsyncResult *res, gpointer user_data) { gboolean ret; GError *error = NULL; CdClient *client = CD_CLIENT (object); ret = cd_client_delete_profile_finish (client, res, &error); if (!ret) { g_warning ("%s", error->message); g_error_free (error); } } static void gcm_session_find_profile_by_filename_cb (GObject *object, GAsyncResult *res, gpointer user_data) { GError *error = NULL; CdProfile *profile; CdClient *client = CD_CLIENT (object); GsdColorManager *manager = GSD_COLOR_MANAGER (user_data); profile = cd_client_find_profile_by_filename_finish (client, res, &error); if (profile == NULL) { g_warning ("%s", error->message); g_error_free (error); goto out; } /* remove it from colord */ cd_client_delete_profile (manager->priv->client, profile, NULL, gcm_session_delete_profile_cb, manager); out: if (profile != NULL) g_object_unref (profile); } static void gcm_session_profile_store_removed_cb (GcmProfileStore *profile_store, const gchar *filename, GsdColorManager *manager) { /* find the ID for the filename */ g_debug ("filename %s removed", filename); cd_client_find_profile_by_filename (manager->priv->client, filename, NULL, gcm_session_find_profile_by_filename_cb, manager); } static void gcm_session_sensor_added_cb (CdClient *client, CdSensor *sensor, GsdColorManager *manager) { ca_context_play (ca_gtk_context_get (), 0, CA_PROP_EVENT_ID, "device-added", /* TRANSLATORS: this is the application name */ CA_PROP_APPLICATION_NAME, _("GNOME Settings Daemon Color Plugin"), /* TRANSLATORS: this is a sound description */ CA_PROP_EVENT_DESCRIPTION, _("Color calibration device added"), NULL); /* open up the color prefs window */ gcm_session_exec_control_center (manager); } static void gcm_session_sensor_removed_cb (CdClient *client, CdSensor *sensor, GsdColorManager *manager) { ca_context_play (ca_gtk_context_get (), 0, CA_PROP_EVENT_ID, "device-removed", /* TRANSLATORS: this is the application name */ CA_PROP_APPLICATION_NAME, _("GNOME Settings Daemon Color Plugin"), /* TRANSLATORS: this is a sound description */ CA_PROP_EVENT_DESCRIPTION, _("Color calibration device removed"), NULL); } static gboolean has_changed (char **strv, const char *str) { guint i; for (i = 0; strv[i] != NULL; i++) { if (g_str_equal (str, strv[i])) return TRUE; } return FALSE; } static void gcm_session_active_changed_cb (GDBusProxy *session, GVariant *changed, char **invalidated, GsdColorManager *manager) { GsdColorManagerPrivate *priv = manager->priv; GVariant *active_v = NULL; gboolean is_active; if (has_changed (invalidated, "SessionIsActive")) return; /* not yet connected to the daemon */ if (!cd_client_get_connected (priv->client)) return; active_v = g_dbus_proxy_get_cached_property (session, "SessionIsActive"); g_return_if_fail (active_v != NULL); is_active = g_variant_get_boolean (active_v); g_variant_unref (active_v); /* When doing the fast-user-switch into a new account, load the * new users chosen profiles. * * If this is the first time the GnomeSettingsSession has been * loaded, then we'll get a change from unknown to active * and we want to avoid reprobing the devices for that. */ if (is_active && !priv->session_is_active) { g_debug ("Done switch to new account, reload devices"); cd_client_get_devices (manager->priv->client, NULL, gcm_session_get_devices_cb, manager); } priv->session_is_active = is_active; } static void gsd_color_manager_class_init (GsdColorManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_color_manager_finalize; g_type_class_add_private (klass, sizeof (GsdColorManagerPrivate)); } static void gsd_color_manager_init (GsdColorManager *manager) { GsdColorManagerPrivate *priv; priv = manager->priv = GSD_COLOR_MANAGER_GET_PRIVATE (manager); /* track the active session */ priv->session = gnome_settings_bus_get_session_proxy (); g_signal_connect (priv->session, "g-properties-changed", G_CALLBACK (gcm_session_active_changed_cb), manager); /* set the _ICC_PROFILE atoms on the root screen */ priv->gdk_window = gdk_screen_get_root_window (gdk_screen_get_default ()); /* parsing the EDID is expensive */ priv->edid_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); /* we don't want to assign devices multiple times at startup */ priv->device_assign_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); /* use DMI data for internal panels */ priv->dmi = gcm_dmi_new (); priv->settings = g_settings_new ("com.canonical.unity.settings-daemon.plugins.color"); priv->client = cd_client_new (); g_signal_connect (priv->client, "device-added", G_CALLBACK (gcm_session_device_added_notify_cb), manager); g_signal_connect (priv->client, "sensor-added", G_CALLBACK (gcm_session_sensor_added_cb), manager); g_signal_connect (priv->client, "sensor-removed", G_CALLBACK (gcm_session_sensor_removed_cb), manager); /* have access to all user profiles */ priv->profile_store = gcm_profile_store_new (); g_signal_connect (priv->profile_store, "added", G_CALLBACK (gcm_session_profile_store_added_cb), manager); g_signal_connect (priv->profile_store, "removed", G_CALLBACK (gcm_session_profile_store_removed_cb), manager); } static void gsd_color_manager_finalize (GObject *object) { GsdColorManager *manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_COLOR_MANAGER (object)); manager = GSD_COLOR_MANAGER (object); g_signal_handlers_disconnect_by_data (manager->priv->session, manager); g_clear_object (&manager->priv->settings); g_clear_object (&manager->priv->client); g_clear_object (&manager->priv->profile_store); g_clear_object (&manager->priv->dmi); g_clear_object (&manager->priv->session); g_clear_pointer (&manager->priv->edid_cache, g_hash_table_destroy); g_clear_pointer (&manager->priv->device_assign_hash, g_hash_table_destroy); g_clear_object (&manager->priv->x11_screen); G_OBJECT_CLASS (gsd_color_manager_parent_class)->finalize (object); } GsdColorManager * gsd_color_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_COLOR_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_COLOR_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/gsd-color-manager.h0000664000175000017500000000476500000000000025323 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * Copyright (C) 2011 Richard Hughes * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_COLOR_MANAGER_H #define __GSD_COLOR_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_COLOR_MANAGER (gsd_color_manager_get_type ()) #define GSD_COLOR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_COLOR_MANAGER, GsdColorManager)) #define GSD_COLOR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_COLOR_MANAGER, GsdColorManagerClass)) #define GSD_IS_COLOR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_COLOR_MANAGER)) #define GSD_IS_COLOR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_COLOR_MANAGER)) #define GSD_COLOR_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_COLOR_MANAGER, GsdColorManagerClass)) #define GSD_COLOR_MANAGER_ERROR (gsd_color_manager_error_quark ()) typedef struct GsdColorManagerPrivate GsdColorManagerPrivate; typedef struct { GObject parent; GsdColorManagerPrivate *priv; } GsdColorManager; typedef struct { GObjectClass parent_class; } GsdColorManagerClass; enum { GSD_COLOR_MANAGER_ERROR_FAILED }; GType gsd_color_manager_get_type (void); GQuark gsd_color_manager_error_quark (void); GsdColorManager * gsd_color_manager_new (void); gboolean gsd_color_manager_start (GsdColorManager *manager, GError **error); void gsd_color_manager_stop (GsdColorManager *manager); G_END_DECLS #endif /* __GSD_COLOR_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/gsd-color-plugin.c0000664000175000017500000000211000000000000025160 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * Copyright (C) 2011 Richard Hughes * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-color-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdColor, gsd_color) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5797668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/test-data/0000775000175000017500000000000000000000000023523 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/test-data/LG-L225W-External.bin0000664000175000017500000000020000000000000027040 0ustar00jeremyjeremymcV^ /x%UI'PTk@qO|.`@0 6(!90b'@h6(8KS L225W t././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/color/test-data/Lenovo-T61-Internal.bin0000664000175000017500000000020000000000000027571 0ustar00jeremyjeremy$M(!x uUO&!PT/`@ @K'`@ @K 2 (LX3LTN154P2-L05 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5797668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/0000775000175000017500000000000000000000000022007 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/Makefile.am0000664000175000017500000000200600000000000024041 0ustar00jeremyjeremyplugin_name = common noinst_LTLIBRARIES = libcommon.la libcommon_la_SOURCES = \ gsd-keygrab.c \ gsd-keygrab.h \ gsd-input-helper.c \ gsd-input-helper.h \ gsd-settings-migrate.c \ gsd-settings-migrate.h libcommon_la_CPPFLAGS = \ $(AM_CPPFLAGS) libcommon_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(COMMON_CFLAGS) \ $(AM_CFLAGS) libcommon_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) libcommon_la_LIBADD = \ $(SETTINGS_PLUGIN_LIBS) \ $(COMMON_LIBS) libexec_PROGRAMS = usd-test-input-helper usd_test_input_helper_SOURCES = test-input-helper.c usd_test_input_helper_LDADD = libcommon.la usd_test_input_helper_CFLAGS = $(libcommon_la_CFLAGS) noinst_PROGRAMS = test-egg-key-parsing test_egg_key_parsing_SOURCES = test-egg-key-parsing.c test_egg_key_parsing_LDADD = libcommon.la $(COMMON_LIBS) test_egg_key_parsing_CFLAGS = $(libcommon_la_CFLAGS) scriptsdir = $(datadir)/unity-settings-daemon-@GSD_API_VERSION@ scripts_DATA = input-device-example.sh EXTRA_DIST = $(scripts_DATA) test-plugin.h ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/gsd-input-helper.c0000664000175000017500000004367700000000000025363 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2010 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include "gsd-input-helper.h" #define INPUT_DEVICES_SCHEMA "com.canonical.unity.settings-daemon.peripherals.input-devices" #define KEY_HOTPLUG_COMMAND "hotplug-command" #define ABS_MT_X "Abs MT Position X" #define ABS_MT_Y "Abs MT Position Y" #define ABS_X "Abs X" #define ABS_Y "Abs Y" typedef gboolean (* InfoIdentifyFunc) (XDeviceInfo *device_info); typedef gboolean (* DeviceIdentifyFunc) (XDevice *xdevice); gboolean device_set_property (XDevice *xdevice, const char *device_name, PropertyHelper *property) { int rc, i; Atom prop; Atom realtype; int realformat; unsigned long nitems, bytes_after; unsigned char *data; prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), property->name, False); if (!prop) return FALSE; gdk_error_trap_push (); rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, 0, property->nitems, False, AnyPropertyType, &realtype, &realformat, &nitems, &bytes_after, &data); if (rc != Success || realtype != property->type || realformat != property->format || nitems < property->nitems) { gdk_error_trap_pop_ignored (); g_warning ("Error reading property \"%s\" for \"%s\"", property->name, device_name); return FALSE; } for (i = 0; i < nitems; i++) { switch (property->format) { case 8: data[i] = property->data.c[i]; break; case 32: ((long*)data)[i] = property->data.i[i]; break; } } XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, realtype, realformat, PropModeReplace, data, nitems); XFree (data); if (gdk_error_trap_pop ()) { g_warning ("Error in setting \"%s\" for \"%s\"", property->name, device_name); return FALSE; } return TRUE; } static gboolean supports_xinput_devices_with_opcode (int *opcode) { gint op_code, event, error; gboolean retval; retval = XQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "XInputExtension", &op_code, &event, &error); if (opcode) *opcode = op_code; return retval; } gboolean supports_xinput_devices (void) { return supports_xinput_devices_with_opcode (NULL); } gboolean supports_xtest (void) { gint op_code, event, error; gboolean retval; retval = XQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "XTEST", &op_code, &event, &error); return retval; } gboolean supports_xinput2_devices (int *opcode) { int major, minor; if (supports_xinput_devices_with_opcode (opcode) == FALSE) return FALSE; gdk_error_trap_push (); major = 2; minor = 3; if (XIQueryVersion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor) != Success) { gdk_error_trap_pop_ignored (); return FALSE; } gdk_error_trap_pop_ignored (); if ((major * 1000 + minor) < (2000)) return FALSE; return TRUE; } gboolean device_is_touchpad (XDevice *xdevice) { Atom realtype, prop; int realformat; unsigned long nitems, bytes_after; unsigned char *data; /* we don't check on the type being XI_TOUCHPAD here, * but having a "Synaptics Off" property should be enough */ prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Off", False); if (!prop) return FALSE; gdk_error_trap_push (); if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, 0, 1, False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &data) == Success) && (realtype != None)) { gdk_error_trap_pop_ignored (); XFree (data); return TRUE; } gdk_error_trap_pop_ignored (); return FALSE; } gboolean device_info_is_touchpad (XDeviceInfo *device_info) { return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_TOUCHPAD, False)); } gboolean device_info_is_touchscreen (XDeviceInfo *device_info) { return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_TOUCHSCREEN, False)); } gboolean device_info_is_tablet (XDeviceInfo *device_info) { /* Note that this doesn't match Wacom tablets */ return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_TABLET, False)); } gboolean device_info_is_mouse (XDeviceInfo *device_info) { return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_MOUSE, False)); } gboolean device_info_is_trackball (XDeviceInfo *device_info) { gboolean retval; retval = (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_TRACKBALL, False)); if (retval == FALSE && device_info->name != NULL) { char *lowercase; lowercase = g_ascii_strdown (device_info->name, -1); retval = strstr (lowercase, "trackball") != NULL; g_free (lowercase); } return retval; } static gboolean device_type_is_present (InfoIdentifyFunc info_func, DeviceIdentifyFunc device_func) { XDeviceInfo *device_info; gint n_devices; guint i; gboolean retval; if (supports_xinput_devices () == FALSE) return TRUE; retval = FALSE; device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &n_devices); if (device_info == NULL) return FALSE; for (i = 0; i < n_devices; i++) { XDevice *device; /* Check with the device info first */ retval = (info_func) (&device_info[i]); if (retval == FALSE) continue; /* If we only have an info func, we're done checking */ if (device_func == NULL) break; gdk_error_trap_push (); device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device_info[i].id); if (gdk_error_trap_pop () || (device == NULL)) continue; retval = (device_func) (device); xdevice_close (device); if (retval) break; } XFreeDeviceList (device_info); return retval; } gboolean touchscreen_is_present (void) { return device_type_is_present (device_info_is_touchscreen, NULL); } gboolean touchpad_is_present (void) { return device_type_is_present (device_info_is_touchpad, device_is_touchpad); } gboolean mouse_is_present (void) { return device_type_is_present (device_info_is_mouse, NULL); } gboolean trackball_is_present (void) { return device_type_is_present (device_info_is_trackball, NULL); } char * xdevice_get_device_node (int deviceid) { Atom prop; Atom act_type; int act_format; unsigned long nitems, bytes_after; unsigned char *data; char *ret; gdk_display_sync (gdk_display_get_default ()); prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Device Node", False); if (!prop) return NULL; gdk_error_trap_push (); if (!XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), deviceid, prop, 0, 1000, False, AnyPropertyType, &act_type, &act_format, &nitems, &bytes_after, &data) == Success) { gdk_error_trap_pop_ignored (); return NULL; } if (gdk_error_trap_pop ()) goto out; if (nitems == 0) goto out; if (act_type != XA_STRING) goto out; /* Unknown string format */ if (act_format != 8) goto out; ret = g_strdup ((char *) data); XFree (data); return ret; out: XFree (data); return NULL; } #define TOOL_ID_FORMAT_SIZE 32 static int get_id_for_index (guchar *data, guint idx) { guchar *ptr; int id; ptr = data; ptr += TOOL_ID_FORMAT_SIZE / 8 * idx; id = *((int32_t*)ptr); id = id & 0xfffff; return id; } #define STYLUS_DEVICE_ID 0x02 #define ERASER_DEVICE_ID 0x0A int xdevice_get_last_tool_id (int deviceid) { Atom prop; Atom act_type; int act_format; unsigned long nitems, bytes_after; unsigned char *data; int id; id = -1; gdk_display_sync (gdk_display_get_default ()); prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), WACOM_SERIAL_IDS_PROP, False); if (!prop) return -1; data = NULL; gdk_error_trap_push (); if (XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), deviceid, prop, 0, 1000, False, AnyPropertyType, &act_type, &act_format, &nitems, &bytes_after, &data) != Success) { gdk_error_trap_pop_ignored (); goto out; } if (gdk_error_trap_pop ()) goto out; if (nitems != 4 && nitems != 5) goto out; if (act_type != XA_INTEGER) goto out; if (act_format != TOOL_ID_FORMAT_SIZE) goto out; /* item 0 = tablet ID * item 1 = old device serial number (== last tool in proximity) * item 2 = old hardware serial number (including tool ID) * item 3 = current serial number (0 if no tool in proximity) * item 4 = current tool ID (since Feb 2012) * * Get the current tool ID first, if available, then the old one */ id = 0x0; if (nitems == 5) id = get_id_for_index (data, 4); if (id == 0x0) id = get_id_for_index (data, 2); /* That means that no tool was set down yet */ if (id == STYLUS_DEVICE_ID || id == ERASER_DEVICE_ID) id = 0x0; out: if (data != NULL) XFree (data); return id; } gboolean set_device_enabled (int device_id, gboolean enabled) { Atom prop; guchar value; prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Device Enabled", False); if (!prop) return FALSE; gdk_error_trap_push (); value = enabled ? 1 : 0; XIChangeProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device_id, prop, XA_INTEGER, 8, PropModeReplace, &value, 1); if (gdk_error_trap_pop ()) return FALSE; return TRUE; } static const char * custom_command_to_string (CustomCommand command) { switch (command) { case COMMAND_DEVICE_ADDED: return "added"; case COMMAND_DEVICE_REMOVED: return "removed"; case COMMAND_DEVICE_PRESENT: return "present"; default: g_assert_not_reached (); } } /* Run a custom command on device presence events. Parameters passed into * the custom command are: * command -t [added|removed|present] -i * Type 'added' and 'removed' signal 'device added' and 'device removed', * respectively. Type 'present' signals 'device present at * gnome-settings-daemon init'. * * The script is expected to run synchronously, and an exit value * of "1" means that no other settings will be applied to this * particular device. * * More options may be added in the future. * * This function returns TRUE if we should not apply any more settings * to the device. */ gboolean run_custom_command (GdkDevice *device, CustomCommand command) { GSettings *settings; GError *error = NULL; char *cmd; char *argv[7]; int exit_status; gboolean rc; int id; settings = g_settings_new (INPUT_DEVICES_SCHEMA); cmd = g_settings_get_string (settings, KEY_HOTPLUG_COMMAND); g_object_unref (settings); if (!cmd || cmd[0] == '\0') { g_free (cmd); return FALSE; } /* Easter egg! */ g_object_get (device, "device-id", &id, NULL); argv[0] = cmd; argv[1] = "-t"; argv[2] = (char *) custom_command_to_string (command); argv[3] = "-i"; argv[4] = g_strdup_printf ("%d", id); argv[5] = (char*) gdk_device_get_name (device); argv[6] = NULL; rc = g_spawn_sync (g_get_home_dir (), argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &exit_status, &error); if (rc == FALSE) { g_warning ("Couldn't execute command '%s', verify that this is a valid command: %s", cmd, error->message); g_clear_error (&error); } g_free (argv[0]); g_free (argv[4]); if (!g_spawn_check_exit_status (exit_status, &error)) { if (g_error_matches (error, G_SPAWN_EXIT_ERROR, 1)) { g_clear_error (&error); return TRUE; } g_clear_error (&error); } return FALSE; } GList * get_disabled_devices (GdkDeviceManager *manager) { XDeviceInfo *device_info; gint n_devices; guint i; GList *ret; ret = NULL; device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &n_devices); if (device_info == NULL) return ret; for (i = 0; i < n_devices; i++) { GdkDevice *device; /* Ignore core devices */ if (device_info[i].use == IsXKeyboard || device_info[i].use == IsXPointer) continue; /* Check whether the device is actually available */ device = gdk_x11_device_manager_lookup (manager, device_info[i].id); if (device != NULL) continue; ret = g_list_prepend (ret, GINT_TO_POINTER (device_info[i].id)); } XFreeDeviceList (device_info); return ret; } gboolean xdevice_get_dimensions (int deviceid, guint *width, guint *height) { GdkDisplay *display = gdk_display_get_default (); XIDeviceInfo *info; guint *value, w, h; int i, n_info; /* ignore errors, device might be removed before config is done as in #1503758 */ gdk_error_trap_push(); info = XIQueryDevice (GDK_DISPLAY_XDISPLAY (display), deviceid, &n_info); gdk_error_trap_pop_ignored (); *width = *height = w = h = 0; if (!info) return FALSE; for (i = 0; i < info->num_classes; i++) { XIValuatorClassInfo *valuator_info; if (info->classes[i]->type != XIValuatorClass) continue; valuator_info = (XIValuatorClassInfo *) info->classes[i]; if (valuator_info->label == gdk_x11_get_xatom_by_name_for_display (display, ABS_X) || valuator_info->label == gdk_x11_get_xatom_by_name_for_display (display, ABS_MT_X)) value = &w; else if (valuator_info->label == gdk_x11_get_xatom_by_name_for_display (display, ABS_Y) || valuator_info->label == gdk_x11_get_xatom_by_name_for_display (display, ABS_MT_Y)) value = &h; else continue; *value = (valuator_info->max - valuator_info->min) * 1000 / valuator_info->resolution; } *width = w; *height = h; XIFreeDeviceInfo (info); return (w != 0 && h != 0); } void xdevice_close (XDevice *xdevice) { gdk_error_trap_push (); XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice); gdk_error_trap_pop_ignored(); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/gsd-input-helper.h0000664000175000017500000000702400000000000025352 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2010 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __GSD_INPUT_HELPER_H #define __GSD_INPUT_HELPER_H G_BEGIN_DECLS #include #include #include #define WACOM_SERIAL_IDS_PROP "Wacom Serial IDs" typedef enum { COMMAND_DEVICE_ADDED, COMMAND_DEVICE_REMOVED, COMMAND_DEVICE_PRESENT } CustomCommand; /* Generic property setting code. Fill up the struct property with the property * data and pass it into device_set_property together with the device to be * changed. Note: doesn't cater for non-zero offsets yet, but we don't have * any settings that require that. */ typedef struct { const char *name; /* property name */ gint nitems; /* number of items in data */ gint format; /* CARD8 or CARD32 sized-items */ gint type; /* Atom representing data type */ union { const gchar *c; /* 8 bit data */ const gint *i; /* 32 bit data */ } data; } PropertyHelper; gboolean supports_xinput_devices (void); gboolean supports_xinput2_devices (int *opcode); gboolean supports_xtest (void); gboolean set_device_enabled (int device_id, gboolean enabled); gboolean device_is_touchpad (XDevice *xdevice); gboolean device_info_is_touchpad (XDeviceInfo *device_info); gboolean device_info_is_touchscreen (XDeviceInfo *device_info); gboolean device_info_is_tablet (XDeviceInfo *device_info); gboolean device_info_is_mouse (XDeviceInfo *device_info); gboolean device_info_is_trackball (XDeviceInfo *device_info); gboolean touchpad_is_present (void); gboolean touchscreen_is_present (void); gboolean mouse_is_present (void); gboolean trackball_is_present (void); gboolean device_set_property (XDevice *xdevice, const char *device_name, PropertyHelper *property); gboolean run_custom_command (GdkDevice *device, CustomCommand command); GList * get_disabled_devices (GdkDeviceManager *manager); char * xdevice_get_device_node (int deviceid); int xdevice_get_last_tool_id (int deviceid); gboolean xdevice_get_dimensions (int deviceid, guint *width, guint *height); void xdevice_close (XDevice *xdevice); G_END_DECLS #endif /* __GSD_INPUT_HELPER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/gsd-keygrab.c0000664000175000017500000005532000000000000024357 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2001-2003 Bastien Nocera * Copyright (C) 2006-2007 William Jon McCann * Copyright (C) 2008 Jens Granseuer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include "gsd-keygrab.h" /* these are the mods whose combinations are ignored by the keygrabbing code */ static GdkModifierType gsd_ignored_mods = 0; /* these are the ones we actually use for global keys, we always only check * for these set */ static GdkModifierType gsd_used_mods = 0; /* Taken from a comment in XF86keysym.h */ #define XF86KEYS_RANGE_MIN 0x10080001 #define XF86KEYS_RANGE_MAX 0x1008FFFF #define FKEYS_RANGE_MIN GDK_KEY_F1 #define FKEYS_RANGE_MAX GDK_KEY_R15 #define IN_RANGE(x, min, max) (x >= min && x <= max) static void setup_modifiers (void) { if (gsd_used_mods == 0 || gsd_ignored_mods == 0) { GdkModifierType dynmods; /* default modifiers */ gsd_ignored_mods = \ 0x2000 /*Xkb modifier*/ | GDK_LOCK_MASK | GDK_HYPER_MASK; gsd_used_mods = \ GDK_SHIFT_MASK | GDK_CONTROL_MASK |\ GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK |\ GDK_MOD5_MASK | GDK_SUPER_MASK | GDK_META_MASK; /* NumLock can be assigned to varying keys so we need to * resolve and ignore it specially */ dynmods = XkbKeysymToModifiers (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_KEY_Num_Lock); gsd_ignored_mods |= dynmods; gsd_used_mods &= ~dynmods; } } static void grab_key_real (guint keycode, GdkWindow *root, gboolean grab, gboolean synchronous, XIGrabModifiers *mods, int num_mods) { XIEventMask evmask; unsigned char mask[(XI_LASTEVENT + 7)/8]; memset (mask, 0, sizeof (mask)); XISetMask (mask, XI_KeyPress); XISetMask (mask, XI_KeyRelease); evmask.deviceid = XIAllMasterDevices; evmask.mask_len = sizeof (mask); evmask.mask = mask; if (grab) { XIGrabKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XIAllMasterDevices, keycode, GDK_WINDOW_XID (root), GrabModeAsync, synchronous ? GrabModeSync : GrabModeAsync, False, &evmask, num_mods, mods); } else { XIUngrabKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XIAllMasterDevices, keycode, GDK_WINDOW_XID (root), num_mods, mods); } } /* Grab the key. In order to ignore GSD_IGNORED_MODS we need to grab * all combinations of the ignored modifiers and those actually used * for the binding (if any). * * inspired by all_combinations from gnome-panel/gnome-panel/global-keys.c * * This may generate X errors. The correct way to use this is like: * * gdk_error_trap_push (); * * grab_key_unsafe (key, grab, screens); * * gdk_flush (); * if (gdk_error_trap_pop ()) * g_warning ("Grab failed, another application may already have access to key '%u'", * key->keycode); * * This is not done in the function itself, to allow doing multiple grab_key * operations with one flush only. */ #define N_BITS 32 static void grab_key_internal (Key *key, gboolean grab, GsdKeygrabFlags flags, GSList *screens) { int indexes[N_BITS]; /* indexes of bits we need to flip */ int i; int bit; int bits_set_cnt; int uppervalue; guint mask, modifiers; GArray *all_mods; GSList *l; setup_modifiers (); mask = gsd_ignored_mods & ~key->state & GDK_MODIFIER_MASK; /* XGrabKey requires real modifiers, not virtual ones */ modifiers = key->state; gdk_keymap_map_virtual_modifiers (gdk_keymap_get_default (), &modifiers); modifiers &= ~(GDK_META_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK); /* If key doesn't have a usable modifier, we don't want * to grab it, since the user might lose a useful key. * * The exception is the XFree86 keys and the Function keys * (which are useful to grab without a modifier). */ if (!(flags & GSD_KEYGRAB_ALLOW_UNMODIFIED) && (modifiers & gsd_used_mods) == 0 && !IN_RANGE(key->keysym, XF86KEYS_RANGE_MIN, XF86KEYS_RANGE_MAX) && !IN_RANGE(key->keysym, FKEYS_RANGE_MIN, FKEYS_RANGE_MAX) && key->keysym != GDK_KEY_Pause && key->keysym != GDK_KEY_Print && key->keysym != GDK_KEY_Scroll_Lock && key->keysym != GDK_KEY_Caps_Lock && key->keysym != GDK_KEY_Pause && key->keysym != GDK_KEY_Break && key->keysym != GDK_KEY_Menu) { GString *keycodes; keycodes = g_string_new (""); if (key->keycodes != NULL) { guint *c; for (c = key->keycodes; *c; ++c) { g_string_printf (keycodes, " %u", *c); } } g_warning ("Key 0x%x (keycodes: %s) with state 0x%x (resolved to 0x%x) " " has no usable modifiers (usable modifiers are 0x%x)", key->keysym, keycodes->str, key->state, modifiers, gsd_used_mods); g_string_free (keycodes, TRUE); return; } bit = 0; /* store the indexes of all set bits in mask in the array */ for (i = 0; mask; ++i, mask >>= 1) { if (mask & 0x1) { indexes[bit++] = i; } } bits_set_cnt = bit; all_mods = g_array_new (FALSE, TRUE, sizeof(XIGrabModifiers)); uppervalue = 1 << bits_set_cnt; /* store all possible modifier combinations for our mask into all_mods */ for (i = 0; i < uppervalue; ++i) { int j; int result = 0; XIGrabModifiers *mod; /* map bits in the counter to those in the mask */ for (j = 0; j < bits_set_cnt; ++j) { if (i & (1 << j)) { result |= (1 << indexes[j]); } } /* Grow the array by one, to fit our new XIGrabModifiers item */ g_array_set_size (all_mods, all_mods->len + 1); mod = &g_array_index (all_mods, XIGrabModifiers, all_mods->len - 1); mod->modifiers = result | modifiers; } /* Capture the actual keycodes with the modifier array */ for (l = screens; l; l = l->next) { GdkScreen *screen = l->data; guint *code; for (code = key->keycodes; *code; ++code) { grab_key_real (*code, gdk_screen_get_root_window (screen), grab, flags & GSD_KEYGRAB_SYNCHRONOUS, (XIGrabModifiers *) all_mods->data, all_mods->len); } } g_array_free (all_mods, TRUE); } static void get_keys_for_bit (guint bit, guint *left, guint *right) { guint left_dummy; guint right_dummy; if (left == NULL) left = &left_dummy; if (right == NULL) right = &right_dummy; *left = 0; *right = 0; switch (1 << bit) { case GDK_SHIFT_MASK: *left = GDK_KEY_Shift_L; *right = GDK_KEY_Shift_R; break; case GDK_CONTROL_MASK: *left = GDK_KEY_Control_L; *right = GDK_KEY_Control_R; break; case GDK_LOCK_MASK: *left = GDK_KEY_Caps_Lock; *right = GDK_KEY_Shift_Lock; break; case GDK_META_MASK: case GDK_MOD1_MASK: *left = GDK_KEY_Alt_L; *right = GDK_KEY_Alt_R; break; case GDK_SUPER_MASK: *left = GDK_KEY_Super_L; *right = GDK_KEY_Super_R; break; } } static guint get_mask_for_key (guint key) { switch (key) { case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: return GDK_SHIFT_MASK; case GDK_KEY_Control_L: case GDK_KEY_Control_R: return GDK_CONTROL_MASK; case GDK_KEY_Caps_Lock: case GDK_KEY_Shift_Lock: return GDK_LOCK_MASK; case GDK_KEY_Meta_L: case GDK_KEY_Meta_R: case GDK_KEY_Alt_L: case GDK_KEY_Alt_R: return GDK_MOD1_MASK; case GDK_KEY_Super_L: case GDK_KEY_Super_R: return GDK_SUPER_MASK; } return 0; } static guint get_mirrored_key (guint key) { switch (key) { case GDK_KEY_Shift_L: return GDK_KEY_Shift_R; case GDK_KEY_Shift_R: return GDK_KEY_Shift_L; case GDK_KEY_Control_L: return GDK_KEY_Control_R; case GDK_KEY_Control_R: return GDK_KEY_Control_L; case GDK_KEY_Meta_L: return GDK_KEY_Meta_R; case GDK_KEY_Meta_R: return GDK_KEY_Meta_L; case GDK_KEY_Alt_L: return GDK_KEY_Alt_R; case GDK_KEY_Alt_R: return GDK_KEY_Alt_L; case GDK_KEY_Super_L: return GDK_KEY_Super_R; case GDK_KEY_Super_R: return GDK_KEY_Super_L; case GDK_KEY_Hyper_L: return GDK_KEY_Hyper_R; case GDK_KEY_Hyper_R: return GDK_KEY_Hyper_L; } return 0; } void grab_key_unsafe (Key *key, GsdKeygrabFlags flags, GSList *screens) { guint key_mask = get_mask_for_key (key->keysym); grab_key_internal (key, TRUE, flags, screens); if (key_mask != 0) { Key copy; guint i, j; if ((key->state & key_mask) != 0) { guint mirror = get_mirrored_key (key->keysym); if (mirror != 0) { gint mirror_keys_len; GdkKeymapKey *mirror_keys; gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), mirror, &mirror_keys, &mirror_keys_len); copy.keysym = mirror; copy.state = key->state; copy.keycodes = g_new0 (guint, mirror_keys_len + 1); for (j = 0; j < mirror_keys_len; j++) copy.keycodes[j] = mirror_keys[j].keycode; grab_key_internal (©, TRUE, flags, screens); g_free (copy.keycodes); g_free (mirror_keys); } } for (i = 0; i < 8 * sizeof (guint); i++) { guint left, right; gint left_keys_len, right_keys_len; GdkKeymapKey *left_keys, *right_keys; if (1 << i == key_mask || (key->state & 1 << i) == 0) continue; get_keys_for_bit (i, &left, &right); if (left == 0 && right == 0) continue; left_keys_len = 0; right_keys_len = 0; left_keys = NULL; right_keys = NULL; if (left != 0) gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), left, &left_keys, &left_keys_len); if (right != 0) gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), right, &right_keys, &right_keys_len); copy.keysym = left != 0 ? left : right; copy.state = (key->state | key_mask) & ~(1 << i); copy.keycodes = g_new0 (guint, left_keys_len + right_keys_len + 1); for (j = 0; j < left_keys_len; j++) copy.keycodes[j] = left_keys[j].keycode; for (j = 0; j < right_keys_len; j++) copy.keycodes[left_keys_len + j] = right_keys[j].keycode; grab_key_internal (©, TRUE, flags, screens); g_free (copy.keycodes); g_free (right_keys); g_free (left_keys); } } } void ungrab_key_unsafe (Key *key, GSList *screens) { guint key_mask = get_mask_for_key (key->keysym); grab_key_internal (key, FALSE, 0, screens); if (key_mask != 0) { Key copy; guint i, j; if ((key->state & key_mask) != 0) { guint mirror = get_mirrored_key (key->keysym); if (mirror != 0) { gint mirror_keys_len; GdkKeymapKey *mirror_keys; gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), mirror, &mirror_keys, &mirror_keys_len); copy.keysym = mirror; copy.state = key->state; copy.keycodes = g_new0 (guint, mirror_keys_len + 1); for (j = 0; j < mirror_keys_len; j++) copy.keycodes[j] = mirror_keys[j].keycode; grab_key_internal (©, FALSE, 0, screens); g_free (copy.keycodes); g_free (mirror_keys); } } for (i = 0; i < 8 * sizeof (guint); i++) { guint left, right; gint left_keys_len, right_keys_len; GdkKeymapKey *left_keys, *right_keys; if (1 << i == key_mask || (key->state & 1 << i) == 0) continue; get_keys_for_bit (i, &left, &right); if (left == 0 && right == 0) continue; left_keys_len = 0; right_keys_len = 0; left_keys = NULL; right_keys = NULL; if (left != 0) gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), left, &left_keys, &left_keys_len); if (right != 0) gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), right, &right_keys, &right_keys_len); copy.keysym = left != 0 ? left : right; copy.state = (key->state | key_mask) & ~(1 << i); copy.keycodes = g_new0 (guint, left_keys_len + right_keys_len + 1); for (j = 0; j < left_keys_len; j++) copy.keycodes[j] = left_keys[j].keycode; for (j = 0; j < right_keys_len; j++) copy.keycodes[left_keys_len + j] = right_keys[j].keycode; grab_key_internal (©, FALSE, 0, screens); g_free (copy.keycodes); g_free (right_keys); g_free (left_keys); } } } static gboolean have_xkb (Display *dpy) { static int have_xkb = -1; if (have_xkb == -1) { int opcode, error_base, major, minor, xkb_event_base; have_xkb = XkbQueryExtension (dpy, &opcode, &xkb_event_base, &error_base, &major, &minor) && XkbUseExtension (dpy, &major, &minor); } return have_xkb; } gboolean key_uses_keycode (const Key *key, guint keycode) { if (key->keycodes != NULL) { guint *c; for (c = key->keycodes; *c; ++c) { if (*c == keycode) return TRUE; } } return FALSE; } /* Adapted from _gdk_x11_device_xi2_translate_state() * in gtk+/gdk/x11/gdkdevice-xi2.c */ static guint device_xi2_translate_state (XIModifierState *mods_state, XIGroupState *group_state) { guint state; gint group; state = (guint) mods_state->base | mods_state->latched | mods_state->locked; group = group_state->base | group_state->latched | group_state->locked; /* FIXME: do we need the XKB complications for this ? */ group = CLAMP(group, 0, 3); state |= group << 13; return state; } gboolean match_xi2_key (Key *key, XIDeviceEvent *event) { guint keyval; GdkModifierType consumed; gint group; guint keycode, state; if (key == NULL) return FALSE; setup_modifiers (); state = device_xi2_translate_state (&event->mods, &event->group); if (have_xkb (event->display)) group = XkbGroupForCoreState (state); else group = (state & GDK_KEY_Mode_switch) ? 1 : 0; keycode = event->detail; /* Check if we find a keysym that matches our current state */ if (gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (), keycode, state, group, &keyval, NULL, NULL, &consumed)) { guint key_bit, event_bit; guint lower, upper; guint mask, full_mask; /* HACK: we don't want to use SysRq as a keybinding, so we avoid * its translation from Alt+Print. */ if (keyval == GDK_KEY_Sys_Req && (state & GDK_MOD1_MASK) != 0) { consumed = 0; keyval = GDK_KEY_Print; } /* The Key structure contains virtual modifiers, whereas * the XEvent will be using the real modifier, so translate those */ key_bit = get_mask_for_key (key->keysym); event_bit = get_mask_for_key (keyval); mask = key->state; full_mask = mask | key_bit; gdk_keymap_map_virtual_modifiers (gdk_keymap_get_default (), &mask); gdk_keymap_map_virtual_modifiers (gdk_keymap_get_default (), &full_mask); mask &= ~(GDK_META_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK); full_mask &= ~(GDK_META_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK); gdk_keyval_convert_case (keyval, &lower, &upper); /* If we are checking against the lower version of the * keysym, we might need the Shift state for matching, * so remove it from the consumed modifiers */ if (lower == key->keysym || event_bit != 0) consumed &= ~GDK_SHIFT_MASK; state &= ~consumed & gsd_used_mods; if (key_bit != 0 && event_bit != 0) { state |= event_bit; gdk_keymap_map_virtual_modifiers (gdk_keymap_get_default (), &state); state &= ~(GDK_META_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK); return state == full_mask; } return (lower == key->keysym || upper == key->keysym) && state == mask; } /* The key we passed doesn't have a keysym, so try with just the keycode */ return (key != NULL && key->state == (state & gsd_used_mods) && key_uses_keycode (key, keycode)); } Key * parse_key (const char *str) { Key *key; if (str == NULL || *str == '\0' || g_str_equal (str, "disabled")) { return NULL; } key = g_new0 (Key, 1); gtk_accelerator_parse_with_keycode (str, &key->keysym, &key->keycodes, &key->state); if (key->keysym == 0 && key->keycodes == NULL && key->state == 0) { g_free (key); return NULL; } return key; } void free_key (Key *key) { if (key == NULL) return; g_free (key->keycodes); g_free (key); } static void grab_button_real (int deviceid, gboolean grab, GdkWindow *root) { XIGrabModifiers mods; mods.modifiers = XIAnyModifier; if (grab) { XIEventMask evmask; unsigned char mask[(XI_LASTEVENT + 7)/8]; memset (mask, 0, sizeof (mask)); XISetMask (mask, XI_ButtonRelease); XISetMask (mask, XI_ButtonPress); evmask.deviceid = deviceid; evmask.mask_len = sizeof (mask); evmask.mask = mask; XIGrabButton (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), deviceid, XIAnyButton, GDK_WINDOW_XID (root), None, GrabModeAsync, GrabModeAsync, False, &evmask, 1, &mods); } else { XIUngrabButton (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), deviceid, XIAnyButton, GDK_WINDOW_XID (root), 1, &mods); } } void grab_button (int deviceid, gboolean grab, GSList *screens) { GSList *l; for (l = screens; l; l = l->next) { GdkScreen *screen = l->data; grab_button_real (deviceid, grab, gdk_screen_get_root_window (screen)); } } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/gsd-keygrab.h0000664000175000017500000000373100000000000024363 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Jens Granseuer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __GSD_COMMON_KEYGRAB_H #define __GSD_COMMON_KEYGRAB_H G_BEGIN_DECLS #include #include #include typedef struct { guint keysym; guint state; guint *keycodes; } Key; typedef enum { GSD_KEYGRAB_NORMAL = 0, GSD_KEYGRAB_ALLOW_UNMODIFIED = 1 << 0, GSD_KEYGRAB_SYNCHRONOUS = 1 << 1 } GsdKeygrabFlags; void grab_key_unsafe (Key *key, GsdKeygrabFlags flags, GSList *screens); void ungrab_key_unsafe (Key *key, GSList *screens); gboolean match_xi2_key (Key *key, XIDeviceEvent *event); gboolean key_uses_keycode (const Key *key, guint keycode); Key * parse_key (const char *str); void free_key (Key *key); void grab_button (int deviceid, gboolean grab, GSList *screens); G_END_DECLS #endif /* __GSD_COMMON_KEYGRAB_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/gsd-settings-migrate.c0000664000175000017500000000471500000000000026223 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2015 Red Hat * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Author: Carlos Garnacho */ #include "config.h" #include #include "gsd-settings-migrate.h" void gsd_settings_migrate_check (const gchar *origin_schema, const gchar *origin_path, const gchar *dest_schema, const gchar *dest_path, GsdSettingsMigrateEntry entries[], guint n_entries) { GSettings *origin_settings, *dest_settings; GVariant *variant; guint i; origin_settings = g_settings_new_with_path (origin_schema, origin_path); dest_settings = g_settings_new_with_path (dest_schema, dest_path); for (i = 0; i < n_entries; i++) { variant = g_settings_get_user_value (origin_settings, entries[i].origin_key); if (!variant) continue; if (entries[i].dest_key) { if (entries[i].func) { GVariant *modified; modified = entries[i].func (variant); g_variant_unref (variant); variant = g_variant_ref_sink (modified); } g_settings_set_value (dest_settings, entries[i].dest_key, variant); } g_settings_reset (origin_settings, entries[i].origin_key); g_variant_unref (variant); } g_object_unref (origin_settings); g_object_unref (dest_settings); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/gsd-settings-migrate.h0000664000175000017500000000323000000000000026217 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2015 Red Hat * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Author: Carlos Garnacho */ #ifndef __GSD_SETTINGS_MIGRATE_H__ #define __GSD_SETTINGS_MIGRATE_H__ typedef struct _GsdSettingsMigrateEntry GsdSettingsMigrateEntry; typedef GVariant * (* GsdSettingsMigrateFunc) (GVariant *variant); struct _GsdSettingsMigrateEntry { const gchar *origin_key; const gchar *dest_key; GsdSettingsMigrateFunc func; }; void gsd_settings_migrate_check (const gchar *origin_schema, const gchar *origin_path, const gchar *dest_schema, const gchar *dest_path, GsdSettingsMigrateEntry entries[], guint n_entries); #endif /* __GSD_SETTINGS_MIGRATE_H__ */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/input-device-example.sh0000664000175000017500000000302000000000000026363 0ustar00jeremyjeremy#!/bin/sh # # This script is an example hotplug script for use with the various # input devices plugins. # # The script is called with the arguments: # -t [added|present|removed] # added ... device was just plugged in # present.. device was present at gnome-settings-daemon startup # removed.. device was just removed # -i # device ID being the XInput device ID # The name of the device # # The script should return 0 if the device is to be # ignored from future configuration. # # Set the script to be used with: # gsettings set com.canonical.unity.settings-daemon.peripherals.input-devices hotplug-command /path/to/script/input-devices.sh # args=`getopt "t:i:" $*` set -- $args while [ $# -gt 0 ] do case $1 in -t) shift; type="$1" ;; -i) shift; id="$1" ;; --) shift; device="$@" break; ;; *) echo "Unknown option $1"; exit 1 ;; esac shift done retval=0 case $type in added) echo "Device '$device' (ID=$id) was added" ;; present) echo "Device '$device' (ID=$id) was already present at startup" ;; removed) echo "Device '$device' (ID=$id) was removed" ;; *) echo "Unknown operation" retval=1 ;; esac # All further processing will be disabled if $retval == 1 exit $retval ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/test-egg-key-parsing.c0000664000175000017500000000110500000000000026116 0ustar00jeremyjeremy#include #define KEY "XF86AudioMute" int main (int argc, char **argv) { guint gdk_accel_key; guint *gdk_accel_codes; GdkModifierType gdk_mods; gtk_init (&argc, &argv); g_message ("gdk_keyval_from_name ('%s') == %d", KEY, gdk_keyval_from_name(KEY)); gtk_accelerator_parse_with_keycode (KEY, &gdk_accel_key, &gdk_accel_codes, &gdk_mods); g_message ("gtk_accelerator_parse_full ('%s') returned keyval '%d' keycode[0]: '%d' mods: 0x%x", KEY, gdk_accel_key, gdk_accel_codes ? gdk_accel_codes[0] : 0, gdk_mods); g_free (gdk_accel_codes); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/test-input-helper.c0000664000175000017500000000772200000000000025554 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2011 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include "gsd-input-helper.h" static void print_disabled_devices (void) { GList *devices, *l; GdkDeviceManager *manager; manager = gdk_display_get_device_manager (gdk_display_get_default ()); devices = get_disabled_devices (manager); g_print ("Disabled devices:\t\t\t"); if (devices == NULL) { g_print ("no\n"); return; } for (l = devices; l != NULL; l = l->next) { g_print ("%d ", GPOINTER_TO_INT (l->data)); } g_list_free (devices); g_print ("\n"); } int main (int argc, char **argv) { gboolean supports_xinput; gboolean has_touchpad, has_touchscreen, has_trackball; XDeviceInfo *device_info; gint n_devices, opcode; guint i; gtk_init (&argc, &argv); supports_xinput = supports_xinput_devices (); if (supports_xinput) { g_print ("Supports XInput:\t\t\tyes\n"); } else { g_print ("Supports XInput:\t\t\tno\n"); return 0; } supports_xinput = supports_xinput2_devices (&opcode); if (supports_xinput) { g_print ("Supports XInput2:\t\t\tyes (opcode: %d)\n", opcode); } else { g_print ("Supports XInput2:\t\t\tno\n"); return 0; } has_touchpad = touchpad_is_present (); g_print ("Has touchpad:\t\t\t\t%s\n", has_touchpad ? "yes" : "no"); has_touchscreen = touchscreen_is_present (); g_print ("Has touchscreen:\t\t\t%s\n", has_touchscreen ? "yes" : "no"); has_trackball = trackball_is_present (); g_print ("Has trackball:\t\t\t\t%s\n", has_trackball ? "yes" : "no"); device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &n_devices); if (device_info == NULL) { g_warning ("Has no input devices"); return 1; } print_disabled_devices (); for (i = 0; i < n_devices; i++) { XDevice *device; if (device_info_is_touchscreen (&device_info[i])) { g_print ("Device %d is touchscreen:\t\t%s\n", (int) device_info[i].id, "yes"); continue; } if (device_info_is_trackball (&device_info[i])) { g_print ("Device %d is trackball:\t\t\t%s\n", (int) device_info[i].id, "yes"); continue; } if (device_info_is_tablet (&device_info[i])) { g_print ("Device %d is tablet:\t\t\t%s\n", (int) device_info[i].id, "yes"); continue; } gdk_error_trap_push (); device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device_info[i].id); if (gdk_error_trap_pop () || (device == NULL)) continue; if (device_is_touchpad (device)) g_print ("Device %d is touchpad:\t\t%s\n", (int) device_info[i].id, "yes"); else { int tool_id; tool_id = xdevice_get_last_tool_id (device_info[i].id); if (tool_id >= 0x0) g_print ("Device %d is touchpad/touchscreen:\t%s (tool ID: 0x%x)\n", (int) device_info[i].id, "no", tool_id); else g_print ("Device %d is touchpad/touchscreen:\t%s\n", (int) device_info[i].id, "no"); } XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device); } XFreeDeviceList (device_info); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/common/test-plugin.h0000664000175000017500000000467000000000000024442 0ustar00jeremyjeremy/** * Create a test app for your plugin quickly. * * #define NEW gsd_media_keys_manager_new * #define START gsd_media_keys_manager_start * #define MANAGER GsdMediaKeysManager * #include "gsd-media-keys-manager.h" * * #include "test-plugin.h" */ #include "config.h" #include #include #include #include #ifndef SCHEMA_NAME #define SCHEMA_NAME PLUGIN_NAME #endif #ifndef PLUGIN_NAME #error Include PLUGIN_CFLAGS in the test application s CFLAGS #endif /* !PLUGIN_NAME */ static MANAGER *manager = NULL; static gboolean has_settings (void) { const gchar * const * list; guint i; list = g_settings_list_schemas (); for (i = 0; list[i] != NULL; i++) { if (g_str_equal (list[i], "com.canonical.unity.settings-daemon.plugins." SCHEMA_NAME)) return TRUE; } return FALSE; } static void print_enable_disable_help (void) { fprintf (stderr, "To deactivate:\n"); fprintf (stderr, "\tgsettings set com.canonical.unity.settings-daemon.plugins." SCHEMA_NAME " active false\n"); fprintf (stderr, "To reactivate:\n"); fprintf (stderr, "\tgsettings set com.canonical.unity.settings-daemon.plugins." SCHEMA_NAME " active true\n"); } int main (int argc, char **argv) { GError *error; GSettings *settings; bindtextdomain (GETTEXT_PACKAGE, GNOME_SETTINGS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); notify_init ("gnome-settings-daemon"); g_setenv ("G_MESSAGES_DEBUG", "all", TRUE); error = NULL; if (! gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) { fprintf (stderr, "%s\n", error->message); g_error_free (error); exit (1); } if (has_settings () == FALSE) { fprintf (stderr, "The schemas for plugin '%s' isn't available, check your installation.\n", SCHEMA_NAME); } else { settings = g_settings_new ("com.canonical.unity.settings-daemon.plugins." SCHEMA_NAME); if (g_settings_get_boolean (settings, "active") != FALSE) { fprintf (stderr, "Plugin '%s' is not disabled. You need to disable it before launching the test application.\n", SCHEMA_NAME); print_enable_disable_help (); exit (1); } print_enable_disable_help(); } manager = NEW (); error = NULL; START (manager, &error); gtk_main (); STOP (manager); g_object_unref (manager); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5797668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/cursor/0000775000175000017500000000000000000000000022034 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/cursor/Makefile.am0000664000175000017500000000340600000000000024073 0ustar00jeremyjeremyplugin_name = cursor plugin_LTLIBRARIES = \ libcursor.la libcursor_la_SOURCES = \ gsd-cursor-manager.c \ gsd-cursor-manager.h \ gsd-cursor-plugin.c libcursor_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common/ \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) libcursor_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(CURSOR_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) libcursor_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) libcursor_la_LIBADD = \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(CURSOR_LIBS) \ $(SETTINGS_PLUGIN_LIBS) libexec_PROGRAMS = usd-test-cursor usd_test_cursor_SOURCES = \ test-cursor.c \ gsd-cursor-manager.c \ gsd-cursor-manager.h usd_test_cursor_CPPFLAGS = \ -I$(top_srcdir)/data/ \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ $(AM_CPPFLAGS) usd_test_cursor_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(CURSOR_CFLAGS) \ $(AM_CFLAGS) usd_test_cursor_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(SETTINGS_DAEMON_LIBS) \ $(SETTINGS_PLUGIN_LIBS) \ $(CURSOR_LIBS) \ -lm plugin_in_files = \ cursor.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = \ $(plugin_in_files) CLEANFILES = \ $(plugin_DATA) DISTCLEANFILES = \ $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/cursor/cursor.gnome-settings-plugin.in0000664000175000017500000000035200000000000030137 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=cursor IAge=0 # Default Priority # Priority=100 _Name=Cursor _Description=Show/hide cursor on tablet devices Authors=Bastien Nocera Copyright=Copyright © 2011 Red Hat, Inc. Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/cursor/gsd-cursor-manager.c0000664000175000017500000003246100000000000025706 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2011-2013 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "gnome-settings-profile.h" #include "gsd-cursor-manager.h" #include "gsd-input-helper.h" #include "gsd-idle-monitor.h" #define XFIXES_CURSOR_HIDING_MAJOR 4 #define GSD_CURSOR_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_CURSOR_MANAGER, GsdCursorManagerPrivate)) struct GsdCursorManagerPrivate { guint added_id; guint removed_id; guint changed_id; gboolean cursor_shown; GHashTable *monitors; }; static void gsd_cursor_manager_class_init (GsdCursorManagerClass *klass); static void gsd_cursor_manager_init (GsdCursorManager *cursor_manager); static void gsd_cursor_manager_finalize (GObject *object); G_DEFINE_TYPE (GsdCursorManager, gsd_cursor_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static gboolean add_all_devices (GsdCursorManager *manager, GdkDevice *exception, GError **error); typedef void (*ForeachScreenFunc) (GdkDisplay *display, GdkScreen *screen, GsdCursorManager *manager, gpointer user_data); static void foreach_screen (GsdCursorManager *manager, ForeachScreenFunc func, gpointer user_data) { GdkDisplay *display; guint n_screens; guint i; display = gdk_display_get_default (); n_screens = gdk_display_get_n_screens (display); for (i = 0; i < n_screens; i++) { GdkScreen *screen; screen = gdk_display_get_screen (display, i); (func) (display, screen, manager, user_data); } } static void set_cursor_visibility_foreach (GdkDisplay *display, GdkScreen *screen, GsdCursorManager *manager, gpointer user_data) { Display *xdisplay; gboolean visible = GPOINTER_TO_INT (user_data); xdisplay = GDK_DISPLAY_XDISPLAY (display); if (visible) XFixesShowCursor (xdisplay, GDK_WINDOW_XID (gdk_screen_get_root_window (screen))); else XFixesHideCursor (xdisplay, GDK_WINDOW_XID (gdk_screen_get_root_window (screen))); } static void set_cursor_visibility (GsdCursorManager *manager, gboolean visible) { g_debug ("Attempting to %s the cursor", visible ? "show" : "hide"); if (manager->priv->cursor_shown == visible) return; gdk_error_trap_push (); foreach_screen (manager, set_cursor_visibility_foreach, GINT_TO_POINTER (visible)); if (gdk_error_trap_pop ()) { g_warning ("An error occurred trying to %s the cursor", visible ? "show" : "hide"); } manager->priv->cursor_shown = visible; } static void monitor_became_active (GsdIdleMonitor *monitor, guint watch_id, gpointer user_data) { GdkDevice *device; int device_id; GsdCursorManager *manager = GSD_CURSOR_MANAGER (user_data); GdkDeviceManager *device_manager; /* Oh, so you're active? */ g_object_get (G_OBJECT (monitor), "device_id", &device_id, NULL); device_manager = gdk_display_get_device_manager (gdk_display_get_default ()); device = gdk_x11_device_manager_lookup (device_manager, device_id); g_debug ("Device %d '%s' became active", gdk_x11_device_get_id (device), gdk_device_get_name (device)); set_cursor_visibility (manager, gdk_device_get_source (device) != GDK_SOURCE_TOUCHSCREEN); /* Remove the device from the watch */ g_hash_table_remove (manager->priv->monitors, device); /* Make sure that all the other devices are watched * (but not the one we just stopped monitoring */ add_all_devices (manager, device, NULL); } static gboolean add_device (GdkDeviceManager *device_manager, GdkDevice *device, GsdCursorManager *manager, GError **error) { GsdIdleMonitor *monitor; int device_id; if (g_hash_table_lookup (manager->priv->monitors, device) != NULL) return TRUE; if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_SLAVE) return TRUE; if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) return TRUE; if (strstr (gdk_device_get_name (device), "XTEST") != NULL) return TRUE; /* Create IdleMonitors for each pointer device */ device_id = gdk_x11_device_get_id (device); monitor = gsd_idle_monitor_get_for_device (device_id); if (!monitor) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Per-device idletime monitor not available"); return FALSE; } g_hash_table_insert (manager->priv->monitors, device, g_object_ref (monitor)); gsd_idle_monitor_add_user_active_watch (monitor, monitor_became_active, manager, NULL); return TRUE; } static void device_added_cb (GdkDeviceManager *device_manager, GdkDevice *device, GsdCursorManager *manager) { add_device (device_manager, device, manager, NULL); } static void device_removed_cb (GdkDeviceManager *device_manager, GdkDevice *device, GsdCursorManager *manager) { g_hash_table_remove (manager->priv->monitors, device); } static void device_changed_cb (GdkDeviceManager *device_manager, GdkDevice *device, GsdCursorManager *manager) { if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_FLOATING) device_removed_cb (device_manager, device, manager); else device_added_cb (device_manager, device, manager); } static gboolean supports_xfixes (void) { gint op_code, event, error; return XQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "XFIXES", &op_code, &event, &error); } static gboolean supports_cursor_xfixes (void) { int major = XFIXES_CURSOR_HIDING_MAJOR; int minor = 0; gdk_error_trap_push (); if (!supports_xfixes ()) { gdk_error_trap_pop_ignored (); return FALSE; } if (!XFixesQueryVersion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor)) { gdk_error_trap_pop_ignored (); return FALSE; } gdk_error_trap_pop_ignored (); if (major >= XFIXES_CURSOR_HIDING_MAJOR) return TRUE; return FALSE; } static gboolean add_all_devices (GsdCursorManager *manager, GdkDevice *exception, GError **error) { GdkDeviceManager *device_manager; GList *devices, *l; gboolean ret = TRUE; device_manager = gdk_display_get_device_manager (gdk_display_get_default ()); devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE); for (l = devices; l != NULL; l = l->next) { GdkDevice *device = l->data; if (device == exception) continue; if (!add_device (device_manager, device, manager, error)) { ret = FALSE; break; } } g_list_free (devices); return ret; } gboolean gsd_cursor_manager_start (GsdCursorManager *manager, GError **error) { GdkDeviceManager *device_manager; g_debug ("Starting cursor manager"); gnome_settings_profile_start (NULL); if (supports_cursor_xfixes () == FALSE) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "XFixes cursor extension not available"); return FALSE; } if (supports_xinput_devices () == FALSE) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "XInput support not available"); return FALSE; } device_manager = gdk_display_get_device_manager (gdk_display_get_default ()); manager->priv->added_id = g_signal_connect (G_OBJECT (device_manager), "device-added", G_CALLBACK (device_added_cb), manager); manager->priv->removed_id = g_signal_connect (G_OBJECT (device_manager), "device-removed", G_CALLBACK (device_removed_cb), manager); manager->priv->changed_id = g_signal_connect (G_OBJECT (device_manager), "device-changed", G_CALLBACK (device_changed_cb), manager); if (!add_all_devices (manager, NULL, error)) { g_debug ("Per-device idletime monitor not available, will not hide the cursor"); gnome_settings_profile_end (NULL); return FALSE; } /* Start by hiding the cursor, and then initialising the default * root window cursor, as the window manager shouldn't do that. */ set_cursor_visibility (manager, FALSE); gnome_settings_profile_end (NULL); return TRUE; } void gsd_cursor_manager_stop (GsdCursorManager *manager) { GdkDeviceManager *device_manager; g_debug ("Stopping cursor manager"); device_manager = gdk_display_get_device_manager (gdk_display_get_default ()); if (manager->priv->added_id > 0) { g_signal_handler_disconnect (G_OBJECT (device_manager), manager->priv->added_id); manager->priv->added_id = 0; } if (manager->priv->removed_id > 0) { g_signal_handler_disconnect (G_OBJECT (device_manager), manager->priv->removed_id); manager->priv->removed_id = 0; } if (manager->priv->changed_id > 0) { g_signal_handler_disconnect (G_OBJECT (device_manager), manager->priv->changed_id); manager->priv->changed_id = 0; } if (manager->priv->cursor_shown == FALSE) set_cursor_visibility (manager, TRUE); } static void gsd_cursor_manager_class_init (GsdCursorManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_cursor_manager_finalize; g_type_class_add_private (klass, sizeof (GsdCursorManagerPrivate)); } static void gsd_cursor_manager_init (GsdCursorManager *manager) { manager->priv = GSD_CURSOR_MANAGER_GET_PRIVATE (manager); manager->priv->cursor_shown = TRUE; manager->priv->monitors = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); } static void gsd_cursor_manager_finalize (GObject *object) { GsdCursorManager *cursor_manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_CURSOR_MANAGER (object)); cursor_manager = GSD_CURSOR_MANAGER (object); g_clear_pointer (&cursor_manager->priv->monitors, g_hash_table_destroy); G_OBJECT_CLASS (gsd_cursor_manager_parent_class)->finalize (object); } GsdCursorManager * gsd_cursor_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_CURSOR_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_CURSOR_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/cursor/gsd-cursor-manager.h0000664000175000017500000000442600000000000025713 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_CURSOR_MANAGER_H #define __GSD_CURSOR_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_CURSOR_MANAGER (gsd_cursor_manager_get_type ()) #define GSD_CURSOR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_CURSOR_MANAGER, GsdCursorManager)) #define GSD_CURSOR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_CURSOR_MANAGER, GsdCursorManagerClass)) #define GSD_IS_CURSOR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_CURSOR_MANAGER)) #define GSD_IS_CURSOR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_CURSOR_MANAGER)) #define GSD_CURSOR_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_CURSOR_MANAGER, GsdCursorManagerClass)) typedef struct GsdCursorManagerPrivate GsdCursorManagerPrivate; typedef struct { GObject parent; GsdCursorManagerPrivate *priv; } GsdCursorManager; typedef struct { GObjectClass parent_class; } GsdCursorManagerClass; GType gsd_cursor_manager_get_type (void); GsdCursorManager * gsd_cursor_manager_new (void); gboolean gsd_cursor_manager_start (GsdCursorManager *manager, GError **error); void gsd_cursor_manager_stop (GsdCursorManager *manager); G_END_DECLS #endif /* __GSD_CURSOR_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/cursor/gsd-cursor-plugin.c0000664000175000017500000000202000000000000025556 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-cursor-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdCursor, gsd_cursor) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/cursor/test-cursor.c0000664000175000017500000000031200000000000024466 0ustar00jeremyjeremy#define NEW gsd_cursor_manager_new #define START gsd_cursor_manager_start #define STOP gsd_cursor_manager_stop #define MANAGER GsdCursorManager #include "gsd-cursor-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5797668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/dummy/0000775000175000017500000000000000000000000021652 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/dummy/Makefile.am0000664000175000017500000000165400000000000023714 0ustar00jeremyjeremyplugin_name = dummy plugin_LTLIBRARIES = \ libdummy.la libdummy_la_SOURCES = \ gsd-dummy-manager.c \ gsd-dummy-manager.h \ gsd-dummy-plugin.c libdummy_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) libdummy_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) libdummy_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) libdummy_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(SETTINGS_PLUGIN_LIBS) \ $(NULL) plugin_in_files = \ dummy.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = \ $(plugin_in_files) CLEANFILES = \ $(plugin_DATA) DISTCLEANFILES = \ $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ # override to _not_ install the test plugin # do not copy into your plugin install-pluginDATA: install-pluginLTLIBRARIES: ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/dummy/dummy.gnome-settings-plugin.in0000664000175000017500000000027500000000000027577 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=dummy IAge=0 # 100 is the default load Priority Priority=100 _Name=Dummy _Description=Dummy plugin Authors=AUTHOR Copyright=Copyright © 2007 AUTHOR Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/dummy/gsd-dummy-manager.c0000664000175000017500000001221300000000000025333 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "gnome-settings-profile.h" #include "gsd-dummy-manager.h" #define GSD_DUMMY_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_DUMMY_MANAGER, GsdDummyManagerPrivate)) struct GsdDummyManagerPrivate { gboolean padding; }; enum { PROP_0, }; static void gsd_dummy_manager_class_init (GsdDummyManagerClass *klass); static void gsd_dummy_manager_init (GsdDummyManager *dummy_manager); static void gsd_dummy_manager_finalize (GObject *object); G_DEFINE_TYPE (GsdDummyManager, gsd_dummy_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; gboolean gsd_dummy_manager_start (GsdDummyManager *manager, GError **error) { g_debug ("Starting dummy manager"); gnome_settings_profile_start (NULL); gnome_settings_profile_end (NULL); return TRUE; } void gsd_dummy_manager_stop (GsdDummyManager *manager) { g_debug ("Stopping dummy manager"); } static void gsd_dummy_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gsd_dummy_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static GObject * gsd_dummy_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { GsdDummyManager *dummy_manager; dummy_manager = GSD_DUMMY_MANAGER (G_OBJECT_CLASS (gsd_dummy_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); return G_OBJECT (dummy_manager); } static void gsd_dummy_manager_dispose (GObject *object) { G_OBJECT_CLASS (gsd_dummy_manager_parent_class)->dispose (object); } static void gsd_dummy_manager_class_init (GsdDummyManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->get_property = gsd_dummy_manager_get_property; object_class->set_property = gsd_dummy_manager_set_property; object_class->constructor = gsd_dummy_manager_constructor; object_class->dispose = gsd_dummy_manager_dispose; object_class->finalize = gsd_dummy_manager_finalize; g_type_class_add_private (klass, sizeof (GsdDummyManagerPrivate)); } static void gsd_dummy_manager_init (GsdDummyManager *manager) { manager->priv = GSD_DUMMY_MANAGER_GET_PRIVATE (manager); } static void gsd_dummy_manager_finalize (GObject *object) { GsdDummyManager *dummy_manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_DUMMY_MANAGER (object)); dummy_manager = GSD_DUMMY_MANAGER (object); g_return_if_fail (dummy_manager->priv != NULL); G_OBJECT_CLASS (gsd_dummy_manager_parent_class)->finalize (object); } GsdDummyManager * gsd_dummy_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_DUMMY_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_DUMMY_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/dummy/gsd-dummy-manager.h0000664000175000017500000000437000000000000025345 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_DUMMY_MANAGER_H #define __GSD_DUMMY_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_DUMMY_MANAGER (gsd_dummy_manager_get_type ()) #define GSD_DUMMY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_DUMMY_MANAGER, GsdDummyManager)) #define GSD_DUMMY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_DUMMY_MANAGER, GsdDummyManagerClass)) #define GSD_IS_DUMMY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_DUMMY_MANAGER)) #define GSD_IS_DUMMY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_DUMMY_MANAGER)) #define GSD_DUMMY_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_DUMMY_MANAGER, GsdDummyManagerClass)) typedef struct GsdDummyManagerPrivate GsdDummyManagerPrivate; typedef struct { GObject parent; GsdDummyManagerPrivate *priv; } GsdDummyManager; typedef struct { GObjectClass parent_class; } GsdDummyManagerClass; GType gsd_dummy_manager_get_type (void); GsdDummyManager * gsd_dummy_manager_new (void); gboolean gsd_dummy_manager_start (GsdDummyManager *manager, GError **error); void gsd_dummy_manager_stop (GsdDummyManager *manager); G_END_DECLS #endif /* __GSD_DUMMY_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/dummy/gsd-dummy-plugin.c0000664000175000017500000000201500000000000025216 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-dummy-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdDummy, gsd_dummy) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5797668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/0000775000175000017500000000000000000000000023205 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/Makefile.am0000664000175000017500000000503000000000000025237 0ustar00jeremyjeremyplugin_name = housekeeping COMMON_FILES = \ gsd-disk-space.c \ gsd-disk-space.h \ gsd-ldsm-dialog.c \ gsd-ldsm-dialog.h \ gsd-disk-space-helper.h \ gsd-disk-space-helper.c noinst_PROGRAMS = gsd-disk-space-test gsd-empty-trash-test gsd_disk_space_test_SOURCES = \ gsd-disk-space-test.c \ $(COMMON_FILES) gsd_disk_space_test_LDADD = $(SETTINGS_PLUGIN_LIBS) $(GIOUNIX_LIBS) $(LIBNOTIFY_LIBS) gsd_disk_space_test_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(GIOUNIX_CFLAGS) \ $(LIBNOTIFY_CFLAGS) \ $(AM_CFLAGS) gsd_empty_trash_test_SOURCES = \ gsd-empty-trash-test.c \ $(COMMON_FILES) gsd_empty_trash_test_LDADD = $(SETTINGS_PLUGIN_LIBS) $(GIOUNIX_LIBS) $(LIBNOTIFY_LIBS) gsd_empty_trash_test_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(GIOUNIX_CFLAGS) \ $(LIBNOTIFY_CFLAGS) \ $(AM_CFLAGS) libexec_PROGRAMS = usd-test-housekeeping usd_test_housekeeping_SOURCES = \ test-housekeeping.c \ gsd-housekeeping-manager.c \ gsd-housekeeping-manager.h \ $(COMMON_FILES) usd_test_housekeeping_CPPFLAGS = \ -I$(top_srcdir)/data/ \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ $(AM_CPPFLAGS) usd_test_housekeeping_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(MOUSE_CFLAGS) \ $(AM_CFLAGS) usd_test_housekeeping_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(SETTINGS_DAEMON_LIBS) \ $(SETTINGS_PLUGIN_LIBS) plugin_LTLIBRARIES = libhousekeeping.la libhousekeeping_la_SOURCES = \ $(COMMON_FILES) \ gsd-housekeeping-manager.c \ gsd-housekeeping-manager.h \ gsd-housekeeping-plugin.c libhousekeeping_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) libhousekeeping_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(GIOUNIX_CFLAGS) \ $(LIBNOTIFY_CFLAGS) \ $(AM_CFLAGS) libhousekeeping_la_LDFLAGS = $(GSD_PLUGIN_LDFLAGS) libhousekeeping_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(SETTINGS_PLUGIN_LIBS) \ $(GIOUNIX_LIBS) \ $(LIBNOTIFY_LIBS) \ $(NULL) plugin_in_files = housekeeping.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = $(plugin_in_files) CLEANFILES = $(plugin_DATA) DISTCLEANFILES = (plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/gsd-disk-space-helper.c0000664000175000017500000000667200000000000027437 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * vim: set et sw=8 ts=8: * * Copyright (c) 2008, Novell, Inc. * Copyright (c) 2012, Red Hat, Inc. * * Authors: Vincent Untz * Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gsd-disk-space-helper.h" gboolean gsd_should_ignore_unix_mount (GUnixMountEntry *mount) { const char *fs, *device; guint i; /* This is borrowed from GLib and used as a way to determine * which mounts we should ignore by default. GLib doesn't * expose this in a way that allows it to be used for this * purpose */ /* We also ignore network filesystems */ const gchar *ignore_fs[] = { "adfs", "afs", "auto", "autofs", "autofs4", "cifs", "cxfs", "devfs", "devpts", "ecryptfs", "fdescfs", "gfs", "gfs2", "kernfs", "linprocfs", "linsysfs", "lustre", "lustre_lite", "ncpfs", "nfs", "nfs4", "nfsd", "ocfs2", "proc", "procfs", "ptyfs", "rpc_pipefs", "selinuxfs", "smbfs", "sysfs", "tmpfs", "usbfs", "zfs", NULL }; const gchar *ignore_devices[] = { "none", "sunrpc", "devpts", "nfsd", "/dev/loop", "/dev/vn", NULL }; fs = g_unix_mount_get_fs_type (mount); device = g_unix_mount_get_device_path (mount); for (i = 0; ignore_fs[i] != NULL; i++) if (g_str_equal (ignore_fs[i], fs)) return TRUE; for (i = 0; ignore_devices[i] != NULL; i++) if (g_str_equal (ignore_devices[i], device)) return TRUE; return FALSE; } gboolean gsd_is_removable_mount (GUnixMountEntry *mount) { const char *mount_path; char *path; mount_path = g_unix_mount_get_mount_path (mount); if (mount_path == NULL) return FALSE; path = g_strdup_printf ("/run/media/%s", g_get_user_name ()); if (g_str_has_prefix (mount_path, path)) { g_free (path); return TRUE; } g_free (path); return FALSE; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/gsd-disk-space-helper.h0000664000175000017500000000242300000000000027432 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * vim: set et sw=8 ts=8: * * Copyright (c) 2008, Novell, Inc. * Copyright (c) 2012, Red Hat, Inc. * * Authors: Vincent Untz * Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_DISK_SPACE_HELPER_H #define __GSD_DISK_SPACE_HELPER_H #include #include G_BEGIN_DECLS gboolean gsd_should_ignore_unix_mount (GUnixMountEntry *mount); gboolean gsd_is_removable_mount (GUnixMountEntry *mount); G_END_DECLS #endif /* __GSD_DISK_SPACE_HELPER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/gsd-disk-space-test.c0000664000175000017500000000251300000000000027125 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * vim: set et sw=8 ts=8: * * Copyright (c) 2008, Novell, Inc. * * Authors: Vincent Untz * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gsd-disk-space.h" int main (int argc, char **argv) { GMainLoop *loop; gtk_init (&argc, &argv); notify_init ("gsd-disk-space-test"); loop = g_main_loop_new (NULL, FALSE); gsd_ldsm_setup (TRUE); g_main_loop_run (loop); gsd_ldsm_clean (); g_main_loop_unref (loop); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/gsd-disk-space.c0000664000175000017500000011472000000000000026154 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * vim: set et sw=8 ts=8: * * Copyright (c) 2008, Novell, Inc. * * Authors: Vincent Untz * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include "gsd-disk-space.h" #include "gsd-ldsm-dialog.h" #include "gsd-disk-space-helper.h" #define GIGABYTE 1024 * 1024 * 1024 #define CHECK_EVERY_X_SECONDS 60 #define DISK_SPACE_ANALYZER "baobab" #define SETTINGS_HOUSEKEEPING_DIR "com.canonical.unity.settings-daemon.plugins.housekeeping" #define SETTINGS_FREE_PC_NOTIFY_KEY "free-percent-notify" #define SETTINGS_FREE_PC_NOTIFY_AGAIN_KEY "free-percent-notify-again" #define SETTINGS_FREE_SIZE_NO_NOTIFY "free-size-gb-no-notify" #define SETTINGS_MIN_NOTIFY_PERIOD "min-notify-period" #define SETTINGS_IGNORE_PATHS "ignore-paths" #define PRIVACY_SETTINGS "org.gnome.desktop.privacy" #define SETTINGS_PURGE_TRASH "remove-old-trash-files" #define SETTINGS_PURGE_TEMP_FILES "remove-old-temp-files" #define SETTINGS_PURGE_AFTER "old-files-age" typedef struct { GUnixMountEntry *mount; struct statvfs buf; time_t notify_time; } LdsmMountInfo; static GHashTable *ldsm_notified_hash = NULL; static unsigned int ldsm_timeout_id = 0; static GUnixMountMonitor *ldsm_monitor = NULL; static double free_percent_notify = 0.05; static double free_percent_notify_again = 0.01; static unsigned int free_size_gb_no_notify = 2; static unsigned int min_notify_period = 10; static GSList *ignore_paths = NULL; static GSettings *settings = NULL; static GSettings *privacy_settings = NULL; static GsdLdsmDialog *dialog = NULL; static NotifyNotification *notification = NULL; static guint64 *time_read; static gboolean purge_trash; static gboolean purge_temp_files; static guint purge_after; static guint purge_trash_id = 0; static guint purge_temp_id = 0; static gchar* ldsm_get_fs_id_for_path (const gchar *path) { GFile *file; GFileInfo *fileinfo; gchar *attr_id_fs; file = g_file_new_for_path (path); fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_ID_FILESYSTEM, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (fileinfo) { attr_id_fs = g_strdup (g_file_info_get_attribute_string (fileinfo, G_FILE_ATTRIBUTE_ID_FILESYSTEM)); g_object_unref (fileinfo); } else { attr_id_fs = NULL; } g_object_unref (file); return attr_id_fs; } static gboolean ldsm_mount_has_trash (LdsmMountInfo *mount) { const gchar *user_data_dir; gchar *user_data_attr_id_fs; gchar *path_attr_id_fs; gboolean mount_uses_user_trash = FALSE; gchar *trash_files_dir; gboolean has_trash = FALSE; GDir *dir; const gchar *path; user_data_dir = g_get_user_data_dir (); user_data_attr_id_fs = ldsm_get_fs_id_for_path (user_data_dir); path = g_unix_mount_get_mount_path (mount->mount); path_attr_id_fs = ldsm_get_fs_id_for_path (path); if (g_strcmp0 (user_data_attr_id_fs, path_attr_id_fs) == 0) { /* The volume that is low on space is on the same volume as our home * directory. This means the trash is at $XDG_DATA_HOME/Trash, * not at the root of the volume which is full. */ mount_uses_user_trash = TRUE; } g_free (user_data_attr_id_fs); g_free (path_attr_id_fs); /* I can't think of a better way to find out if a volume has any trash. Any suggestions? */ if (mount_uses_user_trash) { trash_files_dir = g_build_filename (g_get_user_data_dir (), "Trash", "files", NULL); } else { gchar *uid; uid = g_strdup_printf ("%d", getuid ()); trash_files_dir = g_build_filename (path, ".Trash", uid, "files", NULL); if (!g_file_test (trash_files_dir, G_FILE_TEST_IS_DIR)) { gchar *trash_dir; g_free (trash_files_dir); trash_dir = g_strdup_printf (".Trash-%s", uid); trash_files_dir = g_build_filename (path, trash_dir, "files", NULL); g_free (trash_dir); if (!g_file_test (trash_files_dir, G_FILE_TEST_IS_DIR)) { g_free (trash_files_dir); g_free (uid); return has_trash; } } g_free (uid); } dir = g_dir_open (trash_files_dir, 0, NULL); if (dir) { if (g_dir_read_name (dir)) has_trash = TRUE; g_dir_close (dir); } g_free (trash_files_dir); return has_trash; } static void ldsm_analyze_path (const gchar *path) { const gchar *argv[] = { DISK_SPACE_ANALYZER, path, NULL }; g_spawn_async (NULL, (gchar **) argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); } static gboolean server_has_actions (void) { gboolean has; GList *caps; GList *l; caps = notify_get_server_caps (); if (caps == NULL) { fprintf (stderr, "Failed to receive server caps.\n"); return FALSE; } l = g_list_find_custom (caps, "actions", (GCompareFunc)strcmp); has = l != NULL; g_list_foreach (caps, (GFunc) g_free, NULL); g_list_free (caps); return has; } static void ignore_callback (NotifyNotification *n, const char *action) { g_assert (action != NULL); g_assert (strcmp (action, "ignore") == 0); /* Do nothing */ notify_notification_close (n, NULL); } static void examine_callback (NotifyNotification *n, const char *action, const char *path) { g_assert (action != NULL); g_assert (strcmp (action, "examine") == 0); ldsm_analyze_path (path); notify_notification_close (n, NULL); } static gboolean should_purge_file (GFile *file, GCancellable *cancellable, GDateTime *old) { GFileInfo *info; GDateTime *date; gboolean should_purge; should_purge = FALSE; info = g_file_query_info (file, G_FILE_ATTRIBUTE_TRASH_DELETION_DATE "," G_FILE_ATTRIBUTE_UNIX_UID "," G_FILE_ATTRIBUTE_TIME_CHANGED, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, NULL); date = g_file_info_get_deletion_date (info); if (date == NULL) { guint uid; guint64 ctime; uid = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_UID); if (uid != getuid ()) { should_purge = FALSE; goto out; } ctime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CHANGED); date = g_date_time_new_from_unix_local ((gint64) ctime); } should_purge = g_date_time_difference (old, date) >= 0; g_date_time_unref (date); out: g_object_unref (info); return should_purge; } DeleteData * delete_data_new (GFile *file, GCancellable *cancellable, GDateTime *old, gboolean dry_run, gboolean trash, gint depth) { DeleteData *data; data = g_new (DeleteData, 1); data->ref_count = 1; data->file = g_object_ref (file); data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; data->old = g_date_time_ref (old); data->dry_run = dry_run; data->trash = trash; data->depth = depth; data->name = g_file_get_parse_name (data->file); return data; } static DeleteData * delete_data_ref (DeleteData *data) { data->ref_count += 1; return data; } void delete_data_unref (DeleteData *data) { data->ref_count -= 1; if (data->ref_count > 0) return; g_object_unref (data->file); if (data->cancellable) g_object_unref (data->cancellable); g_date_time_unref (data->old); g_free (data->name); g_free (data); } static void delete_batch (GObject *source, GAsyncResult *res, gpointer user_data) { GFileEnumerator *enumerator = G_FILE_ENUMERATOR (source); DeleteData *data = user_data; GList *files, *f; GFile *child_file; DeleteData *child; GFileInfo *info; GError *error = NULL; files = g_file_enumerator_next_files_finish (enumerator, res, &error); g_debug ("GsdHousekeeping: purging %d children of %s", g_list_length (files), data->name); if (files) { for (f = files; f; f = f->next) { if (g_cancellable_is_cancelled (data->cancellable)) break; info = f->data; child_file = g_file_get_child (data->file, g_file_info_get_name (info)); child = delete_data_new (child_file, data->cancellable, data->old, data->dry_run, data->trash, data->depth + 1); delete_recursively_by_age (child); delete_data_unref (child); g_object_unref (child_file); } g_list_free_full (files, g_object_unref); if (!g_cancellable_is_cancelled (data->cancellable)) { g_file_enumerator_next_files_async (enumerator, 20, 0, data->cancellable, delete_batch, data); return; } } g_file_enumerator_close (enumerator, data->cancellable, NULL); g_object_unref (enumerator); if (data->depth > 0 && !g_cancellable_is_cancelled (data->cancellable)) { if ((data->trash && data->depth > 1) || should_purge_file (data->file, data->cancellable, data->old)) { g_debug ("GsdHousekeeping: purging %s\n", data->name); if (!data->dry_run) { g_file_delete (data->file, data->cancellable, NULL); } } } delete_data_unref (data); } static void delete_subdir (GObject *source, GAsyncResult *res, gpointer user_data) { GFile *file = G_FILE (source); DeleteData *data = user_data; GFileEnumerator *enumerator; GError *error = NULL; g_debug ("GsdHousekeeping: purging %s in %s\n", data->trash ? "trash" : "temporary files", data->name); enumerator = g_file_enumerate_children_finish (file, res, &error); if (error) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY)) g_warning ("Failed to enumerate children of %s: %s\n", data->name, error->message); } if (enumerator) { g_file_enumerator_next_files_async (enumerator, 20, 0, data->cancellable, delete_batch, delete_data_ref (data)); } else if (data->depth > 0 && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY)) { if ((data->trash && data->depth > 1) || should_purge_file (data->file, data->cancellable, data->old)) { if (!data->dry_run) { g_file_delete (data->file, data->cancellable, NULL); } } } if (error) g_error_free (error); delete_data_unref (data); } static void delete_subdir_check_symlink (GObject *source, GAsyncResult *res, gpointer user_data) { GFile *file = G_FILE (source); DeleteData *data = user_data; GFileInfo *info; GFileType type; info = g_file_query_info_finish (file, res, NULL); if (!info) { delete_data_unref (data); return; } type = g_file_info_get_file_type (info); g_object_unref (info); if (type == G_FILE_TYPE_SYMBOLIC_LINK) { if (should_purge_file (data->file, data->cancellable, data->old)) { g_debug ("Purging %s leaf node", data->name); if (!data->dry_run) { g_file_delete (data->file, data->cancellable, NULL); } } } else { g_file_enumerate_children_async (data->file, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, 0, data->cancellable, delete_subdir, delete_data_ref (data)); } delete_data_unref (data); } void delete_recursively_by_age (DeleteData *data) { if (data->trash && (data->depth == 1) && !should_purge_file (data->file, data->cancellable, data->old)) { /* no need to recurse into trashed directories */ return; } g_file_query_info_async (data->file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, 0, data->cancellable, delete_subdir_check_symlink, delete_data_ref (data)); } void gsd_ldsm_purge_trash (GDateTime *old) { GFile *file; DeleteData *data; file = g_file_new_for_uri ("trash:"); data = delete_data_new (file, NULL, old, FALSE, TRUE, 0); delete_recursively_by_age (data); delete_data_unref (data); g_object_unref (file); } void gsd_ldsm_purge_temp_files (GDateTime *old) { DeleteData *data; GFile *file; file = g_file_new_for_path (g_get_tmp_dir ()); data = delete_data_new (file, NULL, old, FALSE, FALSE, 0); delete_recursively_by_age (data); delete_data_unref (data); g_object_unref (file); if (g_strcmp0 (g_get_tmp_dir (), "/var/tmp") != 0) { file = g_file_new_for_path ("/var/tmp"); data = delete_data_new (file, NULL, old, FALSE, FALSE, 0); delete_recursively_by_age (data); delete_data_unref (data); g_object_unref (file); } if (g_strcmp0 (g_get_tmp_dir (), "/tmp") != 0) { file = g_file_new_for_path ("/tmp"); data = delete_data_new (file, NULL, old, FALSE, FALSE, 0); delete_recursively_by_age (data); delete_data_unref (data); g_object_unref (file); } } void gsd_ldsm_show_empty_trash (void) { GFile *file; GDateTime *old; DeleteData *data; old = g_date_time_new_now_local (); file = g_file_new_for_uri ("trash:"); data = delete_data_new (file, NULL, old, TRUE, TRUE, 0); g_object_unref (file); g_date_time_unref (old); delete_recursively_by_age (data); delete_data_unref (data); } static gboolean ldsm_purge_trash_and_temp (gpointer data) { GDateTime *now, *old; now = g_date_time_new_now_local (); old = g_date_time_add_days (now, - purge_after); if (purge_trash) { g_debug ("housekeeping: purge trash older than %u days", purge_after); gsd_ldsm_purge_trash (old); } if (purge_temp_files) { g_debug ("housekeeping: purge temp files older than %u days", purge_after); gsd_ldsm_purge_temp_files (old); } g_date_time_unref (old); g_date_time_unref (now); return G_SOURCE_CONTINUE; } static void empty_trash_callback (NotifyNotification *n, const char *action) { GDateTime *old; g_assert (action != NULL); g_assert (strcmp (action, "empty-trash") == 0); old = g_date_time_new_now_local (); gsd_ldsm_purge_trash (old); g_date_time_unref (old); notify_notification_close (n, NULL); } static void on_notification_closed (NotifyNotification *n) { g_object_unref (notification); notification = NULL; } static gboolean ldsm_notify_for_mount (LdsmMountInfo *mount, gboolean multiple_volumes, gboolean other_usable_volumes) { gchar *name, *program; gint64 free_space; gint response; gboolean has_trash; gboolean has_disk_analyzer; gboolean retval = TRUE; gchar *path; /* Don't show a notice if one is already displayed */ if (dialog != NULL || notification != NULL) return retval; name = g_unix_mount_guess_name (mount->mount); free_space = (gint64) mount->buf.f_frsize * (gint64) mount->buf.f_bavail; has_trash = ldsm_mount_has_trash (mount); path = g_strdup (g_unix_mount_get_mount_path (mount->mount)); program = g_find_program_in_path (DISK_SPACE_ANALYZER); has_disk_analyzer = (program != NULL); g_free (program); if (server_has_actions ()) { char *free_space_str; char *summary; char *body; free_space_str = g_format_size (free_space); if (multiple_volumes) { summary = g_strdup_printf (_("Low Disk Space on \"%s\""), name); if (has_trash) { body = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining. You may free up some space by emptying the trash."), name, free_space_str); } else { body = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining."), name, free_space_str); } } else { summary = g_strdup (_("Low Disk Space")); if (has_trash) { body = g_strdup_printf (_("This computer has only %s disk space remaining. You may free up some space by emptying the trash."), free_space_str); } else { body = g_strdup_printf (_("This computer has only %s disk space remaining."), free_space_str); } } g_free (free_space_str); notification = notify_notification_new (summary, body, "drive-harddisk-symbolic"); g_free (summary); g_free (body); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), NULL); notify_notification_set_app_name (notification, _("Disk space")); notify_notification_set_hint (notification, "transient", g_variant_new_boolean (TRUE)); notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL); notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT); if (has_disk_analyzer) { notify_notification_add_action (notification, "examine", _("Examine"), (NotifyActionCallback) examine_callback, g_strdup (path), g_free); } if (has_trash) { notify_notification_add_action (notification, "empty-trash", _("Empty Trash"), (NotifyActionCallback) empty_trash_callback, NULL, NULL); } notify_notification_add_action (notification, "ignore", _("Ignore"), (NotifyActionCallback) ignore_callback, NULL, NULL); notify_notification_set_category (notification, "device"); if (!notify_notification_show (notification, NULL)) { g_warning ("failed to send disk space notification\n"); } } else { dialog = gsd_ldsm_dialog_new (other_usable_volumes, multiple_volumes, has_disk_analyzer, has_trash, free_space, name, path); g_object_ref (G_OBJECT (dialog)); response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (GTK_WIDGET (dialog)); dialog = NULL; switch (response) { case GTK_RESPONSE_CANCEL: retval = FALSE; break; case GSD_LDSM_DIALOG_RESPONSE_ANALYZE: retval = FALSE; ldsm_analyze_path (path); break; case GSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH: retval = TRUE; gsd_ldsm_show_empty_trash (); break; case GTK_RESPONSE_NONE: case GTK_RESPONSE_DELETE_EVENT: retval = TRUE; break; default: g_assert_not_reached (); } } g_free (name); g_free (path); return retval; } static gboolean ldsm_mount_has_space (LdsmMountInfo *mount) { gdouble free_space; free_space = (double) mount->buf.f_bavail / (double) mount->buf.f_blocks; /* enough free space, nothing to do */ if (free_space > free_percent_notify) return TRUE; if (((gint64) mount->buf.f_frsize * (gint64) mount->buf.f_bavail) > ((gint64) free_size_gb_no_notify * GIGABYTE)) return TRUE; /* If we got here, then this volume is low on space */ return FALSE; } static gboolean ldsm_mount_is_virtual (LdsmMountInfo *mount) { if (mount->buf.f_blocks == 0) { /* Filesystems with zero blocks are virtual */ return TRUE; } return FALSE; } static gint ldsm_ignore_path_compare (gconstpointer a, gconstpointer b) { return g_strcmp0 ((const gchar *)a, (const gchar *)b); } static gboolean ldsm_mount_is_user_ignore (const gchar *path) { if (g_slist_find_custom (ignore_paths, path, (GCompareFunc) ldsm_ignore_path_compare) != NULL) return TRUE; else return FALSE; } static void ldsm_free_mount_info (gpointer data) { LdsmMountInfo *mount = data; g_return_if_fail (mount != NULL); g_unix_mount_free (mount->mount); g_free (mount); } static void ldsm_maybe_warn_mounts (GList *mounts, gboolean multiple_volumes, gboolean other_usable_volumes) { GList *l; gboolean done = FALSE; for (l = mounts; l != NULL; l = l->next) { LdsmMountInfo *mount_info = l->data; LdsmMountInfo *previous_mount_info; gdouble free_space; gdouble previous_free_space; time_t curr_time; const gchar *path; gboolean show_notify; if (done) { /* Don't show any more dialogs if the user took action with the last one. The user action * might free up space on multiple volumes, making the next dialog redundant. */ ldsm_free_mount_info (mount_info); continue; } path = g_unix_mount_get_mount_path (mount_info->mount); previous_mount_info = g_hash_table_lookup (ldsm_notified_hash, path); if (previous_mount_info != NULL) previous_free_space = (gdouble) previous_mount_info->buf.f_bavail / (gdouble) previous_mount_info->buf.f_blocks; free_space = (gdouble) mount_info->buf.f_bavail / (gdouble) mount_info->buf.f_blocks; if (previous_mount_info == NULL) { /* We haven't notified for this mount yet */ show_notify = TRUE; mount_info->notify_time = time (NULL); g_hash_table_replace (ldsm_notified_hash, g_strdup (path), mount_info); } else if ((previous_free_space - free_space) > free_percent_notify_again) { /* We've notified for this mount before and free space has decreased sufficiently since last time to notify again */ curr_time = time (NULL); if (difftime (curr_time, previous_mount_info->notify_time) > (gdouble)(min_notify_period * 60)) { show_notify = TRUE; mount_info->notify_time = curr_time; } else { /* It's too soon to show the dialog again. However, we still replace the LdsmMountInfo * struct in the hash table, but give it the notfiy time from the previous dialog. * This will stop the notification from reappearing unnecessarily as soon as the timeout expires. */ show_notify = FALSE; mount_info->notify_time = previous_mount_info->notify_time; } g_hash_table_replace (ldsm_notified_hash, g_strdup (path), mount_info); } else { /* We've notified for this mount before, but the free space hasn't decreased sufficiently to notify again */ ldsm_free_mount_info (mount_info); show_notify = FALSE; } if (show_notify) { if (ldsm_notify_for_mount (mount_info, multiple_volumes, other_usable_volumes)) done = TRUE; } } } static gboolean ldsm_check_all_mounts (gpointer data) { GList *mounts; GList *l; GList *check_mounts = NULL; GList *full_mounts = NULL; guint number_of_mounts; guint number_of_full_mounts; gboolean multiple_volumes = FALSE; gboolean other_usable_volumes = FALSE; /* We iterate through the static mounts in /etc/fstab first, seeing if * they're mounted by checking if the GUnixMountPoint has a corresponding GUnixMountEntry. * Iterating through the static mounts means we automatically ignore dynamically mounted media. */ mounts = g_unix_mount_points_get (time_read); for (l = mounts; l != NULL; l = l->next) { GUnixMountPoint *mount_point = l->data; GUnixMountEntry *mount; LdsmMountInfo *mount_info; const gchar *path; path = g_unix_mount_point_get_mount_path (mount_point); mount = g_unix_mount_at (path, time_read); g_unix_mount_point_free (mount_point); if (mount == NULL) { /* The GUnixMountPoint is not mounted */ continue; } mount_info = g_new0 (LdsmMountInfo, 1); mount_info->mount = mount; path = g_unix_mount_get_mount_path (mount); if (g_unix_mount_is_readonly (mount)) { ldsm_free_mount_info (mount_info); continue; } if (ldsm_mount_is_user_ignore (g_unix_mount_get_mount_path (mount))) { ldsm_free_mount_info (mount_info); continue; } if (gsd_should_ignore_unix_mount (mount)) { ldsm_free_mount_info (mount_info); continue; } if (statvfs (path, &mount_info->buf) != 0) { ldsm_free_mount_info (mount_info); continue; } if (ldsm_mount_is_virtual (mount_info)) { ldsm_free_mount_info (mount_info); continue; } check_mounts = g_list_prepend (check_mounts, mount_info); } g_list_free (mounts); number_of_mounts = g_list_length (check_mounts); if (number_of_mounts > 1) multiple_volumes = TRUE; for (l = check_mounts; l != NULL; l = l->next) { LdsmMountInfo *mount_info = l->data; if (!ldsm_mount_has_space (mount_info)) { full_mounts = g_list_prepend (full_mounts, mount_info); } else { g_hash_table_remove (ldsm_notified_hash, g_unix_mount_get_mount_path (mount_info->mount)); ldsm_free_mount_info (mount_info); } } number_of_full_mounts = g_list_length (full_mounts); if (number_of_mounts > number_of_full_mounts) other_usable_volumes = TRUE; ldsm_maybe_warn_mounts (full_mounts, multiple_volumes, other_usable_volumes); g_list_free (check_mounts); g_list_free (full_mounts); return TRUE; } static gboolean ldsm_is_hash_item_not_in_mounts (gpointer key, gpointer value, gpointer user_data) { GList *l; for (l = (GList *) user_data; l != NULL; l = l->next) { GUnixMountEntry *mount = l->data; const char *path; path = g_unix_mount_get_mount_path (mount); if (strcmp (path, key) == 0) return FALSE; } return TRUE; } static void ldsm_mounts_changed (GObject *monitor, gpointer data) { GList *mounts; /* remove the saved data for mounts that got removed */ mounts = g_unix_mounts_get (time_read); g_hash_table_foreach_remove (ldsm_notified_hash, ldsm_is_hash_item_not_in_mounts, mounts); g_list_free_full (mounts, (GDestroyNotify) g_unix_mount_free); /* check the status now, for the new mounts */ ldsm_check_all_mounts (NULL); /* and reset the timeout */ if (ldsm_timeout_id) g_source_remove (ldsm_timeout_id); ldsm_timeout_id = g_timeout_add_seconds (CHECK_EVERY_X_SECONDS, ldsm_check_all_mounts, NULL); } static gboolean ldsm_is_hash_item_in_ignore_paths (gpointer key, gpointer value, gpointer user_data) { return ldsm_mount_is_user_ignore (key); } static void gsd_ldsm_get_config (void) { gchar **settings_list; free_percent_notify = g_settings_get_double (settings, SETTINGS_FREE_PC_NOTIFY_KEY); free_percent_notify_again = g_settings_get_double (settings, SETTINGS_FREE_PC_NOTIFY_AGAIN_KEY); free_size_gb_no_notify = g_settings_get_int (settings, SETTINGS_FREE_SIZE_NO_NOTIFY); min_notify_period = g_settings_get_int (settings, SETTINGS_MIN_NOTIFY_PERIOD); if (ignore_paths != NULL) { g_slist_foreach (ignore_paths, (GFunc) g_free, NULL); g_clear_pointer (&ignore_paths, g_slist_free); } settings_list = g_settings_get_strv (settings, SETTINGS_IGNORE_PATHS); if (settings_list != NULL) { guint i; for (i = 0; settings_list[i] != NULL; i++) ignore_paths = g_slist_prepend (ignore_paths, g_strdup (settings_list[i])); /* Make sure we dont leave stale entries in ldsm_notified_hash */ g_hash_table_foreach_remove (ldsm_notified_hash, ldsm_is_hash_item_in_ignore_paths, NULL); g_strfreev (settings_list); } purge_trash = g_settings_get_boolean (privacy_settings, SETTINGS_PURGE_TRASH); purge_temp_files = g_settings_get_boolean (privacy_settings, SETTINGS_PURGE_TEMP_FILES); purge_after = g_settings_get_uint (privacy_settings, SETTINGS_PURGE_AFTER); } static void gsd_ldsm_update_config (GSettings *settings, const gchar *key, gpointer user_data) { gsd_ldsm_get_config (); } void gsd_ldsm_setup (gboolean check_now) { if (ldsm_notified_hash || ldsm_timeout_id || ldsm_monitor) { g_warning ("Low disk space monitor already initialized."); return; } ldsm_notified_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, ldsm_free_mount_info); settings = g_settings_new (SETTINGS_HOUSEKEEPING_DIR); privacy_settings = g_settings_new (PRIVACY_SETTINGS); gsd_ldsm_get_config (); g_signal_connect (G_OBJECT (settings), "changed", G_CALLBACK (gsd_ldsm_update_config), NULL); ldsm_monitor = g_unix_mount_monitor_new (); g_unix_mount_monitor_set_rate_limit (ldsm_monitor, 1000); g_signal_connect (ldsm_monitor, "mounts-changed", G_CALLBACK (ldsm_mounts_changed), NULL); if (check_now) ldsm_check_all_mounts (NULL); ldsm_timeout_id = g_timeout_add_seconds (CHECK_EVERY_X_SECONDS, ldsm_check_all_mounts, NULL); purge_trash_id = g_timeout_add_seconds (3600, ldsm_purge_trash_and_temp, NULL); } void gsd_ldsm_clean (void) { if (purge_trash_id) g_source_remove (purge_trash_id); purge_trash_id = 0; if (purge_temp_id) g_source_remove (purge_temp_id); purge_temp_id = 0; if (ldsm_timeout_id) g_source_remove (ldsm_timeout_id); ldsm_timeout_id = 0; if (ldsm_notified_hash) g_hash_table_destroy (ldsm_notified_hash); ldsm_notified_hash = NULL; if (ldsm_monitor) g_object_unref (ldsm_monitor); ldsm_monitor = NULL; if (settings != NULL) { g_object_unref (settings); } g_clear_object (&privacy_settings); if (dialog) { gtk_widget_destroy (GTK_WIDGET (dialog)); dialog = NULL; } if (notification != NULL) { notify_notification_close (notification, NULL); notification = NULL; } if (ignore_paths) { g_slist_foreach (ignore_paths, (GFunc) g_free, NULL); g_slist_free (ignore_paths); } } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/gsd-disk-space.h0000664000175000017500000000364600000000000026165 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * vim: set et sw=8 ts=8: * * Copyright (c) 2008, Novell, Inc. * * Authors: Vincent Untz * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_DISK_SPACE_H #define __GSD_DISK_SPACE_H #include G_BEGIN_DECLS typedef struct { gint ref_count; GFile *file; GCancellable *cancellable; GDateTime *old; gboolean dry_run; gboolean trash; gchar *name; gint depth; } DeleteData; void delete_data_unref (DeleteData *data); DeleteData *delete_data_new (GFile *file, GCancellable *cancellable, GDateTime *old, gboolean dry_run, gboolean trash, gint depth); void delete_recursively_by_age (DeleteData *data); void gsd_ldsm_setup (gboolean check_now); void gsd_ldsm_clean (void); /* for the test */ void gsd_ldsm_show_empty_trash (void); void gsd_ldsm_purge_trash (GDateTime *old); void gsd_ldsm_purge_temp_files (GDateTime *old); G_END_DECLS #endif /* __GSD_DISK_SPACE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/gsd-empty-trash-test.c0000664000175000017500000000236000000000000027357 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * vim: set et sw=8 ts=8: * * Copyright (c) 2011, Red Hat, Inc. * * Authors: Cosimo Cecchi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include "gsd-disk-space.h" int main (int argc, char **argv) { GMainLoop *loop; gtk_init (&argc, &argv); loop = g_main_loop_new (NULL, FALSE); gsd_ldsm_show_empty_trash (); g_main_loop_run (loop); g_main_loop_unref (loop); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/gsd-housekeeping-manager.c0000664000175000017500000003736500000000000030240 0ustar00jeremyjeremy/* * Copyright (C) 2008 Michael J. Chudobiak * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include "gnome-settings-profile.h" #include "gsd-housekeeping-manager.h" #include "gsd-disk-space.h" /* General */ #define INTERVAL_ONCE_A_DAY 24*60*60 #define INTERVAL_TWO_MINUTES 2*60 /* Thumbnail cleaner */ #define THUMB_PREFIX "org.gnome.desktop.thumbnail-cache" #define THUMB_AGE_KEY "maximum-age" #define THUMB_SIZE_KEY "maximum-size" #define GSD_HOUSEKEEPING_DBUS_PATH "/org/gnome/SettingsDaemon/Housekeeping" static const gchar introspection_xml[] = "" " " " " " " " " ""; struct GsdHousekeepingManagerPrivate { GSettings *settings; guint long_term_cb; guint short_term_cb; GDBusNodeInfo *introspection_data; GDBusConnection *connection; GCancellable *bus_cancellable; }; #define GSD_HOUSEKEEPING_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_HOUSEKEEPING_MANAGER, GsdHousekeepingManagerPrivate)) static void gsd_housekeeping_manager_class_init (GsdHousekeepingManagerClass *klass); static void gsd_housekeeping_manager_init (GsdHousekeepingManager *housekeeping_manager); G_DEFINE_TYPE (GsdHousekeepingManager, gsd_housekeeping_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; typedef struct { glong now; glong max_age; goffset total_size; goffset max_size; } PurgeData; typedef struct { time_t mtime; char *path; glong size; } ThumbData; static void thumb_data_free (gpointer data) { ThumbData *info = data; if (info) { g_free (info->path); g_free (info); } } static GList * read_dir_for_purge (const char *path, GList *files) { GFile *read_path; GFileEnumerator *enum_dir; read_path = g_file_new_for_path (path); enum_dir = g_file_enumerate_children (read_path, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_TIME_MODIFIED "," G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (enum_dir != NULL) { GFileInfo *info; while ((info = g_file_enumerator_next_file (enum_dir, NULL, NULL)) != NULL) { const char *name; name = g_file_info_get_name (info); if (strlen (name) == 36 && strcmp (name + 32, ".png") == 0) { ThumbData *td; GFile *entry; char *entry_path; GTimeVal mod_time; entry = g_file_get_child (read_path, name); entry_path = g_file_get_path (entry); g_object_unref (entry); g_file_info_get_modification_time (info, &mod_time); td = g_new0 (ThumbData, 1); td->path = entry_path; td->mtime = mod_time.tv_sec; td->size = g_file_info_get_size (info); files = g_list_prepend (files, td); } g_object_unref (info); } g_object_unref (enum_dir); } g_object_unref (read_path); return files; } static void purge_old_thumbnails (ThumbData *info, PurgeData *purge_data) { if ((purge_data->now - info->mtime) > purge_data->max_age) { g_unlink (info->path); info->size = 0; } else { purge_data->total_size += info->size; } } static int sort_file_mtime (ThumbData *file1, ThumbData *file2) { return file1->mtime - file2->mtime; } static char ** get_thumbnail_dirs (void) { GPtrArray *array; char *path; array = g_ptr_array_new (); /* check new XDG cache */ path = g_build_filename (g_get_user_cache_dir (), "thumbnails", "normal", NULL); g_ptr_array_add (array, path); path = g_build_filename (g_get_user_cache_dir (), "thumbnails", "large", NULL); g_ptr_array_add (array, path); path = g_build_filename (g_get_user_cache_dir (), "thumbnails", "fail", "gnome-thumbnail-factory", NULL); g_ptr_array_add (array, path); /* cleanup obsolete locations too */ path = g_build_filename (g_get_home_dir (), ".thumbnails", "normal", NULL); g_ptr_array_add (array, path); path = g_build_filename (g_get_home_dir (), ".thumbnails", "large", NULL); g_ptr_array_add (array, path); path = g_build_filename (g_get_home_dir (), ".thumbnails", "fail", "gnome-thumbnail-factory", NULL); g_ptr_array_add (array, path); g_ptr_array_add (array, NULL); return (char **) g_ptr_array_free (array, FALSE); } static void purge_thumbnail_cache (GsdHousekeepingManager *manager) { char **paths; GList *files; PurgeData purge_data; GTimeVal current_time; guint i; g_debug ("housekeeping: checking thumbnail cache size and freshness"); purge_data.max_age = g_settings_get_int (manager->priv->settings, THUMB_AGE_KEY) * 24 * 60 * 60; purge_data.max_size = g_settings_get_int (manager->priv->settings, THUMB_SIZE_KEY) * 1024 * 1024; /* if both are set to -1, we don't need to read anything */ if ((purge_data.max_age < 0) && (purge_data.max_size < 0)) return; paths = get_thumbnail_dirs (); files = NULL; for (i = 0; paths[i] != NULL; i++) files = read_dir_for_purge (paths[i], files); g_strfreev (paths); g_get_current_time (¤t_time); purge_data.now = current_time.tv_sec; purge_data.total_size = 0; if (purge_data.max_age >= 0) g_list_foreach (files, (GFunc) purge_old_thumbnails, &purge_data); if ((purge_data.total_size > purge_data.max_size) && (purge_data.max_size >= 0)) { GList *scan; files = g_list_sort (files, (GCompareFunc) sort_file_mtime); for (scan = files; scan && (purge_data.total_size > purge_data.max_size); scan = scan->next) { ThumbData *info = scan->data; g_unlink (info->path); purge_data.total_size -= info->size; } } g_list_foreach (files, (GFunc) thumb_data_free, NULL); g_list_free (files); } static gboolean do_cleanup (GsdHousekeepingManager *manager) { purge_thumbnail_cache (manager); return TRUE; } static gboolean do_cleanup_once (GsdHousekeepingManager *manager) { do_cleanup (manager); manager->priv->short_term_cb = 0; return FALSE; } static void do_cleanup_soon (GsdHousekeepingManager *manager) { if (manager->priv->short_term_cb == 0) { g_debug ("housekeeping: will tidy up in 2 minutes"); manager->priv->short_term_cb = g_timeout_add_seconds (INTERVAL_TWO_MINUTES, (GSourceFunc) do_cleanup_once, manager); } } static void settings_changed_callback (GSettings *settings, const char *key, GsdHousekeepingManager *manager) { do_cleanup_soon (manager); } static void handle_method_call (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { GDateTime *now; now = g_date_time_new_now_local (); if (g_strcmp0 (method_name, "EmptyTrash") == 0) { gsd_ldsm_purge_trash (now); g_dbus_method_invocation_return_value (invocation, NULL); } else if (g_strcmp0 (method_name, "RemoveTempFiles") == 0) { gsd_ldsm_purge_temp_files (now); g_dbus_method_invocation_return_value (invocation, NULL); } g_date_time_unref (now); } static const GDBusInterfaceVTable interface_vtable = { handle_method_call, NULL, /* Get Property */ NULL, /* Set Property */ }; static void on_bus_gotten (GObject *source_object, GAsyncResult *res, GsdHousekeepingManager *manager) { GDBusConnection *connection; GError *error = NULL; GDBusInterfaceInfo **infos; int i; if (manager->priv->bus_cancellable == NULL || g_cancellable_is_cancelled (manager->priv->bus_cancellable)) { g_warning ("Operation has been cancelled, so not retrieving session bus"); return; } connection = g_bus_get_finish (res, &error); if (connection == NULL) { g_warning ("Could not get session bus: %s", error->message); g_error_free (error); return; } manager->priv->connection = connection; infos = manager->priv->introspection_data->interfaces; for (i = 0; infos[i] != NULL; i++) { g_dbus_connection_register_object (connection, GSD_HOUSEKEEPING_DBUS_PATH, infos[i], &interface_vtable, manager, NULL, NULL); } } static void register_manager_dbus (GsdHousekeepingManager *manager) { manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (manager->priv->introspection_data != NULL); manager->priv->bus_cancellable = g_cancellable_new (); g_bus_get (G_BUS_TYPE_SESSION, manager->priv->bus_cancellable, (GAsyncReadyCallback) on_bus_gotten, manager); } gboolean gsd_housekeeping_manager_start (GsdHousekeepingManager *manager, GError **error) { gchar *dir; g_debug ("Starting housekeeping manager"); gnome_settings_profile_start (NULL); /* Create ~/.local/ as early as possible */ g_mkdir_with_parents(g_get_user_data_dir (), 0700); /* Create ~/.local/share/applications/, see * https://bugzilla.gnome.org/show_bug.cgi?id=703048 */ dir = g_build_filename (g_get_user_data_dir (), "applications", NULL); g_mkdir (dir, 0700); g_free (dir); gsd_ldsm_setup (FALSE); manager->priv->settings = g_settings_new (THUMB_PREFIX); g_signal_connect (G_OBJECT (manager->priv->settings), "changed", G_CALLBACK (settings_changed_callback), manager); /* Clean once, a few minutes after start-up */ do_cleanup_soon (manager); /* Clean periodically, on a daily basis. */ manager->priv->long_term_cb = g_timeout_add_seconds (INTERVAL_ONCE_A_DAY, (GSourceFunc) do_cleanup, manager); gnome_settings_profile_end (NULL); return TRUE; } void gsd_housekeeping_manager_stop (GsdHousekeepingManager *manager) { GsdHousekeepingManagerPrivate *p = manager->priv; g_debug ("Stopping housekeeping manager"); if (manager->priv->bus_cancellable != NULL) { g_cancellable_cancel (manager->priv->bus_cancellable); g_object_unref (manager->priv->bus_cancellable); manager->priv->bus_cancellable = NULL; } if (manager->priv->introspection_data) { g_dbus_node_info_unref (manager->priv->introspection_data); manager->priv->introspection_data = NULL; } if (manager->priv->connection != NULL) { g_object_unref (manager->priv->connection); manager->priv->connection = NULL; } if (p->short_term_cb) { g_source_remove (p->short_term_cb); p->short_term_cb = 0; } if (p->long_term_cb) { g_source_remove (p->long_term_cb); p->long_term_cb = 0; /* Do a clean-up on shutdown if and only if the size or age limits have been set to paranoid levels (zero) */ if ((g_settings_get_int (p->settings, THUMB_AGE_KEY) == 0) || (g_settings_get_int (p->settings, THUMB_SIZE_KEY) == 0)) { do_cleanup (manager); } g_object_unref (p->settings); p->settings = NULL; } gsd_ldsm_clean (); } static void gsd_housekeeping_manager_class_init (GsdHousekeepingManagerClass *klass) { g_type_class_add_private (klass, sizeof (GsdHousekeepingManagerPrivate)); } static void gsd_housekeeping_manager_init (GsdHousekeepingManager *manager) { manager->priv = GSD_HOUSEKEEPING_MANAGER_GET_PRIVATE (manager); } GsdHousekeepingManager * gsd_housekeeping_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_HOUSEKEEPING_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); register_manager_dbus (manager_object); } return GSD_HOUSEKEEPING_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/gsd-housekeeping-manager.h0000664000175000017500000000470500000000000030235 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Michael J. Chudobiak * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_HOUSEKEEPING_MANAGER_H #define __GSD_HOUSEKEEPING_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_HOUSEKEEPING_MANAGER (gsd_housekeeping_manager_get_type ()) #define GSD_HOUSEKEEPING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_HOUSEKEEPING_MANAGER, GsdHousekeepingManager)) #define GSD_HOUSEKEEPING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_HOUSEKEEPING_MANAGER, GsdHousekeepingManagerClass)) #define GSD_IS_HOUSEKEEPING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_HOUSEKEEPING_MANAGER)) #define GSD_IS_HOUSEKEEPING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_HOUSEKEEPING_MANAGER)) #define GSD_HOUSEKEEPING_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_HOUSEKEEPING_MANAGER, GsdHousekeepingManagerClass)) typedef struct GsdHousekeepingManagerPrivate GsdHousekeepingManagerPrivate; typedef struct { GObject parent; GsdHousekeepingManagerPrivate *priv; } GsdHousekeepingManager; typedef struct { GObjectClass parent_class; } GsdHousekeepingManagerClass; GType gsd_housekeeping_manager_get_type (void); GsdHousekeepingManager * gsd_housekeeping_manager_new (void); gboolean gsd_housekeeping_manager_start (GsdHousekeepingManager *manager, GError **error); void gsd_housekeeping_manager_stop (GsdHousekeepingManager *manager); G_END_DECLS #endif /* __GSD_HOUSEKEEPING_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/gsd-housekeeping-plugin.c0000664000175000017500000000205100000000000030104 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Michael J. Chudobiak * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-housekeeping-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdHousekeeping, gsd_housekeeping) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/gsd-ldsm-dialog.c0000664000175000017500000005053500000000000026330 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * gsd-ldsm-dialog.c * Copyright (C) Chris Coulson 2009 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "config.h" #include #include #include "gsd-ldsm-dialog.h" #define SETTINGS_HOUSEKEEPING_DIR "com.canonical.unity.settings-daemon.plugins.housekeeping" enum { PROP_0, PROP_OTHER_USABLE_PARTITIONS, PROP_OTHER_PARTITIONS, PROP_HAS_TRASH, PROP_SPACE_REMAINING, PROP_PARTITION_NAME, PROP_MOUNT_PATH }; struct GsdLdsmDialogPrivate { GtkWidget *primary_label; GtkWidget *secondary_label; GtkWidget *ignore_check_button; gboolean other_usable_partitions; gboolean other_partitions; gboolean has_trash; gint64 space_remaining; gchar *partition_name; gchar *mount_path; }; #define GSD_LDSM_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_LDSM_DIALOG, GsdLdsmDialogPrivate)) static void gsd_ldsm_dialog_class_init (GsdLdsmDialogClass *klass); static void gsd_ldsm_dialog_init (GsdLdsmDialog *dialog); G_DEFINE_TYPE (GsdLdsmDialog, gsd_ldsm_dialog, GTK_TYPE_DIALOG); static const gchar* gsd_ldsm_dialog_get_checkbutton_text (GsdLdsmDialog *dialog) { g_return_val_if_fail (GSD_IS_LDSM_DIALOG (dialog), NULL); if (dialog->priv->other_partitions) return _("Don't show any warnings again for this file system"); else return _("Don't show any warnings again"); } static gchar* gsd_ldsm_dialog_get_primary_text (GsdLdsmDialog *dialog) { gchar *primary_text, *free_space; g_return_val_if_fail (GSD_IS_LDSM_DIALOG (dialog), NULL); free_space = g_format_size (dialog->priv->space_remaining); if (dialog->priv->other_partitions) { primary_text = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining."), dialog->priv->partition_name, free_space); } else { primary_text = g_strdup_printf (_("This computer has only %s disk space remaining."), free_space); } g_free (free_space); return primary_text; } static const gchar* gsd_ldsm_dialog_get_secondary_text (GsdLdsmDialog *dialog) { g_return_val_if_fail (GSD_IS_LDSM_DIALOG (dialog), NULL); if (dialog->priv->other_usable_partitions) { if (dialog->priv->has_trash) { return _("You can free up disk space by emptying the Trash, removing " \ "unused programs or files, or moving files to another disk or partition."); } else { return _("You can free up disk space by removing unused programs or files, " \ "or by moving files to another disk or partition."); } } else { if (dialog->priv->has_trash) { return _("You can free up disk space by emptying the Trash, removing unused " \ "programs or files, or moving files to an external disk."); } else { return _("You can free up disk space by removing unused programs or files, " \ "or by moving files to an external disk."); } } } static gint ignore_path_compare (gconstpointer a, gconstpointer b) { return g_strcmp0 ((const gchar *)a, (const gchar *)b); } static gboolean update_ignore_paths (GSList **ignore_paths, const gchar *mount_path, gboolean ignore) { GSList *found; gchar *path_to_remove; found = g_slist_find_custom (*ignore_paths, mount_path, (GCompareFunc) ignore_path_compare); if (ignore && (found == NULL)) { *ignore_paths = g_slist_prepend (*ignore_paths, g_strdup (mount_path)); return TRUE; } if (!ignore && (found != NULL)) { path_to_remove = found->data; *ignore_paths = g_slist_remove (*ignore_paths, path_to_remove); g_free (path_to_remove); return TRUE; } return FALSE; } static void ignore_check_button_toggled_cb (GtkToggleButton *button, gpointer user_data) { GsdLdsmDialog *dialog = (GsdLdsmDialog *)user_data; GSettings *settings; gchar **settings_list; gboolean ignore, updated; gint i; GSList *ignore_paths = NULL; settings = g_settings_new (SETTINGS_HOUSEKEEPING_DIR); settings_list = g_settings_get_strv (settings, "ignore-paths"); for (i = 0; i < G_N_ELEMENTS (settings_list); i++) { if (settings_list[i] != NULL) ignore_paths = g_slist_append (ignore_paths, g_strdup (settings_list[i])); } ignore = gtk_toggle_button_get_active (button); updated = update_ignore_paths (&ignore_paths, dialog->priv->mount_path, ignore); g_strfreev (settings_list); if (updated) { GSList *l; GPtrArray *array = g_ptr_array_new (); for (l = ignore_paths; l != NULL; l = l->next) g_ptr_array_add (array, l->data); g_ptr_array_add (array, NULL); if (!g_settings_set_strv (settings, "ignore-paths", (const gchar **) array->pdata)) { g_warning ("Cannot change ignore preference - failed to commit changes"); } g_ptr_array_free (array, FALSE); } g_slist_foreach (ignore_paths, (GFunc) g_free, NULL); g_slist_free (ignore_paths); g_object_unref (settings); } static void gsd_ldsm_dialog_init (GsdLdsmDialog *dialog) { GtkWidget *main_vbox, *text_vbox, *hbox; GtkWidget *image; dialog->priv = GSD_LDSM_DIALOG_GET_PRIVATE (dialog); main_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); /* Set up all the window stuff here */ gtk_window_set_title (GTK_WINDOW (dialog), _("Low Disk Space")); gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_DIALOG_WARNING); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE); gtk_window_set_focus_on_map (GTK_WINDOW (dialog), FALSE); gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); /* Create the image */ image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG); gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); /* Create the labels */ dialog->priv->primary_label = gtk_label_new (NULL); gtk_label_set_line_wrap (GTK_LABEL (dialog->priv->primary_label), TRUE); gtk_label_set_single_line_mode (GTK_LABEL (dialog->priv->primary_label), FALSE); gtk_misc_set_alignment (GTK_MISC (dialog->priv->primary_label), 0.0, 0.0); gtk_label_set_max_width_chars (GTK_LABEL (dialog->priv->primary_label), 72); dialog->priv->secondary_label = gtk_label_new (NULL); gtk_label_set_line_wrap (GTK_LABEL (dialog->priv->secondary_label), TRUE); gtk_label_set_single_line_mode (GTK_LABEL (dialog->priv->secondary_label), FALSE); gtk_misc_set_alignment (GTK_MISC (dialog->priv->secondary_label), 0.0, 0.0); gtk_label_set_max_width_chars (GTK_LABEL (dialog->priv->secondary_label), 72); /* Create the check button to ignore future warnings */ dialog->priv->ignore_check_button = gtk_check_button_new (); /* The button should be inactive if the dialog was just called. * I suppose it could be possible for the user to manually edit the GSettings key between * the mount being checked and the dialog appearing, but I don't think it matters * too much */ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->ignore_check_button), FALSE); g_signal_connect (dialog->priv->ignore_check_button, "toggled", G_CALLBACK (ignore_check_button_toggled_cb), dialog); /* Now set up the dialog's GtkBox's' */ gtk_box_set_spacing (GTK_BOX (main_vbox), 14); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); text_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_box_pack_start (GTK_BOX (text_vbox), dialog->priv->primary_label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (text_vbox), dialog->priv->secondary_label, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (text_vbox), dialog->priv->ignore_check_button, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), text_vbox, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0); /* Set up the action area */ gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), 6); gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), 5); gtk_widget_show_all (hbox); } static void gsd_ldsm_dialog_finalize (GObject *object) { GsdLdsmDialog *self; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_LDSM_DIALOG (object)); self = GSD_LDSM_DIALOG (object); if (self->priv->partition_name) g_free (self->priv->partition_name); if (self->priv->mount_path) g_free (self->priv->mount_path); G_OBJECT_CLASS (gsd_ldsm_dialog_parent_class)->finalize (object); } static void gsd_ldsm_dialog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GsdLdsmDialog *self; g_return_if_fail (GSD_IS_LDSM_DIALOG (object)); self = GSD_LDSM_DIALOG (object); switch (prop_id) { case PROP_OTHER_USABLE_PARTITIONS: self->priv->other_usable_partitions = g_value_get_boolean (value); break; case PROP_OTHER_PARTITIONS: self->priv->other_partitions = g_value_get_boolean (value); break; case PROP_HAS_TRASH: self->priv->has_trash = g_value_get_boolean (value); break; case PROP_SPACE_REMAINING: self->priv->space_remaining = g_value_get_int64 (value); break; case PROP_PARTITION_NAME: self->priv->partition_name = g_value_dup_string (value); break; case PROP_MOUNT_PATH: self->priv->mount_path = g_value_dup_string (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gsd_ldsm_dialog_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GsdLdsmDialog *self; g_return_if_fail (GSD_IS_LDSM_DIALOG (object)); self = GSD_LDSM_DIALOG (object); switch (prop_id) { case PROP_OTHER_USABLE_PARTITIONS: g_value_set_boolean (value, self->priv->other_usable_partitions); break; case PROP_OTHER_PARTITIONS: g_value_set_boolean (value, self->priv->other_partitions); break; case PROP_HAS_TRASH: g_value_set_boolean (value, self->priv->has_trash); break; case PROP_SPACE_REMAINING: g_value_set_int64 (value, self->priv->space_remaining); break; case PROP_PARTITION_NAME: g_value_set_string (value, self->priv->partition_name); break; case PROP_MOUNT_PATH: g_value_set_string (value, self->priv->mount_path); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gsd_ldsm_dialog_class_init (GsdLdsmDialogClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_ldsm_dialog_finalize; object_class->set_property = gsd_ldsm_dialog_set_property; object_class->get_property = gsd_ldsm_dialog_get_property; g_object_class_install_property (object_class, PROP_OTHER_USABLE_PARTITIONS, g_param_spec_boolean ("other-usable-partitions", "other-usable-partitions", "Set to TRUE if there are other usable partitions on the system", FALSE, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, PROP_OTHER_PARTITIONS, g_param_spec_boolean ("other-partitions", "other-partitions", "Set to TRUE if there are other partitions on the system", FALSE, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, PROP_HAS_TRASH, g_param_spec_boolean ("has-trash", "has-trash", "Set to TRUE if the partition has files in it's trash folder that can be deleted", FALSE, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, PROP_SPACE_REMAINING, g_param_spec_int64 ("space-remaining", "space-remaining", "Specify how much space is remaining in bytes", G_MININT64, G_MAXINT64, 0, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, PROP_PARTITION_NAME, g_param_spec_string ("partition-name", "partition-name", "Specify the name of the partition", "Unknown", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, PROP_MOUNT_PATH, g_param_spec_string ("mount-path", "mount-path", "Specify the mount path for the partition", "Unknown", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_type_class_add_private (klass, sizeof (GsdLdsmDialogPrivate)); } GsdLdsmDialog* gsd_ldsm_dialog_new (gboolean other_usable_partitions, gboolean other_partitions, gboolean display_baobab, gboolean display_empty_trash, gint64 space_remaining, const gchar *partition_name, const gchar *mount_path) { GsdLdsmDialog *dialog; GtkWidget *button_empty_trash, *button_ignore, *button_analyze; GtkWidget *empty_trash_image, *analyze_image, *ignore_image; gchar *primary_text, *primary_text_markup; const gchar *secondary_text, *checkbutton_text; dialog = GSD_LDSM_DIALOG (g_object_new (GSD_TYPE_LDSM_DIALOG, "other-usable-partitions", other_usable_partitions, "other-partitions", other_partitions, "has-trash", display_empty_trash, "space-remaining", space_remaining, "partition-name", partition_name, "mount-path", mount_path, NULL)); /* Add some buttons */ if (dialog->priv->has_trash) { button_empty_trash = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Empty Trash"), GSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH); empty_trash_image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON); gtk_button_set_image (GTK_BUTTON (button_empty_trash), empty_trash_image); } if (display_baobab) { button_analyze = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Examine…"), GSD_LDSM_DIALOG_RESPONSE_ANALYZE); analyze_image = gtk_image_new_from_icon_name ("baobab", GTK_ICON_SIZE_BUTTON); gtk_button_set_image (GTK_BUTTON (button_analyze), analyze_image); } button_ignore = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Ignore"), GTK_RESPONSE_CANCEL); ignore_image = gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON); gtk_button_set_image (GTK_BUTTON (button_ignore), ignore_image); gtk_widget_grab_default (button_ignore); /* Set the label text */ primary_text = gsd_ldsm_dialog_get_primary_text (dialog); primary_text_markup = g_markup_printf_escaped ("%s", primary_text); gtk_label_set_markup (GTK_LABEL (dialog->priv->primary_label), primary_text_markup); secondary_text = gsd_ldsm_dialog_get_secondary_text (dialog); gtk_label_set_text (GTK_LABEL (dialog->priv->secondary_label), secondary_text); checkbutton_text = gsd_ldsm_dialog_get_checkbutton_text (dialog); gtk_button_set_label (GTK_BUTTON (dialog->priv->ignore_check_button), checkbutton_text); g_free (primary_text); g_free (primary_text_markup); return dialog; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/gsd-ldsm-dialog.h0000664000175000017500000000507700000000000026336 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * gsd-ldsm-dialog.c * Copyright (C) Chris Coulson 2009 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _GSD_LDSM_DIALOG_H_ #define _GSD_LDSM_DIALOG_H_ #include #include G_BEGIN_DECLS #define GSD_TYPE_LDSM_DIALOG (gsd_ldsm_dialog_get_type ()) #define GSD_LDSM_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_LDSM_DIALOG, GsdLdsmDialog)) #define GSD_LDSM_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_LDSM_DIALOG, GsdLdsmDialogClass)) #define GSD_IS_LDSM_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_LDSM_DIALOG)) #define GSD_IS_LDSM_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_LDSM_DIALOG)) #define GSD_LDSM_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_LDSM_DIALOG, GsdLdsmDialogClass)) enum { GSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH = -20, GSD_LDSM_DIALOG_RESPONSE_ANALYZE = -21 }; typedef struct GsdLdsmDialogPrivate GsdLdsmDialogPrivate; typedef struct _GsdLdsmDialogClass GsdLdsmDialogClass; typedef struct _GsdLdsmDialog GsdLdsmDialog; struct _GsdLdsmDialogClass { GtkDialogClass parent_class; }; struct _GsdLdsmDialog { GtkDialog parent_instance; GsdLdsmDialogPrivate *priv; }; GType gsd_ldsm_dialog_get_type (void) G_GNUC_CONST; GsdLdsmDialog * gsd_ldsm_dialog_new (gboolean other_usable_partitions, gboolean other_partitions, gboolean display_baobab, gboolean display_empty_trash, gint64 space_remaining, const gchar *partition_name, const gchar *mount_path); G_END_DECLS #endif /* _GSD_LDSM_DIALOG_H_ */ ././@PaxHeader0000000000000000000000000000021500000000000010213 xustar00113 path=unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/housekeeping.gnome-settings-plugin.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/housekeeping.gnome-settings-plugin0000664000175000017500000000042500000000000032055 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=housekeeping IAge=0 Priority=1 _Name=Housekeeping _Description=Automatically prunes thumbnail caches and other transient files, and warns about low disk space Authors=Michael J. Chudobiak Copyright=Copyright © 2008 Michael J. Chudobiak Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/housekeeping/test-housekeeping.c0000664000175000017500000000035000000000000027012 0ustar00jeremyjeremy#define NEW gsd_housekeeping_manager_new #define START gsd_housekeeping_manager_start #define STOP gsd_housekeeping_manager_stop #define MANAGER GsdHousekeepingManager #include "gsd-housekeeping-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1644246191.583767 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/0000775000175000017500000000000000000000000022317 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/.indent.pro0000664000175000017500000000003000000000000024371 0ustar00jeremyjeremy-kr -i8 -pcs -lps -psl ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/Makefile.am0000664000175000017500000000513100000000000024353 0ustar00jeremyjeremyNULL = plugin_name = keyboard plugin_LTLIBRARIES = \ libkeyboard.la \ $(NULL) themedir = $(pkgdatadir)/icons/hicolor size = 64x64 context = devices iconsdir = $(themedir)/$(size)/$(context) icons_DATA = \ kbd-capslock-off.png kbd-numlock-off.png kbd-scrolllock-off.png \ kbd-capslock-on.png kbd-numlock-on.png kbd-scrolllock-on.png if HAVE_FCITX BUILT_SOURCES = input-method-engines.c endif input-method-engines.c: $(srcdir)/input-method-engines.gperf $(AM_V_GEN) gperf --output-file=input-method-engines.c $< libkeyboard_la_SOURCES = \ gsd-keyboard-plugin.c \ gsd-keyboard-manager.h \ gsd-keyboard-manager.c \ gsd-xkb-utils.h \ gsd-xkb-utils.c \ $(NULL) libkeyboard_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/data \ -I$(top_srcdir)/plugins/common \ -DDATADIR=\""$(pkgdatadir)"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DXKB_BASE=\""$(XKB_BASE)"\" \ $(AM_CPPFLAGS) libkeyboard_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(KEYBOARD_CFLAGS) \ $(AM_CFLAGS) libkeyboard_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) \ $(NULL) libkeyboard_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(top_builddir)/plugins/common/libcommon.la \ $(SETTINGS_PLUGIN_LIBS) \ $(XF86MISC_LIBS) \ $(KEYBOARD_LIBS) \ $(NULL) libexec_PROGRAMS = usd-test-keyboard usd_test_keyboard_SOURCES = \ test-keyboard.c \ gsd-keyboard-manager.h \ gsd-keyboard-manager.c \ gsd-xkb-utils.h \ gsd-xkb-utils.c \ $(NULL) usd_test_keyboard_CFLAGS = $(libkeyboard_la_CFLAGS) usd_test_keyboard_CPPFLAGS = $(libkeyboard_la_CPPFLAGS) usd_test_keyboard_LDADD = $(libkeyboard_la_LIBADD) $(top_builddir)/gnome-settings-daemon/libgsd.la plugin_in_files = \ keyboard.gnome-settings-plugin.in \ $(NULL) plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) if HAVE_IBUS noinst_PROGRAMS = test-keyboard-ibus-utils test_keyboard_ibus_utils_SOURCES = test-keyboard-ibus-utils.c test_keyboard_ibus_utils_CFLAGS = $(libkeyboard_la_CFLAGS) test_keyboard_ibus_utils_CPPFLAGS = $(libkeyboard_la_CPPFLAGS) test_keyboard_ibus_utils_LDADD = $(libkeyboard_la_LIBADD) $(top_builddir)/gnome-settings-daemon/libgsd.la check-local: test-keyboard-ibus-utils $(builddir)/test-keyboard-ibus-utils > /dev/null endif EXTRA_DIST = \ $(icons_DATA) \ $(plugin_in_files) \ $(ui_DATA) \ $(NULL) CLEANFILES = \ $(plugin_DATA) \ $(NULL) DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/gsd-keyboard-manager.c0000664000175000017500000026230500000000000026456 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright © 2001 Ximian, Inc. * Copyright (C) 2007 William Jon McCann * Written by Sergey V. Oudaltsov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define GNOME_DESKTOP_USE_UNSTABLE_API #include #include #ifdef HAVE_IBUS #include #endif #ifdef HAVE_FCITX #include #include #endif #include #include "gnome-settings-bus.h" #include "gnome-settings-profile.h" #include "gsd-keyboard-manager.h" #include "gsd-input-helper.h" #include "gsd-enums.h" #include "gsd-settings-migrate.h" #include "gsd-xkb-utils.h" #ifdef HAVE_FCITX #include "input-method-engines.c" #endif #define GSD_KEYBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_KEYBOARD_MANAGER, GsdKeyboardManagerPrivate)) #define GSD_KEYBOARD_DIR "com.canonical.unity.settings-daemon.peripherals.keyboard" #define GSETTINGS_KEYBOARD_SCHEMA "org.gnome.desktop.peripherals.keyboard" #define KEY_REPEAT "repeat" #define KEY_CLICK "click" #define KEY_INTERVAL "repeat-interval" #define KEY_DELAY "delay" #define KEY_CLICK_VOLUME "click-volume" #define KEY_REMEMBER_NUMLOCK_STATE "remember-numlock-state" #define KEY_NUMLOCK_STATE "numlock-state" #define KEY_BELL_VOLUME "bell-volume" #define KEY_BELL_PITCH "bell-pitch" #define KEY_BELL_DURATION "bell-duration" #define KEY_BELL_MODE "bell-mode" #define KEY_BELL_CUSTOM_FILE "bell-custom-file" #define GNOME_DESKTOP_INTERFACE_DIR "org.gnome.desktop.interface" #define ENV_GTK_IM_MODULE "GTK_IM_MODULE" #define KEY_GTK_IM_MODULE "gtk-im-module" #define GTK_IM_MODULE_SIMPLE "gtk-im-context-simple" #define GTK_IM_MODULE_IBUS "ibus" #define GTK_IM_MODULE_FCITX "fcitx" #define GNOME_DESKTOP_INPUT_SOURCES_DIR "org.gnome.desktop.input-sources" #define KEY_CURRENT_INPUT_SOURCE "current" #define KEY_INPUT_SOURCES "sources" #define KEY_KEYBOARD_OPTIONS "xkb-options" #define INPUT_SOURCE_TYPE_XKB "xkb" #define INPUT_SOURCE_TYPE_IBUS "ibus" #define INPUT_SOURCE_TYPE_FCITX "fcitx" #define FCITX_XKB_PREFIX "fcitx-keyboard-" #define DEFAULT_LANGUAGE "en_US" #define DEFAULT_LAYOUT "us" #define GSD_KEYBOARD_DBUS_NAME "org.gnome.SettingsDaemon.Keyboard" #define GSD_KEYBOARD_DBUS_PATH "/org/gnome/SettingsDaemon/Keyboard" struct GsdKeyboardManagerPrivate { guint start_idle_id; GSettings *settings; GSettings *gsettings; GSettings *input_sources_settings; GSettings *interface_settings; GnomeXkbInfo *xkb_info; GDBusProxy *localed; GCancellable *cancellable; #ifdef HAVE_IBUS IBusBus *ibus; GHashTable *ibus_engines; GCancellable *ibus_cancellable; gboolean is_ibus_active; #endif #ifdef HAVE_FCITX FcitxInputMethod *fcitx; GCancellable *fcitx_cancellable; gulong fcitx_signal_id; gboolean is_fcitx_active; #endif gint xkb_event_base; GsdNumLockState old_state; GdkDeviceManager *device_manager; guint device_added_id; guint device_removed_id; GDBusConnection *dbus_connection; GDBusNodeInfo *dbus_introspection; guint dbus_own_name_id; GSList *dbus_register_object_ids; GDBusMethodInvocation *invocation; guint pending_ops; gint active_input_source; }; static void gsd_keyboard_manager_class_init (GsdKeyboardManagerClass *klass); static void gsd_keyboard_manager_init (GsdKeyboardManager *keyboard_manager); static void gsd_keyboard_manager_finalize (GObject *object); static gboolean apply_input_sources_settings (GSettings *settings, gpointer keys, gint n_keys, GsdKeyboardManager *manager); static void set_gtk_im_module (GsdKeyboardManager *manager, GVariant *sources); static void maybe_return_from_set_input_source (GsdKeyboardManager *manager); static void increment_set_input_source_ops (GsdKeyboardManager *manager); G_DEFINE_TYPE (GsdKeyboardManager, gsd_keyboard_manager, G_TYPE_OBJECT) static const gchar introspection_xml[] = "" " " " " " " " " " " /* Ubuntu-specific */ " " " " " " " " " " ""; static gpointer manager_object = NULL; static void init_builder_with_sources (GVariantBuilder *builder, GSettings *settings) { const gchar *type; const gchar *id; GVariantIter iter; GVariant *sources; sources = g_settings_get_value (settings, KEY_INPUT_SOURCES); g_variant_builder_init (builder, G_VARIANT_TYPE ("a(ss)")); g_variant_iter_init (&iter, sources); while (g_variant_iter_next (&iter, "(&s&s)", &type, &id)) g_variant_builder_add (builder, "(ss)", type, id); g_variant_unref (sources); } static gboolean schema_is_installed (const gchar *name) { const gchar * const *schemas; const gchar * const *s; schemas = g_settings_list_schemas (); for (s = schemas; *s; ++s) if (g_str_equal (*s, name)) return TRUE; return FALSE; } #ifdef HAVE_IBUS static void clear_ibus (GsdKeyboardManager *manager) { GsdKeyboardManagerPrivate *priv = manager->priv; g_cancellable_cancel (priv->ibus_cancellable); g_clear_object (&priv->ibus_cancellable); g_clear_pointer (&priv->ibus_engines, g_hash_table_destroy); g_clear_object (&priv->ibus); } static void fetch_ibus_engines_result (GObject *object, GAsyncResult *result, GsdKeyboardManager *manager) { GsdKeyboardManagerPrivate *priv = manager->priv; GList *list, *l; GError *error = NULL; /* engines shouldn't be there yet */ g_return_if_fail (priv->ibus_engines == NULL); g_clear_object (&priv->ibus_cancellable); list = ibus_bus_list_engines_async_finish (priv->ibus, result, &error); if (!list && error) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Couldn't finish IBus request: %s", error->message); g_error_free (error); clear_ibus (manager); return; } /* Maps IBus engine ids to engine description objects */ priv->ibus_engines = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); for (l = list; l; l = l->next) { IBusEngineDesc *engine = l->data; const gchar *engine_id = ibus_engine_desc_get_name (engine); g_hash_table_replace (priv->ibus_engines, (gpointer)engine_id, engine); } g_list_free (list); apply_input_sources_settings (priv->input_sources_settings, NULL, 0, manager); } static void fetch_ibus_engines (GsdKeyboardManager *manager) { GsdKeyboardManagerPrivate *priv = manager->priv; /* engines shouldn't be there yet */ g_return_if_fail (priv->ibus_engines == NULL); g_return_if_fail (priv->ibus_cancellable == NULL); priv->ibus_cancellable = g_cancellable_new (); ibus_bus_list_engines_async (priv->ibus, -1, priv->ibus_cancellable, (GAsyncReadyCallback)fetch_ibus_engines_result, manager); } static void maybe_start_ibus (GsdKeyboardManager *manager) { if (!manager->priv->ibus) { ibus_init (); manager->priv->ibus = ibus_bus_new_async (); g_signal_connect_swapped (manager->priv->ibus, "connected", G_CALLBACK (fetch_ibus_engines), manager); g_signal_connect_swapped (manager->priv->ibus, "disconnected", G_CALLBACK (clear_ibus), manager); } /* IBus doesn't export API in the session bus. The only thing * we have there is a well known name which we can use as a * sure-fire way to activate it. */ g_bus_unwatch_name (g_bus_watch_name (G_BUS_TYPE_SESSION, IBUS_SERVICE_IBUS, G_BUS_NAME_WATCHER_FLAGS_AUTO_START, NULL, NULL, NULL, NULL)); } static void set_ibus_engine_finish (GObject *object, GAsyncResult *res, GsdKeyboardManager *manager) { gboolean result; IBusBus *ibus = IBUS_BUS (object); GsdKeyboardManagerPrivate *priv = manager->priv; GError *error = NULL; g_clear_object (&priv->ibus_cancellable); result = ibus_bus_set_global_engine_async_finish (ibus, res, &error); if (!result) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Couldn't set IBus engine: %s", error->message); g_error_free (error); return; } maybe_return_from_set_input_source (manager); } static void set_ibus_engine (GsdKeyboardManager *manager, const gchar *engine_id) { GsdKeyboardManagerPrivate *priv = manager->priv; g_return_if_fail (priv->ibus != NULL); g_return_if_fail (priv->ibus_engines != NULL); g_cancellable_cancel (priv->ibus_cancellable); g_clear_object (&priv->ibus_cancellable); priv->ibus_cancellable = g_cancellable_new (); increment_set_input_source_ops (manager); ibus_bus_set_global_engine_async (priv->ibus, engine_id, -1, priv->ibus_cancellable, (GAsyncReadyCallback)set_ibus_engine_finish, manager); } static void set_ibus_xkb_engine (GsdKeyboardManager *manager) { IBusEngineDesc *engine; GsdKeyboardManagerPrivate *priv = manager->priv; if (!priv->ibus_engines) return; /* All the "xkb:..." IBus engines simply "echo" back symbols, despite their naming implying differently, so we always set one in order for XIM applications to work given that we set XMODIFIERS=@im=ibus in the first place so that they can work without restarting when/if the user adds an IBus input source. */ engine = g_hash_table_lookup (priv->ibus_engines, "xkb:us::eng"); if (!engine) return; set_ibus_engine (manager, ibus_engine_desc_get_name (engine)); } static gboolean need_ibus (GVariant *sources) { GVariantIter iter; const gchar *type; g_variant_iter_init (&iter, sources); while (g_variant_iter_next (&iter, "(&s&s)", &type, NULL)) if (g_str_equal (type, INPUT_SOURCE_TYPE_IBUS)) return TRUE; return FALSE; } static void set_gtk_im_module (GsdKeyboardManager *manager, GVariant *sources) { GsdKeyboardManagerPrivate *priv = manager->priv; const gchar *new_module; gchar *current_module; if (!sources || need_ibus (sources)) new_module = GTK_IM_MODULE_IBUS; else new_module = GTK_IM_MODULE_SIMPLE; current_module = g_settings_get_string (priv->interface_settings, KEY_GTK_IM_MODULE); if (!g_str_equal (current_module, new_module)) g_settings_set_string (priv->interface_settings, KEY_GTK_IM_MODULE, new_module); g_free (current_module); } /* XXX: See upstream bug: * https://codereview.appspot.com/6586075/ */ static gchar * layout_from_ibus_layout (const gchar *ibus_layout) { const gchar *p; /* we get something like "layout(variant)[option1,option2]" */ p = ibus_layout; while (*p) { if (*p == '(' || *p == '[') break; p += 1; } return g_strndup (ibus_layout, p - ibus_layout); } static gchar * variant_from_ibus_layout (const gchar *ibus_layout) { const gchar *a, *b; /* we get something like "layout(variant)[option1,option2]" */ a = ibus_layout; while (*a) { if (*a == '(') break; a += 1; } if (!*a) return NULL; a += 1; b = a; while (*b) { if (*b == ')') break; b += 1; } if (!*b) return NULL; return g_strndup (a, b - a); } static gchar ** options_from_ibus_layout (const gchar *ibus_layout) { const gchar *a, *b; GPtrArray *opt_array; /* we get something like "layout(variant)[option1,option2]" */ a = ibus_layout; while (*a) { if (*a == '[') break; a += 1; } if (!*a) return NULL; opt_array = g_ptr_array_new (); do { a += 1; b = a; while (*b) { if (*b == ',' || *b == ']') break; b += 1; } if (!*b) goto out; g_ptr_array_add (opt_array, g_strndup (a, b - a)); a = b; } while (*a && *a == ','); out: g_ptr_array_add (opt_array, NULL); return (gchar **) g_ptr_array_free (opt_array, FALSE); } static const gchar * engine_from_locale (void) { const gchar *locale; const gchar *locale_engine[][2] = { { "as_IN", "m17n:as:phonetic" }, { "bn_IN", "m17n:bn:inscript" }, { "gu_IN", "m17n:gu:inscript" }, { "hi_IN", "m17n:hi:inscript" }, { "ja_JP", "mozc" }, { "kn_IN", "m17n:kn:kgp" }, { "ko_KR", "hangul" }, { "mai_IN", "m17n:mai:inscript" }, { "ml_IN", "m17n:ml:inscript" }, { "mr_IN", "m17n:mr:inscript" }, { "or_IN", "m17n:or:inscript" }, { "pa_IN", "m17n:pa:inscript" }, { "sd_IN", "m17n:sd:inscript" }, { "ta_IN", "m17n:ta:tamil99" }, { "te_IN", "m17n:te:inscript" }, { "zh_CN", "pinyin" }, { "zh_HK", "cangjie3" }, { "zh_TW", "chewing" }, }; gint i; locale = setlocale (LC_CTYPE, NULL); if (!locale) return NULL; for (i = 0; i < G_N_ELEMENTS (locale_engine); ++i) if (g_str_has_prefix (locale, locale_engine[i][0])) return locale_engine[i][1]; return NULL; } static void add_sources_from_locale (GsdKeyboardManager *manager, GSettings *settings) { const gchar *locale_engine; GVariantBuilder builder; locale_engine = engine_from_locale (); if (!locale_engine) return; init_builder_with_sources (&builder, settings); #ifdef HAVE_IBUS if (manager->priv->is_ibus_active) { g_variant_builder_add (&builder, "(ss)", INPUT_SOURCE_TYPE_IBUS, locale_engine); } #endif #ifdef HAVE_FCITX if (manager->priv->is_fcitx_active) { g_variant_builder_add (&builder, "(ss)", INPUT_SOURCE_TYPE_FCITX, locale_engine); } #endif g_settings_set_value (settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder)); } static void convert_ibus (GSettings *settings) { GVariantBuilder builder; GSettings *ibus_settings; gchar **engines, **e; if (!schema_is_installed ("org.freedesktop.ibus.general")) return; init_builder_with_sources (&builder, settings); ibus_settings = g_settings_new ("org.freedesktop.ibus.general"); engines = g_settings_get_strv (ibus_settings, "preload-engines"); for (e = engines; *e; ++e) { if (g_str_has_prefix (*e, "xkb:")) continue; g_variant_builder_add (&builder, "(ss)", INPUT_SOURCE_TYPE_IBUS, *e); } g_settings_set_value (settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder)); g_strfreev (engines); g_object_unref (ibus_settings); } #endif /* HAVE_IBUS */ static gboolean xkb_set_keyboard_autorepeat_rate (guint delay, guint interval) { return XkbSetAutoRepeatRate (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XkbUseCoreKbd, delay, interval); } static gboolean check_xkb_extension (GsdKeyboardManager *manager) { Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); int opcode, error_base, major, minor; gboolean have_xkb; have_xkb = XkbQueryExtension (dpy, &opcode, &manager->priv->xkb_event_base, &error_base, &major, &minor); return have_xkb; } static void xkb_init (GsdKeyboardManager *manager) { Display *dpy; dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); XkbSelectEventDetails (dpy, XkbUseCoreKbd, XkbStateNotify, XkbModifierLockMask, XkbModifierLockMask); } static unsigned numlock_NumLock_modifier_mask (void) { Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); return XkbKeysymToModifiers (dpy, XK_Num_Lock); } static void numlock_set_xkb_state (GsdNumLockState new_state) { unsigned int num_mask; Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); if (new_state != GSD_NUM_LOCK_STATE_ON && new_state != GSD_NUM_LOCK_STATE_OFF) return; num_mask = numlock_NumLock_modifier_mask (); XkbLockModifiers (dpy, XkbUseCoreKbd, num_mask, new_state == GSD_NUM_LOCK_STATE_ON ? num_mask : 0); } static const char * num_lock_state_to_string (GsdNumLockState numlock_state) { switch (numlock_state) { case GSD_NUM_LOCK_STATE_UNKNOWN: return "GSD_NUM_LOCK_STATE_UNKNOWN"; case GSD_NUM_LOCK_STATE_ON: return "GSD_NUM_LOCK_STATE_ON"; case GSD_NUM_LOCK_STATE_OFF: return "GSD_NUM_LOCK_STATE_OFF"; default: return "UNKNOWN"; } } static GdkFilterReturn xkb_events_filter (GdkXEvent *xev_, GdkEvent *gdkev_, gpointer user_data) { XEvent *xev = (XEvent *) xev_; XkbEvent *xkbev = (XkbEvent *) xev; GsdKeyboardManager *manager = (GsdKeyboardManager *) user_data; if (xev->type != manager->priv->xkb_event_base || xkbev->any.xkb_type != XkbStateNotify) return GDK_FILTER_CONTINUE; if (xkbev->state.changed & XkbModifierLockMask) { unsigned num_mask = numlock_NumLock_modifier_mask (); unsigned locked_mods = xkbev->state.locked_mods; GsdNumLockState numlock_state; numlock_state = (num_mask & locked_mods) ? GSD_NUM_LOCK_STATE_ON : GSD_NUM_LOCK_STATE_OFF; if (numlock_state != manager->priv->old_state) { g_debug ("New num-lock state '%s' != Old num-lock state '%s'", num_lock_state_to_string (numlock_state), num_lock_state_to_string (manager->priv->old_state)); g_settings_set_enum (manager->priv->settings, KEY_NUMLOCK_STATE, numlock_state); manager->priv->old_state = numlock_state; } } return GDK_FILTER_CONTINUE; } static void install_xkb_filter (GsdKeyboardManager *manager) { gdk_window_add_filter (NULL, xkb_events_filter, manager); } static void remove_xkb_filter (GsdKeyboardManager *manager) { gdk_window_remove_filter (NULL, xkb_events_filter, manager); } static void free_xkb_component_names (XkbComponentNamesRec *p) { g_return_if_fail (p != NULL); free (p->keymap); free (p->keycodes); free (p->types); free (p->compat); free (p->symbols); free (p->geometry); g_free (p); } static void upload_xkb_description (const gchar *rules_file_path, XkbRF_VarDefsRec *var_defs, XkbComponentNamesRec *comp_names) { Display *display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); XkbDescRec *xkb_desc; gchar *rules_file; /* The layout we want is always in the first XKB group index * so we should enforce it to make sure we never end up with * the wrong one. */ XkbLockGroup (display, XkbUseCoreKbd, 0); /* Upload it to the X server using the same method as setxkbmap */ xkb_desc = XkbGetKeyboardByName (display, XkbUseCoreKbd, comp_names, XkbGBN_AllComponentsMask, XkbGBN_AllComponentsMask & (~XkbGBN_GeometryMask), True); if (!xkb_desc) { g_warning ("Couldn't upload new XKB keyboard description"); return; } XkbFreeKeyboard (xkb_desc, 0, True); rules_file = g_path_get_basename (rules_file_path); if (!XkbRF_SetNamesProp (display, rules_file, var_defs)) g_warning ("Couldn't update the XKB root window property"); g_free (rules_file); } static gchar * build_xkb_group_string (const gchar *user, const gchar *locale, const gchar *latin) { gchar *string; gsize length = 0; guint commas = 2; if (latin) length += strlen (latin); else commas -= 1; if (locale) length += strlen (locale); else commas -= 1; length += strlen (user) + commas + 1; string = malloc (length); if (locale && latin) sprintf (string, "%s,%s,%s", user, locale, latin); else if (locale) sprintf (string, "%s,%s", user, locale); else if (latin) sprintf (string, "%s,%s", user, latin); else sprintf (string, "%s", user); return string; } static gboolean layout_equal (const gchar *layout_a, const gchar *variant_a, const gchar *layout_b, const gchar *variant_b) { return !g_strcmp0 (layout_a, layout_b) && !g_strcmp0 (variant_a, variant_b); } static void get_locale_layout (GsdKeyboardManager *manager, const gchar **layout, const gchar **variant) { const gchar *locale; const gchar *type; const gchar *id; gboolean got_info; *layout = NULL; *variant = NULL; locale = setlocale (LC_MESSAGES, NULL); /* If LANG is empty, default to en_US */ if (!locale) locale = DEFAULT_LANGUAGE; got_info = gnome_get_input_source_from_locale (locale, &type, &id); if (!got_info) if (!gnome_get_input_source_from_locale (DEFAULT_LANGUAGE, &type, &id)) return; if (!g_str_equal (type, INPUT_SOURCE_TYPE_XKB)) return; gnome_xkb_info_get_layout_info (manager->priv->xkb_info, id, NULL, NULL, layout, variant); } static void replace_layout_and_variant (GsdKeyboardManager *manager, XkbRF_VarDefsRec *xkb_var_defs, const gchar *layout, const gchar *variant) { /* Toolkits need to know about both a latin layout to handle * accelerators which are usually defined like Ctrl+C and a * layout with the symbols for the language used in UI strings * to handle mnemonics like Alt+Ф, so we try to find and add * them in XKB group slots after the layout which the user * actually intends to type with. */ const gchar *latin_layout = "us"; const gchar *latin_variant = ""; const gchar *locale_layout = NULL; const gchar *locale_variant = NULL; if (!layout) return; if (!variant) variant = ""; get_locale_layout (manager, &locale_layout, &locale_variant); /* We want to minimize the number of XKB groups if we have * duplicated layout+variant pairs. * * Also, if a layout doesn't have a variant we still have to * include it in the variants string because the number of * variants must agree with the number of layouts. For * instance: * * layouts: "us,ru,us" * variants: "dvorak,," */ if (layout_equal (latin_layout, latin_variant, locale_layout, locale_variant) || layout_equal (latin_layout, latin_variant, layout, variant)) { latin_layout = NULL; latin_variant = NULL; } if (layout_equal (locale_layout, locale_variant, layout, variant)) { locale_layout = NULL; locale_variant = NULL; } free (xkb_var_defs->layout); xkb_var_defs->layout = build_xkb_group_string (layout, locale_layout, latin_layout); free (xkb_var_defs->variant); xkb_var_defs->variant = build_xkb_group_string (variant, locale_variant, latin_variant); } static gchar * build_xkb_options_string (gchar **options) { gchar *string; if (*options) { gint i; gsize len; gchar *ptr; /* First part, getting length */ len = 1 + strlen (options[0]); for (i = 1; options[i] != NULL; i++) len += strlen (options[i]); len += (i - 1); /* commas */ /* Second part, building string */ string = malloc (len); ptr = g_stpcpy (string, *options); for (i = 1; options[i] != NULL; i++) { ptr = g_stpcpy (ptr, ","); ptr = g_stpcpy (ptr, options[i]); } } else { string = malloc (1); *string = '\0'; } return string; } static gchar ** append_options (gchar **a, gchar **b) { gchar **c, **p; if (!a && !b) return NULL; else if (!a) return g_strdupv (b); else if (!b) return g_strdupv (a); c = g_new0 (gchar *, g_strv_length (a) + g_strv_length (b) + 1); p = c; while (*a) { *p = g_strdup (*a); p += 1; a += 1; } while (*b) { *p = g_strdup (*b); p += 1; b += 1; } return c; } static void strip_xkb_option (gchar **options, const gchar *prefix) { guint last; gchar **p = options; if (!p) return; while (*p) { if (g_str_has_prefix (*p, prefix)) { last = g_strv_length (options) - 1; g_free (*p); *p = options[last]; options[last] = NULL; } else { p += 1; } } } static gboolean in_desktop (const gchar *name) { const gchar *desktop_name_list; gchar **names; gboolean in_list = FALSE; gint i; desktop_name_list = g_getenv ("XDG_CURRENT_DESKTOP"); if (!desktop_name_list) return FALSE; names = g_strsplit (desktop_name_list, ":", -1); for (i = 0; names[i] && !in_list; i++) if (strcmp (names[i], name) == 0) { in_list = TRUE; break; } g_strfreev (names); return in_list; } static gchar * prepare_xkb_options (GsdKeyboardManager *manager, guint n_sources, gchar **extra_options) { gchar **options; gchar **settings_options; gchar *options_str; settings_options = g_settings_get_strv (manager->priv->input_sources_settings, KEY_KEYBOARD_OPTIONS); options = append_options (settings_options, extra_options); g_strfreev (settings_options); /* We might set up different layouts in different groups - see * replace_layout_and_variant(). But we don't want the X * server group switching feature to actually switch * them. Regularly, if we have at least two input sources, * gnome-shell will tell us to switch input source at that * point so we fix that automatically. But when there's only * one source, gnome-shell short circuits as an optimization * and doesn't call us so we can't set the group switching XKB * option in the first place otherwise the X server's switch * will take effect and we get a broken configuration. */ if (n_sources < 2 || in_desktop ("Unity")) strip_xkb_option (options, "grp:"); options_str = build_xkb_options_string (options); g_strfreev (options); return options_str; } static void apply_xkb_settings (GsdKeyboardManager *manager, const gchar *layout, const gchar *variant, gchar *options) { XkbRF_RulesRec *xkb_rules; XkbRF_VarDefsRec *xkb_var_defs; gchar *rules_file_path; gsd_xkb_get_var_defs (&rules_file_path, &xkb_var_defs); free (xkb_var_defs->options); xkb_var_defs->options = options; replace_layout_and_variant (manager, xkb_var_defs, layout, variant); gdk_error_trap_push (); xkb_rules = XkbRF_Load (rules_file_path, NULL, True, True); if (xkb_rules) { XkbComponentNamesRec *xkb_comp_names; xkb_comp_names = g_new0 (XkbComponentNamesRec, 1); XkbRF_GetComponents (xkb_rules, xkb_var_defs, xkb_comp_names); upload_xkb_description (rules_file_path, xkb_var_defs, xkb_comp_names); free_xkb_component_names (xkb_comp_names); XkbRF_Free (xkb_rules, True); } else { g_warning ("Couldn't load XKB rules"); } if (gdk_error_trap_pop ()) g_warning ("Error loading XKB rules"); gsd_xkb_free_var_defs (xkb_var_defs); g_free (rules_file_path); XkbLockModifiers (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XkbUseCoreKbd, LockMask, 0); } static void user_notify_is_loaded_cb (GObject *object, GParamSpec *pspec, gpointer user_data) { ActUser *user = ACT_USER (object); GSettings *settings = user_data; if (act_user_is_loaded (user)) { GVariant *sources; GVariantIter iter; const gchar *type; const gchar *name; GVariantBuilder builder; g_signal_handlers_disconnect_by_data (user, user_data); sources = g_settings_get_value (settings, KEY_INPUT_SOURCES); g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{ss}")); g_variant_iter_init (&iter, sources); while (g_variant_iter_next (&iter, "(&s&s)", &type, &name)) { g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{ss}")); g_variant_builder_add (&builder, "{ss}", type, name); g_variant_builder_close (&builder); } g_variant_unref (sources); sources = g_variant_ref_sink (g_variant_builder_end (&builder)); act_user_set_input_sources (user, sources); g_variant_unref (sources); } } static void manager_notify_is_loaded_cb (GObject *object, GParamSpec *pspec, gpointer user_data) { ActUserManager *manager = ACT_USER_MANAGER (object); gboolean loaded; g_object_get (manager, "is-loaded", &loaded, NULL); if (loaded) { ActUser *user; g_signal_handlers_disconnect_by_data (manager, user_data); user = act_user_manager_get_user (manager, g_get_user_name ()); if (act_user_is_loaded (user)) user_notify_is_loaded_cb (G_OBJECT (user), NULL, user_data); else g_signal_connect (user, "notify::is-loaded", user_notify_is_loaded_cb, user_data); } } #ifdef HAVE_FCITX static gchar * get_xkb_name (const gchar *name) { gchar *xkb_name; gchar *separator; if (g_str_has_prefix (name, FCITX_XKB_PREFIX)) name += strlen (FCITX_XKB_PREFIX); xkb_name = g_strdup (name); separator = strchr (xkb_name, '-'); if (separator) *separator = '+'; return xkb_name; } static gchar * get_fcitx_name (const gchar *name) { gchar *fcitx_name = g_strdup (name); gchar *separator = strchr (fcitx_name, '+'); if (separator) *separator = '-'; return fcitx_name; } static gboolean input_source_is_fcitx_engine (const gchar *type, const gchar *name, const gchar *engine) { if (g_str_equal (type, INPUT_SOURCE_TYPE_XKB)) { if (g_str_has_prefix (engine, FCITX_XKB_PREFIX)) { gboolean equal; gchar *fcitx_name = get_fcitx_name (name); equal = g_str_equal (fcitx_name, engine + strlen (FCITX_XKB_PREFIX)); g_free (fcitx_name); return equal; } } else if (g_str_equal (type, INPUT_SOURCE_TYPE_FCITX)) { return g_str_equal (name, engine); } return FALSE; } static void fcitx_engine_changed (GsdKeyboardManager *manager, GParamSpec *pspec, FcitxInputMethod *fcitx) { GSettings *settings = manager->priv->input_sources_settings; gchar *engine = fcitx_input_method_get_current_im (manager->priv->fcitx); if (engine) { GVariant *sources = g_settings_get_value (settings, KEY_INPUT_SOURCES); guint current = g_settings_get_uint (settings, KEY_CURRENT_INPUT_SOURCE); gboolean update = TRUE; if (current >= 0 && current < g_variant_n_children (sources)) { const gchar *type; const gchar *name; g_variant_get_child (sources, current, "(&s&s)", &type, &name); update = !input_source_is_fcitx_engine (type, name, engine); } if (update) { gsize i; for (i = 0; i < g_variant_n_children (sources); i++) { const gchar *type; const gchar *name; if (i == current) continue; g_variant_get_child (sources, i, "(&s&s)", &type, &name); if (input_source_is_fcitx_engine (type, name, engine)) { g_settings_set_uint (settings, KEY_CURRENT_INPUT_SOURCE, i); break; } } } g_variant_unref (sources); g_free (engine); } } static gboolean should_update_input_sources (GVariant *sources, GPtrArray *engines) { GVariantIter iter; const gchar *type; const gchar *name; guint i = 0; g_variant_iter_init (&iter, sources); while (g_variant_iter_next (&iter, "(&s&s)", &type, &name)) { if (g_str_equal (type, INPUT_SOURCE_TYPE_XKB) || g_str_equal (type, INPUT_SOURCE_TYPE_FCITX)) { FcitxIMItem *engine; /* get the next enabled fcitx engine */ for (; i < engines->len; i++) { engine = g_ptr_array_index (engines, i); if (engine->enable) break; } /* there should be an enabled engine and it should match, otherwise we need to update */ if (i++ >= engines->len || !input_source_is_fcitx_engine (type, name, engine->unique_name)) return TRUE; } } /* if there are more enabled engines, we need to update */ for (; i < engines->len; i++) { FcitxIMItem *engine = g_ptr_array_index (engines, i); if (engine->enable) return TRUE; } return FALSE; } static void update_input_sources_from_fcitx_engines (GsdKeyboardManager *manager, FcitxInputMethod *fcitx) { GPtrArray *engines = fcitx_input_method_get_imlist (manager->priv->fcitx); if (engines) { GVariant *sources = g_settings_get_value (manager->priv->input_sources_settings, KEY_INPUT_SOURCES); if (should_update_input_sources (sources, engines)) { GVariantBuilder builder; gboolean update = FALSE; guint i; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ss)")); for (i = 0; i < engines->len; i++) { FcitxIMItem *engine = g_ptr_array_index (engines, i); if (engine->enable) { if (g_str_has_prefix (engine->unique_name, FCITX_XKB_PREFIX)) { gchar *name = get_xkb_name (engine->unique_name); g_variant_builder_add (&builder, "(ss)", INPUT_SOURCE_TYPE_XKB, name); g_free (name); } else { g_variant_builder_add (&builder, "(ss)", INPUT_SOURCE_TYPE_FCITX, engine->unique_name); } update = TRUE; } } if (update) g_settings_set_value (manager->priv->input_sources_settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder)); else g_variant_builder_clear (&builder); } g_variant_unref (sources); g_ptr_array_unref (engines); } } #endif static gboolean apply_input_source (GsdKeyboardManager *manager, guint current) { GsdKeyboardManagerPrivate *priv = manager->priv; GVariant *sources; guint n_sources; const gchar *type = NULL; const gchar *id = NULL; gchar *layout = NULL; gchar *variant = NULL; gchar **options = NULL; sources = g_settings_get_value (priv->input_sources_settings, KEY_INPUT_SOURCES); n_sources = g_variant_n_children (sources); if (n_sources < 1) goto exit; else if (current >= n_sources) current = n_sources - 1; priv->active_input_source = current; #ifdef HAVE_IBUS if (priv->is_ibus_active) { maybe_start_ibus (manager); } #endif g_variant_get_child (sources, current, "(&s&s)", &type, &id); if (g_str_equal (type, INPUT_SOURCE_TYPE_XKB)) { const gchar *l, *v; gnome_xkb_info_get_layout_info (priv->xkb_info, id, NULL, NULL, &l, &v); layout = g_strdup (l); variant = g_strdup (v); if (!layout || !layout[0]) { g_warning ("Couldn't find XKB input source '%s'", id); goto exit; } #ifdef HAVE_FCITX if (priv->is_fcitx_active && priv->fcitx) { gchar *name = g_strdup_printf (FCITX_XKB_PREFIX "%s", id); gchar *fcitx_name = get_fcitx_name (name); fcitx_input_method_set_current_im (priv->fcitx, fcitx_name); g_free (fcitx_name); g_free (name); } #endif #ifdef HAVE_IBUS if (priv->is_ibus_active) { set_gtk_im_module (manager, sources); set_ibus_xkb_engine (manager); } #endif } else if (g_str_equal (type, INPUT_SOURCE_TYPE_IBUS)) { #ifdef HAVE_IBUS if (priv->is_ibus_active) { IBusEngineDesc *engine_desc = NULL; if (priv->ibus_engines) engine_desc = g_hash_table_lookup (priv->ibus_engines, id); else goto exit; /* we'll be called again when ibus is up and running */ if (engine_desc) { const gchar *ibus_layout; ibus_layout = ibus_engine_desc_get_layout (engine_desc); if (ibus_layout) { layout = layout_from_ibus_layout (ibus_layout); variant = variant_from_ibus_layout (ibus_layout); options = options_from_ibus_layout (ibus_layout); } } else { g_warning ("Couldn't find IBus input source '%s'", id); goto exit; } /* NULL here is a shortcut for "I already know I need the IBus module". */ set_gtk_im_module (manager, NULL); set_ibus_engine (manager, id); } else { g_warning ("IBus input source type specified but IBus is not active"); } #else g_warning ("IBus input source type specified but IBus support was not compiled"); #endif } else if (g_str_equal (type, INPUT_SOURCE_TYPE_FCITX)) { #ifdef HAVE_FCITX if (priv->is_fcitx_active) { if (priv->fcitx) { gchar *name = g_strdup (id); fcitx_input_method_set_current_im (priv->fcitx, name); g_free (name); } else { g_warning ("Fcitx input method framework unavailable"); } } else { g_warning ("Fcitx input source type specified but Fcitx is not active"); } #else g_warning ("Fcitx input source type specified but Fcitx support was not compiled"); #endif } else { g_warning ("Unknown input source type '%s'", type); } #ifdef HAVE_FCITX if (priv->is_fcitx_active && priv->fcitx && !priv->fcitx_signal_id) { priv->fcitx_signal_id = g_signal_connect_swapped (manager->priv->fcitx, "notify::current-im", G_CALLBACK (fcitx_engine_changed), manager); g_signal_connect_swapped (manager->priv->fcitx, "imlist-changed", G_CALLBACK (update_input_sources_from_fcitx_engines), manager); } #endif exit: apply_xkb_settings (manager, layout, variant, prepare_xkb_options (manager, n_sources, options)); maybe_return_from_set_input_source (manager); g_variant_unref (sources); g_free (layout); g_free (variant); g_strfreev (options); return TRUE; } #ifdef HAVE_FCITX static const gchar * get_fcitx_engine_for_ibus_engine (const gchar *ibus_engine) { const struct Engine *engine; if (!ibus_engine) return NULL; engine = get_engine_for_ibus_engine (ibus_engine, strlen (ibus_engine)); return engine ? engine->fcitx_engine : NULL; } static void enable_fcitx_engines (GsdKeyboardManager *manager, gboolean migrate) { GsdKeyboardManagerPrivate *priv = manager->priv; GPtrArray *engines; GVariant *sources; GVariantIter iter; const gchar *type; const gchar *name; gboolean changed; guint i; guint j; engines = fcitx_input_method_get_imlist (priv->fcitx); if (!engines) { g_warning ("Cannot update Fcitx engine list"); return; } sources = g_settings_get_value (priv->input_sources_settings, KEY_INPUT_SOURCES); changed = FALSE; i = 0; g_variant_iter_init (&iter, sources); while (g_variant_iter_next (&iter, "(&s&s)", &type, &name)) { if (g_str_equal (type, INPUT_SOURCE_TYPE_XKB)) { gchar *fcitx_name = get_fcitx_name (name); for (j = i; j < engines->len; j++) { FcitxIMItem *engine = g_ptr_array_index (engines, j); if (g_str_has_prefix (engine->unique_name, FCITX_XKB_PREFIX) && g_str_equal (engine->unique_name + strlen (FCITX_XKB_PREFIX), fcitx_name)) { if (!engine->enable) { engine->enable = TRUE; changed = TRUE; } break; } } g_free (fcitx_name); /* j is either the index of the engine "fcitx-keyboard-" * or engines->len, meaning it wasn't found. */ } else if (migrate && g_str_equal (type, INPUT_SOURCE_TYPE_IBUS)) { const gchar *fcitx_name = get_fcitx_engine_for_ibus_engine (name); if (!fcitx_name) continue; for (j = i; j < engines->len; j++) { FcitxIMItem *engine = g_ptr_array_index (engines, j); if (g_str_equal (engine->unique_name, fcitx_name)) { if (!engine->enable) { engine->enable = TRUE; changed = TRUE; } break; } } /* j is either the index of the engine "" * or engines->len, meaning it wasn't found. */ } else if (g_str_equal (type, INPUT_SOURCE_TYPE_FCITX)) { for (j = i; j < engines->len; j++) { FcitxIMItem *engine = g_ptr_array_index (engines, j); if (g_str_equal (engine->unique_name, name)) { if (!engine->enable) { engine->enable = TRUE; changed = TRUE; } break; } } /* j is either the index of the engine "" * or engines->len, meaning it wasn't found. */ } else { continue; } if (j < engines->len) { if (j != i) { gpointer ptr = engines->pdata[i]; engines->pdata[i] = engines->pdata[j]; engines->pdata[j] = ptr; changed = TRUE; } i++; } else { g_warning ("Fcitx engine not found for %s", name); } } /* we should have i enabled fcitx engines: disable everything else. */ for (; i < engines->len; i++) { FcitxIMItem *engine = g_ptr_array_index (engines, i); if (engine->enable) { engine->enable = FALSE; changed = TRUE; } } if (changed) { fcitx_input_method_set_imlist (priv->fcitx, engines); } g_variant_unref (sources); g_ptr_array_unref (engines); } struct _FcitxShareStateConfig { FcitxGenericConfig config; gint share_state; }; typedef struct _FcitxShareStateConfig FcitxShareStateConfig; static CONFIG_BINDING_BEGIN (FcitxShareStateConfig) CONFIG_BINDING_REGISTER ("Program", "ShareStateAmongWindow", share_state) CONFIG_BINDING_END () static CONFIG_DESC_DEFINE (get_fcitx_config_desc, "config.desc") static void update_share_state_from_per_window (GsdKeyboardManager *manager) { FcitxConfigFileDesc *config_file_desc = get_fcitx_config_desc (); if (config_file_desc) { /* Set Fcitx' share state setting based on the GSettings per-window option. */ GSettings *settings = g_settings_new ("org.gnome.libgnomekbd.desktop"); gboolean per_window = g_settings_get_boolean (settings, "group-per-window"); FcitxShareStateConfig config = { { NULL } }; /* Load the user's Fcitx configuration. */ FILE *file = FcitxXDGGetFileUserWithPrefix (NULL, "config", "r", NULL); FcitxConfigFile *config_file = FcitxConfigParseConfigFileFp (file, config_file_desc); FcitxShareStateConfigConfigBind (&config, config_file, config_file_desc); if (file) fclose (file); config.share_state = per_window ? 0 : 1; /* Save the user's Fcitx configuration. */ file = FcitxXDGGetFileUserWithPrefix (NULL, "config", "w", NULL); FcitxConfigSaveConfigFileFp (file, &config.config, config_file_desc); if (file) fclose (file); fcitx_input_method_reload_config (manager->priv->fcitx); g_object_unref (settings); } } static void migrate_fcitx_engines (GsdKeyboardManager *manager) { GPtrArray *engines = fcitx_input_method_get_imlist (manager->priv->fcitx); if (engines) { gboolean migrate = FALSE; gboolean second = FALSE; guint i; /* Migrate if there are at least two enabled fcitx engines or * there is one fcitx engine which is not a keyboard layout. * These are our criteria for determining which direction to * sync fcitx engines with input sources. */ for (i = 0; i < engines->len; i++) { FcitxIMItem *engine = g_ptr_array_index (engines, i); if (engine->enable) { if (second || !g_str_has_prefix (engine->unique_name, FCITX_XKB_PREFIX)) { migrate = TRUE; break; } second = TRUE; } } if (migrate) { /* Migrate Fcitx to GSettings. */ update_input_sources_from_fcitx_engines (manager, manager->priv->fcitx); } else { /* Migrate GSettings to Fcitx. */ enable_fcitx_engines (manager, TRUE); update_share_state_from_per_window (manager); } g_ptr_array_unref (engines); } } #endif static gboolean apply_input_sources_settings (GSettings *settings, gpointer keys, gint n_keys, GsdKeyboardManager *manager) { GsdKeyboardManagerPrivate *priv = manager->priv; GVariant *sources; guint n_sources; guint current; ActUserManager *user_manager; gboolean user_manager_loaded; #ifdef HAVE_FCITX if (priv->is_fcitx_active) { gboolean sources_changed = FALSE; if (keys) { GQuark *quarks = keys; gint i; for (i = 0; i < n_keys; i++) { if (quarks[i] == g_quark_try_string (KEY_INPUT_SOURCES)) { sources_changed = TRUE; break; } } } else { sources_changed = TRUE; } if (sources_changed) { enable_fcitx_engines (manager, FALSE); } } #endif sources = g_settings_get_value (priv->input_sources_settings, KEY_INPUT_SOURCES); n_sources = g_variant_n_children (sources); if (n_sources < 1) { apply_xkb_settings (manager, NULL, NULL, prepare_xkb_options (manager, 0, NULL)); maybe_return_from_set_input_source (manager); goto exit; } current = g_settings_get_uint (priv->input_sources_settings, KEY_CURRENT_INPUT_SOURCE); if (current >= n_sources) { g_settings_set_uint (priv->input_sources_settings, KEY_CURRENT_INPUT_SOURCE, n_sources - 1); goto exit; } user_manager = act_user_manager_get_default (); g_object_get (user_manager, "is-loaded", &user_manager_loaded, NULL); if (user_manager_loaded) manager_notify_is_loaded_cb (G_OBJECT (user_manager), NULL, priv->input_sources_settings); else g_signal_connect (user_manager, "notify::is-loaded", G_CALLBACK (manager_notify_is_loaded_cb), priv->input_sources_settings); apply_input_source (manager, current); exit: g_variant_unref (sources); /* Prevent individual "changed" signal invocations since we don't need them. */ return TRUE; } static void apply_bell (GsdKeyboardManager *manager) { GSettings *settings; XKeyboardControl kbdcontrol; gboolean click; int bell_volume; int bell_pitch; int bell_duration; GsdBellMode bell_mode; int click_volume; g_debug ("Applying the bell settings"); settings = manager->priv->settings; click = g_settings_get_boolean (settings, KEY_CLICK); click_volume = g_settings_get_int (settings, KEY_CLICK_VOLUME); bell_pitch = g_settings_get_int (settings, KEY_BELL_PITCH); bell_duration = g_settings_get_int (settings, KEY_BELL_DURATION); bell_mode = g_settings_get_enum (settings, KEY_BELL_MODE); bell_volume = (bell_mode == GSD_BELL_MODE_ON) ? 50 : 0; /* as percentage from 0..100 inclusive */ if (click_volume < 0) { click_volume = 0; } else if (click_volume > 100) { click_volume = 100; } kbdcontrol.key_click_percent = click ? click_volume : 0; kbdcontrol.bell_percent = bell_volume; kbdcontrol.bell_pitch = bell_pitch; kbdcontrol.bell_duration = bell_duration; gdk_error_trap_push (); XChangeKeyboardControl (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration, &kbdcontrol); XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), FALSE); gdk_error_trap_pop_ignored (); } static void apply_numlock (GsdKeyboardManager *manager) { GSettings *settings; gboolean rnumlock; g_debug ("Applying the num-lock settings"); settings = manager->priv->settings; rnumlock = g_settings_get_boolean (settings, KEY_REMEMBER_NUMLOCK_STATE); manager->priv->old_state = g_settings_get_enum (manager->priv->settings, KEY_NUMLOCK_STATE); gdk_error_trap_push (); if (rnumlock) { g_debug ("Remember num-lock is set, so applying setting '%s'", num_lock_state_to_string (manager->priv->old_state)); numlock_set_xkb_state (manager->priv->old_state); } XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), FALSE); gdk_error_trap_pop_ignored (); } static void apply_repeat (GsdKeyboardManager *manager) { GSettings *settings; gboolean repeat; guint interval; guint delay; g_debug ("Applying the repeat settings"); settings = manager->priv->gsettings; repeat = g_settings_get_boolean (settings, KEY_REPEAT); interval = g_settings_get_uint (settings, KEY_INTERVAL); delay = g_settings_get_uint (settings, KEY_DELAY); gdk_error_trap_push (); if (repeat) { gboolean rate_set = FALSE; XAutoRepeatOn (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); /* Use XKB in preference */ rate_set = xkb_set_keyboard_autorepeat_rate (delay, interval); if (!rate_set) g_warning ("Neither XKeyboard not Xfree86's keyboard extensions are available,\n" "no way to support keyboard autorepeat rate settings"); } else { XAutoRepeatOff (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); } XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), FALSE); gdk_error_trap_pop_ignored (); } static void apply_all_settings (GsdKeyboardManager *manager) { apply_repeat (manager); apply_bell (manager); apply_numlock (manager); } static void settings_changed (GSettings *settings, const char *key, GsdKeyboardManager *manager) { if (g_strcmp0 (key, KEY_CLICK) == 0|| g_strcmp0 (key, KEY_CLICK_VOLUME) == 0 || g_strcmp0 (key, KEY_BELL_PITCH) == 0 || g_strcmp0 (key, KEY_BELL_DURATION) == 0 || g_strcmp0 (key, KEY_BELL_MODE) == 0) { g_debug ("Bell setting '%s' changed, applying bell settings", key); apply_bell (manager); } else if (g_strcmp0 (key, KEY_REMEMBER_NUMLOCK_STATE) == 0) { g_debug ("Remember Num-Lock state '%s' changed, applying num-lock settings", key); apply_numlock (manager); } else if (g_strcmp0 (key, KEY_NUMLOCK_STATE) == 0) { g_debug ("Num-Lock state '%s' changed, will apply at next startup", key); } else { g_warning ("Unhandled settings change, key '%s'", key); } } static void gsettings_changed (GSettings *settings, const char *key, GsdKeyboardManager *manager) { if (g_strcmp0 (key, KEY_REPEAT) == 0 || g_strcmp0 (key, KEY_INTERVAL) == 0 || g_strcmp0 (key, KEY_DELAY) == 0) { g_debug ("Key repeat setting '%s' changed, applying key repeat settings", key); apply_repeat (manager); } else if (g_strcmp0 (key, KEY_BELL_CUSTOM_FILE) == 0){ g_debug ("Ignoring '%s' setting change", KEY_BELL_CUSTOM_FILE); } else { g_warning ("Unhandled settings change, key '%s'", key); } } static void device_added_cb (GdkDeviceManager *device_manager, GdkDevice *device, GsdKeyboardManager *manager) { GdkInputSource source; source = gdk_device_get_source (device); if (source == GDK_SOURCE_KEYBOARD) { g_debug ("New keyboard plugged in, applying all settings"); apply_numlock (manager); apply_input_sources_settings (manager->priv->input_sources_settings, NULL, 0, manager); run_custom_command (device, COMMAND_DEVICE_ADDED); } } static void device_removed_cb (GdkDeviceManager *device_manager, GdkDevice *device, GsdKeyboardManager *manager) { GdkInputSource source; source = gdk_device_get_source (device); if (source == GDK_SOURCE_KEYBOARD) { run_custom_command (device, COMMAND_DEVICE_REMOVED); } } static void set_devicepresence_handler (GsdKeyboardManager *manager) { GdkDeviceManager *device_manager; device_manager = gdk_display_get_device_manager (gdk_display_get_default ()); manager->priv->device_added_id = g_signal_connect (G_OBJECT (device_manager), "device-added", G_CALLBACK (device_added_cb), manager); manager->priv->device_removed_id = g_signal_connect (G_OBJECT (device_manager), "device-removed", G_CALLBACK (device_removed_cb), manager); manager->priv->device_manager = device_manager; } static void get_sources_from_xkb_config (GsdKeyboardManager *manager) { GsdKeyboardManagerPrivate *priv = manager->priv; GVariantBuilder builder; GVariant *v; gint i, n; gchar **layouts = NULL; gchar **variants = NULL; gboolean have_default_layout = FALSE; v = g_dbus_proxy_get_cached_property (priv->localed, "X11Layout"); if (v) { const gchar *s = g_variant_get_string (v, NULL); if (*s) layouts = g_strsplit (s, ",", -1); g_variant_unref (v); } if (!layouts) return; v = g_dbus_proxy_get_cached_property (priv->localed, "X11Variant"); if (v) { const gchar *s = g_variant_get_string (v, NULL); if (*s) variants = g_strsplit (s, ",", -1); g_variant_unref (v); } if (variants && variants[0]) n = MIN (g_strv_length (layouts), g_strv_length (variants)); else n = g_strv_length (layouts); init_builder_with_sources (&builder, priv->input_sources_settings); for (i = 0; i < n && layouts[i][0]; ++i) { gchar *id; if (variants && variants[i] && variants[i][0]) id = g_strdup_printf ("%s+%s", layouts[i], variants[i]); else id = g_strdup (layouts[i]); if (g_str_equal (id, DEFAULT_LAYOUT)) have_default_layout = TRUE; g_variant_builder_add (&builder, "(ss)", INPUT_SOURCE_TYPE_XKB, id); g_free (id); } if (!have_default_layout) g_variant_builder_add (&builder, "(ss)", INPUT_SOURCE_TYPE_XKB, DEFAULT_LAYOUT); g_settings_set_value (priv->input_sources_settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder)); g_strfreev (layouts); g_strfreev (variants); } static void get_options_from_xkb_config (GsdKeyboardManager *manager) { GsdKeyboardManagerPrivate *priv = manager->priv; GVariant *v; gchar **options = NULL; v = g_dbus_proxy_get_cached_property (priv->localed, "X11Options"); if (v) { const gchar *s = g_variant_get_string (v, NULL); if (*s) options = g_strsplit (s, ",", -1); g_variant_unref (v); } if (!options) return; g_settings_set_strv (priv->input_sources_settings, KEY_KEYBOARD_OPTIONS, (const gchar * const*) options); g_strfreev (options); } static void convert_libgnomekbd_options (GSettings *settings) { GPtrArray *opt_array; GSettings *libgnomekbd_settings; gchar **options, **o; if (!schema_is_installed ("org.gnome.libgnomekbd.keyboard")) return; opt_array = g_ptr_array_new_with_free_func (g_free); libgnomekbd_settings = g_settings_new ("org.gnome.libgnomekbd.keyboard"); options = g_settings_get_strv (libgnomekbd_settings, "options"); for (o = options; *o; ++o) { gchar **strv; strv = g_strsplit (*o, "\t", 2); if (strv[0] && strv[1]) g_ptr_array_add (opt_array, g_strdup (strv[1])); g_strfreev (strv); } g_ptr_array_add (opt_array, NULL); g_settings_set_strv (settings, KEY_KEYBOARD_OPTIONS, (const gchar * const*) opt_array->pdata); g_strfreev (options); g_object_unref (libgnomekbd_settings); g_ptr_array_free (opt_array, TRUE); } static void convert_libgnomekbd_layouts (GSettings *settings) { GVariantBuilder builder; GSettings *libgnomekbd_settings; gchar **layouts, **l; if (!schema_is_installed ("org.gnome.libgnomekbd.keyboard")) return; init_builder_with_sources (&builder, settings); libgnomekbd_settings = g_settings_new ("org.gnome.libgnomekbd.keyboard"); layouts = g_settings_get_strv (libgnomekbd_settings, "layouts"); for (l = layouts; *l; ++l) { gchar *id; gchar **strv; strv = g_strsplit (*l, "\t", 2); if (strv[0] && !strv[1]) id = g_strdup (strv[0]); else if (strv[0] && strv[1]) id = g_strdup_printf ("%s+%s", strv[0], strv[1]); else id = NULL; if (id) g_variant_builder_add (&builder, "(ss)", INPUT_SOURCE_TYPE_XKB, id); g_free (id); g_strfreev (strv); } g_settings_set_value (settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder)); g_strfreev (layouts); g_object_unref (libgnomekbd_settings); } static gboolean should_migrate (const gchar *id) { gboolean migrate = FALSE; gchar *stamp_dir_path = NULL; gchar *stamp_file_path = NULL; GError *error = NULL; stamp_dir_path = g_build_filename (g_get_user_data_dir (), PACKAGE_NAME, NULL); if (g_mkdir_with_parents (stamp_dir_path, 0755)) { g_warning ("Failed to create directory %s: %s", stamp_dir_path, g_strerror (errno)); goto out; } stamp_file_path = g_build_filename (stamp_dir_path, id, NULL); if (g_file_test (stamp_file_path, G_FILE_TEST_EXISTS)) goto out; migrate = TRUE; if (!g_file_set_contents (stamp_file_path, "", 0, &error)) { g_warning ("%s", error->message); g_error_free (error); } out: g_free (stamp_file_path); g_free (stamp_dir_path); return migrate; } static void maybe_convert_old_settings (GSettings *settings) { if (should_migrate ("input-sources-converted")) { GVariant *sources; gchar **options; sources = g_settings_get_value (settings, KEY_INPUT_SOURCES); if (g_variant_n_children (sources) < 1) { convert_libgnomekbd_layouts (settings); #ifdef HAVE_IBUS convert_ibus (settings); #endif } g_variant_unref (sources); options = g_settings_get_strv (settings, KEY_KEYBOARD_OPTIONS); if (g_strv_length (options) < 1) convert_libgnomekbd_options (settings); g_strfreev (options); } } static void maybe_create_initial_settings (GsdKeyboardManager *manager) { GSettings *settings; GVariant *sources; gchar **options; settings = manager->priv->input_sources_settings; if (g_getenv ("RUNNING_UNDER_GDM")) { GVariantBuilder builder; /* clean the settings and get them from the "system" */ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ss)")); g_settings_set_value (settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder)); get_sources_from_xkb_config (manager); g_settings_set_strv (settings, KEY_KEYBOARD_OPTIONS, NULL); get_options_from_xkb_config (manager); return; } maybe_convert_old_settings (settings); /* if we still don't have anything do some educated guesses */ sources = g_settings_get_value (settings, KEY_INPUT_SOURCES); if (g_variant_n_children (sources) < 1) { get_sources_from_xkb_config (manager); #if defined(HAVE_IBUS) || defined(HAVE_FCITX) add_sources_from_locale (manager, settings); #endif } g_variant_unref (sources); options = g_settings_get_strv (settings, KEY_KEYBOARD_OPTIONS); if (g_strv_length (options) < 1) get_options_from_xkb_config (manager); g_strfreev (options); } static void set_input_source_return (GDBusMethodInvocation *invocation) { g_dbus_method_invocation_return_value (invocation, NULL); } static void maybe_return_from_set_input_source (GsdKeyboardManager *manager) { GsdKeyboardManagerPrivate *priv = manager->priv; if (!priv->invocation) return; if (priv->pending_ops > 0) { priv->pending_ops -= 1; return; } g_clear_pointer (&priv->invocation, set_input_source_return); } static void increment_set_input_source_ops (GsdKeyboardManager *manager) { GsdKeyboardManagerPrivate *priv = manager->priv; if (!priv->invocation) return; priv->pending_ops += 1; } static void set_input_source (GsdKeyboardManager *manager, gboolean persist) { GsdKeyboardManagerPrivate *priv = manager->priv; guint idx; g_variant_get (g_dbus_method_invocation_get_parameters (priv->invocation), "(u)", &idx); if (persist) { if (idx == priv->active_input_source) { if (idx == g_settings_get_uint (priv->input_sources_settings, KEY_CURRENT_INPUT_SOURCE)) { maybe_return_from_set_input_source (manager); return; } } g_settings_set_uint (priv->input_sources_settings, KEY_CURRENT_INPUT_SOURCE, idx); } else { if (idx == priv->active_input_source) { maybe_return_from_set_input_source (manager); return; } apply_input_source (manager, idx); } } static void handle_dbus_method_call (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, GsdKeyboardManager *manager) { GsdKeyboardManagerPrivate *priv = manager->priv; gboolean is_set_input_source; gboolean is_activate_input_source; is_set_input_source = g_str_equal (method_name, "SetInputSource"); is_activate_input_source = g_str_equal (method_name, "ActivateInputSource"); if (is_set_input_source || is_activate_input_source) { if (priv->invocation) { #ifdef HAVE_IBUS if (priv->is_ibus_active) { /* This can only happen if there's an * ibus_bus_set_global_engine_async() call * going on. */ g_cancellable_cancel (priv->ibus_cancellable); } #endif g_clear_pointer (&priv->invocation, set_input_source_return); priv->pending_ops = 0; } priv->invocation = invocation; set_input_source (manager, is_set_input_source); } } static void on_bus_name_lost (GDBusConnection *connection, const gchar *name, gpointer data) { g_warning ("DBus name %s lost", name); } static void got_session_bus (GObject *source, GAsyncResult *res, GsdKeyboardManager *manager) { GsdKeyboardManagerPrivate *priv; GDBusConnection *connection; GDBusInterfaceInfo **interfaces; GError *error = NULL; GDBusInterfaceVTable vtable = { (GDBusInterfaceMethodCallFunc) handle_dbus_method_call, NULL, NULL, }; connection = g_bus_get_finish (res, &error); if (!connection) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Couldn't get session bus: %s", error->message); g_error_free (error); return; } priv = manager->priv; priv->dbus_connection = connection; interfaces = priv->dbus_introspection->interfaces; if (interfaces) { for (; *interfaces; interfaces++) { guint id = g_dbus_connection_register_object (priv->dbus_connection, GSD_KEYBOARD_DBUS_PATH, *interfaces, &vtable, manager, NULL, &error); if (!id) { GSList *ids; for (ids = priv->dbus_register_object_ids; ids; ids = g_slist_next (ids)) g_dbus_connection_unregister_object (priv->dbus_connection, GPOINTER_TO_UINT (ids->data)); g_slist_free (priv->dbus_register_object_ids); priv->dbus_register_object_ids = NULL; g_warning ("Error registering object: %s", error->message); g_error_free (error); return; } priv->dbus_register_object_ids = g_slist_prepend (priv->dbus_register_object_ids, GUINT_TO_POINTER (id)); } } priv->dbus_own_name_id = g_bus_own_name_on_connection (priv->dbus_connection, GSD_KEYBOARD_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, on_bus_name_lost, NULL, NULL); } static void register_manager_dbus (GsdKeyboardManager *manager) { GError *error = NULL; manager->priv->dbus_introspection = g_dbus_node_info_new_for_xml (introspection_xml, &error); if (error) { g_warning ("Error creating introspection data: %s", error->message); g_error_free (error); return; } g_bus_get (G_BUS_TYPE_SESSION, manager->priv->cancellable, (GAsyncReadyCallback) got_session_bus, manager); } static void localed_proxy_ready (GObject *source, GAsyncResult *res, gpointer data) { GsdKeyboardManager *manager = data; GDBusProxy *proxy; GError *error = NULL; proxy = g_dbus_proxy_new_finish (res, &error); if (!proxy) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_error_free (error); return; } g_warning ("Failed to contact localed: %s", error->message); g_error_free (error); goto out; } manager->priv->localed = proxy; maybe_create_initial_settings (manager); out: apply_input_sources_settings (manager->priv->input_sources_settings, NULL, 0, manager); register_manager_dbus (manager); } #ifdef HAVE_FCITX static void fcitx_appeared (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data) { GsdKeyboardManager *manager = user_data; apply_input_sources_settings (manager->priv->input_sources_settings, NULL, 0, manager); } static void fcitx_vanished (GDBusConnection *connection, const gchar *name, gpointer user_data) { GsdKeyboardManager *manager = user_data; g_signal_handlers_disconnect_by_data (manager->priv->fcitx, manager); manager->priv->fcitx_signal_id = 0; } #endif static gboolean start_keyboard_idle_cb (GsdKeyboardManager *manager) { const gchar *module; GError *error = NULL; gnome_settings_profile_start (NULL); g_debug ("Starting keyboard manager"); module = g_getenv (ENV_GTK_IM_MODULE); #ifdef HAVE_IBUS manager->priv->is_ibus_active = g_strcmp0 (module, GTK_IM_MODULE_IBUS) == 0; #endif #ifdef HAVE_FCITX manager->priv->is_fcitx_active = g_strcmp0 (module, GTK_IM_MODULE_FCITX) == 0; #endif manager->priv->settings = g_settings_new (GSD_KEYBOARD_DIR); manager->priv->gsettings = g_settings_new (GSETTINGS_KEYBOARD_SCHEMA); xkb_init (manager); set_devicepresence_handler (manager); manager->priv->input_sources_settings = g_settings_new (GNOME_DESKTOP_INPUT_SOURCES_DIR); manager->priv->interface_settings = g_settings_new (GNOME_DESKTOP_INTERFACE_DIR); manager->priv->xkb_info = gnome_xkb_info_new (); #ifdef HAVE_FCITX if (manager->priv->is_fcitx_active) { manager->priv->fcitx_cancellable = g_cancellable_new (); manager->priv->fcitx = fcitx_input_method_new (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, 0, manager->priv->fcitx_cancellable, &error); g_clear_object (&manager->priv->fcitx_cancellable); if (manager->priv->fcitx) { manager->priv->fcitx_signal_id = 0; g_bus_watch_name (G_BUS_TYPE_SESSION, "org.fcitx.Fcitx", G_BUS_NAME_WATCHER_FLAGS_NONE, fcitx_appeared, fcitx_vanished, manager, NULL); if (should_migrate ("fcitx-engines-migrated")) migrate_fcitx_engines (manager); else enable_fcitx_engines (manager, FALSE); } else { g_warning ("Fcitx input method framework unavailable: %s", error->message); g_error_free (error); } } #endif manager->priv->cancellable = g_cancellable_new (); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.locale1", "/org/freedesktop/locale1", "org.freedesktop.locale1", manager->priv->cancellable, localed_proxy_ready, manager); /* apply current settings before we install the callback */ g_debug ("Started the keyboard plugin, applying all settings"); apply_all_settings (manager); g_signal_connect (G_OBJECT (manager->priv->settings), "changed", G_CALLBACK (settings_changed), manager); g_signal_connect (G_OBJECT (manager->priv->gsettings), "changed", G_CALLBACK (gsettings_changed), manager); g_signal_connect (G_OBJECT (manager->priv->input_sources_settings), "change-event", G_CALLBACK (apply_input_sources_settings), manager); install_xkb_filter (manager); gnome_settings_profile_end (NULL); manager->priv->start_idle_id = 0; return FALSE; } gboolean gsd_keyboard_manager_start (GsdKeyboardManager *manager, GError **error) { gnome_settings_profile_start (NULL); if (check_xkb_extension (manager) == FALSE) { g_debug ("XKB is not supported, not applying any settings"); return TRUE; } manager->priv->start_idle_id = g_idle_add ((GSourceFunc) start_keyboard_idle_cb, manager); gnome_settings_profile_end (NULL); return TRUE; } void gsd_keyboard_manager_stop (GsdKeyboardManager *manager) { GsdKeyboardManagerPrivate *p = manager->priv; GSList *ids; g_debug ("Stopping keyboard manager"); if (p->dbus_own_name_id) { g_bus_unown_name (p->dbus_own_name_id); p->dbus_own_name_id = 0; } for (ids = p->dbus_register_object_ids; ids; ids = g_slist_next (ids)) g_dbus_connection_unregister_object (p->dbus_connection, GPOINTER_TO_UINT (ids->data)); g_slist_free (p->dbus_register_object_ids); p->dbus_register_object_ids = NULL; g_cancellable_cancel (p->cancellable); g_clear_object (&p->cancellable); g_clear_object (&p->settings); g_clear_object (&p->input_sources_settings); g_clear_object (&p->interface_settings); g_clear_object (&p->xkb_info); g_clear_object (&p->localed); #ifdef HAVE_FCITX if (p->is_fcitx_active) { if (p->fcitx_cancellable) { g_cancellable_cancel (p->fcitx_cancellable); } g_clear_object (&p->fcitx_cancellable); g_clear_object (&p->fcitx); } #endif #ifdef HAVE_IBUS if (p->is_ibus_active) { clear_ibus (manager); } #endif if (p->device_manager != NULL) { g_signal_handler_disconnect (p->device_manager, p->device_added_id); g_signal_handler_disconnect (p->device_manager, p->device_removed_id); p->device_manager = NULL; } remove_xkb_filter (manager); g_clear_pointer (&p->invocation, set_input_source_return); g_clear_pointer (&p->dbus_introspection, g_dbus_node_info_unref); g_clear_object (&p->dbus_connection); } static void gsd_keyboard_manager_class_init (GsdKeyboardManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_keyboard_manager_finalize; g_type_class_add_private (klass, sizeof (GsdKeyboardManagerPrivate)); } static void gsd_keyboard_manager_init (GsdKeyboardManager *manager) { manager->priv = GSD_KEYBOARD_MANAGER_GET_PRIVATE (manager); manager->priv->active_input_source = -1; } static void gsd_keyboard_manager_finalize (GObject *object) { GsdKeyboardManager *keyboard_manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_KEYBOARD_MANAGER (object)); keyboard_manager = GSD_KEYBOARD_MANAGER (object); g_return_if_fail (keyboard_manager->priv != NULL); if (keyboard_manager->priv->start_idle_id != 0) g_source_remove (keyboard_manager->priv->start_idle_id); G_OBJECT_CLASS (gsd_keyboard_manager_parent_class)->finalize (object); } static void migrate_keyboard_settings (void) { GsdSettingsMigrateEntry entries[] = { { "repeat", "repeat", NULL }, { "repeat-interval", "repeat-interval", NULL }, { "delay", "delay", NULL } }; gsd_settings_migrate_check ("com.canonical.unity.settings-daemon.peripherals.keyboard.deprecated", "/com/canonical/unity/settings-daemon/peripherals/keyboard/", "org.gnome.desktop.peripherals.keyboard", "/org/gnome/desktop/peripherals/keyboard/", entries, G_N_ELEMENTS (entries)); } GsdKeyboardManager * gsd_keyboard_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { migrate_keyboard_settings (); manager_object = g_object_new (GSD_TYPE_KEYBOARD_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_KEYBOARD_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/gsd-keyboard-manager.h0000664000175000017500000000452200000000000026456 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_KEYBOARD_MANAGER_H #define __GSD_KEYBOARD_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_KEYBOARD_MANAGER (gsd_keyboard_manager_get_type ()) #define GSD_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_KEYBOARD_MANAGER, GsdKeyboardManager)) #define GSD_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_KEYBOARD_MANAGER, GsdKeyboardManagerClass)) #define GSD_IS_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_KEYBOARD_MANAGER)) #define GSD_IS_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_KEYBOARD_MANAGER)) #define GSD_KEYBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_KEYBOARD_MANAGER, GsdKeyboardManagerClass)) typedef struct GsdKeyboardManagerPrivate GsdKeyboardManagerPrivate; typedef struct { GObject parent; GsdKeyboardManagerPrivate *priv; } GsdKeyboardManager; typedef struct { GObjectClass parent_class; } GsdKeyboardManagerClass; GType gsd_keyboard_manager_get_type (void); GsdKeyboardManager * gsd_keyboard_manager_new (void); gboolean gsd_keyboard_manager_start (GsdKeyboardManager *manager, GError **error); void gsd_keyboard_manager_stop (GsdKeyboardManager *manager); G_END_DECLS #endif /* __GSD_KEYBOARD_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/gsd-keyboard-plugin.c0000664000175000017500000000202600000000000026332 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-keyboard-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdKeyboard, gsd_keyboard) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/gsd-xkb-utils.c0000664000175000017500000000460100000000000025161 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2012 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . * */ #include "config.h" #include #include #include #include #include #include #include "gsd-xkb-utils.h" #ifndef XKB_RULES_FILE #define XKB_RULES_FILE "evdev" #endif #ifndef XKB_LAYOUT #define XKB_LAYOUT "us" #endif #ifndef XKB_MODEL #define XKB_MODEL "pc105+inet" #endif void gsd_xkb_get_var_defs (char **rules, XkbRF_VarDefsRec **var_defs) { Display *display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); char *tmp; g_return_if_fail (rules != NULL); g_return_if_fail (var_defs != NULL); *rules = NULL; *var_defs = g_new0 (XkbRF_VarDefsRec, 1); gdk_error_trap_push (); /* Get it from the X property or fallback on defaults */ if (!XkbRF_GetNamesProp (display, rules, *var_defs) || !*rules) { *rules = strdup (XKB_RULES_FILE); (*var_defs)->model = strdup (XKB_MODEL); (*var_defs)->layout = strdup (XKB_LAYOUT); (*var_defs)->variant = NULL; (*var_defs)->options = NULL; } gdk_error_trap_pop_ignored (); tmp = *rules; if (*rules[0] == '/') *rules = g_strdup (*rules); else *rules = g_build_filename (XKB_BASE, "rules", *rules, NULL); free (tmp); } void gsd_xkb_free_var_defs (XkbRF_VarDefsRec *var_defs) { g_return_if_fail (var_defs != NULL); free (var_defs->model); free (var_defs->layout); free (var_defs->variant); free (var_defs->options); g_free (var_defs); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/gsd-xkb-utils.h0000664000175000017500000000207000000000000025164 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2012 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . * */ #ifndef __GSD_XKB_UTILS_H #define __GSD_XKB_UTILS_H #include #include void gsd_xkb_get_var_defs (char **rules, XkbRF_VarDefsRec **var_defs); void gsd_xkb_free_var_defs (XkbRF_VarDefsRec *var_defs); #endif /* __GSD_XKB_UTILS_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/input-method-engines.gperf0000664000175000017500000001405600000000000027415 0ustar00jeremyjeremy%pic %struct-type %readonly-tables %define slot-name ibus_engine %define hash-function-name ibus_engine_hash %define lookup-function-name get_engine_for_ibus_engine struct Engine { int ibus_engine; const char *fcitx_engine; }; %% Unikey, "unikey" anthy, "anthy" array, "array30" array30, "array30" array30-big, "array30-big" bopomofo, "zhuyin-libpinyin" cangjie, "cangjie3" cangjie-big, "cangjie-big" cangjie3, "cangjie3" cangjie5, "cangjie5" cantonese, "cantonese" cantonhk, "cantonhk" chewing, "chewing" cns11643, "cns11643" compose, "compose" easy-big, "easy-big" emoji-table, "emoji" erbi, "erbi" erbi-qs, "erbi" googlepinyin, "googlepinyin" hangul, "hangul" # input-pad, NULL ipa-x-sampa, "ipa-x-sampa" jyutping, "jyutping" latex, "latex" libbopomofo, "zhuyin-libpinyin" libpinyin, "pinyin-libpinyin" libthai, "thai" m17n:am:sera, "m17n_am_sera" m17n:ar:kbd, "arabic" m17n:as:inscript, "m17n_as_inscript" m17n:as:itrans, "m17n_as_itrans" m17n:as:phonetic, "m17n_as_phonetic" m17n:ath:phonetic, "m17n_ath_phonetic" m17n:be:kbd, "fcitx-keyboard-by" m17n:bla:phonetic, "m17n_bla_phonetic" m17n:bn:disha, "m17n_bn_disha" m17n:bn:inscript, "m17n_bn_inscript" m17n:bn:itrans, "m17n_bn_itrans" m17n:bn:probhat, "m17n_bn_probhat" m17n:bn:unijoy, "m17n_bn_unijoy" m17n:bo:ewts, "m17n_bo_ewts" m17n:bo:tcrc, "m17n_bo_tcrc" m17n:bo:wylie, "m17n_bo_wylie" # m17n:cmc:kbd, NULL m17n:cr:western, "m17n_cr_western" m17n:cs:kbd, "fcitx-keyboard-cz-qwerty_bksl" m17n:da:post, "m17n_da_post" m17n:dv:phonetic, "m17n_dv_phonetic" m17n:el:kbd, "fcitx-keyboard-gr-simple" m17n:eo:h-fundamente, "m17n_eo_h-fundamente" m17n:eo:h-sistemo, "m17n_eo_h-sistemo" m17n:eo:plena, "m17n_eo_plena" m17n:eo:q-sistemo, "m17n_eo_q-sistemo" m17n:eo:vi-sistemo, "m17n_eo_vi-sistemo" m17n:eo:x-sistemo, "m17n_eo_x-sistemo" m17n:fa:isiri, "m17n_fa_isiri" m17n:fr:azerty, "m17n_fr_azerty" m17n:grc:mizuochi, "m17n_grc_mizuochi" m17n:gu:inscript, "m17n_gu_inscript" m17n:gu:itrans, "m17n_gu_itrans" m17n:gu:phonetic, "m17n_gu_phonetic" m17n:he:kbd, "fcitx-keyboard-il" m17n:hi:inscript, "m17n_hi_inscript" m17n:hi:itrans, "m17n_hi_itrans" m17n:hi:phonetic, "m17n_hi_phonetic" m17n:hi:remington, "m17n_hi_remington" m17n:hi:typewriter, "m17n_hi_typewriter" m17n:hi:vedmata, "m17n_hi_vedmata" m17n:hr:kbd, "fcitx-keyboard-hr" m17n:hy:kbd, "fcitx-keyboard-am-eastern-alt" m17n:ii:phonetic, "m17n_ii_phonetic" m17n:iu:phonetic, "m17n_iu_phonetic" m17n:ja:tcode, "m17n_ja_tcode" m17n:ja:trycode, "m17n_ja_trycode" m17n:ka:kbd, "fcitx-keyboard-ge" m17n:kk:arabic, "m17n_kk_arabic" m17n:kk:kbd, "fcitx-keyboard-kz" m17n:km:yannis, "m17n_km_yannis" m17n:kn:inscript, "m17n_kn_inscript" m17n:kn:itrans, "m17n_kn_itrans" m17n:kn:kgp, "m17n_kn_kgp" m17n:kn:typewriter, "m17n_kn_typewriter" # m17n:ko:han2, NULL # m17n:ko:romaja, NULL m17n:ks:inscript, "m17n_ks_inscript" m17n:ks:kbd, "m17n_ks_kbd" m17n:lo:kbd, "fcitx-keyboard-la-stea" m17n:lo:lrt, "m17n_lo_lrt" m17n:mai:inscript, "m17n_mai_inscript" m17n:ml:inscript, "m17n_ml_inscript" m17n:ml:itrans, "m17n_ml_itrans" m17n:ml:mozhi, "m17n_ml_mozhi" m17n:ml:remington, "m17n_ml_remington" m17n:ml:swanalekha, "m17n_ml_swanalekha" m17n:mr:inscript, "m17n_mr_inscript" m17n:mr:itrans, "m17n_mr_itrans" m17n:mr:phonetic, "m17n_mr_phonetic" m17n:my:kbd, "fcitx-keyboard-mm" m17n:ne:rom, "m17n_ne_rom" m17n:ne:trad, "m17n_ne_trad" m17n:nsk:phonetic, "m17n_nsk_phonetic" m17n:oj:phonetic, "m17n_oj_phonetic" m17n:or:inscript, "m17n_or_inscript" m17n:or:itrans, "m17n_or_itrans" m17n:or:phonetic, "m17n_or_phonetic" m17n:pa:anmollipi, "m17n_pa_anmollipi" m17n:pa:inscript, "m17n_pa_inscript" m17n:pa:itrans, "m17n_pa_itrans" m17n:pa:jhelum, "m17n_pa_jhelum" m17n:pa:phonetic, "m17n_pa_phonetic" m17n:ps:phonetic, "m17n_ps_phonetic" m17n:ru:kbd, "fcitx-keyboard-ru" m17n:ru:phonetic, "m17n_ru_phonetic" m17n:ru:translit, "m17n_ru_translit" m17n:ru:yawerty, "m17n_ru_yawerty" m17n:sa:IAST, "m17n_sa_IAST" m17n:sa:harvard-kyoto, "m17n_sa_harvard-kyoto" m17n:sa:itrans, "m17n_sa_itrans" m17n:sd:inscript, "m17n_sd_inscript" m17n:si:phonetic-dynamic, "m17n_si_phonetic-dynamic" m17n:si:samanala, "m17n_si_samanala" m17n:si:singlish, "m17n_si_singlish" m17n:si:sumihiri, "m17n_si_sumihiri" m17n:si:transliteration, "m17n_si_transliteration" m17n:si:wijesekera, "m17n_si_wijesekera" m17n:sk:kbd, "fcitx-keyboard-sk" m17n:sr:kbd, "fcitx-keyboard-rs" m17n:sv:post, "m17n_sv_post" m17n:t:latn-post, "m17n_t_latn-post" m17n:t:latn-pre, "m17n_t_latn-pre" m17n:t:math-latex, "m17n_t_math-latex" m17n:t:rfc1345, "m17n_t_rfc1345" m17n:t:syrc-phonetic, "m17n_t_syrc-phonetic" m17n:t:unicode, "m17n_t_unicode" m17n:ta:inscript, "m17n_ta_inscript" m17n:ta:itrans, "m17n_ta_itrans" m17n:ta:lk-renganathan, "m17n_ta_lk-renganathan" m17n:ta:phonetic, "m17n_ta_phonetic" m17n:ta:tamil99, "m17n_ta_tamil99" m17n:ta:typewriter, "m17n_ta_typewriter" m17n:ta:vutam, "m17n_ta_vutam" m17n:tai:sonla-kbd, "m17n_tai_sonla-kbd" m17n:te:apple, "m17n_te_apple" m17n:te:inscript, "m17n_te_inscript" m17n:te:itrans, "m17n_te_itrans" m17n:te:pothana, "m17n_te_pothana" m17n:te:rts, "m17n_te_rts" m17n:te:sarala, "m17n_te_sarala" m17n:th:kesmanee, "m17n_th_kesmanee" m17n:th:pattachote, "m17n_th_pattachote" m17n:th:tis820, "m17n_th_tis820" m17n:ua:kbd, "fcitx-keyboard-ua" m17n:ug:kbd, "fcitx-keyboard-cn-ug" m17n:ur:phonetic, "m17n_ur_phonetic" m17n:uz:kbd, "fcitx-keyboard-uz" m17n:vi:han, "m17n_vi_han" m17n:vi:nomtelex, "m17n_vi_nomtelex" m17n:vi:nomvni, "m17n_vi_nomvni" m17n:vi:tcvn, "m17n_vi_tcvn" m17n:vi:telex, "m17n_vi_telex" m17n:vi:viqr, "m17n_vi_viqr" m17n:vi:vni, "m17n_vi_vni" m17n:yi:yivo, "m17n_yi_yivo" m17n:zh:bopomofo, "m17n_zh_bopomofo" m17n:zh:cangjie, "cangjie3" m17n:zh:pinyin, "m17n_zh_pinyin" m17n:zh:pinyin-vi, "m17n_zh_pinyin-vi" # m17n:zh:py, NULL m17n:zh:quick, "quick3" # m17n:zh:tonepy, NULL mozc-jp, "mozc" pinyin, "pinyin" quick, "quick3" quick-classic, "quick-classic" quick3, "quick3" quick5, "quick5" rime, "rime" rustrad, "rustrad" scj6, "scj6" skk, "skk" stroke5, "stroke5" sunpinyin, "sunpinyin" # tegaki, NULL thai, "thai" translit, "translit" translit-ua, "translit-ua" viqr, "viqr" wu, "wu" wubi-haifeng86, "wubi" wubi-jidian86, "wubi" # xkbc, NULL yawerty, "yawerty" # yong, NULL %% ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/kbd-capslock-off.png0000664000175000017500000000316200000000000026134 0ustar00jeremyjeremyPNG  IHDR@@iqsBIT|d pHYsnNtEXtSoftwarewww.inkscape.org<IDATxME5|.DM#H(W<9p OzGA=iL< D$ Q? +]I0ay蚥fv&;dW .iْf>m(6d x vUD`p t- ǁ;%P@еpor\NIPPX*NKz?N~3 SC xhvC fފ,Gqh?o~`A9IY00@"ۀ]uO+g嬅]@[,6`w v"*Y5|%bK'5YY`Nrc} !ۜ@2ۇ&n`jrj}1Hڧs>;یa!IN ȹLݾp 5,|&z:M|P~|GS{dJ*5)Z,m0 (D_ᑬx qP>>)Q듂B{!n_D=Bөwd^ 8Tkq[al[b])8_I:KRC6zf`s% ,I9cΔ/1IrE@gf?g 6@c$7p0 ޛ"ic~ ج$gzewdIUdD?zXH6S[=Ƙ}9{ 6#r+qPn69U2֑-d(Iz(FP 9sՓpD'8'x$-l6 6 K|џ>N6 >u^!H4@G޵0WңL-cNCյ}! IY4)IE3+po*e,t*+9$̃9m5/d; }Ǟ,ǵ1r7&I ȗ3hwo3">H "I LkqK޳|r;w:v.f)f maO,d^4͹,1U4fmg JbvWVJlt``#?< ຣ30.ӎ=|ػ j{ܙB7t4vXKaM@a.]D@iJDc'Ocz5ֺer΀rOh@-],mZ\#_hWfd|i*ksK%)in ͝1:qAZCx+]zIzgJOBYjۦI1V ! W[PrO$%|/P@ٞsh$JҼ>NajjLjLIENDB`././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/kbd-capslock-on.png0000664000175000017500000000272000000000000025775 0ustar00jeremyjeremyPNG  IHDR@@iqsRGBbKGD pHYsnNtIME:=PIDATxKhE{#4YSZ|!u!nJk(iDtck] ҅(E4ޒB >jF%!M VHLdr{M3g93"#P 40q`0ӬGN`iR`!/_ԅ^+pH\ڜa$xZKr{IO%8۴3q|Bu \S0PQo1Rw 䁻y9+P,[`h@[`z 4+WD9 fC#۪p,/ tq vQ)|_z|xWÃ[%dZK`n5ckGJ(i2Ljʥ5n=hD͒<R^E綃d f ; @WsGآ 04Lv<&Sc)- `*ףɴ YL0,+0nIrd=Ydei!n1Y[@ 8qSmeN#Cn'dnP <2f. VY@1ǜ(T>W4h1`SfmZ῱yt ,w ~_F`tx둟eӽ2\9*8^ *!bs&00Č,uIh:ogMJ' ][bÚGVk r}Pw! ";*1iUIG U Io WQT7J0r\{,ֹ@( |ؙ$p\8y @ҍ/P@)}1qh#jvI^1 -q'HL r,62er_ 9Smj<"Id{L.K<^>%-{Tv!/Җ„:'N(KSB/M%6 l絹 3)\R&/ stTSO8`*K598C[{vT ql/SU_BcoN|H0IENDB`././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/kbd-numlock-off.png0000664000175000017500000000331600000000000026006 0ustar00jeremyjeremyPNG  IHDR@@iqsBIT|d pHYsnNtEXtSoftwarewww.inkscape.org<KIDATx[VU6b7g}g{8笵ko}Y{*4GdI㍟$&I{scte6lnt\E VAg 8 Fx(*b36H^%|ץcBM%QN~%S`0 ]щD=]lBj[;̎c1g)>fVf‘CEщYpfa#0$`sU` F *$W3|mon0|)$>YlLր9$?[SɁ|7FzY'`/rRB:XcžR c*p0k&!#Jw1KVZ8Gɐ|ׇ#iNr&3W38x0]o~8(a:6z%{ -F|(>*A!~,/RISTg@-ToԙJs+]?J9uGzm]́L4[ p9O0K{XҨ޴$1fUԳ{alUm- Bވ8.c8$OݺM[@q~ PM|"r9I`uoJPS3b**YBEp}̓Խv48-wNh|AE7bIUm+Z SoVU 2ދHd$e܋VH:4Jz_~ 3DR)2{@5Hkkpm % HIw/sIpOJ]wyGa4Is$z)ԭSι'Z G ss0]+m+>1{4G; 'D*tZ mi+e;%؞E0Ob- l>^-@:Ou/c'>XIq~b0[ ` ?l 0Ep lbhV Ֆ୉!r/b]~Qkr.PX$ IKLhs/pJ߈J:;v_Aұ/Wse: lr<@_y`xH,]]$er)0`^Q(2>xKe], rDd&@hj7n~67O] R 1?k9 oaof|Yo>V3Ktrщ/\ >Ǹ؂] Z*T)K]cn+Tg?|wU&IENDB`././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/kbd-numlock-on.png0000664000175000017500000000306700000000000025653 0ustar00jeremyjeremyPNG  IHDR@@iqsRGBbKGD pHYsnNtIMEPLIDATxmhUu9 m±ޖl}^VNiїJCQ"(KA&RӈF\&Wr,Zlmm>ܳ|8?><׻<ߞso<"n%@(W:@\#qYlM`@!IɰO .PL]A}VN\b<&*p)e-f`Pƴqkc鄒4`^'R7ğ%^4R3v;1l1_/p%A=meX=)p^ZkɬFk M@K`D^e._n8CmhhDI50Íu%aE MPxV'Ц)tU\dpLPo&ǛN8ھEҌbԬaLˏEw+|Mj prb+$A`uD~,m P(0LhqDPKG.PHܩ p*d?(C!hNmw:4 L(\ P6Zi=8c .3*^ƍ H=+)Rj x0`Jϭ:@vJ&́;oI}Gs7O%U~xc m` cNXr $Fb5K8﷞`6ļAaGhU#<r0{qt.)up<r5km(4S&qrfwJi<U9޽ʻ[ϦXIyr KoxMl 0{~B;xxW"H.T\3&FGHT4oG*vGk'sʆbھpɽS< t,'.o%:EqDԑ/>`FQ%}poX BxpD"Vn+[ǀ ʇfn\k~Gp5F" 3\j WApd |Ϣ#ZBPQ#S%B<7%tSbv*yR7 <#P&*S)W]k:QZ[Ui紫4Q(HG:`KhLy~ (JkGcė [O-8C@mȄfREg<8E[c}zi`Լ@.h `)$ -BI-5X',WtB]PC~^\4՛i ksM;;k. =8z#͐'% L>df"`zsvJ'5j끀Jа}dE bhUw}GI8n. !IENDB`././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/kbd-scrolllock-off.png0000664000175000017500000000267300000000000026512 0ustar00jeremyjeremyPNG  IHDR@@iqsBIT|d pHYsnNtEXtSoftwarewww.inkscape.org<8IDATxkUGǿ"F4"RЊJK6BnSM?@hiu!Db? آ.]"j(i\(qc]SlJtq癛s_˛y/ 9sΝ;wZ$O^IIssm pX`X_ۯq` <.{[t^}@Z]wIN ]֏ -蚐snFxR+0н߷+ewM Zz]ÛpBXʘ^J@GDϑ7qp8ߞnϙ@S(&`(h h {9Ƕ A(gTk_ *Qh CڼM6&ր8؇e@_{/ 3T2OڰDŽ*^&€{:|`xb40w{>gDIؓxCW=Yh 3<`/k EznßWXx4QZF6 jzmuw$?X*I˙]Js'#Ӓv4YTF'Ӵa?g"BdFAOK m{śͱx^"Kb|T42< @KAɦEv&S`fIӒJA#_J()tz+S|+ȜgAkSiL4Fnbd)a+sι#l\7&)hԀB=AQoz޾`CZ(cJ<ާlI:gkcp70i45v=m[cF $)7)=Gh~ wC(8I%(к~k{8g/ . +fxuȌT-K)5{P2qKe=AcK{-҈&2F4Q[<4Usab!=t9K2aA:)zmnI>Ifn[)VH9/m_lLWyROI%K%iv@?rIENDB`././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/kbd-scrolllock-on.png0000664000175000017500000000247100000000000026350 0ustar00jeremyjeremyPNG  IHDR@@iqsRGBbKGD pHYsnNtIME)zIDATxkTW?o#qDPl ĝBlڐvZB$[Хk.ϡJ"EQ$Cmi)͹3o2<<;sν{~G>( `Iiy_ x% ln |#p0B8#0+ }}y PX48)PhMG~[Nu6^J L NA{;-ЛCϚ0TR'^UnL`ZR!hk, \lX`4%80}\RiКdkg6D FpaNj:By@_"}'Fy =9,&NKc6Q>I T&]'"xxQо, E$jANe[IpO jOe8(`Uk3Z.ĔPsin-5F |Erԅ_0 %GK߳HJPa4æ)p" W]Dఁ2) }q4}%2Vtv#ֹer1[(#޹cJry&tޅ ew+3sB.MU6ziks'Z-䵹~m(r^|'\Yo<.pEjB\1i+:sW[)!VڊX:JT.+>OY>% -u"IENDB`././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/keyboard.gnome-settings-plugin.in0000664000175000017500000000022400000000000030703 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=keyboard IAge=0 Priority=6 _Name=Keyboard _Description=Keyboard plugin Authors= Copyright=Copyright © 2007 Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/test-keyboard-ibus-utils.c0000664000175000017500000000566200000000000027347 0ustar00jeremyjeremy#include "gsd-xkb-utils.c" #include "gsd-keyboard-manager.c" static void test_layout_from_ibus_layout (void) { gint i; const gchar *test_strings[][2] = { /* input output */ { "", "" }, { "a", "a" }, { "a(", "a" }, { "a[", "a" }, }; for (i = 0; i < G_N_ELEMENTS (test_strings); ++i) g_assert_cmpstr (layout_from_ibus_layout (test_strings[i][0]), ==, test_strings[i][1]); } static void test_variant_from_ibus_layout (void) { gint i; const gchar *test_strings[][2] = { /* input output */ { "", NULL }, { "a", NULL }, { "(", NULL }, { "()", "" }, { "(b)", "b" }, { "a(", NULL }, { "a()", "" }, { "a(b)", "b" }, }; for (i = 0; i < G_N_ELEMENTS (test_strings); ++i) g_assert_cmpstr (variant_from_ibus_layout (test_strings[i][0]), ==, test_strings[i][1]); } static void test_options_from_ibus_layout (void) { gint i, j; gchar *output_0[] = { NULL }; gchar *output_1[] = { "", NULL }; gchar *output_2[] = { "b", NULL }; gchar *output_3[] = { "b", "", NULL }; gchar *output_4[] = { "b", "c", NULL }; const gpointer tests[][2] = { /* input output */ { "", NULL }, { "a", NULL }, { "a[", output_0 }, { "a[]", output_1 }, { "a[b]", output_2 }, { "a[b,]", output_3 }, { "a[b,c]", output_4 }, }; for (i = 0; i < G_N_ELEMENTS (tests); ++i) { if (tests[i][1] == NULL) { g_assert (options_from_ibus_layout (tests[i][0]) == NULL); } else { gchar **strv_a = options_from_ibus_layout (tests[i][0]); gchar **strv_b = tests[i][1]; g_assert (g_strv_length (strv_a) == g_strv_length (strv_b)); for (j = 0; j < g_strv_length (strv_a); ++j) g_assert_cmpstr (strv_a[j], ==, strv_b[j]); } } } int main (void) { test_layout_from_ibus_layout (); test_variant_from_ibus_layout (); test_options_from_ibus_layout (); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/keyboard/test-keyboard.c0000664000175000017500000000032400000000000025237 0ustar00jeremyjeremy#define NEW gsd_keyboard_manager_new #define START gsd_keyboard_manager_start #define STOP gsd_keyboard_manager_stop #define MANAGER GsdKeyboardManager #include "gsd-keyboard-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1644246191.583767 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/0000775000175000017500000000000000000000000022547 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/Makefile.am0000664000175000017500000000673600000000000024617 0ustar00jeremyjeremyicondir = $(datadir)/icons/hicolor context = actions plugin_name = media-keys NULL = SUBDIRS = gvc plugin_LTLIBRARIES = libmedia-keys.la BUILT_SOURCES = \ gsd-marshal.h \ gsd-marshal.c \ shell-key-grabber.c \ shell-key-grabber.h \ $(NULL) gsd-marshal.c: gsd-marshal.list $(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=gsd_marshal $< --header --body --internal > $@ gsd-marshal.h: gsd-marshal.list $(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=gsd_marshal $< --header --internal > $@ shell-key-grabber.c: shell-key-grabber.h shell-key-grabber.h: Makefile.am org.gnome.ShellKeyGrabber.xml gdbus-codegen --interface-prefix org.gnome. \ --generate-c-code shell-key-grabber \ --c-namespace Shell \ $(srcdir)/org.gnome.ShellKeyGrabber.xml libmedia_keys_la_SOURCES = \ what-did-you-plug-in/pa-backend.c \ what-did-you-plug-in/dialog-window.c \ gsd-media-keys-plugin.c \ gsd-media-keys-manager.h \ gsd-media-keys-manager.c \ gsd-screenshot-utils.h \ gsd-screenshot-utils.c \ shortcuts-list.h \ shell-keybinding-modes.h \ $(BUILT_SOURCES) \ $(NULL) libmedia_keys_la_CPPFLAGS = \ -I$(top_srcdir)/data/ \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -I$(top_srcdir)/plugins/media-keys/gvc \ -I$(top_srcdir)/plugins/media-keys/what-did-you-plug-in \ -DBINDIR=\"$(bindir)\" \ -DPIXMAPDIR=\""$(pkgdatadir)"\" \ -DGTKBUILDERDIR=\""$(pkgdatadir)"\" \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) libmedia_keys_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(MEDIA_KEYS_CFLAGS) \ $(AM_CFLAGS) libmedia_keys_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) libmedia_keys_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/plugins/media-keys/gvc/libgvc.la \ $(MEDIA_KEYS_LIBS) \ $(SETTINGS_PLUGIN_LIBS) \ -lm plugin_in_files = \ media-keys.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) libexec_PROGRAMS = usd-test-media-keys usd_test_media_keys_SOURCES = \ gsd-media-keys-manager.c \ gsd-media-keys-manager.h \ gsd-screenshot-utils.h \ gsd-screenshot-utils.c \ test-media-keys.c \ what-did-you-plug-in/pa-backend.c \ what-did-you-plug-in/dialog-window.c \ $(BUILT_SOURCES) \ $(NULL) usd_test_media_keys_CPPFLAGS = \ -I$(top_srcdir)/data/ \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -I$(top_srcdir)/plugins/media-keys/gvc \ -I$(top_srcdir)/plugins/media-keys/what-did-you-plug-in \ -DBINDIR=\"$(bindir)\" \ -DPIXMAPDIR=\""$(pkgdatadir)"\" \ -DGTKBUILDERDIR=\""$(pkgdatadir)"\" \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) usd_test_media_keys_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(MEDIA_KEYS_CFLAGS) \ $(AM_CFLAGS) usd_test_media_keys_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/plugins/media-keys/gvc/libgvc.la \ $(SETTINGS_DAEMON_LIBS) \ $(SETTINGS_PLUGIN_LIBS) \ $(MEDIA_KEYS_LIBS) \ -lm EXTRA_DIST = \ gsd-marshal.list \ README.media-keys-API \ org.gnome.ShellKeyGrabber.xml \ $(plugin_in_files) CLEANFILES = \ $(BUILT_SOURCES) \ $(plugin_DATA) DISTCLEANFILES = \ $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/README.media-keys-API0000664000175000017500000000345200000000000026071 0ustar00jeremyjeremyThis is very simple documentation to gnome-settings-daemon's D-Bus API for media players. gnome-settings-daemon will send key press events from multimedia keys to applications that register their interest in those events. This allows the play/pause button to control an audio player that's not focused for example. The D-Bus API is described in gsd-media-keys-manager.c (look for introspection_xml), but a small explanation follows here. 1. Create yourself a proxy object for the remote interface: Object path: /org/gnome/SettingsDaemon/MediaKeys D-Bus name: org.gnome.SettingsDaemon.MediaKeys Interface name: org.gnome.SettingsDaemon.MediaKeys 2. Register your application with gnome-settings-daemon GrabMediaPlayerKeys ("my-application", 0) with the second argument being the current time (usually 0, or the time passed to you from an event, such as a mouse click) 3. Listen to the MediaPlayerKeyPressed() signal 4. When receiving a MediaPlayerKeyPressed() signal, check whether the first argument (application) matches the value you passed to GrabMediaPlayerKeys() and apply the action depending on the key (2nd argument) Possible values of key are: - Play - Pause - Stop - Previous - Next - Rewind - FastForward - Repeat - Shuffle 5. Every time your application is focused, you should call GrabMediaPlayerKeys() again, so that gnome-settings-daemon knows which one was last used. This allows switching between a movie player and a music player, for example, and have the buttons control the last used application. 6. When your application wants to stop using the functionality it can call ReleaseMediaPlayerKeys(). If your application does not call ReleaseMediaPlayerKeys() and releases its D-Bus connection then the application will be automatically removed from the list of applications held by gnome-settings-daemon. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gsd-marshal.list0000664000175000017500000000002300000000000025641 0ustar00jeremyjeremyVOID:STRING,STRING ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gsd-media-keys-manager.c0000664000175000017500000036216700000000000027145 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2001-2003 Bastien Nocera * Copyright (C) 2006-2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_GUDEV #include #endif #include "gnome-settings-plugin.h" #include "gnome-settings-bus.h" #include "gnome-settings-profile.h" #include "gsd-marshal.h" #include "gsd-media-keys-manager.h" #include "shortcuts-list.h" #include "shell-key-grabber.h" #include "gsd-screenshot-utils.h" #include "gsd-input-helper.h" #include "gsd-enums.h" #include #include #include "gvc-mixer-control.h" #include "gvc-mixer-control-private.h" #include "gvc-mixer-sink.h" #include "pa-backend.h" #include "dialog-window.h" #include #ifdef HAVE_FCITX #include #endif #define GSD_MEDIA_KEYS_DBUS_PATH GSD_DBUS_PATH "/MediaKeys" #define GSD_MEDIA_KEYS_DBUS_NAME GSD_DBUS_NAME ".MediaKeys" #define GNOME_KEYRING_DBUS_NAME "org.gnome.keyring" #define GNOME_KEYRING_DBUS_PATH "/org/gnome/keyring/daemon" #define GNOME_KEYRING_DBUS_INTERFACE "org.gnome.keyring.Daemon" #define SHELL_DBUS_NAME "org.gnome.Shell" #define SHELL_DBUS_PATH "/org/gnome/Shell" #define PANEL_DBUS_NAME "org.gnome.Panel" #define UNITY_DBUS_NAME "com.canonical.Unity" #define CUSTOM_BINDING_SCHEMA SETTINGS_BINDING_DIR ".custom-keybinding" #define SHELL_GRABBER_RETRY_INTERVAL 1 static const gchar introspection_xml[] = "" " " " " " " " " " " " " " " " " " " " " " " " " " " " " ""; #define SETTINGS_INTERFACE_DIR "org.gnome.desktop.interface" #define SETTINGS_POWER_DIR "com.canonical.unity.settings-daemon.plugins.power" #define SETTINGS_XSETTINGS_DIR "com.canonical.unity.settings-daemon.plugins.xsettings" #define SETTINGS_TOUCHPAD_DIR "org.gnome.desktop.peripherals.touchpad" #define UNITY_SETTINGS_INTERFACE_DIR "com.canonical.Unity.Interface" #define TOUCHPAD_ENABLED_KEY "send-events" #define HIGH_CONTRAST "HighContrast" #define TEXT_SCALING_FACTOR_KEY (in_desktop ("Unity") ? \ "text-scale-factor" : "text-scaling-factor") #define VOLUME_STEP 6 /* percents for one volume button press */ #define ENV_GTK_IM_MODULE "GTK_IM_MODULE" #define GTK_IM_MODULE_IBUS "ibus" #define GTK_IM_MODULE_FCITX "fcitx" #define GNOME_DESKTOP_INPUT_SOURCES_DIR "org.gnome.desktop.input-sources" #define KEY_CURRENT_INPUT_SOURCE "current" #define KEY_INPUT_SOURCES "sources" #define INPUT_SOURCE_TYPE_XKB "xkb" #define INPUT_SOURCE_TYPE_IBUS "ibus" #define INPUT_SOURCE_TYPE_FCITX "fcitx" #define FCITX_XKB_PREFIX "fcitx-keyboard-" #define SYSTEMD_DBUS_NAME "org.freedesktop.login1" #define SYSTEMD_DBUS_PATH "/org/freedesktop/login1" #define SYSTEMD_DBUS_INTERFACE "org.freedesktop.login1.Manager" #define GSD_MEDIA_KEYS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_MEDIA_KEYS_MANAGER, GsdMediaKeysManagerPrivate)) typedef struct { char *application; char *dbus_name; guint32 time; guint watch_id; } MediaPlayer; typedef struct { MediaKeyType key_type; ShellKeyBindingMode modes; const char *settings_key; const char *hard_coded; char *custom_path; char *custom_command; Key *key; guint accel_id; } MediaKey; typedef struct { GsdMediaKeysManager *manager; MediaKey *key; } GrabData; struct GsdMediaKeysManagerPrivate { /* Volume bits */ GvcMixerControl *volume; GvcMixerStream *sink; GvcMixerStream *source; ca_context *ca; GtkSettings *gtksettings; #ifdef HAVE_GUDEV GHashTable *streams; /* key = X device ID, value = stream id */ GUdevClient *udev_client; #endif /* HAVE_GUDEV */ GSettings *settings; GSettings *input_settings; GHashTable *custom_settings; GSettings *sound_settings; GPtrArray *keys; /* HighContrast theme settings */ GSettings *interface_settings; char *icon_theme; char *gtk_theme; /* Power stuff */ GSettings *power_settings; GDBusProxy *power_proxy; GDBusProxy *power_screen_proxy; GDBusProxy *power_keyboard_proxy; /* Shell stuff */ guint name_owner_id; GDBusProxy *shell_proxy; ShellKeyGrabber *key_grabber; GCancellable *shell_cancellable; GCancellable *grab_cancellable; /* ScreenSaver stuff */ GsdScreenSaver *screen_saver_proxy; /* systemd stuff */ GDBusProxy *logind_proxy; gint inhibit_keys_fd; /* Multihead stuff */ GdkScreen *current_screen; GSList *screens; GdkScreen *screen; int opcode; GList *media_players; GDBusNodeInfo *introspection_data; GDBusConnection *connection; GCancellable *bus_cancellable; GDBusProxy *xrandr_proxy; GCancellable *cancellable; /* Only used for XRandR operations */ guint start_idle_id; /* Ubuntu notifications */ NotifyNotification *volume_notification; NotifyNotification *brightness_notification; NotifyNotification *kb_backlight_notification; /* Legacy keygrabber stuff */ guint unity_name_owner_id; guint panel_name_owner_id; guint have_legacy_keygrabber; #ifdef HAVE_FCITX FcitxInputMethod *fcitx; #endif gboolean is_ibus_active; gboolean is_fcitx_active; /* What did you plug in dialog */ pa_backend *wdypi_pa_backend; }; static void gsd_media_keys_manager_class_init (GsdMediaKeysManagerClass *klass); static void gsd_media_keys_manager_init (GsdMediaKeysManager *media_keys_manager); static void gsd_media_keys_manager_finalize (GObject *object); static void register_manager (GsdMediaKeysManager *manager); static void custom_binding_changed (GSettings *settings, const char *settings_key, GsdMediaKeysManager *manager); static void grab_media_keys (GsdMediaKeysManager *manager); static void grab_media_key (MediaKey *key, GsdMediaKeysManager *manager); static void ungrab_media_key (MediaKey *key, GsdMediaKeysManager *manager); G_DEFINE_TYPE (GsdMediaKeysManager, gsd_media_keys_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; #define NOTIFY_CAP_PRIVATE_SYNCHRONOUS "x-canonical-private-synchronous" #define NOTIFY_CAP_PRIVATE_ICON_ONLY "x-canonical-private-icon-only" #define NOTIFY_HINT_TRUE "true" typedef struct { GsdMediaKeysManager *manager; MediaKeyType type; guint old_percentage; } GsdBrightnessActionData; static const char *volume_icons[] = { "notification-audio-volume-muted", "notification-audio-volume-low", "notification-audio-volume-medium", "notification-audio-volume-high", NULL }; static const char *audio_volume_icons[] = { "audio-volume-muted-symbolic", "audio-volume-low-symbolic", "audio-volume-medium-symbolic", "audio-volume-high-symbolic", NULL }; static const char *mic_volume_icons[] = { "microphone-sensitivity-muted-symbolic", "microphone-sensitivity-low-symbolic", "microphone-sensitivity-medium-symbolic", "microphone-sensitivity-high-symbolic", NULL }; static const char *brightness_icons[] = { "notification-display-brightness-off", "notification-display-brightness-low", "notification-display-brightness-medium", "notification-display-brightness-high", "notification-display-brightness-full", NULL }; static const char *kb_backlight_icons[] = { "notification-keyboard-brightness-off", "notification-keyboard-brightness-low", "notification-keyboard-brightness-medium", "notification-keyboard-brightness-high", "notification-keyboard-brightness-full", NULL }; static gboolean in_desktop (const gchar *name) { const gchar *desktop_name_list; gchar **names; gboolean in_list = FALSE; gint i; desktop_name_list = g_getenv ("XDG_CURRENT_DESKTOP"); if (!desktop_name_list) return FALSE; names = g_strsplit (desktop_name_list, ":", -1); for (i = 0; names[i] && !in_list; i++) if (strcmp (names[i], name) == 0) { in_list = TRUE; break; } g_strfreev (names); return in_list; } static const char * calculate_icon_name (gint value, const char **icon_names) { value = CLAMP (value, 0, 100); gint length = g_strv_length (icon_names); gint s = (length - 1) * value / 100 + 1; s = CLAMP (s, 1, length - 1); return icon_names[s]; } static gboolean ubuntu_osd_notification_is_supported (void) { GList *caps; gboolean has_cap; caps = notify_get_server_caps (); has_cap = (g_list_find_custom (caps, NOTIFY_CAP_PRIVATE_SYNCHRONOUS, (GCompareFunc) g_strcmp0) != NULL); g_list_foreach (caps, (GFunc) g_free, NULL); g_list_free (caps); return has_cap; } static gboolean ubuntu_osd_notification_show_icon (const char *icon, const char *hint) { if (!ubuntu_osd_notification_is_supported ()) return FALSE; NotifyNotification *notification = notify_notification_new (" ", "", icon); notify_notification_set_hint_string (notification, NOTIFY_CAP_PRIVATE_SYNCHRONOUS, hint); notify_notification_set_hint_string (notification, NOTIFY_CAP_PRIVATE_ICON_ONLY, NOTIFY_HINT_TRUE); gboolean res = notify_notification_show (notification, NULL); g_object_unref (notification); return res; } static gboolean ubuntu_osd_do_notification (NotifyNotification **notification, const char *hint, gint value, gboolean muted, const char **icon_names) { if (!ubuntu_osd_notification_is_supported ()) return FALSE; if (!*notification) { *notification = notify_notification_new (" ", "", NULL); notify_notification_set_hint_string (*notification, NOTIFY_CAP_PRIVATE_SYNCHRONOUS, hint); } value = CLAMP (value, -1, 101); const char *icon = muted ? icon_names[0] : calculate_icon_name (value, icon_names); notify_notification_set_hint_int32 (*notification, "value", value); notify_notification_update (*notification, " ", "", icon); return notify_notification_show (*notification, NULL); } static gboolean ubuntu_osd_notification_show_volume (GsdMediaKeysManager *manager, gint value, gboolean muted, gboolean is_mic) { const char **icons_name = is_mic ? mic_volume_icons : volume_icons; return ubuntu_osd_do_notification (&manager->priv->volume_notification, "volume", value, muted, icons_name); } static gboolean ubuntu_osd_notification_show_brightness (GsdMediaKeysManager *manager, gint value) { return ubuntu_osd_do_notification (&manager->priv->brightness_notification, "brightness", value, value <= 0, brightness_icons); } static gboolean ubuntu_osd_notification_show_kb_backlight (GsdMediaKeysManager *manager, gint value) { return ubuntu_osd_do_notification (&manager->priv->kb_backlight_notification, "keyboard", value, value <= 0, kb_backlight_icons); } static void init_screens (GsdMediaKeysManager *manager) { GdkDisplay *display; int i; display = gdk_display_get_default (); for (i = 0; i < gdk_display_get_n_screens (display); i++) { GdkScreen *screen; screen = gdk_display_get_screen (display, i); if (screen == NULL) { continue; } manager->priv->screens = g_slist_append (manager->priv->screens, screen); } manager->priv->current_screen = manager->priv->screens->data; } static void media_key_free (MediaKey *key) { if (key == NULL) return; g_free (key->custom_path); g_free (key->custom_command); if (key->key) free_key (key->key); g_free (key); } static char * get_term_command (GsdMediaKeysManager *manager) { char *cmd_term, *cmd_args;; char *cmd = NULL; GSettings *settings; settings = g_settings_new ("org.gnome.desktop.default-applications.terminal"); cmd_term = g_settings_get_string (settings, "exec"); if (cmd_term[0] == '\0') cmd_term = g_strdup ("gnome-terminal"); cmd_args = g_settings_get_string (settings, "exec-arg"); if (strcmp (cmd_term, "") != 0) { cmd = g_strdup_printf ("%s %s -e", cmd_term, cmd_args); } else { cmd = g_strdup_printf ("%s -e", cmd_term); } g_free (cmd_args); g_free (cmd_term); g_object_unref (settings); return cmd; } static char ** get_keyring_env (GsdMediaKeysManager *manager) { GError *error = NULL; GVariant *variant, *item; GVariantIter *iter; char **envp; variant = g_dbus_connection_call_sync (manager->priv->connection, GNOME_KEYRING_DBUS_NAME, GNOME_KEYRING_DBUS_PATH, GNOME_KEYRING_DBUS_INTERFACE, "GetEnvironment", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (variant == NULL) { g_warning ("Failed to call GetEnvironment on keyring daemon: %s", error->message); g_error_free (error); return NULL; } envp = g_get_environ (); envp = g_environ_unsetenv (envp, "DESKTOP_AUTOSTART_ID"); g_variant_get (variant, "(a{ss})", &iter); while ((item = g_variant_iter_next_value (iter))) { char *key; char *value; g_variant_get (item, "{ss}", &key, &value); envp = g_environ_setenv (envp, key, value, TRUE); g_variant_unref (item); g_free (key); g_free (value); } g_variant_iter_free (iter); g_variant_unref (variant); return envp; } static void execute (GsdMediaKeysManager *manager, char *cmd, gboolean need_term) { gboolean retval; char **argv; int argc; char *exec; char *term = NULL; GError *error = NULL; retval = FALSE; if (need_term) term = get_term_command (manager); if (term) { exec = g_strdup_printf ("%s %s", term, cmd); g_free (term); } else { exec = g_strdup (cmd); } if (g_shell_parse_argv (exec, &argc, &argv, NULL)) { char **envp; envp = get_keyring_env (manager); retval = g_spawn_async (g_get_home_dir (), argv, envp, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error); g_strfreev (argv); g_strfreev (envp); } if (retval == FALSE) { g_warning ("Couldn't execute command: %s: %s", exec, error->message); g_error_free (error); } g_free (exec); } static void print_key_parse_error (MediaKey *key, const char *str) { if (str == NULL || *str == '\0') return; if (key->settings_key != NULL) g_debug ("Unable to parse key '%s' for GSettings entry '%s'", str, key->settings_key); else g_debug ("Unable to parse hard-coded key '%s'", key->hard_coded); } static char * get_key_string (GsdMediaKeysManager *manager, MediaKey *key) { if (key->settings_key == "switch-input-source" || key->settings_key == "switch-input-source-backward") return g_settings_get_strv (manager->priv->input_settings, key->settings_key)[0]; else if (key->settings_key != NULL) return g_settings_get_string (manager->priv->settings, key->settings_key); else if (key->hard_coded != NULL) return g_strdup (key->hard_coded); else if (key->custom_path != NULL) { GSettings *settings; settings = g_hash_table_lookup (manager->priv->custom_settings, key->custom_path); return g_settings_get_string (settings, "binding"); } else g_assert_not_reached (); } static void ensure_cancellable (GCancellable **cancellable) { if (*cancellable == NULL) { *cancellable = g_cancellable_new (); g_object_add_weak_pointer (G_OBJECT (*cancellable), (gpointer *)cancellable); } else { g_object_ref (*cancellable); } } static void show_osd (GsdMediaKeysManager *manager, const char *icon, const char *label, int level) { GVariantBuilder builder; if (manager->priv->shell_proxy == NULL) return; g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE); g_variant_builder_open (&builder, G_VARIANT_TYPE_VARDICT); if (icon) g_variant_builder_add (&builder, "{sv}", "icon", g_variant_new_string (icon)); if (label) g_variant_builder_add (&builder, "{sv}", "label", g_variant_new_string (label)); if (level >= 0) g_variant_builder_add (&builder, "{sv}", "level", g_variant_new_int32 (level)); g_variant_builder_close (&builder); g_dbus_proxy_call (manager->priv->shell_proxy, "ShowOSD", g_variant_builder_end (&builder), G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, manager->priv->shell_cancellable, NULL, NULL); } static const char * get_icon_name_for_volume (gboolean is_mic, gboolean muted, int volume) { int n; if (muted) { n = 0; } else { /* select image */ n = 3 * volume / 100 + 1; if (n < 1) { n = 1; } else if (n > 3) { n = 3; } } if (is_mic) return mic_volume_icons[n]; else return audio_volume_icons[n]; } static gboolean retry_grabs (gpointer data) { GsdMediaKeysManager *manager = data; g_debug ("Retrying to grab accelerators"); grab_media_keys (manager); return FALSE; } static void grab_accelerators_complete (GObject *object, GAsyncResult *result, gpointer user_data) { GVariant *actions; gboolean retry = FALSE; GError *error = NULL; GsdMediaKeysManager *manager = user_data; shell_key_grabber_call_grab_accelerators_finish (SHELL_KEY_GRABBER (object), &actions, result, &error); if (error) { retry = (error->code == G_DBUS_ERROR_UNKNOWN_METHOD); if (!retry && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to grab accelerators: %s (%d)", error->message, error->code); else if (retry) g_debug ("Failed to grab accelerators, will retry: %s (%d)", error->message, error->code); g_error_free (error); } else { int i; for (i = 0; i < manager->priv->keys->len; i++) { MediaKey *key; key = g_ptr_array_index (manager->priv->keys, i); g_variant_get_child (actions, i, "u", &key->accel_id); } } if (retry) g_timeout_add_seconds (SHELL_GRABBER_RETRY_INTERVAL, retry_grabs, manager); } static void grab_media_keys (GsdMediaKeysManager *manager) { GVariantBuilder builder; int i; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(su)")); for (i = 0; i < manager->priv->keys->len; i++) { MediaKey *key; char *tmp; key = g_ptr_array_index (manager->priv->keys, i); tmp = get_key_string (manager, key); g_variant_builder_add (&builder, "(su)", tmp, key->modes); g_free (tmp); } shell_key_grabber_call_grab_accelerators (manager->priv->key_grabber, g_variant_builder_end (&builder), manager->priv->grab_cancellable, grab_accelerators_complete, manager); } static void grab_accelerator_complete (GObject *object, GAsyncResult *result, gpointer user_data) { GrabData *data = user_data; MediaKey *key = data->key; GError *error = NULL; if (!shell_key_grabber_call_grab_accelerator_finish (SHELL_KEY_GRABBER (object), &key->accel_id, result, &error)) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to grab accelerator: %s", error->message); g_error_free (error); } g_slice_free (GrabData, data); } static void grab_media_key (MediaKey *key, GsdMediaKeysManager *manager) { GrabData *data; char *tmp; ungrab_media_key (key, manager); tmp = get_key_string (manager, key); data = g_slice_new0 (GrabData); data->manager = manager; data->key = key; shell_key_grabber_call_grab_accelerator (manager->priv->key_grabber, tmp, key->modes, manager->priv->grab_cancellable, grab_accelerator_complete, data); g_free (tmp); } static gboolean grab_media_key_legacy (MediaKey *key, GsdMediaKeysManager *manager) { char *tmp; gboolean need_flush; need_flush = FALSE; if (key->key != NULL) { need_flush = TRUE; ungrab_key_unsafe (key->key, manager->priv->screens); } free_key (key->key); key->key = NULL; tmp = get_key_string (manager, key); key->key = parse_key (tmp); if (key->key == NULL) { print_key_parse_error (key, tmp); g_free (tmp); return need_flush; } grab_key_unsafe (key->key, GSD_KEYGRAB_NORMAL, manager->priv->screens); g_free (tmp); return TRUE; } static void ungrab_accelerator_complete (GObject *object, GAsyncResult *result, gpointer user_data) { GsdMediaKeysManager *manager = user_data; GError *error = NULL; if (!shell_key_grabber_call_ungrab_accelerator_finish (SHELL_KEY_GRABBER (object), NULL, result, &error)) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to ungrab accelerator: %s", error->message); g_error_free (error); } } static void ungrab_media_key (MediaKey *key, GsdMediaKeysManager *manager) { if (key->accel_id == 0) return; shell_key_grabber_call_ungrab_accelerator (manager->priv->key_grabber, key->accel_id, manager->priv->grab_cancellable, ungrab_accelerator_complete, manager); key->accel_id = 0; } static void gsettings_changed_cb (GSettings *settings, const gchar *settings_key, GsdMediaKeysManager *manager) { int i; gboolean need_flush = FALSE; if (manager->priv->have_legacy_keygrabber) need_flush = TRUE; /* Give up if we don't have proxy to the shell */ else if (!manager->priv->key_grabber) return; /* handled in gsettings_custom_changed_cb() */ if (g_str_equal (settings_key, "custom-keybindings")) return; if (manager->priv->have_legacy_keygrabber) gdk_error_trap_push (); /* Find the key that was modified */ for (i = 0; i < manager->priv->keys->len; i++) { MediaKey *key; key = g_ptr_array_index (manager->priv->keys, i); /* Skip over hard-coded and GConf keys */ if (key->settings_key == NULL) continue; if (strcmp (settings_key, key->settings_key) == 0) { if (!manager->priv->have_legacy_keygrabber) grab_media_key (key, manager); else { if (grab_media_key_legacy (key, manager)) need_flush = TRUE; } break; } } if (manager->priv->have_legacy_keygrabber) { if (need_flush) gdk_flush (); if (gdk_error_trap_pop ()) g_warning ("Grab failed for some keys, another application may already have access the them."); } } static MediaKey * media_key_new_for_path (GsdMediaKeysManager *manager, char *path) { GSettings *settings; char *command, *binding; MediaKey *key; g_debug ("media_key_new_for_path: %s", path); settings = g_hash_table_lookup (manager->priv->custom_settings, path); if (settings == NULL) { settings = g_settings_new_with_path (CUSTOM_BINDING_SCHEMA, path); g_signal_connect (settings, "changed", G_CALLBACK (custom_binding_changed), manager); g_hash_table_insert (manager->priv->custom_settings, g_strdup (path), settings); } command = g_settings_get_string (settings, "command"); binding = g_settings_get_string (settings, "binding"); if (*command == '\0' && *binding == '\0') { g_debug ("Key binding (%s) is incomplete", path); g_free (command); g_free (binding); return NULL; } g_free (binding); key = g_new0 (MediaKey, 1); key->key_type = CUSTOM_KEY; key->modes = GSD_KEYBINDING_MODE_LAUNCHER; key->custom_path = g_strdup (path); key->custom_command = command; return key; } static void update_custom_binding (GsdMediaKeysManager *manager, char *path) { MediaKey *key; int i; /* Remove the existing key */ for (i = 0; i < manager->priv->keys->len; i++) { key = g_ptr_array_index (manager->priv->keys, i); if (key->custom_path == NULL) continue; if (strcmp (key->custom_path, path) == 0) { g_debug ("Removing custom key binding %s", path); ungrab_media_key (key, manager); g_ptr_array_remove_index_fast (manager->priv->keys, i); break; } } /* And create a new one! */ key = media_key_new_for_path (manager, path); if (key) { g_debug ("Adding new custom key binding %s", path); g_ptr_array_add (manager->priv->keys, key); grab_media_key (key, manager); } } static void custom_binding_changed (GSettings *settings, const char *settings_key, GsdMediaKeysManager *manager) { char *path; if (strcmp (settings_key, "name") == 0) return; /* we don't care */ g_object_get (settings, "path", &path, NULL); update_custom_binding (manager, path); g_free (path); } static void gsettings_custom_changed_cb (GSettings *settings, const char *settings_key, GsdMediaKeysManager *manager) { char **bindings; int i, j, n_bindings; bindings = g_settings_get_strv (settings, settings_key); n_bindings = g_strv_length (bindings); /* Handle additions */ for (i = 0; i < n_bindings; i++) { if (g_hash_table_lookup (manager->priv->custom_settings, bindings[i])) continue; update_custom_binding (manager, bindings[i]); } /* Handle removals */ for (i = 0; i < manager->priv->keys->len; i++) { gboolean found = FALSE; MediaKey *key = g_ptr_array_index (manager->priv->keys, i); if (key->key_type != CUSTOM_KEY) continue; for (j = 0; j < n_bindings && !found; j++) found = strcmp (bindings[j], key->custom_path) == 0; if (found) continue; if (manager->priv->have_legacy_keygrabber && key->key) { gdk_error_trap_push (); ungrab_key_unsafe (key->key, manager->priv->screens); gdk_flush (); if (gdk_error_trap_pop ()) g_warning ("Ungrab failed for custom key '%s'", key->custom_path); } else ungrab_media_key (key, manager); g_hash_table_remove (manager->priv->custom_settings, key->custom_path); g_ptr_array_remove_index_fast (manager->priv->keys, i); --i; /* make up for the removed key */ } g_strfreev (bindings); } static void add_key (GsdMediaKeysManager *manager, guint i) { MediaKey *key; key = g_new0 (MediaKey, 1); key->key_type = media_keys[i].key_type; key->settings_key = media_keys[i].settings_key; key->hard_coded = media_keys[i].hard_coded; key->modes = media_keys[i].modes; g_ptr_array_add (manager->priv->keys, key); if (manager->priv->have_legacy_keygrabber) grab_media_key_legacy (key, manager); } static void init_kbd (GsdMediaKeysManager *manager) { char **custom_paths; int i; gnome_settings_profile_start (NULL); if (manager->priv->have_legacy_keygrabber) gdk_error_trap_push (); /* Media keys * Add hard-coded shortcuts first so that they can't be preempted */ for (i = 0; i < G_N_ELEMENTS (media_keys); i++) { if (media_keys[i].hard_coded) add_key (manager, i); } for (i = 0; i < G_N_ELEMENTS (media_keys); i++) { if (media_keys[i].hard_coded == NULL) add_key (manager, i); } /* Custom shortcuts */ custom_paths = g_settings_get_strv (manager->priv->settings, "custom-keybindings"); for (i = 0; i < g_strv_length (custom_paths); i++) { MediaKey *key; g_debug ("Setting up custom keybinding %s", custom_paths[i]); key = media_key_new_for_path (manager, custom_paths[i]); if (!key) { continue; } g_ptr_array_add (manager->priv->keys, key); if (manager->priv->have_legacy_keygrabber) grab_media_key_legacy (key, manager); } g_strfreev (custom_paths); if (!manager->priv->have_legacy_keygrabber) grab_media_keys (manager); else { gdk_flush (); if (gdk_error_trap_pop ()) g_warning ("Grab failed for some keys, another application may already have access the them."); } gnome_settings_profile_end (NULL); } static void launch_app (GAppInfo *app_info, gint64 timestamp) { GError *error = NULL; GdkAppLaunchContext *launch_context; /* setup the launch context so the startup notification is correct */ launch_context = gdk_display_get_app_launch_context (gdk_display_get_default ()); gdk_app_launch_context_set_timestamp (launch_context, timestamp); if (!g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error)) { g_warning ("Could not launch '%s': %s", g_app_info_get_commandline (app_info), error->message); g_error_free (error); } g_object_unref (launch_context); } static void do_url_action (GsdMediaKeysManager *manager, const char *scheme, gint64 timestamp) { GAppInfo *app_info; app_info = g_app_info_get_default_for_uri_scheme (scheme); if (app_info != NULL) { launch_app (app_info, timestamp); g_object_unref (app_info); } else { g_warning ("Could not find default application for '%s' scheme", scheme); } } static void do_media_action (GsdMediaKeysManager *manager, gint64 timestamp) { GAppInfo *app_info; app_info = g_app_info_get_default_for_type ("audio/x-vorbis+ogg", FALSE); if (app_info != NULL) { launch_app (app_info, timestamp); g_object_unref (app_info); } else { g_warning ("Could not find default application for '%s' mime-type", "audio/x-vorbis+ogg"); } } static void do_terminal_action (GsdMediaKeysManager *manager) { GSettings *settings; char *term; settings = g_settings_new ("org.gnome.desktop.default-applications.terminal"); term = g_settings_get_string (settings, "exec"); if (term) execute (manager, term, FALSE); g_free (term); g_object_unref (settings); } static void gnome_session_shutdown (GsdMediaKeysManager *manager) { GError *error = NULL; GVariant *variant; GDBusProxy *proxy; proxy = G_DBUS_PROXY (gnome_settings_bus_get_session_proxy ()); variant = g_dbus_proxy_call_sync (proxy, "Shutdown", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (variant == NULL) { g_warning ("Failed to call Shutdown on session manager: %s", error->message); g_error_free (error); return; } g_variant_unref (variant); g_object_unref (proxy); } static void do_logout_action (GsdMediaKeysManager *manager) { execute (manager, "gnome-session-quit --logout", FALSE); } static void do_eject_action_cb (GDrive *drive, GAsyncResult *res, GsdMediaKeysManager *manager) { g_drive_eject_with_operation_finish (drive, res, NULL); } #define NO_SCORE 0 #define SCORE_CAN_EJECT 50 #define SCORE_HAS_MEDIA 100 static void do_eject_action (GsdMediaKeysManager *manager) { GList *drives, *l; GDrive *fav_drive; guint score; GVolumeMonitor *volume_monitor; volume_monitor = g_volume_monitor_get (); /* Find the best drive to eject */ fav_drive = NULL; score = NO_SCORE; drives = g_volume_monitor_get_connected_drives (volume_monitor); for (l = drives; l != NULL; l = l->next) { GDrive *drive = l->data; if (g_drive_can_eject (drive) == FALSE) continue; if (g_drive_is_media_removable (drive) == FALSE) continue; if (score < SCORE_CAN_EJECT) { fav_drive = drive; score = SCORE_CAN_EJECT; } if (g_drive_has_media (drive) == FALSE) continue; if (score < SCORE_HAS_MEDIA) { fav_drive = drive; score = SCORE_HAS_MEDIA; break; } } /* Show OSD */ if (!ubuntu_osd_notification_show_icon ("notification-device-eject", "Eject")) { show_osd (manager, "media-eject-symbolic", NULL, -1); } /* Clean up the drive selection and exit if no suitable * drives are found */ if (fav_drive != NULL) fav_drive = g_object_ref (fav_drive); g_list_foreach (drives, (GFunc) g_object_unref, NULL); if (fav_drive == NULL) return; /* Eject! */ g_drive_eject_with_operation (fav_drive, G_MOUNT_UNMOUNT_FORCE, NULL, NULL, (GAsyncReadyCallback) do_eject_action_cb, manager); g_object_unref (fav_drive); g_object_unref (volume_monitor); } static void do_home_key_action (GsdMediaKeysManager *manager, gint64 timestamp) { GFile *file; GError *error = NULL; char *uri; file = g_file_new_for_path (g_get_home_dir ()); uri = g_file_get_uri (file); g_object_unref (file); if (gtk_show_uri (NULL, uri, timestamp, &error) == FALSE) { g_warning ("Failed to launch '%s': %s", uri, error->message); g_error_free (error); } g_free (uri); } static void do_search_action (GsdMediaKeysManager *manager, gint64 timestamp) { g_dbus_proxy_call (manager->priv->shell_proxy, "FocusSearch", NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, manager->priv->shell_cancellable, NULL, NULL); } static void do_execute_desktop_or_desktop (GsdMediaKeysManager *manager, const char *desktop, const char *alt_desktop, gint64 timestamp) { GDesktopAppInfo *app_info; app_info = g_desktop_app_info_new (desktop); if (app_info == NULL) app_info = g_desktop_app_info_new (alt_desktop); if (app_info != NULL) { launch_app (G_APP_INFO (app_info), timestamp); g_object_unref (app_info); return; } g_warning ("Could not find application '%s' or '%s'", desktop, alt_desktop); } static void do_touchpad_osd_action (GsdMediaKeysManager *manager, gboolean state) { if (!ubuntu_osd_notification_show_icon ((!state) ? "touchpad-disabled-symbolic" : "input-touchpad-symbolic", "Touchpad")) { show_osd (manager, state ? "input-touchpad-symbolic" : "touchpad-disabled-symbolic", NULL, -1); } } static void do_touchpad_action (GsdMediaKeysManager *manager) { GSettings *settings; gboolean state; if (touchpad_is_present () == FALSE) { do_touchpad_osd_action (manager, FALSE); return; } settings = g_settings_new (SETTINGS_TOUCHPAD_DIR); state = (g_settings_get_enum (settings, TOUCHPAD_ENABLED_KEY) == G_DESKTOP_DEVICE_SEND_EVENTS_ENABLED); do_touchpad_osd_action (manager, !state); g_settings_set_enum (settings, TOUCHPAD_ENABLED_KEY, !state ? G_DESKTOP_DEVICE_SEND_EVENTS_ENABLED : G_DESKTOP_DEVICE_SEND_EVENTS_DISABLED); g_object_unref (settings); } static void on_screen_locked (GsdScreenSaver *screen_saver, GAsyncResult *result, GsdMediaKeysManager *manager) { gboolean is_locked; GError *error = NULL; is_locked = gsd_screen_saver_call_lock_finish (screen_saver, result, &error); if (!is_locked) { g_warning ("Couldn't lock screen: %s", error->message); g_error_free (error); return; } } static void do_lock_screensaver (GsdMediaKeysManager *manager) { GsdMediaKeysManagerPrivate *priv = manager->priv; if (priv->screen_saver_proxy == NULL) priv->screen_saver_proxy = gnome_settings_bus_get_screen_saver_proxy (); gsd_screen_saver_call_lock (priv->screen_saver_proxy, priv->bus_cancellable, (GAsyncReadyCallback) on_screen_locked, manager); } static void sound_theme_changed (GtkSettings *settings, GParamSpec *pspec, GsdMediaKeysManager *manager) { char *theme_name; g_object_get (G_OBJECT (manager->priv->gtksettings), "gtk-sound-theme-name", &theme_name, NULL); if (theme_name) ca_context_change_props (manager->priv->ca, CA_PROP_CANBERRA_XDG_THEME_NAME, theme_name, NULL); g_free (theme_name); } static void ensure_canberra (GsdMediaKeysManager *manager) { char *theme_name; if (manager->priv->ca != NULL) return; ca_context_create (&manager->priv->ca); ca_context_set_driver (manager->priv->ca, "pulse"); ca_context_change_props (manager->priv->ca, 0, CA_PROP_APPLICATION_ID, "org.gnome.VolumeControl", NULL); manager->priv->gtksettings = gtk_settings_get_for_screen (gdk_screen_get_default ()); g_object_get (G_OBJECT (manager->priv->gtksettings), "gtk-sound-theme-name", &theme_name, NULL); if (theme_name) ca_context_change_props (manager->priv->ca, CA_PROP_CANBERRA_XDG_THEME_NAME, theme_name, NULL); g_free (theme_name); g_signal_connect (manager->priv->gtksettings, "notify::gtk-sound-theme-name", G_CALLBACK (sound_theme_changed), manager); } static void update_dialog (GsdMediaKeysManager *manager, GvcMixerStream *stream, guint vol, gboolean muted, gboolean sound_changed, gboolean quiet) { GvcMixerUIDevice *device; const GvcMixerStreamPort *port; const char *icon; if (ubuntu_osd_notification_show_volume (manager, vol, muted, !GVC_IS_MIXER_SINK (stream))) goto done; vol = CLAMP (vol, 0, 100); icon = get_icon_name_for_volume (!GVC_IS_MIXER_SINK (stream), muted, vol); port = gvc_mixer_stream_get_port (stream); if (g_strcmp0 (gvc_mixer_stream_get_form_factor (stream), "internal") != 0 || (port != NULL && g_strcmp0 (port->port, "analog-output-speaker") != 0 && g_strcmp0 (port->port, "analog-output") != 0)) { device = gvc_mixer_control_lookup_device_from_stream (manager->priv->volume, stream); show_osd (manager, icon, gvc_mixer_ui_device_get_description (device), vol); } else { show_osd (manager, icon, NULL, vol); } done: if (quiet == FALSE && sound_changed != FALSE && muted == FALSE) { ensure_canberra (manager); ca_context_change_device (manager->priv->ca, gvc_mixer_stream_get_name (stream)); ca_context_play (manager->priv->ca, 1, CA_PROP_EVENT_ID, "audio-volume-change", CA_PROP_EVENT_DESCRIPTION, "volume changed through key press", CA_PROP_CANBERRA_CACHE_CONTROL, "permanent", NULL); } } #ifdef HAVE_GUDEV /* PulseAudio gives us /devices/... paths, when udev * expects /sys/devices/... paths. */ static GUdevDevice * get_udev_device_for_sysfs_path (GsdMediaKeysManager *manager, const char *sysfs_path) { char *path; GUdevDevice *dev; path = g_strdup_printf ("/sys%s", sysfs_path); dev = g_udev_client_query_by_sysfs_path (manager->priv->udev_client, path); g_free (path); return dev; } static GvcMixerStream * get_stream_for_device_id (GsdMediaKeysManager *manager, gboolean is_output, guint deviceid) { char *devnode; gpointer id_ptr; GvcMixerStream *res; GUdevDevice *dev, *parent; GSList *streams, *l; id_ptr = g_hash_table_lookup (manager->priv->streams, GUINT_TO_POINTER (deviceid)); if (id_ptr != NULL) { if (GPOINTER_TO_UINT (id_ptr) == (guint) -1) return NULL; else return gvc_mixer_control_lookup_stream_id (manager->priv->volume, GPOINTER_TO_UINT (id_ptr)); } devnode = xdevice_get_device_node (deviceid); if (devnode == NULL) { g_debug ("Could not find device node for XInput device %d", deviceid); return NULL; } dev = g_udev_client_query_by_device_file (manager->priv->udev_client, devnode); if (dev == NULL) { g_debug ("Could not find udev device for device path '%s'", devnode); g_free (devnode); return NULL; } g_free (devnode); if (g_strcmp0 (g_udev_device_get_property (dev, "ID_BUS"), "usb") != 0) { g_debug ("Not handling XInput device %d, not USB", deviceid); g_hash_table_insert (manager->priv->streams, GUINT_TO_POINTER (deviceid), GUINT_TO_POINTER ((guint) -1)); g_object_unref (dev); return NULL; } parent = g_udev_device_get_parent_with_subsystem (dev, "usb", "usb_device"); if (parent == NULL) { g_warning ("No USB device parent for XInput device %d even though it's USB", deviceid); g_object_unref (dev); return NULL; } res = NULL; if (is_output) streams = gvc_mixer_control_get_sinks (manager->priv->volume); else streams = gvc_mixer_control_get_sources (manager->priv->volume); for (l = streams; l; l = l->next) { GvcMixerStream *stream = l->data; const char *sysfs_path; GUdevDevice *stream_dev, *stream_parent; sysfs_path = gvc_mixer_stream_get_sysfs_path (stream); stream_dev = get_udev_device_for_sysfs_path (manager, sysfs_path); if (stream_dev == NULL) continue; stream_parent = g_udev_device_get_parent_with_subsystem (stream_dev, "usb", "usb_device"); g_object_unref (stream_dev); if (stream_parent == NULL) continue; if (g_strcmp0 (g_udev_device_get_sysfs_path (stream_parent), g_udev_device_get_sysfs_path (parent)) == 0) { res = stream; } g_object_unref (stream_parent); if (res != NULL) break; } g_slist_free (streams); if (res) g_hash_table_insert (manager->priv->streams, GUINT_TO_POINTER (deviceid), GUINT_TO_POINTER (gvc_mixer_stream_get_id (res))); else g_hash_table_insert (manager->priv->streams, GUINT_TO_POINTER (deviceid), GUINT_TO_POINTER ((guint) -1)); return res; } #endif /* HAVE_GUDEV */ static void do_sound_action (GsdMediaKeysManager *manager, guint deviceid, int type, gboolean is_output, gboolean quiet) { GvcMixerStream *stream; gboolean old_muted, new_muted; guint old_vol, new_vol, norm_vol_step, osd_vol; gboolean sound_changed; pa_volume_t max_volume; /* Find the stream that corresponds to the device, if any */ stream = NULL; #ifdef HAVE_GUDEV stream = get_stream_for_device_id (manager, is_output, deviceid); #endif /* HAVE_GUDEV */ if (stream == NULL) { if (is_output) stream = manager->priv->sink; else stream = manager->priv->source; } if (stream == NULL) return; if (g_settings_get_boolean (manager->priv->sound_settings, "allow-amplified-volume")) max_volume = PA_VOLUME_UI_MAX; else max_volume = PA_VOLUME_NORM; norm_vol_step = PA_VOLUME_NORM * VOLUME_STEP / 100; /* FIXME: this is racy */ new_vol = old_vol = gvc_mixer_stream_get_volume (stream); new_muted = old_muted = gvc_mixer_stream_get_is_muted (stream); sound_changed = FALSE; switch (type) { case MUTE_KEY: new_muted = !old_muted; break; case VOLUME_DOWN_KEY: if (old_vol <= norm_vol_step) { new_vol = 0; new_muted = TRUE; } else { new_vol = old_vol - norm_vol_step; } break; case VOLUME_UP_KEY: new_muted = FALSE; /* When coming out of mute only increase the volume if it was 0 */ if (!old_muted || old_vol == 0) new_vol = MIN (old_vol + norm_vol_step, max_volume); break; } if (old_muted != new_muted) { gvc_mixer_stream_change_is_muted (stream, new_muted); sound_changed = TRUE; } if (old_vol != new_vol) { if (gvc_mixer_stream_set_volume (stream, new_vol) != FALSE) { gvc_mixer_stream_push_volume (stream); sound_changed = TRUE; } } if (type == VOLUME_DOWN_KEY && old_vol == 0 && old_muted) osd_vol = -1; else if (type == VOLUME_UP_KEY && old_vol == max_volume && !old_muted) osd_vol = 101; else if (!new_muted) osd_vol = (int) (100 * (double) new_vol / max_volume); else osd_vol = 0; update_dialog (manager, stream, osd_vol, new_muted, sound_changed, quiet); } static void update_default_sink (GsdMediaKeysManager *manager) { GvcMixerStream *stream; stream = gvc_mixer_control_get_default_sink (manager->priv->volume); if (stream == manager->priv->sink) return; g_clear_object (&manager->priv->sink); if (stream != NULL) { manager->priv->sink = g_object_ref (stream); } else { g_warning ("Unable to get default sink"); } } static void update_default_source (GsdMediaKeysManager *manager) { GvcMixerStream *stream; stream = gvc_mixer_control_get_default_source (manager->priv->volume); if (stream == manager->priv->source) return; g_clear_object (&manager->priv->source); if (stream != NULL) { manager->priv->source = g_object_ref (stream); } else { g_warning ("Unable to get default source"); } } static void on_control_state_changed (GvcMixerControl *control, GvcMixerControlState new_state, GsdMediaKeysManager *manager) { update_default_sink (manager); update_default_source (manager); } static void on_control_default_sink_changed (GvcMixerControl *control, guint id, GsdMediaKeysManager *manager) { update_default_sink (manager); } static void on_control_default_source_changed (GvcMixerControl *control, guint id, GsdMediaKeysManager *manager) { update_default_source (manager); } #ifdef HAVE_GUDEV static gboolean remove_stream (gpointer key, gpointer value, gpointer id) { if (GPOINTER_TO_UINT (value) == GPOINTER_TO_UINT (id)) return TRUE; return FALSE; } #endif /* HAVE_GUDEV */ static void on_control_stream_removed (GvcMixerControl *control, guint id, GsdMediaKeysManager *manager) { if (manager->priv->sink != NULL) { if (gvc_mixer_stream_get_id (manager->priv->sink) == id) g_clear_object (&manager->priv->sink); } if (manager->priv->source != NULL) { if (gvc_mixer_stream_get_id (manager->priv->source) == id) g_clear_object (&manager->priv->source); } #ifdef HAVE_GUDEV g_hash_table_foreach_remove (manager->priv->streams, (GHRFunc) remove_stream, GUINT_TO_POINTER (id)); #endif } static void free_media_player (MediaPlayer *player) { if (player->watch_id > 0) { g_bus_unwatch_name (player->watch_id); player->watch_id = 0; } g_free (player->application); g_free (player->dbus_name); g_free (player); } static gint find_by_application (gconstpointer a, gconstpointer b) { return strcmp (((MediaPlayer *)a)->application, b); } static gint find_by_name (gconstpointer a, gconstpointer b) { return strcmp (((MediaPlayer *)a)->dbus_name, b); } static gint find_by_time (gconstpointer a, gconstpointer b) { return ((MediaPlayer *)a)->time < ((MediaPlayer *)b)->time; } static void name_vanished_handler (GDBusConnection *connection, const gchar *name, GsdMediaKeysManager *manager) { GList *iter; iter = g_list_find_custom (manager->priv->media_players, name, find_by_name); if (iter != NULL) { MediaPlayer *player; player = iter->data; g_debug ("Deregistering vanished %s (dbus_name: %s)", player->application, player->dbus_name); free_media_player (player); manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter); } } /* * Register a new media player. Most applications will want to call * this with time = GDK_CURRENT_TIME. This way, the last registered * player will receive media events. In some cases, applications * may want to register with a lower priority (usually 1), to grab * events only nobody is interested. */ static void gsd_media_keys_manager_grab_media_player_keys (GsdMediaKeysManager *manager, const char *application, const char *dbus_name, guint32 time) { GList *iter; MediaPlayer *media_player; guint watch_id; if (time == GDK_CURRENT_TIME) { GTimeVal tv; g_get_current_time (&tv); time = tv.tv_sec * 1000 + tv.tv_usec / 1000; } iter = g_list_find_custom (manager->priv->media_players, application, find_by_application); if (iter != NULL) { if (((MediaPlayer *)iter->data)->time < time) { MediaPlayer *player = iter->data; free_media_player (player); manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter); } else { return; } } watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION, dbus_name, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, (GBusNameVanishedCallback) name_vanished_handler, manager, NULL); g_debug ("Registering %s at %u", application, time); media_player = g_new0 (MediaPlayer, 1); media_player->application = g_strdup (application); media_player->dbus_name = g_strdup (dbus_name); media_player->time = time; media_player->watch_id = watch_id; manager->priv->media_players = g_list_insert_sorted (manager->priv->media_players, media_player, find_by_time); } static void gsd_media_keys_manager_release_media_player_keys (GsdMediaKeysManager *manager, const char *application, const char *name) { GList *iter = NULL; g_return_if_fail (application != NULL || name != NULL); if (application != NULL) { iter = g_list_find_custom (manager->priv->media_players, application, find_by_application); } if (iter == NULL && name != NULL) { iter = g_list_find_custom (manager->priv->media_players, name, find_by_name); } if (iter != NULL) { MediaPlayer *player; player = iter->data; g_debug ("Deregistering %s (dbus_name: %s)", application, player->dbus_name); free_media_player (player); manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter); } } static gboolean gsd_media_player_key_pressed (GsdMediaKeysManager *manager, const char *key) { const char *application; gboolean have_listeners; GError *error = NULL; MediaPlayer *player; g_return_val_if_fail (key != NULL, FALSE); g_debug ("Media key '%s' pressed", key); have_listeners = (manager->priv->media_players != NULL); if (!have_listeners) { /* Popup a dialog with an (/) icon */ show_osd (manager, "action-unavailable-symbolic", NULL, -1); return TRUE; } player = manager->priv->media_players->data; application = player->application; if (g_dbus_connection_emit_signal (manager->priv->connection, player->dbus_name, GSD_MEDIA_KEYS_DBUS_PATH, GSD_MEDIA_KEYS_DBUS_NAME, "MediaPlayerKeyPressed", g_variant_new ("(ss)", application ? application : "", key), &error) == FALSE) { g_debug ("Error emitting signal: %s", error->message); g_error_free (error); } return !have_listeners; } static void handle_method_call (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { GsdMediaKeysManager *manager = (GsdMediaKeysManager *) user_data; g_debug ("Calling method '%s' for media-keys", method_name); if (g_strcmp0 (method_name, "ReleaseMediaPlayerKeys") == 0) { const char *app_name; g_variant_get (parameters, "(&s)", &app_name); gsd_media_keys_manager_release_media_player_keys (manager, app_name, sender); g_dbus_method_invocation_return_value (invocation, NULL); } else if (g_strcmp0 (method_name, "GrabMediaPlayerKeys") == 0) { const char *app_name; guint32 time; g_variant_get (parameters, "(&su)", &app_name, &time); gsd_media_keys_manager_grab_media_player_keys (manager, app_name, sender, time); g_dbus_method_invocation_return_value (invocation, NULL); } } static const GDBusInterfaceVTable interface_vtable = { handle_method_call, NULL, /* Get Property */ NULL, /* Set Property */ }; static gboolean do_multimedia_player_action (GsdMediaKeysManager *manager, const char *icon, const char *key) { if (icon != NULL) ubuntu_osd_notification_show_icon (icon, key); return gsd_media_player_key_pressed (manager, key); } static void on_xrandr_action_call_finished (GObject *source_object, GAsyncResult *res, GsdMediaKeysManager *manager) { GError *error = NULL; GVariant *variant; char *action; action = g_object_get_data (G_OBJECT (source_object), "gsd-media-keys-manager-xrandr-action"); variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); g_object_unref (manager->priv->cancellable); manager->priv->cancellable = NULL; if (error != NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to complete XRandR action: %s", error->message); g_error_free (error); } else { g_variant_unref (variant); } g_free (action); } static void do_xrandr_action (GsdMediaKeysManager *manager, const char *action, gint64 timestamp) { GsdMediaKeysManagerPrivate *priv = manager->priv; if (priv->connection == NULL || priv->xrandr_proxy == NULL) { g_warning ("No existing D-Bus connection trying to handle XRANDR keys"); return; } if (priv->cancellable != NULL) { g_debug ("xrandr action already in flight"); return; } priv->cancellable = g_cancellable_new (); g_object_set_data (G_OBJECT (priv->xrandr_proxy), "gsd-media-keys-manager-xrandr-action", g_strdup (action)); g_dbus_proxy_call (priv->xrandr_proxy, action, g_variant_new ("(x)", timestamp), G_DBUS_CALL_FLAGS_NONE, -1, priv->cancellable, (GAsyncReadyCallback) on_xrandr_action_call_finished, manager); } static gboolean do_video_out_action (GsdMediaKeysManager *manager, gint64 timestamp) { do_xrandr_action (manager, "VideoModeSwitch", timestamp); return FALSE; } static gboolean do_video_rotate_action (GsdMediaKeysManager *manager, gint64 timestamp) { do_xrandr_action (manager, "Rotate", timestamp); return FALSE; } static void do_toggle_accessibility_key (const char *key) { GSettings *settings; gboolean state; settings = g_settings_new ("org.gnome.desktop.a11y.applications"); state = g_settings_get_boolean (settings, key); g_settings_set_boolean (settings, key, !state); g_object_unref (settings); } static void do_magnifier_action (GsdMediaKeysManager *manager) { do_toggle_accessibility_key ("screen-magnifier-enabled"); } static void do_screenreader_action (GsdMediaKeysManager *manager) { do_toggle_accessibility_key ("screen-reader-enabled"); } static void do_on_screen_keyboard_action (GsdMediaKeysManager *manager) { do_toggle_accessibility_key ("screen-keyboard-enabled"); } static void do_text_size_action (GsdMediaKeysManager *manager, MediaKeyType type) { GSettings *settings; gdouble factor, best, distance; guint i; /* Same values used in the Seeing tab of the Universal Access panel */ static gdouble factors[] = { 0.75, 1.0, 1.25, 1.5 }; const gchar *text_scaling_key = TEXT_SCALING_FACTOR_KEY; if (in_desktop ("Unity")) { settings = g_settings_new (UNITY_SETTINGS_INTERFACE_DIR); } else { settings = g_object_ref (manager->priv->interface_settings); } /* Figure out the current DPI scaling factor */ factor = g_settings_get_double (settings, text_scaling_key); factor += (type == INCREASE_TEXT_KEY ? 0.25 : -0.25); /* Try to find a matching value */ distance = 1e6; best = 1.0; for (i = 0; i < G_N_ELEMENTS(factors); i++) { gdouble d; d = fabs (factor - factors[i]); if (d < distance) { best = factors[i]; distance = d; } } if (best == 1.0) g_settings_reset (settings, text_scaling_key); else g_settings_set_double (settings, text_scaling_key, best); g_object_unref (settings); } static void do_magnifier_zoom_action (GsdMediaKeysManager *manager, MediaKeyType type) { GSettings *settings; gdouble offset, value; if (type == MAGNIFIER_ZOOM_IN_KEY) offset = 1.0; else offset = -1.0; settings = g_settings_new ("org.gnome.desktop.a11y.magnifier"); value = g_settings_get_double (settings, "mag-factor"); value += offset; value = roundl (value); g_settings_set_double (settings, "mag-factor", value); g_object_unref (settings); } static void do_toggle_contrast_action (GsdMediaKeysManager *manager) { gboolean high_contrast; char *theme; /* Are we using HighContrast now? */ theme = g_settings_get_string (manager->priv->interface_settings, "gtk-theme"); high_contrast = g_str_equal (theme, HIGH_CONTRAST); g_free (theme); if (high_contrast != FALSE) { if (manager->priv->gtk_theme == NULL) g_settings_reset (manager->priv->interface_settings, "gtk-theme"); else g_settings_set (manager->priv->interface_settings, "gtk-theme", manager->priv->gtk_theme); g_settings_set (manager->priv->interface_settings, "icon-theme", manager->priv->icon_theme); } else { g_settings_set (manager->priv->interface_settings, "gtk-theme", HIGH_CONTRAST); g_settings_set (manager->priv->interface_settings, "icon-theme", HIGH_CONTRAST); } } static void power_action (GsdMediaKeysManager *manager, const char *action, gboolean allow_interaction) { g_dbus_proxy_call (manager->priv->logind_proxy, action, g_variant_new ("(b)", allow_interaction), G_DBUS_CALL_FLAGS_NONE, G_MAXINT, manager->priv->bus_cancellable, NULL, NULL); } static void do_config_power_action (GsdMediaKeysManager *manager, const gchar *config_key, gboolean in_lock_screen) { GsdPowerActionType action_type; action_type = g_settings_get_enum (manager->priv->power_settings, config_key); switch (action_type) { case GSD_POWER_ACTION_SUSPEND: power_action (manager, "Suspend", !in_lock_screen); break; case GSD_POWER_ACTION_INTERACTIVE: if (!in_lock_screen) gnome_session_shutdown (manager); break; case GSD_POWER_ACTION_SHUTDOWN: power_action (manager, "PowerOff", !in_lock_screen); break; case GSD_POWER_ACTION_HIBERNATE: power_action (manager, "Hibernate", !in_lock_screen); break; case GSD_POWER_ACTION_BLANK: case GSD_POWER_ACTION_NOTHING: /* these actions cannot be handled by media-keys and * are not used in this context */ break; } } #ifdef HAVE_FCITX static gchar * get_fcitx_name (const gchar *name) { gchar *fcitx_name = g_strdup (name); gchar *separator = strchr (fcitx_name, '+'); if (separator) *separator = '-'; return fcitx_name; } static gboolean input_source_is_fcitx_engine (const gchar *type, const gchar *name, const gchar *engine) { if (g_str_equal (type, INPUT_SOURCE_TYPE_XKB)) { if (g_str_has_prefix (engine, FCITX_XKB_PREFIX)) { gboolean equal; gchar *fcitx_name = get_fcitx_name (name); equal = g_str_equal (fcitx_name, engine + strlen (FCITX_XKB_PREFIX)); g_free (fcitx_name); return equal; } } else if (g_str_equal (type, INPUT_SOURCE_TYPE_FCITX)) { return g_str_equal (name, engine); } return FALSE; } #endif static void do_switch_input_source_action (GsdMediaKeysManager *manager, MediaKeyType type) { GsdMediaKeysManagerPrivate *priv = manager->priv; GSettings *settings; GVariant *sources; const gchar *source_type; guint first; gint i, n; if (g_strcmp0 (g_getenv ("DESKTOP_SESSION"), "unity") != 0) if (!priv->have_legacy_keygrabber) return; settings = g_settings_new (GNOME_DESKTOP_INPUT_SOURCES_DIR); sources = g_settings_get_value (settings, KEY_INPUT_SOURCES); n = g_variant_n_children (sources); if (n < 2) goto out; i = -1; #ifdef HAVE_FCITX if (priv->is_fcitx_active && priv->fcitx) { gchar *engine = fcitx_input_method_get_current_im (priv->fcitx); if (engine) { GVariantIter iter; const gchar *source_name; g_variant_iter_init (&iter, sources); for (i = 0; g_variant_iter_next (&iter, "(&s&s)", &source_type, &source_name); i++) { if (input_source_is_fcitx_engine (source_type, source_name, engine)) { break; } } if (i >= g_variant_n_children (sources)) i = -1; g_free (engine); } } #endif if (i < 0) i = g_settings_get_uint (settings, KEY_CURRENT_INPUT_SOURCE); first = i; if (type == SWITCH_INPUT_SOURCE_KEY) { do { i = (i + 1) % n; g_variant_get_child (sources, i, "(&s&s)", &source_type, NULL); } while (i != first && ((g_str_equal (source_type, INPUT_SOURCE_TYPE_IBUS) && !priv->is_ibus_active) || (g_str_equal (source_type, INPUT_SOURCE_TYPE_FCITX) && !priv->is_fcitx_active))); } else { do { i = (i + n - 1) % n; g_variant_get_child (sources, i, "(&s&s)", &source_type, NULL); } while (i != first && ((g_str_equal (source_type, INPUT_SOURCE_TYPE_IBUS) && !priv->is_ibus_active) || (g_str_equal (source_type, INPUT_SOURCE_TYPE_FCITX) && !priv->is_fcitx_active))); } if (i != first) g_settings_set_uint (settings, KEY_CURRENT_INPUT_SOURCE, i); out: g_variant_unref (sources); g_object_unref (settings); } static void update_screen_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GError *error = NULL; guint percentage; GVariant *new_percentage; GsdBrightnessActionData *data = (GsdBrightnessActionData *) user_data; GsdMediaKeysManager *manager = data->manager; new_percentage = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); if (new_percentage == NULL) { g_warning ("Failed to set new screen percentage: %s", error->message); g_error_free (error); g_free (data); return; } /* update the dialog with the new value */ g_variant_get (new_percentage, "(u)", &percentage); guint osd_percentage; if (data->old_percentage == 100 && data->type == SCREEN_BRIGHTNESS_UP_KEY) osd_percentage = 101; else if (data->old_percentage == 0 && data->type == SCREEN_BRIGHTNESS_DOWN_KEY) osd_percentage = -1; else osd_percentage = CLAMP (percentage, 0, 100); if (!ubuntu_osd_notification_show_brightness (manager, osd_percentage)) { show_osd (manager, "display-brightness-symbolic", NULL, percentage); } g_free (data); g_variant_unref (new_percentage); } static void do_screen_brightness_action_real (GObject *source_object, GAsyncResult *res, gpointer user_data) { GsdBrightnessActionData *data = (GsdBrightnessActionData *) user_data; GsdMediaKeysManager *manager = data->manager; GError *error = NULL; GVariant *old_percentage = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); if (old_percentage == NULL) { g_warning ("Failed to get old screen percentage: %s", error->message); g_error_free (error); g_free (data); return; } g_variant_get (old_percentage, "(u)", &data->old_percentage); /* call into the power plugin */ g_dbus_proxy_call (manager->priv->power_screen_proxy, data->type == SCREEN_BRIGHTNESS_UP_KEY ? "StepUp" : "StepDown", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, update_screen_cb, data); g_variant_unref (old_percentage); } static void do_screen_brightness_action (GsdMediaKeysManager *manager, MediaKeyType type) { if (manager->priv->connection == NULL || manager->priv->power_screen_proxy == NULL) { g_warning ("No existing D-Bus connection trying to handle power keys"); return; } GsdBrightnessActionData *data = g_new0 (GsdBrightnessActionData, 1); data->manager = manager; data->type = type; g_dbus_proxy_call (manager->priv->power_screen_proxy, "GetPercentage", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, do_screen_brightness_action_real, data); } static void update_keyboard_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GError *error = NULL; guint percentage; GVariant *new_percentage; GsdMediaKeysManager *manager = GSD_MEDIA_KEYS_MANAGER (user_data); new_percentage = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); if (new_percentage == NULL) { g_warning ("Failed to set new keyboard percentage: %s", error->message); g_error_free (error); return; } /* update the dialog with the new value */ g_variant_get (new_percentage, "(u)", &percentage); /* FIXME: No overshoot effect for keyboard, as the power plugin has no interface * to get the old brightness */ if (!ubuntu_osd_notification_show_kb_backlight (manager, CLAMP (percentage, 0, 100))) { show_osd (manager, "keyboard-brightness-symbolic", NULL, percentage); } g_variant_unref (new_percentage); } static void do_keyboard_brightness_action (GsdMediaKeysManager *manager, MediaKeyType type) { const char *cmd; if (manager->priv->connection == NULL || manager->priv->power_keyboard_proxy == NULL) { g_warning ("No existing D-Bus connection trying to handle power keys"); return; } switch (type) { case KEYBOARD_BRIGHTNESS_UP_KEY: cmd = "StepUp"; break; case KEYBOARD_BRIGHTNESS_DOWN_KEY: cmd = "StepDown"; break; case KEYBOARD_BRIGHTNESS_TOGGLE_KEY: cmd = "Toggle"; break; default: g_assert_not_reached (); } /* call into the power plugin */ g_dbus_proxy_call (manager->priv->power_keyboard_proxy, cmd, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, update_keyboard_cb, manager); } static void do_screenshot_action (GsdMediaKeysManager *manager, MediaKeyType type) { switch (type){ case SCREENSHOT_KEY: execute (manager, "gnome-screenshot", FALSE); break; case WINDOW_SCREENSHOT_KEY: execute (manager, "gnome-screenshot --window", FALSE); break; case AREA_SCREENSHOT_KEY: execute (manager, "gnome-screenshot --area", FALSE); break; case SCREENSHOT_CLIP_KEY: execute (manager, "gnome-screenshot --clipboard", FALSE); break; case WINDOW_SCREENSHOT_CLIP_KEY: execute (manager, "gnome-screenshot --window --clipboard", FALSE); break; case AREA_SCREENSHOT_CLIP_KEY: execute (manager, "gnome-screenshot --area --clipboard", FALSE); } } static void do_custom_action (GsdMediaKeysManager *manager, guint deviceid, MediaKey *key, gint64 timestamp) { g_debug ("Launching custom action for key (on device id %d)", deviceid); execute (manager, key->custom_command, FALSE); } static gboolean do_action (GsdMediaKeysManager *manager, guint deviceid, MediaKeyType type, gint64 timestamp) { g_debug ("Launching action for key type '%d' (on device id %d)", type, deviceid); switch (type) { case TOUCHPAD_KEY: do_touchpad_action (manager); break; case TOUCHPAD_ON_KEY: do_touchpad_osd_action (manager, TRUE); break; case TOUCHPAD_OFF_KEY: do_touchpad_osd_action (manager, FALSE); break; case MUTE_KEY: case VOLUME_DOWN_KEY: case VOLUME_UP_KEY: do_sound_action (manager, deviceid, type, TRUE, FALSE); break; case MIC_MUTE_KEY: do_sound_action (manager, deviceid, MUTE_KEY, FALSE, TRUE); break; case MUTE_QUIET_KEY: do_sound_action (manager, deviceid, MUTE_KEY, TRUE, TRUE); break; case VOLUME_DOWN_QUIET_KEY: do_sound_action (manager, deviceid, VOLUME_DOWN_KEY, TRUE, TRUE); break; case VOLUME_UP_QUIET_KEY: do_sound_action (manager, deviceid, VOLUME_UP_KEY, TRUE, TRUE); break; case LOGOUT_KEY: do_logout_action (manager); break; case EJECT_KEY: do_eject_action (manager); break; case HOME_KEY: do_home_key_action (manager, timestamp); break; case SEARCH_KEY: do_search_action (manager, timestamp); break; case EMAIL_KEY: do_url_action (manager, "mailto", timestamp); break; case SCREENSAVER_KEY: do_lock_screensaver (manager); break; case HELP_KEY: do_url_action (manager, "ghelp", timestamp); break; case SCREENSHOT_KEY: case SCREENSHOT_CLIP_KEY: case WINDOW_SCREENSHOT_KEY: case WINDOW_SCREENSHOT_CLIP_KEY: case AREA_SCREENSHOT_KEY: case AREA_SCREENSHOT_CLIP_KEY: do_screenshot_action (manager, type); break; case TERMINAL_KEY: do_terminal_action (manager); break; case WWW_KEY: do_url_action (manager, "http", timestamp); break; case MEDIA_KEY: do_media_action (manager, timestamp); break; case CALCULATOR_KEY: do_execute_desktop_or_desktop (manager, "org.gnome.Calculator.desktop", "gnome-calculator.desktop", timestamp); break; case PLAY_KEY: return do_multimedia_player_action (manager, NULL, "Play"); case PAUSE_KEY: return do_multimedia_player_action (manager, NULL, "Pause"); case STOP_KEY: return do_multimedia_player_action (manager, NULL, "Stop"); case PREVIOUS_KEY: return do_multimedia_player_action (manager, NULL, "Previous"); case NEXT_KEY: return do_multimedia_player_action (manager, NULL, "Next"); case REWIND_KEY: return do_multimedia_player_action (manager, NULL, "Rewind"); case FORWARD_KEY: return do_multimedia_player_action (manager, NULL, "FastForward"); case REPEAT_KEY: return do_multimedia_player_action (manager, NULL, "Repeat"); case RANDOM_KEY: return do_multimedia_player_action (manager, NULL, "Shuffle"); case VIDEO_OUT_KEY: do_video_out_action (manager, timestamp); break; case ROTATE_VIDEO_KEY: do_video_rotate_action (manager, timestamp); break; case MAGNIFIER_KEY: do_magnifier_action (manager); break; case SCREENREADER_KEY: do_screenreader_action (manager); break; case ON_SCREEN_KEYBOARD_KEY: do_on_screen_keyboard_action (manager); break; case INCREASE_TEXT_KEY: case DECREASE_TEXT_KEY: do_text_size_action (manager, type); break; case MAGNIFIER_ZOOM_IN_KEY: case MAGNIFIER_ZOOM_OUT_KEY: do_magnifier_zoom_action (manager, type); break; case TOGGLE_CONTRAST_KEY: do_toggle_contrast_action (manager); break; case POWER_KEY: do_config_power_action (manager, "button-power", FALSE); break; case SLEEP_KEY: do_config_power_action (manager, "button-sleep", FALSE); break; case SUSPEND_KEY: do_config_power_action (manager, "button-suspend", FALSE); break; case HIBERNATE_KEY: do_config_power_action (manager, "button-hibernate", FALSE); break; case POWER_KEY_NO_DIALOG: do_config_power_action (manager, "button-power", TRUE); break; case SLEEP_KEY_NO_DIALOG: do_config_power_action (manager, "button-sleep", TRUE); break; case SUSPEND_KEY_NO_DIALOG: do_config_power_action (manager, "button-suspend", TRUE); break; case HIBERNATE_KEY_NO_DIALOG: do_config_power_action (manager, "button-hibernate", TRUE); break; case SCREEN_BRIGHTNESS_UP_KEY: case SCREEN_BRIGHTNESS_DOWN_KEY: do_screen_brightness_action (manager, type); break; case KEYBOARD_BRIGHTNESS_UP_KEY: case KEYBOARD_BRIGHTNESS_DOWN_KEY: case KEYBOARD_BRIGHTNESS_TOGGLE_KEY: do_keyboard_brightness_action (manager, type); break; case BATTERY_KEY: do_execute_desktop_or_desktop (manager, "gnome-power-statistics.desktop", "", timestamp); break; case SWITCH_INPUT_SOURCE_KEY: case SWITCH_INPUT_SOURCE_BACKWARD_KEY: do_switch_input_source_action (manager, type); break; /* Note, no default so compiler catches missing keys */ case CUSTOM_KEY: g_assert_not_reached (); } return FALSE; } static GdkScreen * get_screen_from_root (GsdMediaKeysManager *manager, Window root) { GSList *l; /* Look for which screen we're receiving events */ for (l = manager->priv->screens; l != NULL; l = l->next) { GdkScreen *screen = (GdkScreen *) l->data; GdkWindow *window = gdk_screen_get_root_window (screen); if (GDK_WINDOW_XID (window) == root) return screen; } return NULL; } static GdkFilterReturn filter_key_events (XEvent *xevent, GdkEvent *event, GsdMediaKeysManager *manager) { static gboolean ok_to_switch = TRUE; XIEvent *xiev; XIDeviceEvent *xev; XGenericEventCookie *cookie; guint i; guint deviceid; /* verify we have a key event */ if (xevent->type != GenericEvent) return GDK_FILTER_CONTINUE; cookie = &xevent->xcookie; if (cookie->extension != manager->priv->opcode) return GDK_FILTER_CONTINUE; xiev = (XIEvent *) xevent->xcookie.data; if (xiev->evtype != XI_KeyPress && xiev->evtype != XI_KeyRelease) return GDK_FILTER_CONTINUE; xev = (XIDeviceEvent *) xiev; deviceid = xev->sourceid; if (xiev->evtype == XI_KeyPress) ok_to_switch = TRUE; for (i = 0; i < manager->priv->keys->len; i++) { MediaKey *key; key = g_ptr_array_index (manager->priv->keys, i); if (match_xi2_key (key->key, xev)) { switch (key->key_type) { case VOLUME_DOWN_KEY: case VOLUME_UP_KEY: case VOLUME_DOWN_QUIET_KEY: case VOLUME_UP_QUIET_KEY: case SCREEN_BRIGHTNESS_UP_KEY: case SCREEN_BRIGHTNESS_DOWN_KEY: case KEYBOARD_BRIGHTNESS_UP_KEY: case KEYBOARD_BRIGHTNESS_DOWN_KEY: /* auto-repeatable keys */ if (xiev->evtype != XI_KeyPress) return GDK_FILTER_CONTINUE; break; default: if (xiev->evtype != XI_KeyRelease) { return GDK_FILTER_CONTINUE; } } manager->priv->current_screen = get_screen_from_root (manager, xev->root); if (key->key_type == CUSTOM_KEY) { do_custom_action (manager, deviceid, key, xev->time); return GDK_FILTER_REMOVE; } if (key->key_type == SWITCH_INPUT_SOURCE_KEY || key->key_type == SWITCH_INPUT_SOURCE_BACKWARD_KEY) { if (ok_to_switch) { do_action (manager, deviceid, key->key_type, xev->time); ok_to_switch = FALSE; } return GDK_FILTER_CONTINUE; } if (do_action (manager, deviceid, key->key_type, xev->time) == FALSE) { return GDK_FILTER_REMOVE; } else { return GDK_FILTER_CONTINUE; } } } return GDK_FILTER_CONTINUE; } static void on_accelerator_activated (ShellKeyGrabber *grabber, guint accel_id, guint deviceid, guint timestamp, GsdMediaKeysManager *manager) { guint i; g_debug ("Received accel id %u (device-id: %u, timestamp: %u", accel_id, deviceid, timestamp); for (i = 0; i < manager->priv->keys->len; i++) { MediaKey *key; key = g_ptr_array_index (manager->priv->keys, i); if (key->accel_id != accel_id) continue; if (key->key_type == CUSTOM_KEY) do_custom_action (manager, deviceid, key, timestamp); else do_action (manager, deviceid, key->key_type, timestamp); return; } g_warning ("Could not find accelerator for accel id %u", accel_id); } static void update_theme_settings (GSettings *settings, const char *key, GsdMediaKeysManager *manager) { char *theme; theme = g_settings_get_string (manager->priv->interface_settings, key); if (g_str_equal (theme, HIGH_CONTRAST)) { g_free (theme); } else { if (g_str_equal (key, "gtk-theme")) { g_free (manager->priv->gtk_theme); manager->priv->gtk_theme = theme; } else { g_free (manager->priv->icon_theme); manager->priv->icon_theme = theme; } } } static void on_wdypi_action (int action, void *userdata) { GsdMediaKeysManager *manager = userdata; pa_backend *pb = manager->priv->wdypi_pa_backend; pa_backend_set_context(pb, gvc_mixer_control_get_pa_context(manager->priv->volume)); switch (action) { case WDYPI_DIALOG_SOUND_SETTINGS: execute(manager, "unity-control-center sound", FALSE); break; case WDYPI_DIALOG_HEADPHONES: pa_backend_set_port(pb, "analog-output-headphones", true); pa_backend_set_port(pb, "analog-input-internal-mic", false); break; case WDYPI_DIALOG_HEADSET: pa_backend_set_port(pb, "analog-output-headphones", true); pa_backend_set_port(pb, "analog-input-headset-mic", false); break; case WDYPI_DIALOG_MICROPHONE: pa_backend_set_port(pb, "analog-output-speaker", true); pa_backend_set_port(pb, "analog-input-headphone-mic", false); break; default: break; } } static void on_wdypi_popup (bool hsmic, bool hpmic, void *userdata) { if (!hpmic && !hsmic) wdypi_dialog_kill(); else wdypi_dialog_run(hsmic, hpmic, on_wdypi_action, userdata); } static void on_control_card_info_updated (GvcMixerControl *control, gpointer card_info, GsdMediaKeysManager *manager) { pa_backend_card_changed (manager->priv->wdypi_pa_backend, card_info); #ifdef TEST_WDYPI_DIALOG /* Just a simple way to test the dialog on all types of hardware (pops up dialog on program start, and on every plug in) */ on_wdypi_popup (true, true, manager); #endif } static void initialize_volume_handler (GsdMediaKeysManager *manager) { /* initialise Volume handler * * We do this one here to force checking gstreamer cache, etc. * The rest (grabbing and setting the keys) can happen in an * idle. */ gnome_settings_profile_start ("gvc_mixer_control_new"); manager->priv->volume = gvc_mixer_control_new ("GNOME Volume Control Media Keys"); manager->priv->wdypi_pa_backend = pa_backend_new(on_wdypi_popup, manager); g_signal_connect (manager->priv->volume, "state-changed", G_CALLBACK (on_control_state_changed), manager); g_signal_connect (manager->priv->volume, "default-sink-changed", G_CALLBACK (on_control_default_sink_changed), manager); g_signal_connect (manager->priv->volume, "default-source-changed", G_CALLBACK (on_control_default_source_changed), manager); g_signal_connect (manager->priv->volume, "stream-removed", G_CALLBACK (on_control_stream_removed), manager); g_signal_connect (manager->priv->volume, "card-info", G_CALLBACK (on_control_card_info_updated), manager); gvc_mixer_control_open (manager->priv->volume); gnome_settings_profile_end ("gvc_mixer_control_new"); } static void on_shell_proxy_ready (GObject *source, GAsyncResult *result, gpointer data) { GsdMediaKeysManager *manager = data; manager->priv->shell_proxy = g_dbus_proxy_new_for_bus_finish (result, NULL); } static void on_key_grabber_ready (GObject *source, GAsyncResult *result, gpointer data) { GsdMediaKeysManager *manager = data; GError *error = NULL; manager->priv->key_grabber = shell_key_grabber_proxy_new_for_bus_finish (result, &error); if (!manager->priv->key_grabber) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to create proxy for key grabber: %s", error->message); g_error_free (error); return; } g_signal_connect (manager->priv->key_grabber, "accelerator-activated", G_CALLBACK (on_accelerator_activated), manager); init_kbd (manager); } static gboolean session_has_key_grabber (void) { const gchar *session = g_getenv ("DESKTOP_SESSION"); return g_strcmp0 (session, "gnome") == 0 || g_strcmp0 (session, "unity") == 0; } static void on_shell_appeared (GDBusConnection *connection, const char *name, const char *name_owner, gpointer user_data) { if (!session_has_key_grabber ()) return; GsdMediaKeysManager *manager = user_data; shell_key_grabber_proxy_new_for_bus (G_BUS_TYPE_SESSION, 0, name_owner, SHELL_DBUS_PATH, manager->priv->grab_cancellable, on_key_grabber_ready, manager); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, 0, NULL, name_owner, SHELL_DBUS_PATH, SHELL_DBUS_NAME, manager->priv->shell_cancellable, on_shell_proxy_ready, manager); } static void on_shell_vanished (GDBusConnection *connection, const char *name, gpointer user_data) { if (!session_has_key_grabber ()) return; GsdMediaKeysManager *manager = user_data; g_ptr_array_set_size (manager->priv->keys, 0); g_clear_object (&manager->priv->key_grabber); g_clear_object (&manager->priv->shell_proxy); } static void start_legacy_grabber (GDBusConnection *connection, const char *name, const char *name_owner, gpointer user_data) { GsdMediaKeysManager *manager = user_data; GSList *l; if (session_has_key_grabber ()) return; manager->priv->have_legacy_keygrabber = TRUE; g_debug ("start_legacy_grabber"); if (manager->priv->keys == NULL) return; if (!name_owner) return; init_screens (manager); init_kbd (manager); /* Start filtering the events */ for (l = manager->priv->screens; l != NULL; l = l->next) { gnome_settings_profile_start ("gdk_window_add_filter"); g_debug ("adding key filter for screen: %d", gdk_screen_get_number (l->data)); gdk_window_add_filter (gdk_screen_get_root_window (l->data), (GdkFilterFunc) filter_key_events, manager); gnome_settings_profile_end ("gdk_window_add_filter"); } } static void stop_legacy_grabber (GDBusConnection *connection, const char *name, gpointer user_data) { GsdMediaKeysManager *manager = user_data; if (session_has_key_grabber ()) return; manager->priv->have_legacy_keygrabber = FALSE; g_ptr_array_set_size (manager->priv->keys, 0); } static gboolean start_media_keys_idle_cb (GsdMediaKeysManager *manager) { const gchar *module; g_debug ("Starting media_keys manager"); gnome_settings_profile_start (NULL); module = g_getenv (ENV_GTK_IM_MODULE); #ifdef HAVE_IBUS manager->priv->is_ibus_active = g_strcmp0 (module, GTK_IM_MODULE_IBUS) == 0; #endif #ifdef HAVE_FCITX manager->priv->is_fcitx_active = g_strcmp0 (module, GTK_IM_MODULE_FCITX) == 0; if (manager->priv->is_fcitx_active) { GError *error = NULL; manager->priv->fcitx = fcitx_input_method_new (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, 0, NULL, &error); if (!manager->priv->fcitx) { g_warning ("Fcitx connection unavailable: %s", error->message); g_error_free (error); } } #endif manager->priv->keys = g_ptr_array_new_with_free_func ((GDestroyNotify) media_key_free); initialize_volume_handler (manager); manager->priv->settings = g_settings_new (SETTINGS_BINDING_DIR); g_signal_connect (G_OBJECT (manager->priv->settings), "changed", G_CALLBACK (gsettings_changed_cb), manager); g_signal_connect (G_OBJECT (manager->priv->settings), "changed::custom-keybindings", G_CALLBACK (gsettings_custom_changed_cb), manager); manager->priv->input_settings = g_settings_new (INPUT_SETTINGS_BINDING_DIR); g_signal_connect (G_OBJECT (manager->priv->input_settings), "changed", G_CALLBACK (gsettings_changed_cb), manager); g_signal_connect (G_OBJECT (manager->priv->input_settings), "changed::custom-keybindings", G_CALLBACK (gsettings_custom_changed_cb), manager); manager->priv->custom_settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); manager->priv->sound_settings = g_settings_new ("com.ubuntu.sound"); /* for the power plugin interface code */ manager->priv->power_settings = g_settings_new (SETTINGS_POWER_DIR); /* Logic from http://git.gnome.org/browse/gnome-shell/tree/js/ui/status/accessibility.js#n163 */ manager->priv->interface_settings = g_settings_new (SETTINGS_INTERFACE_DIR); g_signal_connect (G_OBJECT (manager->priv->interface_settings), "changed::gtk-theme", G_CALLBACK (update_theme_settings), manager); g_signal_connect (G_OBJECT (manager->priv->interface_settings), "changed::icon-theme", G_CALLBACK (update_theme_settings), manager); manager->priv->gtk_theme = g_settings_get_string (manager->priv->interface_settings, "gtk-theme"); if (g_str_equal (manager->priv->gtk_theme, HIGH_CONTRAST)) { g_free (manager->priv->gtk_theme); manager->priv->gtk_theme = NULL; } manager->priv->icon_theme = g_settings_get_string (manager->priv->interface_settings, "icon-theme"); ensure_cancellable (&manager->priv->grab_cancellable); ensure_cancellable (&manager->priv->shell_cancellable); manager->priv->name_owner_id = g_bus_watch_name (G_BUS_TYPE_SESSION, SHELL_DBUS_NAME, 0, on_shell_appeared, on_shell_vanished, manager, NULL); manager->priv->unity_name_owner_id = g_bus_watch_name (G_BUS_TYPE_SESSION, UNITY_DBUS_NAME, 0, start_legacy_grabber, stop_legacy_grabber, manager, NULL); manager->priv->panel_name_owner_id = g_bus_watch_name (G_BUS_TYPE_SESSION, PANEL_DBUS_NAME, 0, start_legacy_grabber, stop_legacy_grabber, manager, NULL); gnome_settings_profile_end (NULL); manager->priv->start_idle_id = 0; return FALSE; } gboolean gsd_media_keys_manager_start (GsdMediaKeysManager *manager, GError **error) { const char * const subsystems[] = { "input", "usb", "sound", NULL }; gnome_settings_profile_start (NULL); if (supports_xinput2_devices (&manager->priv->opcode) == FALSE) { g_debug ("No Xinput2 support, disabling plugin"); return TRUE; } #ifdef HAVE_GUDEV manager->priv->streams = g_hash_table_new (g_direct_hash, g_direct_equal); manager->priv->udev_client = g_udev_client_new (subsystems); #endif manager->priv->start_idle_id = g_idle_add ((GSourceFunc) start_media_keys_idle_cb, manager); register_manager (manager_object); gnome_settings_profile_end (NULL); return TRUE; } void gsd_media_keys_manager_stop (GsdMediaKeysManager *manager) { GsdMediaKeysManagerPrivate *priv = manager->priv; GSList *ls; int i; g_debug ("Stopping media_keys manager"); if (priv->bus_cancellable != NULL) { g_cancellable_cancel (priv->bus_cancellable); g_object_unref (priv->bus_cancellable); priv->bus_cancellable = NULL; } if (manager->priv->have_legacy_keygrabber){ for (ls = priv->screens; ls != NULL; ls = ls->next) { gdk_window_remove_filter (gdk_screen_get_root_window (ls->data), (GdkFilterFunc) filter_key_events, manager); } } if (manager->priv->gtksettings != NULL) { g_signal_handlers_disconnect_by_func (manager->priv->gtksettings, sound_theme_changed, manager); manager->priv->gtksettings = NULL; } g_clear_pointer (&manager->priv->ca, ca_context_destroy); #ifdef HAVE_GUDEV g_clear_pointer (&priv->streams, g_hash_table_destroy); g_clear_object (&priv->udev_client); #endif /* HAVE_GUDEV */ g_clear_object (&priv->logind_proxy); g_clear_object (&priv->settings); g_clear_object (&priv->input_settings); g_clear_object (&priv->power_settings); g_clear_object (&priv->power_proxy); g_clear_object (&priv->power_screen_proxy); g_clear_object (&priv->power_keyboard_proxy); g_clear_object (&priv->sound_settings); if (manager->priv->name_owner_id) { g_bus_unwatch_name (manager->priv->name_owner_id); manager->priv->name_owner_id = 0; } if (manager->priv->unity_name_owner_id) { g_bus_unwatch_name (manager->priv->unity_name_owner_id); manager->priv->unity_name_owner_id = 0; } if (manager->priv->panel_name_owner_id) { g_bus_unwatch_name (manager->priv->panel_name_owner_id); manager->priv->panel_name_owner_id = 0; } if (priv->cancellable != NULL) { g_cancellable_cancel (priv->cancellable); g_clear_object (&priv->cancellable); } g_clear_pointer (&priv->introspection_data, g_dbus_node_info_unref); g_clear_object (&priv->connection); if (priv->volume_notification != NULL) { notify_notification_close (priv->volume_notification, NULL); g_object_unref (priv->volume_notification); priv->volume_notification = NULL; } if (priv->brightness_notification != NULL) { notify_notification_close (priv->brightness_notification, NULL); g_object_unref (priv->brightness_notification); priv->brightness_notification = NULL; } if (priv->kb_backlight_notification != NULL) { notify_notification_close (priv->kb_backlight_notification, NULL); g_object_unref (priv->kb_backlight_notification); priv->kb_backlight_notification = NULL; } if (priv->keys != NULL) { if (manager->priv->have_legacy_keygrabber) gdk_error_trap_push (); for (i = 0; i < priv->keys->len; ++i) { MediaKey *key; key = g_ptr_array_index (manager->priv->keys, i); if (manager->priv->have_legacy_keygrabber && key->key) ungrab_key_unsafe (key->key, priv->screens); else ungrab_media_key (key, manager); } g_ptr_array_free (priv->keys, TRUE); priv->keys = NULL; } if (manager->priv->have_legacy_keygrabber){ gdk_flush (); gdk_error_trap_pop_ignored (); } if (manager->priv->wdypi_pa_backend) { pa_backend_free (manager->priv->wdypi_pa_backend); manager->priv->wdypi_pa_backend = NULL; } wdypi_dialog_kill(); if (priv->grab_cancellable != NULL) { g_cancellable_cancel (priv->grab_cancellable); g_clear_object (&priv->grab_cancellable); } if (priv->shell_cancellable != NULL) { g_cancellable_cancel (priv->shell_cancellable); g_clear_object (&priv->shell_cancellable); } g_clear_pointer (&priv->screens, g_slist_free); g_clear_object (&priv->sink); g_clear_object (&priv->source); g_clear_object (&priv->volume); if (priv->media_players != NULL) { g_list_free_full (priv->media_players, (GDestroyNotify) free_media_player); priv->media_players = NULL; } } static GObject * gsd_media_keys_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { GsdMediaKeysManager *media_keys_manager; media_keys_manager = GSD_MEDIA_KEYS_MANAGER (G_OBJECT_CLASS (gsd_media_keys_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); return G_OBJECT (media_keys_manager); } static void gsd_media_keys_manager_class_init (GsdMediaKeysManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructor = gsd_media_keys_manager_constructor; object_class->finalize = gsd_media_keys_manager_finalize; g_type_class_add_private (klass, sizeof (GsdMediaKeysManagerPrivate)); } static void inhibit_done (GObject *source, GAsyncResult *result, gpointer user_data) { GDBusProxy *proxy = G_DBUS_PROXY (source); GsdMediaKeysManager *manager = GSD_MEDIA_KEYS_MANAGER (user_data); GError *error = NULL; GVariant *res; GUnixFDList *fd_list = NULL; gint idx; res = g_dbus_proxy_call_with_unix_fd_list_finish (proxy, &fd_list, result, &error); if (res == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Unable to inhibit keypresses: %s", error->message); g_error_free (error); } else { g_variant_get (res, "(h)", &idx); manager->priv->inhibit_keys_fd = g_unix_fd_list_get (fd_list, idx, &error); if (manager->priv->inhibit_keys_fd == -1) { g_warning ("Failed to receive system inhibitor fd: %s", error->message); g_error_free (error); } g_debug ("System inhibitor fd is %d", manager->priv->inhibit_keys_fd); g_object_unref (fd_list); g_variant_unref (res); } } static void gsd_media_keys_manager_init (GsdMediaKeysManager *manager) { GError *error; GDBusConnection *bus; error = NULL; manager->priv = GSD_MEDIA_KEYS_MANAGER_GET_PRIVATE (manager); bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (bus == NULL) { g_warning ("Failed to connect to system bus: %s", error->message); g_error_free (error); return; } manager->priv->logind_proxy = g_dbus_proxy_new_sync (bus, 0, NULL, SYSTEMD_DBUS_NAME, SYSTEMD_DBUS_PATH, SYSTEMD_DBUS_INTERFACE, NULL, &error); if (manager->priv->logind_proxy == NULL) { g_warning ("Failed to connect to systemd: %s", error->message); g_error_free (error); } g_object_unref (bus); g_debug ("Adding system inhibitors for power keys"); manager->priv->inhibit_keys_fd = -1; g_dbus_proxy_call_with_unix_fd_list (manager->priv->logind_proxy, "Inhibit", g_variant_new ("(ssss)", "handle-power-key:handle-suspend-key:handle-hibernate-key", g_get_user_name (), "GNOME handling keypresses", "block"), 0, G_MAXINT, NULL, NULL, inhibit_done, manager); } static void gsd_media_keys_manager_finalize (GObject *object) { GsdMediaKeysManager *media_keys_manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_MEDIA_KEYS_MANAGER (object)); media_keys_manager = GSD_MEDIA_KEYS_MANAGER (object); g_return_if_fail (media_keys_manager->priv != NULL); if (media_keys_manager->priv->start_idle_id != 0) g_source_remove (media_keys_manager->priv->start_idle_id); if (media_keys_manager->priv->inhibit_keys_fd != -1) close (media_keys_manager->priv->inhibit_keys_fd); g_clear_object (&media_keys_manager->priv->screen_saver_proxy); G_OBJECT_CLASS (gsd_media_keys_manager_parent_class)->finalize (object); } static void xrandr_ready_cb (GObject *source_object, GAsyncResult *res, GsdMediaKeysManager *manager) { GError *error = NULL; manager->priv->xrandr_proxy = g_dbus_proxy_new_finish (res, &error); if (manager->priv->xrandr_proxy == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to get proxy for XRandR operations: %s", error->message); g_error_free (error); } } static void power_ready_cb (GObject *source_object, GAsyncResult *res, GsdMediaKeysManager *manager) { GError *error = NULL; manager->priv->power_proxy = g_dbus_proxy_new_finish (res, &error); if (manager->priv->power_proxy == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to get proxy for power: %s", error->message); g_error_free (error); } } static void power_screen_ready_cb (GObject *source_object, GAsyncResult *res, GsdMediaKeysManager *manager) { GError *error = NULL; manager->priv->power_screen_proxy = g_dbus_proxy_new_finish (res, &error); if (manager->priv->power_screen_proxy == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to get proxy for power (screen): %s", error->message); g_error_free (error); } } static void power_keyboard_ready_cb (GObject *source_object, GAsyncResult *res, GsdMediaKeysManager *manager) { GError *error = NULL; manager->priv->power_keyboard_proxy = g_dbus_proxy_new_finish (res, &error); if (manager->priv->power_keyboard_proxy == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to get proxy for power (keyboard): %s", error->message); g_error_free (error); } } static void on_bus_gotten (GObject *source_object, GAsyncResult *res, GsdMediaKeysManager *manager) { GDBusConnection *connection; GError *error = NULL; connection = g_bus_get_finish (res, &error); if (connection == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Could not get session bus: %s", error->message); g_error_free (error); return; } manager->priv->connection = connection; g_dbus_connection_register_object (connection, GSD_MEDIA_KEYS_DBUS_PATH, manager->priv->introspection_data->interfaces[0], &interface_vtable, manager, NULL, NULL); g_dbus_proxy_new (manager->priv->connection, G_DBUS_PROXY_FLAGS_NONE, NULL, GSD_DBUS_NAME ".XRANDR", GSD_DBUS_PATH "/XRANDR", GSD_DBUS_BASE_INTERFACE ".XRANDR_2", NULL, (GAsyncReadyCallback) xrandr_ready_cb, manager); g_dbus_proxy_new (manager->priv->connection, G_DBUS_PROXY_FLAGS_NONE, NULL, GSD_DBUS_NAME ".Power", GSD_DBUS_PATH "/Power", GSD_DBUS_BASE_INTERFACE ".Power", NULL, (GAsyncReadyCallback) power_ready_cb, manager); g_dbus_proxy_new (manager->priv->connection, G_DBUS_PROXY_FLAGS_NONE, NULL, GSD_DBUS_NAME ".Power", GSD_DBUS_PATH "/Power", GSD_DBUS_BASE_INTERFACE ".Power.Screen", NULL, (GAsyncReadyCallback) power_screen_ready_cb, manager); g_dbus_proxy_new (manager->priv->connection, G_DBUS_PROXY_FLAGS_NONE, NULL, GSD_DBUS_NAME ".Power", GSD_DBUS_PATH "/Power", GSD_DBUS_BASE_INTERFACE ".Power.Keyboard", NULL, (GAsyncReadyCallback) power_keyboard_ready_cb, manager); } static void register_manager (GsdMediaKeysManager *manager) { manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); manager->priv->bus_cancellable = g_cancellable_new (); g_assert (manager->priv->introspection_data != NULL); g_bus_get (G_BUS_TYPE_SESSION, manager->priv->bus_cancellable, (GAsyncReadyCallback) on_bus_gotten, manager); } GsdMediaKeysManager * gsd_media_keys_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_MEDIA_KEYS_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_MEDIA_KEYS_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gsd-media-keys-manager.h0000664000175000017500000000522400000000000027136 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_MEDIA_KEYS_MANAGER_H #define __GSD_MEDIA_KEYS_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_MEDIA_KEYS_MANAGER (gsd_media_keys_manager_get_type ()) #define GSD_MEDIA_KEYS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_MEDIA_KEYS_MANAGER, GsdMediaKeysManager)) #define GSD_MEDIA_KEYS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_MEDIA_KEYS_MANAGER, GsdMediaKeysManagerClass)) #define GSD_IS_MEDIA_KEYS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_MEDIA_KEYS_MANAGER)) #define GSD_IS_MEDIA_KEYS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_MEDIA_KEYS_MANAGER)) #define GSD_MEDIA_KEYS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_MEDIA_KEYS_MANAGER, GsdMediaKeysManagerClass)) typedef struct GsdMediaKeysManagerPrivate GsdMediaKeysManagerPrivate; typedef struct { GObject parent; GsdMediaKeysManagerPrivate *priv; } GsdMediaKeysManager; typedef struct { GObjectClass parent_class; void (* media_player_key_pressed) (GsdMediaKeysManager *manager, const char *application, const char *key); } GsdMediaKeysManagerClass; GType gsd_media_keys_manager_get_type (void); GsdMediaKeysManager * gsd_media_keys_manager_new (void); gboolean gsd_media_keys_manager_start (GsdMediaKeysManager *manager, GError **error); void gsd_media_keys_manager_stop (GsdMediaKeysManager *manager); G_END_DECLS #endif /* __GSD_MEDIA_KEYS_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gsd-media-keys-plugin.c0000664000175000017500000000203300000000000027010 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-media-keys-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdMediaKeys, gsd_media_keys) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gsd-screenshot-utils.c0000664000175000017500000002314500000000000027006 0ustar00jeremyjeremy/* gsd-screenshot-utils.c - utilities to take screenshots * * Copyright (C) 2012 Red Hat, Inc. * * Adapted from gnome-screenshot code, which is * Copyright (C) 2001-2006 Jonathan Blandford * Copyright (C) 2006 Emmanuele Bassi * Copyright (C) 2008-2012 Cosimo Cecchi * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ #include #include #include #include #include #include #include #include "gsd-screenshot-utils.h" #define SHELL_SCREENSHOT_BUS_NAME "org.gnome.Shell" #define SHELL_SCREENSHOT_BUS_PATH "/org/gnome/Shell/Screenshot" #define SHELL_SCREENSHOT_BUS_IFACE "org.gnome.Shell.Screenshot" typedef enum { SCREENSHOT_TYPE_SCREEN, SCREENSHOT_TYPE_WINDOW, SCREENSHOT_TYPE_AREA } ScreenshotType; typedef struct { ScreenshotType type; gboolean copy_to_clipboard; GdkRectangle area_selection; gchar *save_filename; gchar *used_filename; GDBusConnection *connection; } ScreenshotContext; static void screenshot_play_sound_effect (const gchar *event_id, const gchar *event_desc) { ca_context *c; c = ca_gtk_context_get (); ca_context_play (c, 0, CA_PROP_EVENT_ID, event_id, CA_PROP_EVENT_DESCRIPTION, event_desc, CA_PROP_CANBERRA_CACHE_CONTROL, "permanent", NULL); } static void screenshot_context_free (ScreenshotContext *ctx) { g_free (ctx->save_filename); g_free (ctx->used_filename); g_clear_object (&ctx->connection); g_slice_free (ScreenshotContext, ctx); } static void screenshot_context_error (ScreenshotContext *ctx, GError *error, const gchar *warning_format) { screenshot_play_sound_effect ("dialog-error", _("Unable to capture a screenshot")); g_warning (warning_format, error->message); g_error_free (error); } static void screenshot_save_to_recent (ScreenshotContext *ctx) { GFile *file = g_file_new_for_path (ctx->used_filename); gchar *uri = g_file_get_uri (file); gtk_recent_manager_add_item (gtk_recent_manager_get_default (), uri); g_free (uri); g_object_unref (file); } static void screenshot_save_to_clipboard (ScreenshotContext *ctx) { GdkPixbuf *screenshot; GtkClipboard *clipboard; GError *error = NULL; screenshot = gdk_pixbuf_new_from_file (ctx->used_filename, &error); if (error != NULL) { screenshot_context_error (ctx, error, "Failed to save a screenshot to clipboard: %s\n"); return; } screenshot_play_sound_effect ("screen-capture", _("Screenshot taken")); clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (), GDK_SELECTION_CLIPBOARD); gtk_clipboard_set_image (clipboard, screenshot); /* remove the temporary file created by the shell */ g_unlink (ctx->used_filename); g_object_unref (screenshot); } static void bus_call_ready_cb (GObject *source, GAsyncResult *res, gpointer user_data) { GError *error = NULL; ScreenshotContext *ctx = user_data; GVariant *variant; gboolean success; variant = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error); if (error != NULL) { screenshot_context_error (ctx, error, "Failed to save a screenshot: %s\n"); screenshot_context_free (ctx); return; } g_variant_get (variant, "(bs)", &success, &ctx->used_filename); if (success) { if (ctx->copy_to_clipboard) { screenshot_save_to_clipboard (ctx); } else { screenshot_play_sound_effect ("screen-capture", _("Screenshot taken")); screenshot_save_to_recent (ctx); } } screenshot_context_free (ctx); g_variant_unref (variant); } static void screenshot_call_shell (ScreenshotContext *ctx) { const gchar *method_name; GVariant *method_params; if (ctx->type == SCREENSHOT_TYPE_SCREEN) { method_name = "Screenshot"; method_params = g_variant_new ("(bbs)", FALSE, /* include pointer */ TRUE, /* flash */ ctx->save_filename); } else if (ctx->type == SCREENSHOT_TYPE_WINDOW) { method_name = "ScreenshotWindow"; method_params = g_variant_new ("(bbbs)", TRUE, /* include border */ FALSE, /* include pointer */ TRUE, /* flash */ ctx->save_filename); } else { method_name = "ScreenshotArea"; method_params = g_variant_new ("(iiiibs)", ctx->area_selection.x, ctx->area_selection.y, ctx->area_selection.width, ctx->area_selection.height, TRUE, /* flash */ ctx->save_filename); } g_dbus_connection_call (ctx->connection, SHELL_SCREENSHOT_BUS_NAME, SHELL_SCREENSHOT_BUS_PATH, SHELL_SCREENSHOT_BUS_IFACE, method_name, method_params, NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, bus_call_ready_cb, ctx); } static void area_selection_ready_cb (GObject *source, GAsyncResult *res, gpointer user_data) { GdkRectangle rectangle; ScreenshotContext *ctx = user_data; GVariant *geometry; geometry = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, NULL); /* cancelled by the user */ if (!geometry) { screenshot_context_free (ctx); return; } g_variant_get (geometry, "(iiii)", &rectangle.x, &rectangle.y, &rectangle.width, &rectangle.height); ctx->area_selection = rectangle; screenshot_call_shell (ctx); g_variant_unref (geometry); } static void bus_connection_ready_cb (GObject *source, GAsyncResult *res, gpointer user_data) { GError *error = NULL; ScreenshotContext *ctx = user_data; ctx->connection = g_bus_get_finish (res, &error); if (error != NULL) { screenshot_context_error (ctx, error, "Failed to save a screenshot: %s\n"); screenshot_context_free (ctx); return; } if (ctx->type == SCREENSHOT_TYPE_AREA) g_dbus_connection_call (ctx->connection, SHELL_SCREENSHOT_BUS_NAME, SHELL_SCREENSHOT_BUS_PATH, SHELL_SCREENSHOT_BUS_IFACE, "SelectArea", NULL, NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, area_selection_ready_cb, ctx); else screenshot_call_shell (ctx); } static void screenshot_take (ScreenshotContext *ctx) { g_bus_get (G_BUS_TYPE_SESSION, NULL, bus_connection_ready_cb, ctx); } static gchar * screenshot_build_tmp_path (void) { gchar *path; gint fd; fd = g_file_open_tmp ("gnome-settings-daemon-screenshot-XXXXXX", &path, NULL); close (fd); return path; } static gchar * screenshot_build_filename (void) { char *file_name, *origin; GDateTime *d; d = g_date_time_new_now_local (); origin = g_date_time_format (d, "%Y-%m-%d %H:%M:%S"); g_date_time_unref (d); /* translators: this is the name of the file that gets made up * with the screenshot */ file_name = g_strdup_printf (_("Screenshot from %s"), origin); g_free (origin); return file_name; } static void screenshot_check_name_ready (ScreenshotContext *ctx) { if (ctx->copy_to_clipboard) ctx->save_filename = screenshot_build_tmp_path (); else ctx->save_filename = screenshot_build_filename (); screenshot_take (ctx); } void gsd_screenshot_take (MediaKeyType key_type) { ScreenshotContext *ctx = g_slice_new0 (ScreenshotContext); ctx->copy_to_clipboard = (key_type == SCREENSHOT_CLIP_KEY || key_type == WINDOW_SCREENSHOT_CLIP_KEY || key_type == AREA_SCREENSHOT_CLIP_KEY); switch (key_type) { case SCREENSHOT_KEY: case SCREENSHOT_CLIP_KEY: ctx->type = SCREENSHOT_TYPE_SCREEN; break; case WINDOW_SCREENSHOT_KEY: case WINDOW_SCREENSHOT_CLIP_KEY: ctx->type = SCREENSHOT_TYPE_WINDOW; break; case AREA_SCREENSHOT_KEY: case AREA_SCREENSHOT_CLIP_KEY: ctx->type = SCREENSHOT_TYPE_AREA; break; default: g_assert_not_reached (); break; } screenshot_check_name_ready (ctx); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gsd-screenshot-utils.h0000664000175000017500000000234300000000000027010 0ustar00jeremyjeremy/* gsd-screenshot-utils.h - utilities to take screenshots * * Copyright (C) 2012 Red Hat, Inc. * * Adapted from gnome-screenshot code, which is * Copyright (C) 2001-2006 Jonathan Blandford * Copyright (C) 2006 Emmanuele Bassi * Copyright (C) 2008-2012 Cosimo Cecchi * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ #ifndef __GSD_SCREENSHOT_UTILS_H__ #define __GSD_SCREENSHOT_UTILS_H__ #include "shortcuts-list.h" G_BEGIN_DECLS void gsd_screenshot_take (MediaKeyType key_type); G_END_DECLS #endif /* __GSD_SCREENSHOT_UTILS_H__ */ ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1644246191.587767 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/0000775000175000017500000000000000000000000023326 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/Makefile.am0000664000175000017500000000266300000000000025371 0ustar00jeremyjeremy noinst_LTLIBRARIES = libgvc.la INTROSPECTION_SCANNER_ARGS = --warn-all libgvc_la_CPPFLAGS = \ $(WARN_CFLAGS) \ $(GVC_CFLAGS) \ -I$(srcdir) \ -DWITH_INTROSPECTION \ -DG_LOG_DOMAIN="\"Gvc\"" libgvc_la_gir_sources = \ gvc-mixer-card.h \ gvc-mixer-card.c \ gvc-mixer-stream.h \ gvc-mixer-stream.c \ gvc-channel-map.h \ gvc-channel-map.c \ gvc-mixer-ui-device.h \ gvc-mixer-ui-device.c \ gvc-mixer-sink.h \ gvc-mixer-sink.c \ gvc-mixer-source.h \ gvc-mixer-source.c \ gvc-mixer-sink-input.h \ gvc-mixer-sink-input.c \ gvc-mixer-source-output.h \ gvc-mixer-source-output.c \ gvc-mixer-event-role.h \ gvc-mixer-event-role.c \ gvc-mixer-control.h \ gvc-mixer-control.c \ $(NULL) libgvc_la_SOURCES = \ $(libgvc_la_gir_sources) \ gvc-mixer-card-private.h \ gvc-mixer-stream-private.h \ gvc-channel-map-private.h \ gvc-mixer-control-private.h \ gvc-pulseaudio-fake.h \ $(NULL) libgvc_la_LIBADD = \ $(GVC_LIBS) \ $(NULL) if HAVE_INTROSPECTION include $(INTROSPECTION_MAKEFILE) Gvc-1.0.gir: libgvc.la Gvc_1_0_gir_INCLUDES = GObject-2.0 Gio-2.0 Gvc_1_0_gir_CFLAGS = $(INCLUDES) -I$(srcdir) -DWITH_INTROSPECTION Gvc_1_0_gir_LIBS = libgvc.la Gvc_1_0_gir_FILES = $(addprefix $(srcdir)/,$(libgvc_la_gir_sources)) INTROSPECTION_GIRS = Gvc-1.0.gir typelibdir = $(pkglibdir) typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) CLEANFILES = Gvc-1.0.gir $(typelib_DATA) endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-channel-map-private.h0000664000175000017500000000305600000000000030113 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_CHANNEL_MAP_PRIVATE_H #define __GVC_CHANNEL_MAP_PRIVATE_H #include #include G_BEGIN_DECLS GvcChannelMap * gvc_channel_map_new_from_pa_channel_map (const pa_channel_map *map); const pa_channel_map * gvc_channel_map_get_pa_channel_map (const GvcChannelMap *map); void gvc_channel_map_volume_changed (GvcChannelMap *map, const pa_cvolume *cv, gboolean set); const pa_cvolume * gvc_channel_map_get_cvolume (const GvcChannelMap *map); G_END_DECLS #endif /* __GVC_CHANNEL_MAP_PRIVATE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-channel-map.c0000664000175000017500000001661400000000000026442 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include "gvc-channel-map.h" #include "gvc-channel-map-private.h" #define GVC_CHANNEL_MAP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_CHANNEL_MAP, GvcChannelMapPrivate)) struct GvcChannelMapPrivate { pa_channel_map pa_map; gboolean pa_volume_is_set; pa_cvolume pa_volume; gdouble extern_volume[NUM_TYPES]; /* volume, balance, fade, lfe */ gboolean can_balance; gboolean can_fade; }; enum { VOLUME_CHANGED, LAST_SIGNAL }; static guint signals [LAST_SIGNAL] = { 0, }; static void gvc_channel_map_class_init (GvcChannelMapClass *klass); static void gvc_channel_map_init (GvcChannelMap *channel_map); static void gvc_channel_map_finalize (GObject *object); G_DEFINE_TYPE (GvcChannelMap, gvc_channel_map, G_TYPE_OBJECT) guint gvc_channel_map_get_num_channels (const GvcChannelMap *map) { g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), 0); if (!pa_channel_map_valid(&map->priv->pa_map)) return 0; return map->priv->pa_map.channels; } const gdouble * gvc_channel_map_get_volume (GvcChannelMap *map) { g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL); if (!pa_channel_map_valid(&map->priv->pa_map)) return NULL; map->priv->extern_volume[VOLUME] = (gdouble) pa_cvolume_max (&map->priv->pa_volume); if (gvc_channel_map_can_balance (map)) map->priv->extern_volume[BALANCE] = (gdouble) pa_cvolume_get_balance (&map->priv->pa_volume, &map->priv->pa_map); else map->priv->extern_volume[BALANCE] = 0; if (gvc_channel_map_can_fade (map)) map->priv->extern_volume[FADE] = (gdouble) pa_cvolume_get_fade (&map->priv->pa_volume, &map->priv->pa_map); else map->priv->extern_volume[FADE] = 0; if (gvc_channel_map_has_lfe (map)) map->priv->extern_volume[LFE] = (gdouble) pa_cvolume_get_position (&map->priv->pa_volume, &map->priv->pa_map, PA_CHANNEL_POSITION_LFE); else map->priv->extern_volume[LFE] = 0; return map->priv->extern_volume; } gboolean gvc_channel_map_can_balance (const GvcChannelMap *map) { g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE); return map->priv->can_balance; } gboolean gvc_channel_map_can_fade (const GvcChannelMap *map) { g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE); return map->priv->can_fade; } const char * gvc_channel_map_get_mapping (const GvcChannelMap *map) { g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL); if (!pa_channel_map_valid(&map->priv->pa_map)) return NULL; return pa_channel_map_to_pretty_name (&map->priv->pa_map); } /** * gvc_channel_map_has_position: (skip) * @map: * @position: * * Returns: */ gboolean gvc_channel_map_has_position (const GvcChannelMap *map, pa_channel_position_t position) { g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), FALSE); return pa_channel_map_has_position (&(map->priv->pa_map), position); } const pa_channel_map * gvc_channel_map_get_pa_channel_map (const GvcChannelMap *map) { g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL); if (!pa_channel_map_valid(&map->priv->pa_map)) return NULL; return &map->priv->pa_map; } const pa_cvolume * gvc_channel_map_get_cvolume (const GvcChannelMap *map) { g_return_val_if_fail (GVC_IS_CHANNEL_MAP (map), NULL); if (!pa_channel_map_valid(&map->priv->pa_map)) return NULL; return &map->priv->pa_volume; } static void gvc_channel_map_class_init (GvcChannelMapClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = gvc_channel_map_finalize; signals [VOLUME_CHANGED] = g_signal_new ("volume-changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcChannelMapClass, volume_changed), NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN); g_type_class_add_private (klass, sizeof (GvcChannelMapPrivate)); } void gvc_channel_map_volume_changed (GvcChannelMap *map, const pa_cvolume *cv, gboolean set) { g_return_if_fail (GVC_IS_CHANNEL_MAP (map)); g_return_if_fail (cv != NULL); g_return_if_fail (pa_cvolume_compatible_with_channel_map(cv, &map->priv->pa_map)); if (pa_cvolume_equal(cv, &map->priv->pa_volume)) return; map->priv->pa_volume = *cv; if (map->priv->pa_volume_is_set == FALSE) { map->priv->pa_volume_is_set = TRUE; return; } g_signal_emit (map, signals[VOLUME_CHANGED], 0, set); } static void gvc_channel_map_init (GvcChannelMap *map) { map->priv = GVC_CHANNEL_MAP_GET_PRIVATE (map); map->priv->pa_volume_is_set = FALSE; } static void gvc_channel_map_finalize (GObject *object) { GvcChannelMap *channel_map; g_return_if_fail (object != NULL); g_return_if_fail (GVC_IS_CHANNEL_MAP (object)); channel_map = GVC_CHANNEL_MAP (object); g_return_if_fail (channel_map->priv != NULL); G_OBJECT_CLASS (gvc_channel_map_parent_class)->finalize (object); } GvcChannelMap * gvc_channel_map_new (void) { GObject *map; map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL); return GVC_CHANNEL_MAP (map); } static void set_from_pa_map (GvcChannelMap *map, const pa_channel_map *pa_map) { g_assert (pa_channel_map_valid(pa_map)); map->priv->can_balance = pa_channel_map_can_balance (pa_map); map->priv->can_fade = pa_channel_map_can_fade (pa_map); map->priv->pa_map = *pa_map; pa_cvolume_set(&map->priv->pa_volume, pa_map->channels, PA_VOLUME_NORM); } GvcChannelMap * gvc_channel_map_new_from_pa_channel_map (const pa_channel_map *pa_map) { GObject *map; map = g_object_new (GVC_TYPE_CHANNEL_MAP, NULL); set_from_pa_map (GVC_CHANNEL_MAP (map), pa_map); return GVC_CHANNEL_MAP (map); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-channel-map.h0000664000175000017500000000557000000000000026446 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_CHANNEL_MAP_H #define __GVC_CHANNEL_MAP_H #include #include G_BEGIN_DECLS #define GVC_TYPE_CHANNEL_MAP (gvc_channel_map_get_type ()) #define GVC_CHANNEL_MAP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_CHANNEL_MAP, GvcChannelMap)) #define GVC_CHANNEL_MAP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_CHANNEL_MAP, GvcChannelMapClass)) #define GVC_IS_CHANNEL_MAP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_CHANNEL_MAP)) #define GVC_IS_CHANNEL_MAP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_CHANNEL_MAP)) #define GVC_CHANNEL_MAP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_CHANNEL_MAP, GvcChannelMapClass)) typedef struct GvcChannelMapPrivate GvcChannelMapPrivate; typedef struct { GObject parent; GvcChannelMapPrivate *priv; } GvcChannelMap; typedef struct { GObjectClass parent_class; void (*volume_changed) (GvcChannelMap *channel_map, gboolean set); } GvcChannelMapClass; enum { VOLUME, BALANCE, FADE, LFE, NUM_TYPES }; GType gvc_channel_map_get_type (void); GvcChannelMap * gvc_channel_map_new (void); guint gvc_channel_map_get_num_channels (const GvcChannelMap *map); const gdouble * gvc_channel_map_get_volume (GvcChannelMap *map); gboolean gvc_channel_map_can_balance (const GvcChannelMap *map); gboolean gvc_channel_map_can_fade (const GvcChannelMap *map); gboolean gvc_channel_map_has_position (const GvcChannelMap *map, pa_channel_position_t position); #define gvc_channel_map_has_lfe(x) gvc_channel_map_has_position (x, PA_CHANNEL_POSITION_LFE) const char * gvc_channel_map_get_mapping (const GvcChannelMap *map); G_END_DECLS #endif /* __GVC_CHANNEL_MAP_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-card-private.h0000664000175000017500000000237500000000000027766 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008-2009 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_MIXER_CARD_PRIVATE_H #define __GVC_MIXER_CARD_PRIVATE_H #include #include "gvc-mixer-card.h" G_BEGIN_DECLS GvcMixerCard * gvc_mixer_card_new (pa_context *context, guint index); pa_context * gvc_mixer_card_get_pa_context (GvcMixerCard *card); G_END_DECLS #endif /* __GVC_MIXER_CARD_PRIVATE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-card.c0000664000175000017500000004463000000000000026311 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 William Jon McCann * Copyright (C) 2009 Bastien Nocera * Copyright (C) Conor Curran 2011 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include "gvc-mixer-card.h" #include "gvc-mixer-card-private.h" #define GVC_MIXER_CARD_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_CARD, GvcMixerCardPrivate)) static guint32 card_serial = 1; struct GvcMixerCardPrivate { pa_context *pa_context; guint id; guint index; char *name; char *icon_name; char *profile; char *target_profile; char *human_profile; GList *profiles; pa_operation *profile_op; GList *ports; }; enum { PROP_0, PROP_ID, PROP_PA_CONTEXT, PROP_INDEX, PROP_NAME, PROP_ICON_NAME, PROP_PROFILE, PROP_HUMAN_PROFILE, }; static void gvc_mixer_card_class_init (GvcMixerCardClass *klass); static void gvc_mixer_card_init (GvcMixerCard *mixer_card); static void gvc_mixer_card_finalize (GObject *object); G_DEFINE_TYPE (GvcMixerCard, gvc_mixer_card, G_TYPE_OBJECT) static guint32 get_next_card_serial (void) { guint32 serial; serial = card_serial++; if ((gint32)card_serial < 0) { card_serial = 1; } return serial; } pa_context * gvc_mixer_card_get_pa_context (GvcMixerCard *card) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), 0); return card->priv->pa_context; } guint gvc_mixer_card_get_index (GvcMixerCard *card) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), 0); return card->priv->index; } guint gvc_mixer_card_get_id (GvcMixerCard *card) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), 0); return card->priv->id; } const char * gvc_mixer_card_get_name (GvcMixerCard *card) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL); return card->priv->name; } gboolean gvc_mixer_card_set_name (GvcMixerCard *card, const char *name) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE); g_free (card->priv->name); card->priv->name = g_strdup (name); g_object_notify (G_OBJECT (card), "name"); return TRUE; } const char * gvc_mixer_card_get_icon_name (GvcMixerCard *card) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL); return card->priv->icon_name; } gboolean gvc_mixer_card_set_icon_name (GvcMixerCard *card, const char *icon_name) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE); g_free (card->priv->icon_name); card->priv->icon_name = g_strdup (icon_name); g_object_notify (G_OBJECT (card), "icon-name"); return TRUE; } /** * gvc_mixer_card_get_profile: (skip) * @card: * * Returns: */ GvcMixerCardProfile * gvc_mixer_card_get_profile (GvcMixerCard *card) { GList *l; g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL); g_return_val_if_fail (card->priv->profiles != NULL, NULL); for (l = card->priv->profiles; l != NULL; l = l->next) { GvcMixerCardProfile *p = l->data; if (g_str_equal (card->priv->profile, p->profile)) { return p; } } g_assert_not_reached (); return NULL; } gboolean gvc_mixer_card_set_profile (GvcMixerCard *card, const char *profile) { GList *l; g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE); g_return_val_if_fail (card->priv->profiles != NULL, FALSE); g_free (card->priv->profile); card->priv->profile = g_strdup (profile); g_free (card->priv->human_profile); card->priv->human_profile = NULL; for (l = card->priv->profiles; l != NULL; l = l->next) { GvcMixerCardProfile *p = l->data; if (g_str_equal (card->priv->profile, p->profile)) { card->priv->human_profile = g_strdup (p->human_profile); break; } } g_object_notify (G_OBJECT (card), "profile"); return TRUE; } static void _pa_context_set_card_profile_by_index_cb (pa_context *context, int success, void *userdata) { GvcMixerCard *card = GVC_MIXER_CARD (userdata); g_assert (card->priv->target_profile); if (success > 0) { gvc_mixer_card_set_profile (card, card->priv->target_profile); } else { g_debug ("Failed to switch profile on '%s' from '%s' to '%s'", card->priv->name, card->priv->profile, card->priv->target_profile); } g_free (card->priv->target_profile); card->priv->target_profile = NULL; pa_operation_unref (card->priv->profile_op); card->priv->profile_op = NULL; } gboolean gvc_mixer_card_change_profile (GvcMixerCard *card, const char *profile) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE); g_return_val_if_fail (card->priv->profiles != NULL, FALSE); /* Same profile, or already requested? */ if (g_strcmp0 (card->priv->profile, profile) == 0) return TRUE; if (g_strcmp0 (profile, card->priv->target_profile) == 0) return TRUE; if (card->priv->profile_op != NULL) { pa_operation_cancel (card->priv->profile_op); pa_operation_unref (card->priv->profile_op); card->priv->profile_op = NULL; } if (card->priv->profile != NULL) { g_free (card->priv->target_profile); card->priv->target_profile = g_strdup (profile); card->priv->profile_op = pa_context_set_card_profile_by_index (card->priv->pa_context, card->priv->index, card->priv->target_profile, _pa_context_set_card_profile_by_index_cb, card); if (card->priv->profile_op == NULL) { g_warning ("pa_context_set_card_profile_by_index() failed"); return FALSE; } } else { g_assert (card->priv->human_profile == NULL); card->priv->profile = g_strdup (profile); } return TRUE; } /** * gvc_mixer_card_get_profiles: * * Return value: (transfer none) (element-type GvcMixerCardProfile): */ const GList * gvc_mixer_card_get_profiles (GvcMixerCard *card) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL); return card->priv->profiles; } /** * gvc_mixer_card_get_ports: * * Return value: (transfer none) (element-type GvcMixerCardPort): */ const GList * gvc_mixer_card_get_ports (GvcMixerCard *card) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL); return card->priv->ports; } /** * gvc_mixer_card_profile_compare: * * Return value: 1 if @a has a higher priority, -1 if @b has a higher * priority, 0 if @a and @b have the same priority. */ int gvc_mixer_card_profile_compare (GvcMixerCardProfile *a, GvcMixerCardProfile *b) { if (a->priority == b->priority) return 0; if (a->priority > b->priority) return 1; return -1; } /** * gvc_mixer_card_set_profiles: * @profiles: (transfer full) (element-type GvcMixerCardProfile): */ gboolean gvc_mixer_card_set_profiles (GvcMixerCard *card, GList *profiles) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE); g_return_val_if_fail (card->priv->profiles == NULL, FALSE); card->priv->profiles = g_list_sort (profiles, (GCompareFunc) gvc_mixer_card_profile_compare); return TRUE; } /** * gvc_mixer_card_get_gicon: * @card: * * Return value: (transfer full): */ GIcon * gvc_mixer_card_get_gicon (GvcMixerCard *card) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), NULL); if (card->priv->icon_name == NULL) return NULL; return g_themed_icon_new_with_default_fallbacks (card->priv->icon_name); } /** * gvc_mixer_card_set_ports: * @ports: (transfer full) (element-type GvcMixerCardPort): */ gboolean gvc_mixer_card_set_ports (GvcMixerCard *card, GList *ports) { g_return_val_if_fail (GVC_IS_MIXER_CARD (card), FALSE); g_return_val_if_fail (card->priv->ports == NULL, FALSE); card->priv->ports = ports; return TRUE; } static void gvc_mixer_card_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GvcMixerCard *self = GVC_MIXER_CARD (object); switch (prop_id) { case PROP_PA_CONTEXT: self->priv->pa_context = g_value_get_pointer (value); break; case PROP_INDEX: self->priv->index = g_value_get_ulong (value); break; case PROP_ID: self->priv->id = g_value_get_ulong (value); break; case PROP_NAME: gvc_mixer_card_set_name (self, g_value_get_string (value)); break; case PROP_ICON_NAME: gvc_mixer_card_set_icon_name (self, g_value_get_string (value)); break; case PROP_PROFILE: gvc_mixer_card_set_profile (self, g_value_get_string (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gvc_mixer_card_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GvcMixerCard *self = GVC_MIXER_CARD (object); switch (prop_id) { case PROP_PA_CONTEXT: g_value_set_pointer (value, self->priv->pa_context); break; case PROP_INDEX: g_value_set_ulong (value, self->priv->index); break; case PROP_ID: g_value_set_ulong (value, self->priv->id); break; case PROP_NAME: g_value_set_string (value, self->priv->name); break; case PROP_ICON_NAME: g_value_set_string (value, self->priv->icon_name); break; case PROP_PROFILE: g_value_set_string (value, self->priv->profile); break; case PROP_HUMAN_PROFILE: g_value_set_string (value, self->priv->human_profile); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static GObject * gvc_mixer_card_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_params) { GObject *object; GvcMixerCard *self; object = G_OBJECT_CLASS (gvc_mixer_card_parent_class)->constructor (type, n_construct_properties, construct_params); self = GVC_MIXER_CARD (object); self->priv->id = get_next_card_serial (); return object; } static void gvc_mixer_card_class_init (GvcMixerCardClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->constructor = gvc_mixer_card_constructor; gobject_class->finalize = gvc_mixer_card_finalize; gobject_class->set_property = gvc_mixer_card_set_property; gobject_class->get_property = gvc_mixer_card_get_property; g_object_class_install_property (gobject_class, PROP_INDEX, g_param_spec_ulong ("index", "Index", "The index for this card", 0, G_MAXULONG, 0, G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (gobject_class, PROP_ID, g_param_spec_ulong ("id", "id", "The id for this card", 0, G_MAXULONG, 0, G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (gobject_class, PROP_PA_CONTEXT, g_param_spec_pointer ("pa-context", "PulseAudio context", "The PulseAudio context for this card", G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (gobject_class, PROP_NAME, g_param_spec_string ("name", "Name", "Name to display for this card", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_ICON_NAME, g_param_spec_string ("icon-name", "Icon Name", "Name of icon to display for this card", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_PROFILE, g_param_spec_string ("profile", "Profile", "Name of current profile for this card", NULL, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_HUMAN_PROFILE, g_param_spec_string ("human-profile", "Profile (Human readable)", "Name of current profile for this card in human readable form", NULL, G_PARAM_READABLE)); g_type_class_add_private (klass, sizeof (GvcMixerCardPrivate)); } static void gvc_mixer_card_init (GvcMixerCard *card) { card->priv = GVC_MIXER_CARD_GET_PRIVATE (card); } GvcMixerCard * gvc_mixer_card_new (pa_context *context, guint index) { GObject *object; object = g_object_new (GVC_TYPE_MIXER_CARD, "index", index, "pa-context", context, NULL); return GVC_MIXER_CARD (object); } static void free_profile (GvcMixerCardProfile *p) { g_free (p->profile); g_free (p->human_profile); g_free (p->status); g_free (p); } static void gvc_mixer_card_finalize (GObject *object) { GvcMixerCard *mixer_card; g_return_if_fail (object != NULL); g_return_if_fail (GVC_IS_MIXER_CARD (object)); mixer_card = GVC_MIXER_CARD (object); g_return_if_fail (mixer_card->priv != NULL); g_free (mixer_card->priv->name); mixer_card->priv->name = NULL; g_free (mixer_card->priv->icon_name); mixer_card->priv->icon_name = NULL; g_free (mixer_card->priv->target_profile); mixer_card->priv->target_profile = NULL; g_free (mixer_card->priv->profile); mixer_card->priv->profile = NULL; g_free (mixer_card->priv->human_profile); mixer_card->priv->human_profile = NULL; g_list_foreach (mixer_card->priv->profiles, (GFunc) free_profile, NULL); g_list_free (mixer_card->priv->profiles); mixer_card->priv->profiles = NULL; G_OBJECT_CLASS (gvc_mixer_card_parent_class)->finalize (object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-card.h0000664000175000017500000000774200000000000026321 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008-2009 Red Hat, Inc. * Copyright (C) Conor Curran 2011 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_MIXER_CARD_H #define __GVC_MIXER_CARD_H #include #include G_BEGIN_DECLS #define GVC_TYPE_MIXER_CARD (gvc_mixer_card_get_type ()) #define GVC_MIXER_CARD(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_CARD, GvcMixerCard)) #define GVC_MIXER_CARD_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_CARD, GvcMixerCardClass)) #define GVC_IS_MIXER_CARD(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_CARD)) #define GVC_IS_MIXER_CARD_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_CARD)) #define GVC_MIXER_CARD_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_CARD, GvcMixerCardClass)) typedef struct GvcMixerCardPrivate GvcMixerCardPrivate; typedef struct { GObject parent; GvcMixerCardPrivate *priv; } GvcMixerCard; typedef struct { GObjectClass parent_class; /* vtable */ } GvcMixerCardClass; typedef struct { char *profile; char *human_profile; char *status; guint priority; guint n_sinks, n_sources; } GvcMixerCardProfile; typedef struct { char *port; char *human_port; guint priority; gint available; gint direction; GList *profiles; } GvcMixerCardPort; GType gvc_mixer_card_get_type (void); guint gvc_mixer_card_get_id (GvcMixerCard *card); guint gvc_mixer_card_get_index (GvcMixerCard *card); const char * gvc_mixer_card_get_name (GvcMixerCard *card); const char * gvc_mixer_card_get_icon_name (GvcMixerCard *card); GvcMixerCardProfile * gvc_mixer_card_get_profile (GvcMixerCard *card); const GList * gvc_mixer_card_get_profiles (GvcMixerCard *card); const GList * gvc_mixer_card_get_ports (GvcMixerCard *card); gboolean gvc_mixer_card_change_profile (GvcMixerCard *card, const char *profile); GIcon * gvc_mixer_card_get_gicon (GvcMixerCard *card); int gvc_mixer_card_profile_compare (GvcMixerCardProfile *a, GvcMixerCardProfile *b); /* private */ gboolean gvc_mixer_card_set_name (GvcMixerCard *card, const char *name); gboolean gvc_mixer_card_set_icon_name (GvcMixerCard *card, const char *name); gboolean gvc_mixer_card_set_profile (GvcMixerCard *card, const char *profile); gboolean gvc_mixer_card_set_profiles (GvcMixerCard *card, GList *profiles); gboolean gvc_mixer_card_set_ports (GvcMixerCard *stream, GList *ports); G_END_DECLS #endif /* __GVC_MIXER_CARD_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-control-private.h0000664000175000017500000000224400000000000030530 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_MIXER_CONTROL_PRIVATE_H #define __GVC_MIXER_CONTROL_PRIVATE_H #include #include #include "gvc-mixer-stream.h" #include "gvc-mixer-card.h" G_BEGIN_DECLS pa_context * gvc_mixer_control_get_pa_context (GvcMixerControl *control); G_END_DECLS #endif /* __GVC_MIXER_CONTROL_PRIVATE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-control.c0000664000175000017500000037413500000000000027066 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2006-2008 Lennart Poettering * Copyright (C) 2008 Sjoerd Simons * Copyright (C) 2008 William Jon McCann * Copyright (C) 2012 Conor Curran * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include "gvc-mixer-control.h" #include "gvc-mixer-sink.h" #include "gvc-mixer-source.h" #include "gvc-mixer-sink-input.h" #include "gvc-mixer-source-output.h" #include "gvc-mixer-event-role.h" #include "gvc-mixer-card.h" #include "gvc-mixer-card-private.h" #include "gvc-channel-map-private.h" #include "gvc-mixer-control-private.h" #include "gvc-mixer-ui-device.h" #define GVC_MIXER_CONTROL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_CONTROL, GvcMixerControlPrivate)) #define RECONNECT_DELAY 5 enum { PROP_0, PROP_NAME }; struct GvcMixerControlPrivate { pa_glib_mainloop *pa_mainloop; pa_mainloop_api *pa_api; pa_context *pa_context; int n_outstanding; guint reconnect_id; char *name; gboolean default_sink_is_set; guint default_sink_id; char *default_sink_name; gboolean default_source_is_set; guint default_source_id; char *default_source_name; gboolean event_sink_input_is_set; guint event_sink_input_id; GHashTable *all_streams; GHashTable *sinks; /* fixed outputs */ GHashTable *sources; /* fixed inputs */ GHashTable *sink_inputs; /* routable output streams */ GHashTable *source_outputs; /* routable input streams */ GHashTable *clients; GHashTable *cards; GvcMixerStream *new_default_sink_stream; /* new default sink stream, used in gvc_mixer_control_set_default_sink () */ GvcMixerStream *new_default_source_stream; /* new default source stream, used in gvc_mixer_control_set_default_source () */ GHashTable *ui_outputs; /* UI visible outputs */ GHashTable *ui_inputs; /* UI visible inputs */ /* When we change profile on a device that is not the server default sink, * it will jump back to the default sink set by the server to prevent the * audio setup from being 'outputless'. * * All well and good but then when we get the new stream created for the * new profile how do we know that this is the intended default or selected * device the user wishes to use. */ guint profile_swapping_device_id; GvcMixerControlState state; }; enum { STATE_CHANGED, STREAM_ADDED, STREAM_REMOVED, CARD_ADDED, CARD_REMOVED, DEFAULT_SINK_CHANGED, DEFAULT_SOURCE_CHANGED, ACTIVE_OUTPUT_UPDATE, ACTIVE_INPUT_UPDATE, OUTPUT_ADDED, INPUT_ADDED, OUTPUT_REMOVED, INPUT_REMOVED, CARD_INFO, LAST_SIGNAL }; static guint signals [LAST_SIGNAL] = { 0, }; static void gvc_mixer_control_class_init (GvcMixerControlClass *klass); static void gvc_mixer_control_init (GvcMixerControl *mixer_control); static void gvc_mixer_control_finalize (GObject *object); G_DEFINE_TYPE (GvcMixerControl, gvc_mixer_control, G_TYPE_OBJECT) pa_context * gvc_mixer_control_get_pa_context (GvcMixerControl *control) { g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); return control->priv->pa_context; } /** * gvc_mixer_control_get_event_sink_input: * @control: * * Returns: (transfer none): */ GvcMixerStream * gvc_mixer_control_get_event_sink_input (GvcMixerControl *control) { GvcMixerStream *stream; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); stream = g_hash_table_lookup (control->priv->all_streams, GUINT_TO_POINTER (control->priv->event_sink_input_id)); return stream; } static void gvc_mixer_control_stream_restore_cb (pa_context *c, GvcMixerStream *new_stream, const pa_ext_stream_restore_info *info, GvcMixerControl *control) { pa_operation *o; pa_ext_stream_restore_info new_info; if (new_stream == NULL) return; new_info.name = info->name; new_info.channel_map = info->channel_map; new_info.volume = info->volume; new_info.mute = info->mute; new_info.device = gvc_mixer_stream_get_name (new_stream); o = pa_ext_stream_restore_write (control->priv->pa_context, PA_UPDATE_REPLACE, &new_info, 1, TRUE, NULL, NULL); if (o == NULL) { g_warning ("pa_ext_stream_restore_write() failed: %s", pa_strerror (pa_context_errno (control->priv->pa_context))); return; } g_debug ("Changed default device for %s to %s", info->name, new_info.device); pa_operation_unref (o); } static void gvc_mixer_control_stream_restore_sink_cb (pa_context *c, const pa_ext_stream_restore_info *info, int eol, void *userdata) { GvcMixerControl *control = (GvcMixerControl *) userdata; if (eol || info == NULL || !g_str_has_prefix(info->name, "sink-input-by")) return; gvc_mixer_control_stream_restore_cb (c, control->priv->new_default_sink_stream, info, control); } static void gvc_mixer_control_stream_restore_source_cb (pa_context *c, const pa_ext_stream_restore_info *info, int eol, void *userdata) { GvcMixerControl *control = (GvcMixerControl *) userdata; if (eol || info == NULL || !g_str_has_prefix(info->name, "source-output-by")) return; gvc_mixer_control_stream_restore_cb (c, control->priv->new_default_source_stream, info, control); } /** * gvc_mixer_control_lookup_device_from_stream: * @control: * @stream: * * Returns: (transfer none): a #GvcUIDevice or %NULL */ GvcMixerUIDevice * gvc_mixer_control_lookup_device_from_stream (GvcMixerControl *control, GvcMixerStream *stream) { GList *devices, *d; gboolean is_network_stream; const GList *ports; GvcMixerUIDevice *ret; if (GVC_IS_MIXER_SOURCE (stream)) devices = g_hash_table_get_values (control->priv->ui_inputs); else devices = g_hash_table_get_values (control->priv->ui_outputs); ret = NULL; ports = gvc_mixer_stream_get_ports (stream); is_network_stream = (ports == NULL); for (d = devices; d != NULL; d = d->next) { GvcMixerUIDevice *device = d->data; gint stream_id = G_MAXINT; g_object_get (G_OBJECT (device), "stream-id", &stream_id, NULL); if (is_network_stream && stream_id == gvc_mixer_stream_get_id (stream)) { g_debug ("lookup device from stream - %s - it is a network_stream ", gvc_mixer_ui_device_get_description (device)); ret = device; break; } else if (!is_network_stream) { const GvcMixerStreamPort *port; port = gvc_mixer_stream_get_port (stream); if (stream_id == gvc_mixer_stream_get_id (stream) && g_strcmp0 (gvc_mixer_ui_device_get_port (device), port->port) == 0) { g_debug ("lookup-device-from-stream found device: device description '%s', device port = '%s', device stream id %i AND stream port = '%s' stream id '%u' and stream description '%s'", gvc_mixer_ui_device_get_description (device), gvc_mixer_ui_device_get_port (device), stream_id, port->port, gvc_mixer_stream_get_id (stream), gvc_mixer_stream_get_description (stream)); ret = device; break; } } } g_debug ("gvc_mixer_control_lookup_device_from_stream - Could not find a device for stream '%s'",gvc_mixer_stream_get_description (stream)); g_list_free (devices); return ret; } gboolean gvc_mixer_control_set_default_sink (GvcMixerControl *control, GvcMixerStream *stream) { pa_operation *o; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), FALSE); g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_debug ("about to set default sink on server"); o = pa_context_set_default_sink (control->priv->pa_context, gvc_mixer_stream_get_name (stream), NULL, NULL); if (o == NULL) { g_warning ("pa_context_set_default_sink() failed: %s", pa_strerror (pa_context_errno (control->priv->pa_context))); return FALSE; } pa_operation_unref (o); control->priv->new_default_sink_stream = stream; g_object_add_weak_pointer (G_OBJECT (stream), (gpointer *) &control->priv->new_default_sink_stream); o = pa_ext_stream_restore_read (control->priv->pa_context, gvc_mixer_control_stream_restore_sink_cb, control); if (o == NULL) { g_warning ("pa_ext_stream_restore_read() failed: %s", pa_strerror (pa_context_errno (control->priv->pa_context))); return FALSE; } pa_operation_unref (o); return TRUE; } gboolean gvc_mixer_control_set_default_source (GvcMixerControl *control, GvcMixerStream *stream) { GvcMixerUIDevice* input; pa_operation *o; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), FALSE); g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); o = pa_context_set_default_source (control->priv->pa_context, gvc_mixer_stream_get_name (stream), NULL, NULL); if (o == NULL) { g_warning ("pa_context_set_default_source() failed"); return FALSE; } pa_operation_unref (o); control->priv->new_default_source_stream = stream; g_object_add_weak_pointer (G_OBJECT (stream), (gpointer *) &control->priv->new_default_source_stream); o = pa_ext_stream_restore_read (control->priv->pa_context, gvc_mixer_control_stream_restore_source_cb, control); if (o == NULL) { g_warning ("pa_ext_stream_restore_read() failed: %s", pa_strerror (pa_context_errno (control->priv->pa_context))); return FALSE; } pa_operation_unref (o); /* source change successful, update the UI. */ input = gvc_mixer_control_lookup_device_from_stream (control, stream); g_signal_emit (G_OBJECT (control), signals[ACTIVE_INPUT_UPDATE], 0, gvc_mixer_ui_device_get_id (input)); return TRUE; } /** * gvc_mixer_control_get_default_sink: * @control: * * Returns: (transfer none): */ GvcMixerStream * gvc_mixer_control_get_default_sink (GvcMixerControl *control) { GvcMixerStream *stream; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); if (control->priv->default_sink_is_set) { stream = g_hash_table_lookup (control->priv->all_streams, GUINT_TO_POINTER (control->priv->default_sink_id)); } else { stream = NULL; } return stream; } /** * gvc_mixer_control_get_default_source: * @control: * * Returns: (transfer none): */ GvcMixerStream * gvc_mixer_control_get_default_source (GvcMixerControl *control) { GvcMixerStream *stream; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); if (control->priv->default_source_is_set) { stream = g_hash_table_lookup (control->priv->all_streams, GUINT_TO_POINTER (control->priv->default_source_id)); } else { stream = NULL; } return stream; } static gpointer gvc_mixer_control_lookup_id (GHashTable *hash_table, guint id) { return g_hash_table_lookup (hash_table, GUINT_TO_POINTER (id)); } /** * gvc_mixer_control_lookup_stream_id: * @control: * @id: * * Returns: (transfer none): */ GvcMixerStream * gvc_mixer_control_lookup_stream_id (GvcMixerControl *control, guint id) { g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); return gvc_mixer_control_lookup_id (control->priv->all_streams, id); } /** * gvc_mixer_control_lookup_card_id: * @control: * @id: * * Returns: (transfer none): */ GvcMixerCard * gvc_mixer_control_lookup_card_id (GvcMixerControl *control, guint id) { g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); return gvc_mixer_control_lookup_id (control->priv->cards, id); } /** * gvc_mixer_control_lookup_output_id: * @control: * @id: * * Returns: (transfer none): */ GvcMixerUIDevice * gvc_mixer_control_lookup_output_id (GvcMixerControl *control, guint id) { g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); return gvc_mixer_control_lookup_id (control->priv->ui_outputs, id); } /** * gvc_mixer_control_lookup_input_id: * @control: * @id: * * Returns: (transfer none): */ GvcMixerUIDevice * gvc_mixer_control_lookup_input_id (GvcMixerControl *control, guint id) { g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); return gvc_mixer_control_lookup_id (control->priv->ui_inputs, id); } /** * gvc_mixer_control_get_stream_from_device: * @control: * @device: * * Returns: (transfer none): */ GvcMixerStream * gvc_mixer_control_get_stream_from_device (GvcMixerControl *control, GvcMixerUIDevice *device) { gint stream_id; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL); stream_id = gvc_mixer_ui_device_get_stream_id (device); if (stream_id == GVC_MIXER_UI_DEVICE_INVALID) { g_debug ("gvc_mixer_control_get_stream_from_device - device has a null stream"); return NULL; } return gvc_mixer_control_lookup_stream_id (control, stream_id); } /** * gvc_mixer_control_change_profile_on_selected_device: * @control: * @device: * @profile: Can be null if any profile present on this port is okay * * Returns: This method will attempt to swap the profile on the card of * the device with given profile name. If successfull it will set the * preferred profile on that device so as we know the next time the user * moves to that device it should have this profile active. */ gboolean gvc_mixer_control_change_profile_on_selected_device (GvcMixerControl *control, GvcMixerUIDevice *device, const gchar *profile) { const gchar *best_profile; GvcMixerCardProfile *current_profile; GvcMixerCard *card; g_object_get (G_OBJECT (device), "card", &card, NULL); current_profile = gvc_mixer_card_get_profile (card); if (current_profile) best_profile = gvc_mixer_ui_device_get_best_profile (device, profile, current_profile->profile); else best_profile = profile; g_assert (best_profile); g_debug ("Selected '%s', moving to profile '%s' on card '%s' on stream id %i", profile ? profile : "(any)", best_profile, gvc_mixer_card_get_name (card), gvc_mixer_ui_device_get_stream_id (device)); g_debug ("default sink name = %s and default sink id %u", control->priv->default_sink_name, control->priv->default_sink_id); control->priv->profile_swapping_device_id = gvc_mixer_ui_device_get_id (device); if (gvc_mixer_card_change_profile (card, best_profile)) { gvc_mixer_ui_device_set_user_preferred_profile (device, best_profile); return TRUE; } return FALSE; } /** * gvc_mixer_control_change_output: * @control: * @output: * This method is called from the UI when the user selects a previously unselected device. * - Firstly it queries the stream from the device. * - It assumes that if the stream is null that it cannot be a bluetooth or network stream (they never show unless they have valid sinks and sources) * In the scenario of a NULL stream on the device * - It fetches the device's preferred profile or if NUll the profile with the highest priority on that device. * - It then caches this device in control->priv->cached_desired_output_id so that when the update_sink triggered * from when we attempt to change profile we will know exactly what device to highlight on that stream. * - It attempts to swap the profile on the card from that device and returns. * - Next, it handles network or bluetooth streams that only require their stream to be made the default. * - Next it deals with port changes so if the stream's active port is not the same as the port on the device * it will attempt to change the port on that stream to be same as the device. If this fails it will return. * - Finally it will set this new stream to be the default stream and emit a signal for the UI confirming the active output device. */ void gvc_mixer_control_change_output (GvcMixerControl *control, GvcMixerUIDevice* output) { GvcMixerStream *stream; GvcMixerStream *default_stream; const GvcMixerStreamPort *active_port; const gchar *output_port; g_debug ("control change output"); stream = gvc_mixer_control_get_stream_from_device (control, output); if (stream == NULL) { gvc_mixer_control_change_profile_on_selected_device (control, output, NULL); return; } /* Handle a network sink as a portless or cardless device */ if (!gvc_mixer_ui_device_has_ports (output)) { g_debug ("Did we try to move to a software/bluetooth sink ?"); if (gvc_mixer_control_set_default_sink (control, stream)) { /* sink change was successful, update the UI.*/ g_signal_emit (G_OBJECT (control), signals[ACTIVE_OUTPUT_UPDATE], 0, gvc_mixer_ui_device_get_id (output)); } else { g_warning ("Failed to set default sink with stream from output %s", gvc_mixer_ui_device_get_description (output)); } return; } active_port = gvc_mixer_stream_get_port (stream); output_port = gvc_mixer_ui_device_get_port (output); /* First ensure the correct port is active on the sink */ if (g_strcmp0 (active_port->port, output_port) != 0) { g_debug ("Port change, switch to = %s", output_port); if (gvc_mixer_stream_change_port (stream, output_port) == FALSE) { g_warning ("Could not change port !"); return; } } default_stream = gvc_mixer_control_get_default_sink (control); /* Finally if we are not on the correct stream, swap over. */ if (stream != default_stream) { GvcMixerUIDevice* output; g_debug ("Attempting to swap over to stream %s ", gvc_mixer_stream_get_description (stream)); if (gvc_mixer_control_set_default_sink (control, stream)) { output = gvc_mixer_control_lookup_device_from_stream (control, stream); g_signal_emit (G_OBJECT (control), signals[ACTIVE_OUTPUT_UPDATE], 0, gvc_mixer_ui_device_get_id (output)); } else { /* If the move failed for some reason reset the UI. */ output = gvc_mixer_control_lookup_device_from_stream (control, default_stream); g_signal_emit (G_OBJECT (control), signals[ACTIVE_OUTPUT_UPDATE], 0, gvc_mixer_ui_device_get_id (output)); } } } /** * gvc_mixer_control_change_input: * @control: * @input: * This method is called from the UI when the user selects a previously unselected device. * - Firstly it queries the stream from the device. * - It assumes that if the stream is null that it cannot be a bluetooth or network stream (they never show unless they have valid sinks and sources) * In the scenario of a NULL stream on the device * - It fetches the device's preferred profile or if NUll the profile with the highest priority on that device. * - It then caches this device in control->priv->cached_desired_input_id so that when the update_source triggered * from when we attempt to change profile we will know exactly what device to highlight on that stream. * - It attempts to swap the profile on the card from that device and returns. * - Next, it handles network or bluetooth streams that only require their stream to be made the default. * - Next it deals with port changes so if the stream's active port is not the same as the port on the device * it will attempt to change the port on that stream to be same as the device. If this fails it will return. * - Finally it will set this new stream to be the default stream and emit a signal for the UI confirming the active input device. */ void gvc_mixer_control_change_input (GvcMixerControl *control, GvcMixerUIDevice* input) { GvcMixerStream *stream; GvcMixerStream *default_stream; const GvcMixerStreamPort *active_port; const gchar *input_port; stream = gvc_mixer_control_get_stream_from_device (control, input); if (stream == NULL) { gvc_mixer_control_change_profile_on_selected_device (control, input, NULL); return; } /* Handle a network sink as a portless/cardless device */ if (!gvc_mixer_ui_device_has_ports (input)) { g_debug ("Did we try to move to a software/bluetooth source ?"); if (! gvc_mixer_control_set_default_source (control, stream)) { g_warning ("Failed to set default source with stream from input %s", gvc_mixer_ui_device_get_description (input)); } return; } active_port = gvc_mixer_stream_get_port (stream); input_port = gvc_mixer_ui_device_get_port (input); /* First ensure the correct port is active on the sink */ if (g_strcmp0 (active_port->port, input_port) != 0) { g_debug ("Port change, switch to = %s", input_port); if (gvc_mixer_stream_change_port (stream, input_port) == FALSE) { g_warning ("Could not change port!"); return; } } default_stream = gvc_mixer_control_get_default_source (control); /* Finally if we are not on the correct stream, swap over. */ if (stream != default_stream) { g_debug ("change-input - attempting to swap over to stream %s", gvc_mixer_stream_get_description (stream)); gvc_mixer_control_set_default_source (control, stream); } } static void listify_hash_values_hfunc (gpointer key, gpointer value, gpointer user_data) { GSList **list = user_data; *list = g_slist_prepend (*list, value); } static int gvc_name_collate (const char *namea, const char *nameb) { if (nameb == NULL && namea == NULL) return 0; if (nameb == NULL) return 1; if (namea == NULL) return -1; return g_utf8_collate (namea, nameb); } static int gvc_card_collate (GvcMixerCard *a, GvcMixerCard *b) { const char *namea; const char *nameb; g_return_val_if_fail (a == NULL || GVC_IS_MIXER_CARD (a), 0); g_return_val_if_fail (b == NULL || GVC_IS_MIXER_CARD (b), 0); namea = gvc_mixer_card_get_name (a); nameb = gvc_mixer_card_get_name (b); return gvc_name_collate (namea, nameb); } /** * gvc_mixer_control_get_cards: * @control: * * Returns: (transfer container) (element-type Gvc.MixerCard): */ GSList * gvc_mixer_control_get_cards (GvcMixerControl *control) { GSList *retval; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); retval = NULL; g_hash_table_foreach (control->priv->cards, listify_hash_values_hfunc, &retval); return g_slist_sort (retval, (GCompareFunc) gvc_card_collate); } static int gvc_stream_collate (GvcMixerStream *a, GvcMixerStream *b) { const char *namea; const char *nameb; g_return_val_if_fail (a == NULL || GVC_IS_MIXER_STREAM (a), 0); g_return_val_if_fail (b == NULL || GVC_IS_MIXER_STREAM (b), 0); namea = gvc_mixer_stream_get_name (a); nameb = gvc_mixer_stream_get_name (b); return gvc_name_collate (namea, nameb); } /** * gvc_mixer_control_get_streams: * @control: * * Returns: (transfer container) (element-type Gvc.MixerStream): */ GSList * gvc_mixer_control_get_streams (GvcMixerControl *control) { GSList *retval; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); retval = NULL; g_hash_table_foreach (control->priv->all_streams, listify_hash_values_hfunc, &retval); return g_slist_sort (retval, (GCompareFunc) gvc_stream_collate); } /** * gvc_mixer_control_get_sinks: * @control: * * Returns: (transfer container) (element-type Gvc.MixerSink): */ GSList * gvc_mixer_control_get_sinks (GvcMixerControl *control) { GSList *retval; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); retval = NULL; g_hash_table_foreach (control->priv->sinks, listify_hash_values_hfunc, &retval); return g_slist_sort (retval, (GCompareFunc) gvc_stream_collate); } /** * gvc_mixer_control_get_sources: * @control: * * Returns: (transfer container) (element-type Gvc.MixerSource): */ GSList * gvc_mixer_control_get_sources (GvcMixerControl *control) { GSList *retval; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); retval = NULL; g_hash_table_foreach (control->priv->sources, listify_hash_values_hfunc, &retval); return g_slist_sort (retval, (GCompareFunc) gvc_stream_collate); } /** * gvc_mixer_control_get_sink_inputs: * @control: * * Returns: (transfer container) (element-type Gvc.MixerSinkInput): */ GSList * gvc_mixer_control_get_sink_inputs (GvcMixerControl *control) { GSList *retval; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); retval = NULL; g_hash_table_foreach (control->priv->sink_inputs, listify_hash_values_hfunc, &retval); return g_slist_sort (retval, (GCompareFunc) gvc_stream_collate); } /** * gvc_mixer_control_get_source_outputs: * @control: * * Returns: (transfer container) (element-type Gvc.MixerSourceOutput): */ GSList * gvc_mixer_control_get_source_outputs (GvcMixerControl *control) { GSList *retval; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), NULL); retval = NULL; g_hash_table_foreach (control->priv->source_outputs, listify_hash_values_hfunc, &retval); return g_slist_sort (retval, (GCompareFunc) gvc_stream_collate); } static void dec_outstanding (GvcMixerControl *control) { if (control->priv->n_outstanding <= 0) { return; } if (--control->priv->n_outstanding <= 0) { control->priv->state = GVC_STATE_READY; g_signal_emit (G_OBJECT (control), signals[STATE_CHANGED], 0, GVC_STATE_READY); } } GvcMixerControlState gvc_mixer_control_get_state (GvcMixerControl *control) { g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), FALSE); return control->priv->state; } static void on_default_source_port_notify (GObject *object, GParamSpec *pspec, GvcMixerControl *control) { char *port; GvcMixerUIDevice *input; g_object_get (object, "port", &port, NULL); input = gvc_mixer_control_lookup_device_from_stream (control, GVC_MIXER_STREAM (object)); g_debug ("on_default_source_port_notify - moved to port '%s' which SHOULD ?? correspond to output '%s'", port, gvc_mixer_ui_device_get_description (input)); g_signal_emit (G_OBJECT (control), signals[ACTIVE_INPUT_UPDATE], 0, gvc_mixer_ui_device_get_id (input)); g_free (port); } static void _set_default_source (GvcMixerControl *control, GvcMixerStream *stream) { guint new_id; if (stream == NULL) { control->priv->default_source_id = 0; control->priv->default_source_is_set = FALSE; g_signal_emit (control, signals[DEFAULT_SOURCE_CHANGED], 0, PA_INVALID_INDEX); return; } new_id = gvc_mixer_stream_get_id (stream); if (control->priv->default_source_id != new_id) { GvcMixerUIDevice *input; control->priv->default_source_id = new_id; control->priv->default_source_is_set = TRUE; g_signal_emit (control, signals[DEFAULT_SOURCE_CHANGED], 0, new_id); if (control->priv->default_source_is_set) { g_signal_handlers_disconnect_by_func (gvc_mixer_control_get_default_source (control), on_default_source_port_notify, control); } g_signal_connect (stream, "notify::port", G_CALLBACK (on_default_source_port_notify), control); input = gvc_mixer_control_lookup_device_from_stream (control, stream); g_signal_emit (G_OBJECT (control), signals[ACTIVE_INPUT_UPDATE], 0, gvc_mixer_ui_device_get_id (input)); } } static void on_default_sink_port_notify (GObject *object, GParamSpec *pspec, GvcMixerControl *control) { char *port; GvcMixerUIDevice *output; g_object_get (object, "port", &port, NULL); output = gvc_mixer_control_lookup_device_from_stream (control, GVC_MIXER_STREAM (object)); if (output != NULL) { g_debug ("on_default_sink_port_notify - moved to port %s - which SHOULD correspond to output %s", port, gvc_mixer_ui_device_get_description (output)); g_signal_emit (G_OBJECT (control), signals[ACTIVE_OUTPUT_UPDATE], 0, gvc_mixer_ui_device_get_id (output)); } g_free (port); } static void _set_default_sink (GvcMixerControl *control, GvcMixerStream *stream) { guint new_id; if (stream == NULL) { /* Don't tell front-ends about an unset default * sink if it's already unset */ if (control->priv->default_sink_is_set == FALSE) return; control->priv->default_sink_id = 0; control->priv->default_sink_is_set = FALSE; g_signal_emit (control, signals[DEFAULT_SINK_CHANGED], 0, PA_INVALID_INDEX); return; } new_id = gvc_mixer_stream_get_id (stream); if (control->priv->default_sink_id != new_id) { GvcMixerUIDevice *output; if (control->priv->default_sink_is_set) { g_signal_handlers_disconnect_by_func (gvc_mixer_control_get_default_sink (control), on_default_sink_port_notify, control); } control->priv->default_sink_id = new_id; control->priv->default_sink_is_set = TRUE; g_signal_emit (control, signals[DEFAULT_SINK_CHANGED], 0, new_id); g_signal_connect (stream, "notify::port", G_CALLBACK (on_default_sink_port_notify), control); output = gvc_mixer_control_lookup_device_from_stream (control, stream); g_debug ("active_sink change"); g_signal_emit (G_OBJECT (control), signals[ACTIVE_OUTPUT_UPDATE], 0, gvc_mixer_ui_device_get_id (output)); } } static gboolean _stream_has_name (gpointer key, GvcMixerStream *stream, const char *name) { const char *t_name; t_name = gvc_mixer_stream_get_name (stream); if (t_name != NULL && name != NULL && strcmp (t_name, name) == 0) { return TRUE; } return FALSE; } static GvcMixerStream * find_stream_for_name (GvcMixerControl *control, const char *name) { GvcMixerStream *stream; stream = g_hash_table_find (control->priv->all_streams, (GHRFunc)_stream_has_name, (char *)name); return stream; } static void update_default_source_from_name (GvcMixerControl *control, const char *name) { gboolean changed = FALSE; if ((control->priv->default_source_name == NULL && name != NULL) || (control->priv->default_source_name != NULL && name == NULL) || (name != NULL && strcmp (control->priv->default_source_name, name) != 0)) { changed = TRUE; } if (changed) { GvcMixerStream *stream; g_free (control->priv->default_source_name); control->priv->default_source_name = g_strdup (name); stream = find_stream_for_name (control, name); _set_default_source (control, stream); } } static void update_default_sink_from_name (GvcMixerControl *control, const char *name) { gboolean changed = FALSE; if ((control->priv->default_sink_name == NULL && name != NULL) || (control->priv->default_sink_name != NULL && name == NULL) || (name != NULL && strcmp (control->priv->default_sink_name, name) != 0)) { changed = TRUE; } if (changed) { GvcMixerStream *stream; g_free (control->priv->default_sink_name); control->priv->default_sink_name = g_strdup (name); stream = find_stream_for_name (control, name); _set_default_sink (control, stream); } } static void update_server (GvcMixerControl *control, const pa_server_info *info) { if (info->default_source_name != NULL) { update_default_source_from_name (control, info->default_source_name); } if (info->default_sink_name != NULL) { g_debug ("update server"); update_default_sink_from_name (control, info->default_sink_name); } } static void remove_stream (GvcMixerControl *control, GvcMixerStream *stream) { guint id; g_object_ref (stream); id = gvc_mixer_stream_get_id (stream); if (id == control->priv->default_sink_id) { _set_default_sink (control, NULL); } else if (id == control->priv->default_source_id) { _set_default_source (control, NULL); } g_hash_table_remove (control->priv->all_streams, GUINT_TO_POINTER (id)); g_signal_emit (G_OBJECT (control), signals[STREAM_REMOVED], 0, gvc_mixer_stream_get_id (stream)); g_object_unref (stream); } static void add_stream (GvcMixerControl *control, GvcMixerStream *stream) { g_hash_table_insert (control->priv->all_streams, GUINT_TO_POINTER (gvc_mixer_stream_get_id (stream)), stream); g_signal_emit (G_OBJECT (control), signals[STREAM_ADDED], 0, gvc_mixer_stream_get_id (stream)); } /* This method will match individual stream ports against its corresponding device * It does this by: * - iterates through our devices and finds the one where the card-id on the device is the same as the card-id on the stream * and the port-name on the device is the same as the streamport-name. * This should always find a match and is used exclusively by sync_devices(). */ static gboolean match_stream_with_devices (GvcMixerControl *control, GvcMixerStreamPort *stream_port, GvcMixerStream *stream) { GList *devices, *d; guint stream_card_id; guint stream_id; gboolean in_possession = FALSE; stream_id = gvc_mixer_stream_get_id (stream); stream_card_id = gvc_mixer_stream_get_card_index (stream); devices = g_hash_table_get_values (GVC_IS_MIXER_SOURCE (stream) ? control->priv->ui_inputs : control->priv->ui_outputs); for (d = devices; d != NULL; d = d->next) { GvcMixerUIDevice *device; gint device_stream_id; gchar *device_port_name; gchar *origin; gchar *description; GvcMixerCard *card; gint card_id; device = d->data; g_object_get (G_OBJECT (device), "stream-id", &device_stream_id, "card", &card, "origin", &origin, "description", &description, "port-name", &device_port_name, NULL); card_id = gvc_mixer_card_get_index (card); g_debug ("Attempt to match_stream update_with_existing_outputs - Try description : '%s', origin : '%s', device port name : '%s', card : %p, AGAINST stream port: '%s', sink card id %i", description, origin, device_port_name, card, stream_port->port, stream_card_id); if (stream_card_id == card_id && g_strcmp0 (device_port_name, stream_port->port) == 0) { g_debug ("Match device with stream: We have a match with description: '%s', origin: '%s', cached already with device id %u, so set stream id to %i", description, origin, gvc_mixer_ui_device_get_id (device), stream_id); g_object_set (G_OBJECT (device), "stream-id", (gint)stream_id, NULL); in_possession = TRUE; } g_free (device_port_name); g_free (origin); g_free (description); if (in_possession == TRUE) break; } g_list_free (devices); return in_possession; } /* * This method attempts to match a sink or source with its relevant UI device. * GvcMixerStream can represent both a sink or source. * Using static card port introspection implies that we know beforehand what * outputs and inputs are available to the user. * But that does not mean that all of these inputs and outputs are available to be used. * For instance we might be able to see that there is a HDMI port available but if * we are on the default analog stereo output profile there is no valid sink for * that HDMI device. We first need to change profile and when update_sink() is called * only then can we match the new hdmi sink with its corresponding device. * * Firstly it checks to see if the incoming stream has no ports. * - If a stream has no ports but has a valid card ID (bluetooth), it will attempt * to match the device with the stream using the card id. * - If a stream has no ports and no valid card id, it goes ahead and makes a new * device (software/network devices are only detectable at the sink/source level) * If the stream has ports it will match each port against the stream using match_stream_with_devices(). * * This method should always find a match. */ static void sync_devices (GvcMixerControl *control, GvcMixerStream* stream) { /* Go through ports to see what outputs can be created. */ const GList *stream_ports; const GList *n = NULL; gboolean is_output = !GVC_IS_MIXER_SOURCE (stream); gint stream_port_count = 0; stream_ports = gvc_mixer_stream_get_ports (stream); if (stream_ports == NULL) { GvcMixerUIDevice *device; /* Bluetooth, no ports but a valid card */ if (gvc_mixer_stream_get_card_index (stream) != PA_INVALID_INDEX) { GList *devices, *d; gboolean in_possession = FALSE; devices = g_hash_table_get_values (is_output ? control->priv->ui_outputs : control->priv->ui_inputs); for (d = devices; d != NULL; d = d->next) { GvcMixerCard *card; gint card_id; device = d->data; g_object_get (G_OBJECT (device), "card", &card, NULL); card_id = gvc_mixer_card_get_index (card); g_debug ("sync devices, device description - '%s', device card id - %i, stream description - %s, stream card id - %i", gvc_mixer_ui_device_get_description (device), card_id, gvc_mixer_stream_get_description (stream), gvc_mixer_stream_get_card_index (stream)); if (card_id == gvc_mixer_stream_get_card_index (stream)) { in_possession = TRUE; break; } } g_list_free (devices); if (!in_possession) { g_warning ("Couldn't match the portless stream (with card) - '%s' is it an input ? -> %i, streams card id -> %i", gvc_mixer_stream_get_description (stream), GVC_IS_MIXER_SOURCE (stream), gvc_mixer_stream_get_card_index (stream)); return; } g_object_set (G_OBJECT (device), "stream-id", (gint)gvc_mixer_stream_get_id (stream), "description", gvc_mixer_stream_get_description (stream), "origin", "", /*Leave it empty for these special cases*/ "port-name", NULL, "port-available", TRUE, NULL); } else { /* Network sink/source has no ports and no card. */ GObject *object; object = g_object_new (GVC_TYPE_MIXER_UI_DEVICE, "stream-id", (gint)gvc_mixer_stream_get_id (stream), "description", gvc_mixer_stream_get_description (stream), "origin", "", /* Leave it empty for these special cases */ "port-name", NULL, "port-available", TRUE, NULL); device = GVC_MIXER_UI_DEVICE (object); g_hash_table_insert (is_output ? control->priv->ui_outputs : control->priv->ui_inputs, GUINT_TO_POINTER (gvc_mixer_ui_device_get_id (device)), g_object_ref (device)); } g_signal_emit (G_OBJECT (control), signals[is_output ? OUTPUT_ADDED : INPUT_ADDED], 0, gvc_mixer_ui_device_get_id (device)); return; } /* Go ahead and make sure to match each port against a previously created device */ for (n = stream_ports; n != NULL; n = n->next) { GvcMixerStreamPort *stream_port; stream_port = n->data; stream_port_count ++; if (match_stream_with_devices (control, stream_port, stream)) continue; g_warning ("Sync_devices: Failed to match stream id: %u, description: '%s', origin: '%s'", gvc_mixer_stream_get_id (stream), stream_port->human_port, gvc_mixer_stream_get_description (stream)); } } static void set_icon_name_from_proplist (GvcMixerStream *stream, pa_proplist *l, const char *default_icon_name) { const char *t; if ((t = pa_proplist_gets (l, PA_PROP_DEVICE_ICON_NAME))) { goto finish; } if ((t = pa_proplist_gets (l, PA_PROP_MEDIA_ICON_NAME))) { goto finish; } if ((t = pa_proplist_gets (l, PA_PROP_WINDOW_ICON_NAME))) { goto finish; } if ((t = pa_proplist_gets (l, PA_PROP_APPLICATION_ICON_NAME))) { goto finish; } if ((t = pa_proplist_gets (l, PA_PROP_MEDIA_ROLE))) { if (strcmp (t, "video") == 0 || strcmp (t, "phone") == 0) { goto finish; } if (strcmp (t, "music") == 0) { t = "audio"; goto finish; } if (strcmp (t, "game") == 0) { t = "applications-games"; goto finish; } if (strcmp (t, "event") == 0) { t = "dialog-information"; goto finish; } } t = default_icon_name; finish: gvc_mixer_stream_set_icon_name (stream, t); } /* * Called when anything changes with a sink. */ static void update_sink (GvcMixerControl *control, const pa_sink_info *info) { GvcMixerStream *stream; gboolean is_new; pa_volume_t max_volume; GvcChannelMap *map; char map_buff[PA_CHANNEL_MAP_SNPRINT_MAX]; pa_channel_map_snprint (map_buff, PA_CHANNEL_MAP_SNPRINT_MAX, &info->channel_map); #if 1 g_debug ("Updating sink: index=%u name='%s' description='%s' map='%s'", info->index, info->name, info->description, map_buff); #endif map = NULL; is_new = FALSE; stream = g_hash_table_lookup (control->priv->sinks, GUINT_TO_POINTER (info->index)); if (stream == NULL) { GList *list = NULL; guint i; map = gvc_channel_map_new_from_pa_channel_map (&info->channel_map); stream = gvc_mixer_sink_new (control->priv->pa_context, info->index, map); for (i = 0; i < info->n_ports; i++) { GvcMixerStreamPort *port; port = g_slice_new0 (GvcMixerStreamPort); port->port = g_strdup (info->ports[i]->name); port->human_port = g_strdup (info->ports[i]->description); port->priority = info->ports[i]->priority; port->available = info->ports[i]->available != PA_PORT_AVAILABLE_NO; list = g_list_prepend (list, port); } gvc_mixer_stream_set_ports (stream, list); g_object_unref (map); is_new = TRUE; } else if (gvc_mixer_stream_is_running (stream)) { /* Ignore events if volume changes are outstanding */ g_debug ("Ignoring event, volume changes are outstanding"); return; } max_volume = pa_cvolume_max (&info->volume); gvc_mixer_stream_set_name (stream, info->name); gvc_mixer_stream_set_card_index (stream, info->card); gvc_mixer_stream_set_description (stream, info->description); set_icon_name_from_proplist (stream, info->proplist, "audio-card"); gvc_mixer_stream_set_form_factor (stream, pa_proplist_gets (info->proplist, PA_PROP_DEVICE_FORM_FACTOR)); gvc_mixer_stream_set_sysfs_path (stream, pa_proplist_gets (info->proplist, "sysfs.path")); gvc_mixer_stream_set_volume (stream, (guint)max_volume); gvc_mixer_stream_set_is_muted (stream, info->mute); gvc_mixer_stream_set_can_decibel (stream, !!(info->flags & PA_SINK_DECIBEL_VOLUME)); gvc_mixer_stream_set_base_volume (stream, (guint32) info->base_volume); /* Messy I know but to set the port everytime regardless of whether it has changed will cost us a * port change notify signal which causes the frontend to resync. * Only update the UI when something has changed. */ if (info->active_port != NULL) { if (is_new) gvc_mixer_stream_set_port (stream, info->active_port->name); else { const GvcMixerStreamPort *active_port; active_port = gvc_mixer_stream_get_port (stream); if (active_port == NULL || g_strcmp0 (active_port->port, info->active_port->name) != 0) { g_debug ("update sink - apparently a port update"); gvc_mixer_stream_set_port (stream, info->active_port->name); } } } if (is_new) { g_debug ("update sink - is new"); g_hash_table_insert (control->priv->sinks, GUINT_TO_POINTER (info->index), g_object_ref (stream)); add_stream (control, stream); /* Always sink on a new stream to able to assign the right stream id * to the appropriate outputs (multiple potential outputs per stream). */ sync_devices (control, stream); } /* * When we change profile on a device that is not the server default sink, * it will jump back to the default sink set by the server to prevent the audio setup from being 'outputless'. * All well and good but then when we get the new stream created for the new profile how do we know * that this is the intended default or selected device the user wishes to use. * This is messy but it's the only reliable way that it can be done without ripping the whole thing apart. */ if (control->priv->profile_swapping_device_id != GVC_MIXER_UI_DEVICE_INVALID) { GvcMixerUIDevice *dev = NULL; dev = gvc_mixer_control_lookup_output_id (control, control->priv->profile_swapping_device_id); if (dev != NULL) { /* now check to make sure this new stream is the same stream just matched and set on the device object */ if (gvc_mixer_ui_device_get_stream_id (dev) == gvc_mixer_stream_get_id (stream)) { g_debug ("Looks like we profile swapped on a non server default sink"); gvc_mixer_control_set_default_sink (control, stream); } } control->priv->profile_swapping_device_id = GVC_MIXER_UI_DEVICE_INVALID; } if (control->priv->default_sink_name != NULL && info->name != NULL && strcmp (control->priv->default_sink_name, info->name) == 0) { _set_default_sink (control, stream); } if (map == NULL) map = (GvcChannelMap *) gvc_mixer_stream_get_channel_map (stream); gvc_channel_map_volume_changed (map, &info->volume, FALSE); } static void update_source (GvcMixerControl *control, const pa_source_info *info) { GvcMixerStream *stream; gboolean is_new; pa_volume_t max_volume; #if 1 g_debug ("Updating source: index=%u name='%s' description='%s'", info->index, info->name, info->description); #endif /* completely ignore monitors, they're not real sources */ if (info->monitor_of_sink != PA_INVALID_INDEX) { return; } is_new = FALSE; stream = g_hash_table_lookup (control->priv->sources, GUINT_TO_POINTER (info->index)); if (stream == NULL) { GList *list = NULL; guint i; GvcChannelMap *map; map = gvc_channel_map_new_from_pa_channel_map (&info->channel_map); stream = gvc_mixer_source_new (control->priv->pa_context, info->index, map); for (i = 0; i < info->n_ports; i++) { GvcMixerStreamPort *port; port = g_slice_new0 (GvcMixerStreamPort); port->port = g_strdup (info->ports[i]->name); port->human_port = g_strdup (info->ports[i]->description); port->priority = info->ports[i]->priority; list = g_list_prepend (list, port); } gvc_mixer_stream_set_ports (stream, list); g_object_unref (map); is_new = TRUE; } else if (gvc_mixer_stream_is_running (stream)) { /* Ignore events if volume changes are outstanding */ g_debug ("Ignoring event, volume changes are outstanding"); return; } max_volume = pa_cvolume_max (&info->volume); gvc_mixer_stream_set_name (stream, info->name); gvc_mixer_stream_set_card_index (stream, info->card); gvc_mixer_stream_set_description (stream, info->description); set_icon_name_from_proplist (stream, info->proplist, "audio-input-microphone"); gvc_mixer_stream_set_form_factor (stream, pa_proplist_gets (info->proplist, PA_PROP_DEVICE_FORM_FACTOR)); gvc_mixer_stream_set_volume (stream, (guint)max_volume); gvc_mixer_stream_set_is_muted (stream, info->mute); gvc_mixer_stream_set_can_decibel (stream, !!(info->flags & PA_SOURCE_DECIBEL_VOLUME)); gvc_mixer_stream_set_base_volume (stream, (guint32) info->base_volume); g_debug ("update source"); if (info->active_port != NULL) { if (is_new) gvc_mixer_stream_set_port (stream, info->active_port->name); else { const GvcMixerStreamPort *active_port; active_port = gvc_mixer_stream_get_port (stream); if (active_port == NULL || g_strcmp0 (active_port->port, info->active_port->name) != 0) { g_debug ("update source - apparently a port update"); gvc_mixer_stream_set_port (stream, info->active_port->name); } } } if (is_new) { g_hash_table_insert (control->priv->sources, GUINT_TO_POINTER (info->index), g_object_ref (stream)); add_stream (control, stream); sync_devices (control, stream); } if (control->priv->profile_swapping_device_id != GVC_MIXER_UI_DEVICE_INVALID) { GvcMixerUIDevice *dev = NULL; dev = gvc_mixer_control_lookup_input_id (control, control->priv->profile_swapping_device_id); if (dev != NULL) { /* now check to make sure this new stream is the same stream just matched and set on the device object */ if (gvc_mixer_ui_device_get_stream_id (dev) == gvc_mixer_stream_get_id (stream)) { g_debug ("Looks like we profile swapped on a non server default sink"); gvc_mixer_control_set_default_source (control, stream); } } control->priv->profile_swapping_device_id = GVC_MIXER_UI_DEVICE_INVALID; } if (control->priv->default_source_name != NULL && info->name != NULL && strcmp (control->priv->default_source_name, info->name) == 0) { _set_default_source (control, stream); } } static void set_is_event_stream_from_proplist (GvcMixerStream *stream, pa_proplist *l) { const char *t; gboolean is_event_stream; is_event_stream = FALSE; if ((t = pa_proplist_gets (l, PA_PROP_MEDIA_ROLE))) { if (g_str_equal (t, "event")) is_event_stream = TRUE; } gvc_mixer_stream_set_is_event_stream (stream, is_event_stream); } static void set_application_id_from_proplist (GvcMixerStream *stream, pa_proplist *l) { const char *t; if ((t = pa_proplist_gets (l, PA_PROP_APPLICATION_ID))) { gvc_mixer_stream_set_application_id (stream, t); } } static void update_sink_input (GvcMixerControl *control, const pa_sink_input_info *info) { GvcMixerStream *stream; gboolean is_new; pa_volume_t max_volume; const char *name; #if 0 g_debug ("Updating sink input: index=%u name='%s' client=%u sink=%u", info->index, info->name, info->client, info->sink); #endif is_new = FALSE; stream = g_hash_table_lookup (control->priv->sink_inputs, GUINT_TO_POINTER (info->index)); if (stream == NULL) { GvcChannelMap *map; map = gvc_channel_map_new_from_pa_channel_map (&info->channel_map); stream = gvc_mixer_sink_input_new (control->priv->pa_context, info->index, map); g_object_unref (map); is_new = TRUE; } else if (gvc_mixer_stream_is_running (stream)) { /* Ignore events if volume changes are outstanding */ g_debug ("Ignoring event, volume changes are outstanding"); return; } max_volume = pa_cvolume_max (&info->volume); name = (const char *)g_hash_table_lookup (control->priv->clients, GUINT_TO_POINTER (info->client)); gvc_mixer_stream_set_name (stream, name); gvc_mixer_stream_set_description (stream, info->name); set_application_id_from_proplist (stream, info->proplist); set_is_event_stream_from_proplist (stream, info->proplist); set_icon_name_from_proplist (stream, info->proplist, "applications-multimedia"); gvc_mixer_stream_set_volume (stream, (guint)max_volume); gvc_mixer_stream_set_is_muted (stream, info->mute); gvc_mixer_stream_set_is_virtual (stream, info->client == PA_INVALID_INDEX); if (is_new) { g_hash_table_insert (control->priv->sink_inputs, GUINT_TO_POINTER (info->index), g_object_ref (stream)); add_stream (control, stream); } } static void update_source_output (GvcMixerControl *control, const pa_source_output_info *info) { GvcMixerStream *stream; gboolean is_new; const char *name; #if 1 g_debug ("Updating source output: index=%u name='%s' client=%u source=%u", info->index, info->name, info->client, info->source); #endif is_new = FALSE; stream = g_hash_table_lookup (control->priv->source_outputs, GUINT_TO_POINTER (info->index)); if (stream == NULL) { GvcChannelMap *map; map = gvc_channel_map_new_from_pa_channel_map (&info->channel_map); stream = gvc_mixer_source_output_new (control->priv->pa_context, info->index, map); g_object_unref (map); is_new = TRUE; } name = (const char *)g_hash_table_lookup (control->priv->clients, GUINT_TO_POINTER (info->client)); gvc_mixer_stream_set_name (stream, name); gvc_mixer_stream_set_description (stream, info->name); set_application_id_from_proplist (stream, info->proplist); set_is_event_stream_from_proplist (stream, info->proplist); set_icon_name_from_proplist (stream, info->proplist, "audio-input-microphone"); if (is_new) { g_hash_table_insert (control->priv->source_outputs, GUINT_TO_POINTER (info->index), g_object_ref (stream)); add_stream (control, stream); } } static void update_client (GvcMixerControl *control, const pa_client_info *info) { #if 1 g_debug ("Updating client: index=%u name='%s'", info->index, info->name); #endif g_hash_table_insert (control->priv->clients, GUINT_TO_POINTER (info->index), g_strdup (info->name)); } static char * card_num_streams_to_status (guint sinks, guint sources) { char *sinks_str; char *sources_str; char *ret; if (sinks == 0 && sources == 0) { /* translators: * The device has been disabled */ return g_strdup (_("Disabled")); } if (sinks == 0) { sinks_str = NULL; } else { /* translators: * The number of sound outputs on a particular device */ sinks_str = g_strdup_printf (ngettext ("%u Output", "%u Outputs", sinks), sinks); } if (sources == 0) { sources_str = NULL; } else { /* translators: * The number of sound inputs on a particular device */ sources_str = g_strdup_printf (ngettext ("%u Input", "%u Inputs", sources), sources); } if (sources_str == NULL) return sinks_str; if (sinks_str == NULL) return sources_str; ret = g_strdup_printf ("%s / %s", sinks_str, sources_str); g_free (sinks_str); g_free (sources_str); return ret; } /* * A utility method to gather which card profiles are relevant to the port . */ static GList * determine_profiles_for_port (pa_card_port_info *port, GList* card_profiles) { gint i; GList *supported_profiles = NULL; GList *p; for (i = 0; i < port->n_profiles; i++) { for (p = card_profiles; p != NULL; p = p->next) { GvcMixerCardProfile *prof; prof = p->data; if (g_strcmp0 (port->profiles[i]->name, prof->profile) == 0) supported_profiles = g_list_append (supported_profiles, prof); } } g_debug ("%i profiles supported on port %s", g_list_length (supported_profiles), port->description); return g_list_sort (supported_profiles, (GCompareFunc) gvc_mixer_card_profile_compare); } static gboolean is_card_port_an_output (GvcMixerCardPort* port) { return port->direction == PA_DIRECTION_OUTPUT ? TRUE : FALSE; } /* * This method will create a ui device for the given port. */ static void create_ui_device_from_port (GvcMixerControl* control, GvcMixerCardPort* port, GvcMixerCard* card) { GvcMixerUIDeviceDirection direction; GObject *object; GvcMixerUIDevice *uidevice; gboolean available = port->available != PA_PORT_AVAILABLE_NO; direction = (is_card_port_an_output (port) == TRUE) ? UIDeviceOutput : UIDeviceInput; object = g_object_new (GVC_TYPE_MIXER_UI_DEVICE, "type", (uint)direction, "card", card, "port-name", port->port, "description", port->human_port, "origin", gvc_mixer_card_get_name (card), "port-available", available, NULL); uidevice = GVC_MIXER_UI_DEVICE (object); gvc_mixer_ui_device_set_profiles (uidevice, port->profiles); g_hash_table_insert (is_card_port_an_output (port) ? control->priv->ui_outputs : control->priv->ui_inputs, GUINT_TO_POINTER (gvc_mixer_ui_device_get_id (uidevice)), g_object_ref (uidevice)); if (available) { g_signal_emit (G_OBJECT (control), signals[is_card_port_an_output (port) ? OUTPUT_ADDED : INPUT_ADDED], 0, gvc_mixer_ui_device_get_id (uidevice)); } g_debug ("create_ui_device_from_port, direction %u, description '%s', origin '%s', port available %i", direction, port->human_port, gvc_mixer_card_get_name (card), available); } /* * This method will match up GvcMixerCardPorts with existing devices. * A match is achieved if the device's card-id and the port's card-id are the same * && the device's port-name and the card-port's port member are the same. * A signal is then sent adding or removing that device from the UI depending on the availability of the port. */ static void match_card_port_with_existing_device (GvcMixerControl *control, GvcMixerCardPort *card_port, GvcMixerCard *card, gboolean available) { GList *d; GList *devices; GvcMixerUIDevice *device; gboolean is_output = is_card_port_an_output (card_port); devices = g_hash_table_get_values (is_output ? control->priv->ui_outputs : control->priv->ui_inputs); for (d = devices; d != NULL; d = d->next) { GvcMixerCard *device_card; gchar *device_port_name; device = d->data; g_object_get (G_OBJECT (device), "card", &device_card, "port-name", &device_port_name, NULL); if (g_strcmp0 (card_port->port, device_port_name) == 0 && device_card == card) { g_debug ("Found the relevant device %s, update its port availability flag to %i, is_output %i", device_port_name, available, is_output); g_object_set (G_OBJECT (device), "port-available", available, NULL); g_signal_emit (G_OBJECT (control), is_output ? signals[available ? OUTPUT_ADDED : OUTPUT_REMOVED] : signals[available ? INPUT_ADDED : INPUT_REMOVED], 0, gvc_mixer_ui_device_get_id (device)); } g_free (device_port_name); } g_list_free (devices); } static void create_ui_device_from_card (GvcMixerControl *control, GvcMixerCard *card) { GObject *object; GvcMixerUIDevice *in; GvcMixerUIDevice *out; const GList *profiles; /* For now just create two devices and presume this device is multi directional * Ensure to remove both on card removal (available to false by default) */ profiles = gvc_mixer_card_get_profiles (card); g_debug ("Portless card just registered - %i", gvc_mixer_card_get_index (card)); object = g_object_new (GVC_TYPE_MIXER_UI_DEVICE, "type", UIDeviceInput, "description", gvc_mixer_card_get_name (card), "origin", "", /* Leave it empty for these special cases */ "port-name", NULL, "port-available", FALSE, "card", card, NULL); in = GVC_MIXER_UI_DEVICE (object); gvc_mixer_ui_device_set_profiles (in, profiles); g_hash_table_insert (control->priv->ui_inputs, GUINT_TO_POINTER (gvc_mixer_ui_device_get_id (in)), g_object_ref (in)); object = g_object_new (GVC_TYPE_MIXER_UI_DEVICE, "type", UIDeviceOutput, "description", gvc_mixer_card_get_name (card), "origin", "", /* Leave it empty for these special cases */ "port-name", NULL, "port-available", FALSE, "card", card, NULL); out = GVC_MIXER_UI_DEVICE (object); gvc_mixer_ui_device_set_profiles (out, profiles); g_hash_table_insert (control->priv->ui_outputs, GUINT_TO_POINTER (gvc_mixer_ui_device_get_id (out)), g_object_ref (out)); } /* * At this point we can determine all devices available to us (besides network 'ports') * This is done by the following: * * - gvc_mixer_card and gvc_mixer_card_ports are created and relevant setters are called. * - First it checks to see if it's a portless card. Bluetooth devices are portless AFAIHS. * If so it creates two devices, an input and an output. * - If it's a 'normal' card with ports it will create a new ui-device or * synchronise port availability with the existing device cached for that port on this card. */ static void update_card (GvcMixerControl *control, const pa_card_info *info) { const GList *card_ports = NULL; const GList *m = NULL; GvcMixerCard *card; gboolean is_new = FALSE; #if 1 guint i; const char *key; void *state; g_debug ("Udpating card %s (index: %u driver: %s):", info->name, info->index, info->driver); for (i = 0; i < info->n_profiles; i++) { struct pa_card_profile_info pi = info->profiles[i]; gboolean is_default; is_default = (g_strcmp0 (pi.name, info->active_profile->name) == 0); g_debug ("\tProfile '%s': %d sources %d sinks%s", pi.name, pi.n_sources, pi.n_sinks, is_default ? " (Current)" : ""); } state = NULL; key = pa_proplist_iterate (info->proplist, &state); while (key != NULL) { g_debug ("\tProperty: '%s' = '%s'", key, pa_proplist_gets (info->proplist, key)); key = pa_proplist_iterate (info->proplist, &state); } #endif card = g_hash_table_lookup (control->priv->cards, GUINT_TO_POINTER (info->index)); if (card == NULL) { GList *profile_list = NULL; GList *port_list = NULL; for (i = 0; i < info->n_profiles; i++) { GvcMixerCardProfile *profile; struct pa_card_profile_info pi = info->profiles[i]; profile = g_new0 (GvcMixerCardProfile, 1); profile->profile = g_strdup (pi.name); profile->human_profile = g_strdup (pi.description); profile->status = card_num_streams_to_status (pi.n_sinks, pi.n_sources); profile->n_sinks = pi.n_sinks; profile->n_sources = pi.n_sources; profile->priority = pi.priority; profile_list = g_list_prepend (profile_list, profile); } card = gvc_mixer_card_new (control->priv->pa_context, info->index); gvc_mixer_card_set_profiles (card, profile_list); for (i = 0; i < info->n_ports; i++) { GvcMixerCardPort *port; port = g_new0 (GvcMixerCardPort, 1); port->port = g_strdup (info->ports[i]->name); port->human_port = g_strdup (info->ports[i]->description); port->priority = info->ports[i]->priority; port->available = info->ports[i]->available; port->direction = info->ports[i]->direction; port->profiles = determine_profiles_for_port (info->ports[i], profile_list); port_list = g_list_prepend (port_list, port); } gvc_mixer_card_set_ports (card, port_list); is_new = TRUE; } gvc_mixer_card_set_name (card, pa_proplist_gets (info->proplist, "device.description")); gvc_mixer_card_set_icon_name (card, pa_proplist_gets (info->proplist, "device.icon_name")); gvc_mixer_card_set_profile (card, info->active_profile->name); if (is_new) { g_hash_table_insert (control->priv->cards, GUINT_TO_POINTER (info->index), g_object_ref (card)); } card_ports = gvc_mixer_card_get_ports (card); if (card_ports == NULL && is_new) { g_debug ("Portless card just registered - %s", gvc_mixer_card_get_name (card)); create_ui_device_from_card (control, card); } for (m = card_ports; m != NULL; m = m->next) { GvcMixerCardPort *card_port; card_port = m->data; if (is_new) create_ui_device_from_port (control, card_port, card); else { for (i = 0; i < info->n_ports; i++) { if (g_strcmp0 (card_port->port, info->ports[i]->name) == 0) { if (card_port->available != info->ports[i]->available) { card_port->available = info->ports[i]->available; g_debug ("sync port availability on card %i, card port name '%s', new available value %i", gvc_mixer_card_get_index (card), card_port->port, card_port->available); match_card_port_with_existing_device (control, card_port, card, card_port->available != PA_PORT_AVAILABLE_NO); } } } } } g_signal_emit (G_OBJECT (control), signals[CARD_INFO], 0, info); g_signal_emit (G_OBJECT (control), signals[CARD_ADDED], 0, info->index); } static void _pa_context_get_sink_info_cb (pa_context *context, const pa_sink_info *i, int eol, void *userdata) { GvcMixerControl *control = GVC_MIXER_CONTROL (userdata); if (eol < 0) { if (pa_context_errno (context) == PA_ERR_NOENTITY) { return; } g_warning ("Sink callback failure"); return; } if (eol > 0) { dec_outstanding (control); return; } update_sink (control, i); } static void _pa_context_get_source_info_cb (pa_context *context, const pa_source_info *i, int eol, void *userdata) { GvcMixerControl *control = GVC_MIXER_CONTROL (userdata); if (eol < 0) { if (pa_context_errno (context) == PA_ERR_NOENTITY) { return; } g_warning ("Source callback failure"); return; } if (eol > 0) { dec_outstanding (control); return; } update_source (control, i); } static void _pa_context_get_sink_input_info_cb (pa_context *context, const pa_sink_input_info *i, int eol, void *userdata) { GvcMixerControl *control = GVC_MIXER_CONTROL (userdata); if (eol < 0) { if (pa_context_errno (context) == PA_ERR_NOENTITY) { return; } g_warning ("Sink input callback failure"); return; } if (eol > 0) { dec_outstanding (control); return; } update_sink_input (control, i); } static void _pa_context_get_source_output_info_cb (pa_context *context, const pa_source_output_info *i, int eol, void *userdata) { GvcMixerControl *control = GVC_MIXER_CONTROL (userdata); if (eol < 0) { if (pa_context_errno (context) == PA_ERR_NOENTITY) { return; } g_warning ("Source output callback failure"); return; } if (eol > 0) { dec_outstanding (control); return; } update_source_output (control, i); } static void _pa_context_get_client_info_cb (pa_context *context, const pa_client_info *i, int eol, void *userdata) { GvcMixerControl *control = GVC_MIXER_CONTROL (userdata); if (eol < 0) { if (pa_context_errno (context) == PA_ERR_NOENTITY) { return; } g_warning ("Client callback failure"); return; } if (eol > 0) { dec_outstanding (control); return; } update_client (control, i); } static void _pa_context_get_card_info_by_index_cb (pa_context *context, const pa_card_info *i, int eol, void *userdata) { GvcMixerControl *control = GVC_MIXER_CONTROL (userdata); if (eol < 0) { if (pa_context_errno (context) == PA_ERR_NOENTITY) return; g_warning ("Card callback failure"); return; } if (eol > 0) { dec_outstanding (control); return; } update_card (control, i); } static void _pa_context_get_server_info_cb (pa_context *context, const pa_server_info *i, void *userdata) { GvcMixerControl *control = GVC_MIXER_CONTROL (userdata); if (i == NULL) { g_warning ("Server info callback failure"); return; } g_debug ("get server info"); update_server (control, i); dec_outstanding (control); } static void remove_event_role_stream (GvcMixerControl *control) { g_debug ("Removing event role"); } static void update_event_role_stream (GvcMixerControl *control, const pa_ext_stream_restore_info *info) { GvcMixerStream *stream; gboolean is_new; pa_volume_t max_volume; if (strcmp (info->name, "sink-input-by-media-role:event") != 0) { return; } #if 0 g_debug ("Updating event role: name='%s' device='%s'", info->name, info->device); #endif is_new = FALSE; if (!control->priv->event_sink_input_is_set) { pa_channel_map pa_map; GvcChannelMap *map; pa_map.channels = 1; pa_map.map[0] = PA_CHANNEL_POSITION_MONO; map = gvc_channel_map_new_from_pa_channel_map (&pa_map); stream = gvc_mixer_event_role_new (control->priv->pa_context, info->device, map); control->priv->event_sink_input_id = gvc_mixer_stream_get_id (stream); control->priv->event_sink_input_is_set = TRUE; is_new = TRUE; } else { stream = g_hash_table_lookup (control->priv->all_streams, GUINT_TO_POINTER (control->priv->event_sink_input_id)); } max_volume = pa_cvolume_max (&info->volume); gvc_mixer_stream_set_name (stream, _("System Sounds")); gvc_mixer_stream_set_icon_name (stream, "multimedia-volume-control"); gvc_mixer_stream_set_volume (stream, (guint)max_volume); gvc_mixer_stream_set_is_muted (stream, info->mute); if (is_new) { add_stream (control, stream); } } static void _pa_ext_stream_restore_read_cb (pa_context *context, const pa_ext_stream_restore_info *i, int eol, void *userdata) { GvcMixerControl *control = GVC_MIXER_CONTROL (userdata); if (eol < 0) { g_debug ("Failed to initialized stream_restore extension: %s", pa_strerror (pa_context_errno (context))); remove_event_role_stream (control); return; } if (eol > 0) { dec_outstanding (control); /* If we don't have an event stream to restore, then * set one up with a default 100% volume */ if (!control->priv->event_sink_input_is_set) { pa_ext_stream_restore_info info; memset (&info, 0, sizeof(info)); info.name = "sink-input-by-media-role:event"; info.volume.channels = 1; info.volume.values[0] = PA_VOLUME_NORM; update_event_role_stream (control, &info); } return; } update_event_role_stream (control, i); } static void _pa_ext_stream_restore_subscribe_cb (pa_context *context, void *userdata) { GvcMixerControl *control = GVC_MIXER_CONTROL (userdata); pa_operation *o; o = pa_ext_stream_restore_read (context, _pa_ext_stream_restore_read_cb, control); if (o == NULL) { g_warning ("pa_ext_stream_restore_read() failed"); return; } pa_operation_unref (o); } static void req_update_server_info (GvcMixerControl *control, int index) { pa_operation *o; o = pa_context_get_server_info (control->priv->pa_context, _pa_context_get_server_info_cb, control); if (o == NULL) { g_warning ("pa_context_get_server_info() failed"); return; } pa_operation_unref (o); } static void req_update_client_info (GvcMixerControl *control, int index) { pa_operation *o; if (index < 0) { o = pa_context_get_client_info_list (control->priv->pa_context, _pa_context_get_client_info_cb, control); } else { o = pa_context_get_client_info (control->priv->pa_context, index, _pa_context_get_client_info_cb, control); } if (o == NULL) { g_warning ("pa_context_client_info_list() failed"); return; } pa_operation_unref (o); } static void req_update_card (GvcMixerControl *control, int index) { pa_operation *o; if (index < 0) { o = pa_context_get_card_info_list (control->priv->pa_context, _pa_context_get_card_info_by_index_cb, control); } else { o = pa_context_get_card_info_by_index (control->priv->pa_context, index, _pa_context_get_card_info_by_index_cb, control); } if (o == NULL) { g_warning ("pa_context_get_card_info_by_index() failed"); return; } pa_operation_unref (o); } static void req_update_sink_info (GvcMixerControl *control, int index) { pa_operation *o; if (index < 0) { o = pa_context_get_sink_info_list (control->priv->pa_context, _pa_context_get_sink_info_cb, control); } else { o = pa_context_get_sink_info_by_index (control->priv->pa_context, index, _pa_context_get_sink_info_cb, control); } if (o == NULL) { g_warning ("pa_context_get_sink_info_list() failed"); return; } pa_operation_unref (o); } static void req_update_source_info (GvcMixerControl *control, int index) { pa_operation *o; if (index < 0) { o = pa_context_get_source_info_list (control->priv->pa_context, _pa_context_get_source_info_cb, control); } else { o = pa_context_get_source_info_by_index(control->priv->pa_context, index, _pa_context_get_source_info_cb, control); } if (o == NULL) { g_warning ("pa_context_get_source_info_list() failed"); return; } pa_operation_unref (o); } static void req_update_sink_input_info (GvcMixerControl *control, int index) { pa_operation *o; if (index < 0) { o = pa_context_get_sink_input_info_list (control->priv->pa_context, _pa_context_get_sink_input_info_cb, control); } else { o = pa_context_get_sink_input_info (control->priv->pa_context, index, _pa_context_get_sink_input_info_cb, control); } if (o == NULL) { g_warning ("pa_context_get_sink_input_info_list() failed"); return; } pa_operation_unref (o); } static void req_update_source_output_info (GvcMixerControl *control, int index) { pa_operation *o; if (index < 0) { o = pa_context_get_source_output_info_list (control->priv->pa_context, _pa_context_get_source_output_info_cb, control); } else { o = pa_context_get_source_output_info (control->priv->pa_context, index, _pa_context_get_source_output_info_cb, control); } if (o == NULL) { g_warning ("pa_context_get_source_output_info_list() failed"); return; } pa_operation_unref (o); } static void remove_client (GvcMixerControl *control, guint index) { g_hash_table_remove (control->priv->clients, GUINT_TO_POINTER (index)); } static void remove_card (GvcMixerControl *control, guint index) { GList *devices, *d; devices = g_list_concat (g_hash_table_get_values (control->priv->ui_inputs), g_hash_table_get_values (control->priv->ui_outputs)); for (d = devices; d != NULL; d = d->next) { GvcMixerCard *card; GvcMixerUIDevice *device = d->data; g_object_get (G_OBJECT (device), "card", &card, NULL); if (gvc_mixer_card_get_index (card) == index) { g_signal_emit (G_OBJECT (control), signals[gvc_mixer_ui_device_is_output (device) ? OUTPUT_REMOVED : INPUT_REMOVED], 0, gvc_mixer_ui_device_get_id (device)); g_debug ("Card removal remove device %s", gvc_mixer_ui_device_get_description (device)); g_hash_table_remove (gvc_mixer_ui_device_is_output (device) ? control->priv->ui_outputs : control->priv->ui_inputs, GUINT_TO_POINTER (gvc_mixer_ui_device_get_id (device))); } } g_list_free (devices); g_hash_table_remove (control->priv->cards, GUINT_TO_POINTER (index)); g_signal_emit (G_OBJECT (control), signals[CARD_REMOVED], 0, index); } static void remove_sink (GvcMixerControl *control, guint index) { GvcMixerStream *stream; GvcMixerUIDevice *device; g_debug ("Removing sink: index=%u", index); stream = g_hash_table_lookup (control->priv->sinks, GUINT_TO_POINTER (index)); if (stream == NULL) return; device = gvc_mixer_control_lookup_device_from_stream (control, stream); if (device != NULL) { gvc_mixer_ui_device_invalidate_stream (device); if (!gvc_mixer_ui_device_has_ports (device)) { g_signal_emit (G_OBJECT (control), signals[OUTPUT_REMOVED], 0, gvc_mixer_ui_device_get_id (device)); } else { GList *devices, *d; devices = g_hash_table_get_values (control->priv->ui_outputs); for (d = devices; d != NULL; d = d->next) { gint stream_id = GVC_MIXER_UI_DEVICE_INVALID; device = d->data; g_object_get (G_OBJECT (device), "stream-id", &stream_id, NULL); if (stream_id == gvc_mixer_stream_get_id (stream)) gvc_mixer_ui_device_invalidate_stream (device); } g_list_free (devices); } } g_hash_table_remove (control->priv->sinks, GUINT_TO_POINTER (index)); remove_stream (control, stream); } static void remove_source (GvcMixerControl *control, guint index) { GvcMixerStream *stream; GvcMixerUIDevice *device; g_debug ("Removing source: index=%u", index); stream = g_hash_table_lookup (control->priv->sources, GUINT_TO_POINTER (index)); if (stream == NULL) return; device = gvc_mixer_control_lookup_device_from_stream (control, stream); if (device != NULL) { gvc_mixer_ui_device_invalidate_stream (device); if (!gvc_mixer_ui_device_has_ports (device)) { g_signal_emit (G_OBJECT (control), signals[INPUT_REMOVED], 0, gvc_mixer_ui_device_get_id (device)); } else { GList *devices, *d; devices = g_hash_table_get_values (control->priv->ui_inputs); for (d = devices; d != NULL; d = d->next) { gint stream_id = GVC_MIXER_UI_DEVICE_INVALID; device = d->data; g_object_get (G_OBJECT (device), "stream-id", &stream_id, NULL); if (stream_id == gvc_mixer_stream_get_id (stream)) gvc_mixer_ui_device_invalidate_stream (device); } g_list_free (devices); } } g_hash_table_remove (control->priv->sources, GUINT_TO_POINTER (index)); remove_stream (control, stream); } static void remove_sink_input (GvcMixerControl *control, guint index) { GvcMixerStream *stream; g_debug ("Removing sink input: index=%u", index); stream = g_hash_table_lookup (control->priv->sink_inputs, GUINT_TO_POINTER (index)); if (stream == NULL) { return; } g_hash_table_remove (control->priv->sink_inputs, GUINT_TO_POINTER (index)); remove_stream (control, stream); } static void remove_source_output (GvcMixerControl *control, guint index) { GvcMixerStream *stream; g_debug ("Removing source output: index=%u", index); stream = g_hash_table_lookup (control->priv->source_outputs, GUINT_TO_POINTER (index)); if (stream == NULL) { return; } g_hash_table_remove (control->priv->source_outputs, GUINT_TO_POINTER (index)); remove_stream (control, stream); } static void _pa_context_subscribe_cb (pa_context *context, pa_subscription_event_type_t t, uint32_t index, void *userdata) { GvcMixerControl *control = GVC_MIXER_CONTROL (userdata); switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) { case PA_SUBSCRIPTION_EVENT_SINK: if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { remove_sink (control, index); } else { req_update_sink_info (control, index); } break; case PA_SUBSCRIPTION_EVENT_SOURCE: if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { remove_source (control, index); } else { req_update_source_info (control, index); } break; case PA_SUBSCRIPTION_EVENT_SINK_INPUT: if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { remove_sink_input (control, index); } else { req_update_sink_input_info (control, index); } break; case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT: if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { remove_source_output (control, index); } else { req_update_source_output_info (control, index); } break; case PA_SUBSCRIPTION_EVENT_CLIENT: if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { remove_client (control, index); } else { req_update_client_info (control, index); } break; case PA_SUBSCRIPTION_EVENT_SERVER: req_update_server_info (control, index); break; case PA_SUBSCRIPTION_EVENT_CARD: if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { remove_card (control, index); } else { req_update_card (control, index); } break; } } static void gvc_mixer_control_ready (GvcMixerControl *control) { pa_operation *o; pa_context_set_subscribe_callback (control->priv->pa_context, _pa_context_subscribe_cb, control); o = pa_context_subscribe (control->priv->pa_context, (pa_subscription_mask_t) (PA_SUBSCRIPTION_MASK_SINK| PA_SUBSCRIPTION_MASK_SOURCE| PA_SUBSCRIPTION_MASK_SINK_INPUT| PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT| PA_SUBSCRIPTION_MASK_CLIENT| PA_SUBSCRIPTION_MASK_SERVER| PA_SUBSCRIPTION_MASK_CARD), NULL, NULL); if (o == NULL) { g_warning ("pa_context_subscribe() failed"); return; } pa_operation_unref (o); req_update_server_info (control, -1); req_update_card (control, -1); req_update_client_info (control, -1); req_update_sink_info (control, -1); req_update_source_info (control, -1); req_update_sink_input_info (control, -1); req_update_source_output_info (control, -1); control->priv->n_outstanding = 6; /* This call is not always supported */ o = pa_ext_stream_restore_read (control->priv->pa_context, _pa_ext_stream_restore_read_cb, control); if (o != NULL) { pa_operation_unref (o); control->priv->n_outstanding++; pa_ext_stream_restore_set_subscribe_cb (control->priv->pa_context, _pa_ext_stream_restore_subscribe_cb, control); o = pa_ext_stream_restore_subscribe (control->priv->pa_context, 1, NULL, NULL); if (o != NULL) { pa_operation_unref (o); } } else { g_debug ("Failed to initialized stream_restore extension: %s", pa_strerror (pa_context_errno (control->priv->pa_context))); } } static void gvc_mixer_new_pa_context (GvcMixerControl *self) { pa_proplist *proplist; g_return_if_fail (self); g_return_if_fail (!self->priv->pa_context); proplist = pa_proplist_new (); pa_proplist_sets (proplist, PA_PROP_APPLICATION_NAME, self->priv->name); pa_proplist_sets (proplist, PA_PROP_APPLICATION_ID, "org.gnome.VolumeControl"); pa_proplist_sets (proplist, PA_PROP_APPLICATION_ICON_NAME, "multimedia-volume-control"); pa_proplist_sets (proplist, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION); self->priv->pa_context = pa_context_new_with_proplist (self->priv->pa_api, NULL, proplist); pa_proplist_free (proplist); g_assert (self->priv->pa_context); } static void remove_all_streams (GvcMixerControl *control, GHashTable *hash_table) { GHashTableIter iter; gpointer key, value; g_hash_table_iter_init (&iter, hash_table); while (g_hash_table_iter_next (&iter, &key, &value)) { remove_stream (control, value); g_hash_table_iter_remove (&iter); } } static gboolean idle_reconnect (gpointer data) { GvcMixerControl *control = GVC_MIXER_CONTROL (data); GHashTableIter iter; gpointer key, value; g_return_val_if_fail (control, FALSE); if (control->priv->pa_context) { pa_context_unref (control->priv->pa_context); control->priv->pa_context = NULL; gvc_mixer_new_pa_context (control); } remove_all_streams (control, control->priv->sinks); remove_all_streams (control, control->priv->sources); remove_all_streams (control, control->priv->sink_inputs); remove_all_streams (control, control->priv->source_outputs); g_hash_table_iter_init (&iter, control->priv->clients); while (g_hash_table_iter_next (&iter, &key, &value)) g_hash_table_iter_remove (&iter); gvc_mixer_control_open (control); /* cannot fail */ control->priv->reconnect_id = 0; return FALSE; } static void _pa_context_state_cb (pa_context *context, void *userdata) { GvcMixerControl *control = GVC_MIXER_CONTROL (userdata); switch (pa_context_get_state (context)) { case PA_CONTEXT_UNCONNECTED: case PA_CONTEXT_CONNECTING: case PA_CONTEXT_AUTHORIZING: case PA_CONTEXT_SETTING_NAME: break; case PA_CONTEXT_READY: gvc_mixer_control_ready (control); break; case PA_CONTEXT_FAILED: control->priv->state = GVC_STATE_FAILED; g_signal_emit (control, signals[STATE_CHANGED], 0, GVC_STATE_FAILED); if (control->priv->reconnect_id == 0) control->priv->reconnect_id = g_timeout_add_seconds (RECONNECT_DELAY, idle_reconnect, control); break; case PA_CONTEXT_TERMINATED: default: /* FIXME: */ break; } } gboolean gvc_mixer_control_open (GvcMixerControl *control) { int res; g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), FALSE); g_return_val_if_fail (control->priv->pa_context != NULL, FALSE); g_return_val_if_fail (pa_context_get_state (control->priv->pa_context) == PA_CONTEXT_UNCONNECTED, FALSE); pa_context_set_state_callback (control->priv->pa_context, _pa_context_state_cb, control); control->priv->state = GVC_STATE_CONNECTING; g_signal_emit (G_OBJECT (control), signals[STATE_CHANGED], 0, GVC_STATE_CONNECTING); res = pa_context_connect (control->priv->pa_context, NULL, (pa_context_flags_t) PA_CONTEXT_NOFAIL, NULL); if (res < 0) { g_warning ("Failed to connect context: %s", pa_strerror (pa_context_errno (control->priv->pa_context))); } return res; } gboolean gvc_mixer_control_close (GvcMixerControl *control) { g_return_val_if_fail (GVC_IS_MIXER_CONTROL (control), FALSE); g_return_val_if_fail (control->priv->pa_context != NULL, FALSE); pa_context_disconnect (control->priv->pa_context); control->priv->state = GVC_STATE_CLOSED; g_signal_emit (G_OBJECT (control), signals[STATE_CHANGED], 0, GVC_STATE_CLOSED); return TRUE; } static void gvc_mixer_control_dispose (GObject *object) { GvcMixerControl *control = GVC_MIXER_CONTROL (object); if (control->priv->reconnect_id != 0) { g_source_remove (control->priv->reconnect_id); control->priv->reconnect_id = 0; } if (control->priv->pa_context != NULL) { pa_context_unref (control->priv->pa_context); control->priv->pa_context = NULL; } if (control->priv->default_source_name != NULL) { g_free (control->priv->default_source_name); control->priv->default_source_name = NULL; } if (control->priv->default_sink_name != NULL) { g_free (control->priv->default_sink_name); control->priv->default_sink_name = NULL; } if (control->priv->pa_mainloop != NULL) { pa_glib_mainloop_free (control->priv->pa_mainloop); control->priv->pa_mainloop = NULL; } if (control->priv->all_streams != NULL) { g_hash_table_destroy (control->priv->all_streams); control->priv->all_streams = NULL; } if (control->priv->sinks != NULL) { g_hash_table_destroy (control->priv->sinks); control->priv->sinks = NULL; } if (control->priv->sources != NULL) { g_hash_table_destroy (control->priv->sources); control->priv->sources = NULL; } if (control->priv->sink_inputs != NULL) { g_hash_table_destroy (control->priv->sink_inputs); control->priv->sink_inputs = NULL; } if (control->priv->source_outputs != NULL) { g_hash_table_destroy (control->priv->source_outputs); control->priv->source_outputs = NULL; } if (control->priv->clients != NULL) { g_hash_table_destroy (control->priv->clients); control->priv->clients = NULL; } if (control->priv->cards != NULL) { g_hash_table_destroy (control->priv->cards); control->priv->cards = NULL; } if (control->priv->ui_outputs != NULL) { g_hash_table_destroy (control->priv->ui_outputs); control->priv->ui_outputs = NULL; } if (control->priv->ui_inputs != NULL) { g_hash_table_destroy (control->priv->ui_inputs); control->priv->ui_inputs = NULL; } G_OBJECT_CLASS (gvc_mixer_control_parent_class)->dispose (object); } static void gvc_mixer_control_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GvcMixerControl *self = GVC_MIXER_CONTROL (object); switch (prop_id) { case PROP_NAME: g_free (self->priv->name); self->priv->name = g_value_dup_string (value); g_object_notify (G_OBJECT (self), "name"); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gvc_mixer_control_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GvcMixerControl *self = GVC_MIXER_CONTROL (object); switch (prop_id) { case PROP_NAME: g_value_set_string (value, self->priv->name); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static GObject * gvc_mixer_control_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_params) { GObject *object; GvcMixerControl *self; object = G_OBJECT_CLASS (gvc_mixer_control_parent_class)->constructor (type, n_construct_properties, construct_params); self = GVC_MIXER_CONTROL (object); gvc_mixer_new_pa_context (self); self->priv->profile_swapping_device_id = GVC_MIXER_UI_DEVICE_INVALID; return object; } static void gvc_mixer_control_class_init (GvcMixerControlClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructor = gvc_mixer_control_constructor; object_class->dispose = gvc_mixer_control_dispose; object_class->finalize = gvc_mixer_control_finalize; object_class->set_property = gvc_mixer_control_set_property; object_class->get_property = gvc_mixer_control_get_property; g_object_class_install_property (object_class, PROP_NAME, g_param_spec_string ("name", "Name", "Name to display for this mixer control", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)); signals [STATE_CHANGED] = g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, state_changed), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [STREAM_ADDED] = g_signal_new ("stream-added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, stream_added), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [STREAM_REMOVED] = g_signal_new ("stream-removed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, stream_removed), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [CARD_INFO] = g_signal_new ("card-info", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); signals [CARD_ADDED] = g_signal_new ("card-added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, card_added), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [CARD_REMOVED] = g_signal_new ("card-removed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, card_removed), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [DEFAULT_SINK_CHANGED] = g_signal_new ("default-sink-changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, default_sink_changed), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [DEFAULT_SOURCE_CHANGED] = g_signal_new ("default-source-changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, default_source_changed), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [ACTIVE_OUTPUT_UPDATE] = g_signal_new ("active-output-update", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, active_output_update), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [ACTIVE_INPUT_UPDATE] = g_signal_new ("active-input-update", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, active_input_update), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [OUTPUT_ADDED] = g_signal_new ("output-added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, output_added), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [INPUT_ADDED] = g_signal_new ("input-added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, input_added), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [OUTPUT_REMOVED] = g_signal_new ("output-removed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, output_removed), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); signals [INPUT_REMOVED] = g_signal_new ("input-removed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GvcMixerControlClass, input_removed), NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); g_type_class_add_private (klass, sizeof (GvcMixerControlPrivate)); } static void gvc_mixer_control_init (GvcMixerControl *control) { control->priv = GVC_MIXER_CONTROL_GET_PRIVATE (control); control->priv->pa_mainloop = pa_glib_mainloop_new (g_main_context_default ()); g_assert (control->priv->pa_mainloop); control->priv->pa_api = pa_glib_mainloop_get_api (control->priv->pa_mainloop); g_assert (control->priv->pa_api); control->priv->all_streams = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_object_unref); control->priv->sinks = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_object_unref); control->priv->sources = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_object_unref); control->priv->sink_inputs = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_object_unref); control->priv->source_outputs = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_object_unref); control->priv->cards = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_object_unref); control->priv->ui_outputs = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_object_unref); control->priv->ui_inputs = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_object_unref); control->priv->clients = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_free); control->priv->state = GVC_STATE_CLOSED; } static void gvc_mixer_control_finalize (GObject *object) { GvcMixerControl *mixer_control; g_return_if_fail (object != NULL); g_return_if_fail (GVC_IS_MIXER_CONTROL (object)); mixer_control = GVC_MIXER_CONTROL (object); g_free (mixer_control->priv->name); mixer_control->priv->name = NULL; g_return_if_fail (mixer_control->priv != NULL); G_OBJECT_CLASS (gvc_mixer_control_parent_class)->finalize (object); } GvcMixerControl * gvc_mixer_control_new (const char *name) { GObject *control; control = g_object_new (GVC_TYPE_MIXER_CONTROL, "name", name, NULL); return GVC_MIXER_CONTROL (control); } gdouble gvc_mixer_control_get_vol_max_norm (GvcMixerControl *control) { return (gdouble) PA_VOLUME_NORM; } gdouble gvc_mixer_control_get_vol_max_amplified (GvcMixerControl *control) { return (gdouble) PA_VOLUME_UI_MAX; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-control.h0000664000175000017500000001637200000000000027067 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_MIXER_CONTROL_H #define __GVC_MIXER_CONTROL_H #include #include "gvc-mixer-stream.h" #include "gvc-mixer-card.h" #include "gvc-mixer-ui-device.h" G_BEGIN_DECLS typedef enum { GVC_STATE_CLOSED, GVC_STATE_READY, GVC_STATE_CONNECTING, GVC_STATE_FAILED } GvcMixerControlState; #define GVC_TYPE_MIXER_CONTROL (gvc_mixer_control_get_type ()) #define GVC_MIXER_CONTROL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_CONTROL, GvcMixerControl)) #define GVC_MIXER_CONTROL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_CONTROL, GvcMixerControlClass)) #define GVC_IS_MIXER_CONTROL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_CONTROL)) #define GVC_IS_MIXER_CONTROL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_CONTROL)) #define GVC_MIXER_CONTROL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_CONTROL, GvcMixerControlClass)) typedef struct GvcMixerControlPrivate GvcMixerControlPrivate; typedef struct { GObject parent; GvcMixerControlPrivate *priv; } GvcMixerControl; typedef struct { GObjectClass parent_class; void (*state_changed) (GvcMixerControl *control, GvcMixerControlState new_state); void (*stream_added) (GvcMixerControl *control, guint id); void (*stream_removed) (GvcMixerControl *control, guint id); void (*card_added) (GvcMixerControl *control, guint id); void (*card_removed) (GvcMixerControl *control, guint id); void (*default_sink_changed) (GvcMixerControl *control, guint id); void (*default_source_changed) (GvcMixerControl *control, guint id); void (*active_output_update) (GvcMixerControl *control, guint id); void (*active_input_update) (GvcMixerControl *control, guint id); void (*output_added) (GvcMixerControl *control, guint id); void (*input_added) (GvcMixerControl *control, guint id); void (*output_removed) (GvcMixerControl *control, guint id); void (*input_removed) (GvcMixerControl *control, guint id); } GvcMixerControlClass; GType gvc_mixer_control_get_type (void); GvcMixerControl * gvc_mixer_control_new (const char *name); gboolean gvc_mixer_control_open (GvcMixerControl *control); gboolean gvc_mixer_control_close (GvcMixerControl *control); GSList * gvc_mixer_control_get_cards (GvcMixerControl *control); GSList * gvc_mixer_control_get_streams (GvcMixerControl *control); GSList * gvc_mixer_control_get_sinks (GvcMixerControl *control); GSList * gvc_mixer_control_get_sources (GvcMixerControl *control); GSList * gvc_mixer_control_get_sink_inputs (GvcMixerControl *control); GSList * gvc_mixer_control_get_source_outputs (GvcMixerControl *control); GvcMixerStream * gvc_mixer_control_lookup_stream_id (GvcMixerControl *control, guint id); GvcMixerCard * gvc_mixer_control_lookup_card_id (GvcMixerControl *control, guint id); GvcMixerUIDevice * gvc_mixer_control_lookup_output_id (GvcMixerControl *control, guint id); GvcMixerUIDevice * gvc_mixer_control_lookup_input_id (GvcMixerControl *control, guint id); GvcMixerUIDevice * gvc_mixer_control_lookup_device_from_stream (GvcMixerControl *control, GvcMixerStream *stream); GvcMixerStream * gvc_mixer_control_get_default_sink (GvcMixerControl *control); GvcMixerStream * gvc_mixer_control_get_default_source (GvcMixerControl *control); GvcMixerStream * gvc_mixer_control_get_event_sink_input (GvcMixerControl *control); gboolean gvc_mixer_control_set_default_sink (GvcMixerControl *control, GvcMixerStream *stream); gboolean gvc_mixer_control_set_default_source (GvcMixerControl *control, GvcMixerStream *stream); gdouble gvc_mixer_control_get_vol_max_norm (GvcMixerControl *control); gdouble gvc_mixer_control_get_vol_max_amplified (GvcMixerControl *control); void gvc_mixer_control_change_output (GvcMixerControl *control, GvcMixerUIDevice* output); void gvc_mixer_control_change_input (GvcMixerControl *control, GvcMixerUIDevice* input); GvcMixerStream* gvc_mixer_control_get_stream_from_device (GvcMixerControl *control, GvcMixerUIDevice *device); gboolean gvc_mixer_control_change_profile_on_selected_device (GvcMixerControl *control, GvcMixerUIDevice *device, const gchar* profile); GvcMixerControlState gvc_mixer_control_get_state (GvcMixerControl *control); G_END_DECLS #endif /* __GVC_MIXER_CONTROL_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-event-role.c0000664000175000017500000001701100000000000027451 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include "gvc-mixer-event-role.h" #include "gvc-mixer-stream-private.h" #include "gvc-channel-map-private.h" #define GVC_MIXER_EVENT_ROLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_EVENT_ROLE, GvcMixerEventRolePrivate)) struct GvcMixerEventRolePrivate { char *device; }; enum { PROP_0, PROP_DEVICE }; static void gvc_mixer_event_role_class_init (GvcMixerEventRoleClass *klass); static void gvc_mixer_event_role_init (GvcMixerEventRole *mixer_event_role); static void gvc_mixer_event_role_finalize (GObject *object); G_DEFINE_TYPE (GvcMixerEventRole, gvc_mixer_event_role, GVC_TYPE_MIXER_STREAM) static gboolean update_settings (GvcMixerEventRole *role, gboolean is_muted, gpointer *op) { pa_operation *o; const GvcChannelMap *map; pa_context *context; pa_ext_stream_restore_info info; map = gvc_mixer_stream_get_channel_map (GVC_MIXER_STREAM(role)); info.volume = *gvc_channel_map_get_cvolume(map); info.name = "sink-input-by-media-role:event"; info.channel_map = *gvc_channel_map_get_pa_channel_map(map); info.device = role->priv->device; info.mute = is_muted; context = gvc_mixer_stream_get_pa_context (GVC_MIXER_STREAM (role)); o = pa_ext_stream_restore_write (context, PA_UPDATE_REPLACE, &info, 1, TRUE, NULL, NULL); if (o == NULL) { g_warning ("pa_ext_stream_restore_write() failed"); return FALSE; } if (op != NULL) *op = o; return TRUE; } static gboolean gvc_mixer_event_role_push_volume (GvcMixerStream *stream, gpointer *op) { return update_settings (GVC_MIXER_EVENT_ROLE (stream), gvc_mixer_stream_get_is_muted (stream), op); } static gboolean gvc_mixer_event_role_change_is_muted (GvcMixerStream *stream, gboolean is_muted) { /* Apply change straight away so that we don't get a race with * gvc_mixer_event_role_push_volume(). * See https://bugs.freedesktop.org/show_bug.cgi?id=51413 */ gvc_mixer_stream_set_is_muted (stream, is_muted); return update_settings (GVC_MIXER_EVENT_ROLE (stream), is_muted, NULL); } static gboolean gvc_mixer_event_role_set_device (GvcMixerEventRole *role, const char *device) { g_return_val_if_fail (GVC_IS_MIXER_EVENT_ROLE (role), FALSE); g_free (role->priv->device); role->priv->device = g_strdup (device); g_object_notify (G_OBJECT (role), "device"); return TRUE; } static void gvc_mixer_event_role_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GvcMixerEventRole *self = GVC_MIXER_EVENT_ROLE (object); switch (prop_id) { case PROP_DEVICE: gvc_mixer_event_role_set_device (self, g_value_get_string (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gvc_mixer_event_role_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GvcMixerEventRole *self = GVC_MIXER_EVENT_ROLE (object); switch (prop_id) { case PROP_DEVICE: g_value_set_string (value, self->priv->device); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gvc_mixer_event_role_class_init (GvcMixerEventRoleClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass); object_class->finalize = gvc_mixer_event_role_finalize; object_class->set_property = gvc_mixer_event_role_set_property; object_class->get_property = gvc_mixer_event_role_get_property; stream_class->push_volume = gvc_mixer_event_role_push_volume; stream_class->change_is_muted = gvc_mixer_event_role_change_is_muted; g_object_class_install_property (object_class, PROP_DEVICE, g_param_spec_string ("device", "Device", "Device", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_type_class_add_private (klass, sizeof (GvcMixerEventRolePrivate)); } static void gvc_mixer_event_role_init (GvcMixerEventRole *event_role) { event_role->priv = GVC_MIXER_EVENT_ROLE_GET_PRIVATE (event_role); } static void gvc_mixer_event_role_finalize (GObject *object) { GvcMixerEventRole *mixer_event_role; g_return_if_fail (object != NULL); g_return_if_fail (GVC_IS_MIXER_EVENT_ROLE (object)); mixer_event_role = GVC_MIXER_EVENT_ROLE (object); g_return_if_fail (mixer_event_role->priv != NULL); g_free (mixer_event_role->priv->device); G_OBJECT_CLASS (gvc_mixer_event_role_parent_class)->finalize (object); } /** * gvc_mixer_event_role_new: (skip) * @context: * @device: * @channel_map: * * Returns: */ GvcMixerStream * gvc_mixer_event_role_new (pa_context *context, const char *device, GvcChannelMap *channel_map) { GObject *object; object = g_object_new (GVC_TYPE_MIXER_EVENT_ROLE, "pa-context", context, "index", 0, "device", device, "channel-map", channel_map, NULL); return GVC_MIXER_STREAM (object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-event-role.h0000664000175000017500000000433400000000000027462 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_MIXER_EVENT_ROLE_H #define __GVC_MIXER_EVENT_ROLE_H #include #include "gvc-mixer-stream.h" G_BEGIN_DECLS #define GVC_TYPE_MIXER_EVENT_ROLE (gvc_mixer_event_role_get_type ()) #define GVC_MIXER_EVENT_ROLE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_EVENT_ROLE, GvcMixerEventRole)) #define GVC_MIXER_EVENT_ROLE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_EVENT_ROLE, GvcMixerEventRoleClass)) #define GVC_IS_MIXER_EVENT_ROLE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_EVENT_ROLE)) #define GVC_IS_MIXER_EVENT_ROLE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_EVENT_ROLE)) #define GVC_MIXER_EVENT_ROLE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_EVENT_ROLE, GvcMixerEventRoleClass)) typedef struct GvcMixerEventRolePrivate GvcMixerEventRolePrivate; typedef struct { GvcMixerStream parent; GvcMixerEventRolePrivate *priv; } GvcMixerEventRole; typedef struct { GvcMixerStreamClass parent_class; } GvcMixerEventRoleClass; GType gvc_mixer_event_role_get_type (void); GvcMixerStream * gvc_mixer_event_role_new (pa_context *context, const char *device, GvcChannelMap *channel_map); G_END_DECLS #endif /* __GVC_MIXER_EVENT_ROLE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-sink-input.c0000664000175000017500000001170200000000000027473 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include "gvc-mixer-sink-input.h" #include "gvc-mixer-stream-private.h" #include "gvc-channel-map-private.h" #define GVC_MIXER_SINK_INPUT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SINK_INPUT, GvcMixerSinkInputPrivate)) struct GvcMixerSinkInputPrivate { gpointer dummy; }; static void gvc_mixer_sink_input_class_init (GvcMixerSinkInputClass *klass); static void gvc_mixer_sink_input_init (GvcMixerSinkInput *mixer_sink_input); static void gvc_mixer_sink_input_finalize (GObject *object); G_DEFINE_TYPE (GvcMixerSinkInput, gvc_mixer_sink_input, GVC_TYPE_MIXER_STREAM) static gboolean gvc_mixer_sink_input_push_volume (GvcMixerStream *stream, gpointer *op) { pa_operation *o; guint index; const GvcChannelMap *map; pa_context *context; const pa_cvolume *cv; index = gvc_mixer_stream_get_index (stream); map = gvc_mixer_stream_get_channel_map (stream); cv = gvc_channel_map_get_cvolume(map); context = gvc_mixer_stream_get_pa_context (stream); o = pa_context_set_sink_input_volume (context, index, cv, NULL, NULL); if (o == NULL) { g_warning ("pa_context_set_sink_input_volume() failed"); return FALSE; } *op = o; return TRUE; } static gboolean gvc_mixer_sink_input_change_is_muted (GvcMixerStream *stream, gboolean is_muted) { pa_operation *o; guint index; pa_context *context; index = gvc_mixer_stream_get_index (stream); context = gvc_mixer_stream_get_pa_context (stream); o = pa_context_set_sink_input_mute (context, index, is_muted, NULL, NULL); if (o == NULL) { g_warning ("pa_context_set_sink_input_mute_by_index() failed"); return FALSE; } pa_operation_unref(o); return TRUE; } static void gvc_mixer_sink_input_class_init (GvcMixerSinkInputClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass); object_class->finalize = gvc_mixer_sink_input_finalize; stream_class->push_volume = gvc_mixer_sink_input_push_volume; stream_class->change_is_muted = gvc_mixer_sink_input_change_is_muted; g_type_class_add_private (klass, sizeof (GvcMixerSinkInputPrivate)); } static void gvc_mixer_sink_input_init (GvcMixerSinkInput *sink_input) { sink_input->priv = GVC_MIXER_SINK_INPUT_GET_PRIVATE (sink_input); } static void gvc_mixer_sink_input_finalize (GObject *object) { GvcMixerSinkInput *mixer_sink_input; g_return_if_fail (object != NULL); g_return_if_fail (GVC_IS_MIXER_SINK_INPUT (object)); mixer_sink_input = GVC_MIXER_SINK_INPUT (object); g_return_if_fail (mixer_sink_input->priv != NULL); G_OBJECT_CLASS (gvc_mixer_sink_input_parent_class)->finalize (object); } /** * gvc_mixer_sink_input_new: (skip) * @context: * @index: * @channel_map: * * Returns: */ GvcMixerStream * gvc_mixer_sink_input_new (pa_context *context, guint index, GvcChannelMap *channel_map) { GObject *object; object = g_object_new (GVC_TYPE_MIXER_SINK_INPUT, "pa-context", context, "index", index, "channel-map", channel_map, NULL); return GVC_MIXER_STREAM (object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-sink-input.h0000664000175000017500000000433300000000000027502 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_MIXER_SINK_INPUT_H #define __GVC_MIXER_SINK_INPUT_H #include #include "gvc-mixer-stream.h" G_BEGIN_DECLS #define GVC_TYPE_MIXER_SINK_INPUT (gvc_mixer_sink_input_get_type ()) #define GVC_MIXER_SINK_INPUT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_SINK_INPUT, GvcMixerSinkInput)) #define GVC_MIXER_SINK_INPUT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_SINK_INPUT, GvcMixerSinkInputClass)) #define GVC_IS_MIXER_SINK_INPUT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_SINK_INPUT)) #define GVC_IS_MIXER_SINK_INPUT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_SINK_INPUT)) #define GVC_MIXER_SINK_INPUT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_SINK_INPUT, GvcMixerSinkInputClass)) typedef struct GvcMixerSinkInputPrivate GvcMixerSinkInputPrivate; typedef struct { GvcMixerStream parent; GvcMixerSinkInputPrivate *priv; } GvcMixerSinkInput; typedef struct { GvcMixerStreamClass parent_class; } GvcMixerSinkInputClass; GType gvc_mixer_sink_input_get_type (void); GvcMixerStream * gvc_mixer_sink_input_new (pa_context *context, guint index, GvcChannelMap *channel_map); G_END_DECLS #endif /* __GVC_MIXER_SINK_INPUT_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-sink.c0000664000175000017500000001334000000000000026336 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include "gvc-mixer-sink.h" #include "gvc-mixer-stream-private.h" #include "gvc-channel-map-private.h" #define GVC_MIXER_SINK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SINK, GvcMixerSinkPrivate)) struct GvcMixerSinkPrivate { gpointer dummy; }; static void gvc_mixer_sink_class_init (GvcMixerSinkClass *klass); static void gvc_mixer_sink_init (GvcMixerSink *mixer_sink); static void gvc_mixer_sink_finalize (GObject *object); G_DEFINE_TYPE (GvcMixerSink, gvc_mixer_sink, GVC_TYPE_MIXER_STREAM) static gboolean gvc_mixer_sink_push_volume (GvcMixerStream *stream, gpointer *op) { pa_operation *o; guint index; const GvcChannelMap *map; pa_context *context; const pa_cvolume *cv; index = gvc_mixer_stream_get_index (stream); map = gvc_mixer_stream_get_channel_map (stream); /* set the volume */ cv = gvc_channel_map_get_cvolume(map); context = gvc_mixer_stream_get_pa_context (stream); o = pa_context_set_sink_volume_by_index (context, index, cv, NULL, NULL); if (o == NULL) { g_warning ("pa_context_set_sink_volume_by_index() failed: %s", pa_strerror(pa_context_errno(context))); return FALSE; } *op = o; return TRUE; } static gboolean gvc_mixer_sink_change_is_muted (GvcMixerStream *stream, gboolean is_muted) { pa_operation *o; guint index; pa_context *context; index = gvc_mixer_stream_get_index (stream); context = gvc_mixer_stream_get_pa_context (stream); o = pa_context_set_sink_mute_by_index (context, index, is_muted, NULL, NULL); if (o == NULL) { g_warning ("pa_context_set_sink_mute_by_index() failed: %s", pa_strerror(pa_context_errno(context))); return FALSE; } pa_operation_unref(o); return TRUE; } static gboolean gvc_mixer_sink_change_port (GvcMixerStream *stream, const char *port) { pa_operation *o; guint index; pa_context *context; index = gvc_mixer_stream_get_index (stream); context = gvc_mixer_stream_get_pa_context (stream); o = pa_context_set_sink_port_by_index (context, index, port, NULL, NULL); if (o == NULL) { g_warning ("pa_context_set_sink_port_by_index() failed: %s", pa_strerror(pa_context_errno(context))); return FALSE; } pa_operation_unref(o); return TRUE; } static void gvc_mixer_sink_class_init (GvcMixerSinkClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass); object_class->finalize = gvc_mixer_sink_finalize; stream_class->push_volume = gvc_mixer_sink_push_volume; stream_class->change_port = gvc_mixer_sink_change_port; stream_class->change_is_muted = gvc_mixer_sink_change_is_muted; g_type_class_add_private (klass, sizeof (GvcMixerSinkPrivate)); } static void gvc_mixer_sink_init (GvcMixerSink *sink) { sink->priv = GVC_MIXER_SINK_GET_PRIVATE (sink); } static void gvc_mixer_sink_finalize (GObject *object) { GvcMixerSink *mixer_sink; g_return_if_fail (object != NULL); g_return_if_fail (GVC_IS_MIXER_SINK (object)); mixer_sink = GVC_MIXER_SINK (object); g_return_if_fail (mixer_sink->priv != NULL); G_OBJECT_CLASS (gvc_mixer_sink_parent_class)->finalize (object); } /** * gvc_mixer_sink_new: (skip) * @context: * @index: * @channel_map: * * Returns: */ GvcMixerStream * gvc_mixer_sink_new (pa_context *context, guint index, GvcChannelMap *channel_map) { GObject *object; object = g_object_new (GVC_TYPE_MIXER_SINK, "pa-context", context, "index", index, "channel-map", channel_map, NULL); return GVC_MIXER_STREAM (object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-sink.h0000664000175000017500000000412400000000000026343 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_MIXER_SINK_H #define __GVC_MIXER_SINK_H #include #include "gvc-mixer-stream.h" G_BEGIN_DECLS #define GVC_TYPE_MIXER_SINK (gvc_mixer_sink_get_type ()) #define GVC_MIXER_SINK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_SINK, GvcMixerSink)) #define GVC_MIXER_SINK_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_SINK, GvcMixerSinkClass)) #define GVC_IS_MIXER_SINK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_SINK)) #define GVC_IS_MIXER_SINK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_SINK)) #define GVC_MIXER_SINK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_SINK, GvcMixerSinkClass)) typedef struct GvcMixerSinkPrivate GvcMixerSinkPrivate; typedef struct { GvcMixerStream parent; GvcMixerSinkPrivate *priv; } GvcMixerSink; typedef struct { GvcMixerStreamClass parent_class; } GvcMixerSinkClass; GType gvc_mixer_sink_get_type (void); GvcMixerStream * gvc_mixer_sink_new (pa_context *context, guint index, GvcChannelMap *channel_map); G_END_DECLS #endif /* __GVC_MIXER_SINK_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-source-output.c0000664000175000017500000000717400000000000030240 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include "gvc-mixer-source-output.h" #define GVC_MIXER_SOURCE_OUTPUT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SOURCE_OUTPUT, GvcMixerSourceOutputPrivate)) struct GvcMixerSourceOutputPrivate { gpointer dummy; }; static void gvc_mixer_source_output_class_init (GvcMixerSourceOutputClass *klass); static void gvc_mixer_source_output_init (GvcMixerSourceOutput *mixer_source_output); static void gvc_mixer_source_output_finalize (GObject *object); G_DEFINE_TYPE (GvcMixerSourceOutput, gvc_mixer_source_output, GVC_TYPE_MIXER_STREAM) static gboolean gvc_mixer_source_output_push_volume (GvcMixerStream *stream, gpointer *op) { /* FIXME: */ *op = NULL; return TRUE; } static gboolean gvc_mixer_source_output_change_is_muted (GvcMixerStream *stream, gboolean is_muted) { /* FIXME: */ return TRUE; } static void gvc_mixer_source_output_class_init (GvcMixerSourceOutputClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass); object_class->finalize = gvc_mixer_source_output_finalize; stream_class->push_volume = gvc_mixer_source_output_push_volume; stream_class->change_is_muted = gvc_mixer_source_output_change_is_muted; g_type_class_add_private (klass, sizeof (GvcMixerSourceOutputPrivate)); } static void gvc_mixer_source_output_init (GvcMixerSourceOutput *source_output) { source_output->priv = GVC_MIXER_SOURCE_OUTPUT_GET_PRIVATE (source_output); } static void gvc_mixer_source_output_finalize (GObject *object) { GvcMixerSourceOutput *mixer_source_output; g_return_if_fail (object != NULL); g_return_if_fail (GVC_IS_MIXER_SOURCE_OUTPUT (object)); mixer_source_output = GVC_MIXER_SOURCE_OUTPUT (object); g_return_if_fail (mixer_source_output->priv != NULL); G_OBJECT_CLASS (gvc_mixer_source_output_parent_class)->finalize (object); } /** * gvc_mixer_source_output_new: (skip) * @context: * @index: * @channel_map: * * Returns: */ GvcMixerStream * gvc_mixer_source_output_new (pa_context *context, guint index, GvcChannelMap *channel_map) { GObject *object; object = g_object_new (GVC_TYPE_MIXER_SOURCE_OUTPUT, "pa-context", context, "index", index, "channel-map", channel_map, NULL); return GVC_MIXER_STREAM (object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-source-output.h0000664000175000017500000000445700000000000030246 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_MIXER_SOURCE_OUTPUT_H #define __GVC_MIXER_SOURCE_OUTPUT_H #include #include "gvc-mixer-stream.h" G_BEGIN_DECLS #define GVC_TYPE_MIXER_SOURCE_OUTPUT (gvc_mixer_source_output_get_type ()) #define GVC_MIXER_SOURCE_OUTPUT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_SOURCE_OUTPUT, GvcMixerSourceOutput)) #define GVC_MIXER_SOURCE_OUTPUT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_SOURCE_OUTPUT, GvcMixerSourceOutputClass)) #define GVC_IS_MIXER_SOURCE_OUTPUT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_SOURCE_OUTPUT)) #define GVC_IS_MIXER_SOURCE_OUTPUT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_SOURCE_OUTPUT)) #define GVC_MIXER_SOURCE_OUTPUT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_SOURCE_OUTPUT, GvcMixerSourceOutputClass)) typedef struct GvcMixerSourceOutputPrivate GvcMixerSourceOutputPrivate; typedef struct { GvcMixerStream parent; GvcMixerSourceOutputPrivate *priv; } GvcMixerSourceOutput; typedef struct { GvcMixerStreamClass parent_class; } GvcMixerSourceOutputClass; GType gvc_mixer_source_output_get_type (void); GvcMixerStream * gvc_mixer_source_output_new (pa_context *context, guint index, GvcChannelMap *channel_map); G_END_DECLS #endif /* __GVC_MIXER_SOURCE_OUTPUT_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-source.c0000664000175000017500000001353400000000000026677 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include "gvc-mixer-source.h" #include "gvc-mixer-stream-private.h" #include "gvc-channel-map-private.h" #define GVC_MIXER_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_SOURCE, GvcMixerSourcePrivate)) struct GvcMixerSourcePrivate { gpointer dummy; }; static void gvc_mixer_source_class_init (GvcMixerSourceClass *klass); static void gvc_mixer_source_init (GvcMixerSource *mixer_source); static void gvc_mixer_source_finalize (GObject *object); G_DEFINE_TYPE (GvcMixerSource, gvc_mixer_source, GVC_TYPE_MIXER_STREAM) static gboolean gvc_mixer_source_push_volume (GvcMixerStream *stream, gpointer *op) { pa_operation *o; guint index; const GvcChannelMap *map; pa_context *context; const pa_cvolume *cv; index = gvc_mixer_stream_get_index (stream); map = gvc_mixer_stream_get_channel_map (stream); /* set the volume */ cv = gvc_channel_map_get_cvolume (map); context = gvc_mixer_stream_get_pa_context (stream); o = pa_context_set_source_volume_by_index (context, index, cv, NULL, NULL); if (o == NULL) { g_warning ("pa_context_set_source_volume_by_index() failed: %s", pa_strerror(pa_context_errno(context))); return FALSE; } *op = o; return TRUE; } static gboolean gvc_mixer_source_change_is_muted (GvcMixerStream *stream, gboolean is_muted) { pa_operation *o; guint index; pa_context *context; index = gvc_mixer_stream_get_index (stream); context = gvc_mixer_stream_get_pa_context (stream); o = pa_context_set_source_mute_by_index (context, index, is_muted, NULL, NULL); if (o == NULL) { g_warning ("pa_context_set_source_mute_by_index() failed: %s", pa_strerror(pa_context_errno(context))); return FALSE; } pa_operation_unref(o); return TRUE; } static gboolean gvc_mixer_source_change_port (GvcMixerStream *stream, const char *port) { pa_operation *o; guint index; pa_context *context; index = gvc_mixer_stream_get_index (stream); context = gvc_mixer_stream_get_pa_context (stream); o = pa_context_set_source_port_by_index (context, index, port, NULL, NULL); if (o == NULL) { g_warning ("pa_context_set_source_port_by_index() failed: %s", pa_strerror(pa_context_errno(context))); return FALSE; } pa_operation_unref(o); return TRUE; } static void gvc_mixer_source_class_init (GvcMixerSourceClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass); object_class->finalize = gvc_mixer_source_finalize; stream_class->push_volume = gvc_mixer_source_push_volume; stream_class->change_is_muted = gvc_mixer_source_change_is_muted; stream_class->change_port = gvc_mixer_source_change_port; g_type_class_add_private (klass, sizeof (GvcMixerSourcePrivate)); } static void gvc_mixer_source_init (GvcMixerSource *source) { source->priv = GVC_MIXER_SOURCE_GET_PRIVATE (source); } static void gvc_mixer_source_finalize (GObject *object) { GvcMixerSource *mixer_source; g_return_if_fail (object != NULL); g_return_if_fail (GVC_IS_MIXER_SOURCE (object)); mixer_source = GVC_MIXER_SOURCE (object); g_return_if_fail (mixer_source->priv != NULL); G_OBJECT_CLASS (gvc_mixer_source_parent_class)->finalize (object); } /** * gvc_mixer_source_new: (skip) * @context: * @index: * @channel_map: * * Returns: */ GvcMixerStream * gvc_mixer_source_new (pa_context *context, guint index, GvcChannelMap *channel_map) { GObject *object; object = g_object_new (GVC_TYPE_MIXER_SOURCE, "pa-context", context, "index", index, "channel-map", channel_map, NULL); return GVC_MIXER_STREAM (object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-source.h0000664000175000017500000000420400000000000026676 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_MIXER_SOURCE_H #define __GVC_MIXER_SOURCE_H #include #include "gvc-mixer-stream.h" G_BEGIN_DECLS #define GVC_TYPE_MIXER_SOURCE (gvc_mixer_source_get_type ()) #define GVC_MIXER_SOURCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_SOURCE, GvcMixerSource)) #define GVC_MIXER_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_SOURCE, GvcMixerSourceClass)) #define GVC_IS_MIXER_SOURCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_SOURCE)) #define GVC_IS_MIXER_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_SOURCE)) #define GVC_MIXER_SOURCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_SOURCE, GvcMixerSourceClass)) typedef struct GvcMixerSourcePrivate GvcMixerSourcePrivate; typedef struct { GvcMixerStream parent; GvcMixerSourcePrivate *priv; } GvcMixerSource; typedef struct { GvcMixerStreamClass parent_class; } GvcMixerSourceClass; GType gvc_mixer_source_get_type (void); GvcMixerStream * gvc_mixer_source_new (pa_context *context, guint index, GvcChannelMap *channel_map); G_END_DECLS #endif /* __GVC_MIXER_SOURCE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-stream-private.h0000664000175000017500000000214000000000000030336 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_MIXER_STREAM_PRIVATE_H #define __GVC_MIXER_STREAM_PRIVATE_H #include #include "gvc-channel-map.h" G_BEGIN_DECLS pa_context * gvc_mixer_stream_get_pa_context (GvcMixerStream *stream); G_END_DECLS #endif /* __GVC_MIXER_STREAM_PRIVATE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-stream.c0000664000175000017500000011071300000000000026667 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include "gvc-mixer-stream.h" #include "gvc-mixer-stream-private.h" #include "gvc-channel-map-private.h" #define GVC_MIXER_STREAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_STREAM, GvcMixerStreamPrivate)) static guint32 stream_serial = 1; struct GvcMixerStreamPrivate { pa_context *pa_context; guint id; guint index; gint card_index; GvcChannelMap *channel_map; char *name; char *description; char *application_id; char *icon_name; char *form_factor; char *sysfs_path; gboolean is_muted; gboolean can_decibel; gboolean is_event_stream; gboolean is_virtual; pa_volume_t base_volume; pa_operation *change_volume_op; char *port; char *human_port; GList *ports; }; enum { PROP_0, PROP_ID, PROP_PA_CONTEXT, PROP_CHANNEL_MAP, PROP_INDEX, PROP_NAME, PROP_DESCRIPTION, PROP_APPLICATION_ID, PROP_ICON_NAME, PROP_FORM_FACTOR, PROP_SYSFS_PATH, PROP_VOLUME, PROP_DECIBEL, PROP_IS_MUTED, PROP_CAN_DECIBEL, PROP_IS_EVENT_STREAM, PROP_IS_VIRTUAL, PROP_CARD_INDEX, PROP_PORT, }; static void gvc_mixer_stream_class_init (GvcMixerStreamClass *klass); static void gvc_mixer_stream_init (GvcMixerStream *mixer_stream); static void gvc_mixer_stream_finalize (GObject *object); G_DEFINE_ABSTRACT_TYPE (GvcMixerStream, gvc_mixer_stream, G_TYPE_OBJECT) static void free_port (GvcMixerStreamPort *p) { g_free (p->port); g_free (p->human_port); g_slice_free (GvcMixerStreamPort, p); } static GvcMixerStreamPort * dup_port (GvcMixerStreamPort *p) { GvcMixerStreamPort *m; m = g_slice_new (GvcMixerStreamPort); *m = *p; m->port = g_strdup (p->port); m->human_port = g_strdup (p->human_port); return m; } G_DEFINE_BOXED_TYPE (GvcMixerStreamPort, gvc_mixer_stream_port, dup_port, free_port) static guint32 get_next_stream_serial (void) { guint32 serial; serial = stream_serial++; if ((gint32)stream_serial < 0) { stream_serial = 1; } return serial; } pa_context * gvc_mixer_stream_get_pa_context (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), 0); return stream->priv->pa_context; } guint gvc_mixer_stream_get_index (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), 0); return stream->priv->index; } guint gvc_mixer_stream_get_id (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), 0); return stream->priv->id; } const GvcChannelMap * gvc_mixer_stream_get_channel_map (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), NULL); return stream->priv->channel_map; } /** * gvc_mixer_stream_get_volume: * @stream: * * Returns: (type guint32) (transfer none): */ pa_volume_t gvc_mixer_stream_get_volume (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), 0); return (pa_volume_t) gvc_channel_map_get_volume(stream->priv->channel_map)[VOLUME]; } gdouble gvc_mixer_stream_get_decibel (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), 0); return pa_sw_volume_to_dB( (pa_volume_t) gvc_channel_map_get_volume(stream->priv->channel_map)[VOLUME]); } /** * gvc_mixer_stream_set_volume: * @stream: * @volume: (type guint32): * * Returns: */ gboolean gvc_mixer_stream_set_volume (GvcMixerStream *stream, pa_volume_t volume) { pa_cvolume cv; g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); cv = *gvc_channel_map_get_cvolume(stream->priv->channel_map); pa_cvolume_scale(&cv, volume); if (!pa_cvolume_equal(gvc_channel_map_get_cvolume(stream->priv->channel_map), &cv)) { gvc_channel_map_volume_changed(stream->priv->channel_map, &cv, FALSE); g_object_notify (G_OBJECT (stream), "volume"); return TRUE; } return FALSE; } gboolean gvc_mixer_stream_set_decibel (GvcMixerStream *stream, gdouble db) { pa_cvolume cv; g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); cv = *gvc_channel_map_get_cvolume(stream->priv->channel_map); pa_cvolume_scale(&cv, pa_sw_volume_from_dB(db)); if (!pa_cvolume_equal(gvc_channel_map_get_cvolume(stream->priv->channel_map), &cv)) { gvc_channel_map_volume_changed(stream->priv->channel_map, &cv, FALSE); g_object_notify (G_OBJECT (stream), "volume"); } return TRUE; } gboolean gvc_mixer_stream_get_is_muted (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); return stream->priv->is_muted; } gboolean gvc_mixer_stream_get_can_decibel (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); return stream->priv->can_decibel; } gboolean gvc_mixer_stream_set_is_muted (GvcMixerStream *stream, gboolean is_muted) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); if (is_muted != stream->priv->is_muted) { stream->priv->is_muted = is_muted; g_object_notify (G_OBJECT (stream), "is-muted"); } return TRUE; } gboolean gvc_mixer_stream_set_can_decibel (GvcMixerStream *stream, gboolean can_decibel) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); if (can_decibel != stream->priv->can_decibel) { stream->priv->can_decibel = can_decibel; g_object_notify (G_OBJECT (stream), "can-decibel"); } return TRUE; } const char * gvc_mixer_stream_get_name (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), NULL); return stream->priv->name; } const char * gvc_mixer_stream_get_description (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), NULL); return stream->priv->description; } gboolean gvc_mixer_stream_set_name (GvcMixerStream *stream, const char *name) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_free (stream->priv->name); stream->priv->name = g_strdup (name); g_object_notify (G_OBJECT (stream), "name"); return TRUE; } gboolean gvc_mixer_stream_set_description (GvcMixerStream *stream, const char *description) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_free (stream->priv->description); stream->priv->description = g_strdup (description); g_object_notify (G_OBJECT (stream), "description"); return TRUE; } gboolean gvc_mixer_stream_is_event_stream (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); return stream->priv->is_event_stream; } gboolean gvc_mixer_stream_set_is_event_stream (GvcMixerStream *stream, gboolean is_event_stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); stream->priv->is_event_stream = is_event_stream; g_object_notify (G_OBJECT (stream), "is-event-stream"); return TRUE; } gboolean gvc_mixer_stream_is_virtual (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); return stream->priv->is_virtual; } gboolean gvc_mixer_stream_set_is_virtual (GvcMixerStream *stream, gboolean is_virtual) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); stream->priv->is_virtual = is_virtual; g_object_notify (G_OBJECT (stream), "is-virtual"); return TRUE; } const char * gvc_mixer_stream_get_application_id (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), NULL); return stream->priv->application_id; } gboolean gvc_mixer_stream_set_application_id (GvcMixerStream *stream, const char *application_id) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_free (stream->priv->application_id); stream->priv->application_id = g_strdup (application_id); g_object_notify (G_OBJECT (stream), "application-id"); return TRUE; } static void on_channel_map_volume_changed (GvcChannelMap *channel_map, gboolean set, GvcMixerStream *stream) { if (set == TRUE) gvc_mixer_stream_push_volume (stream); g_object_notify (G_OBJECT (stream), "volume"); } static gboolean gvc_mixer_stream_set_channel_map (GvcMixerStream *stream, GvcChannelMap *channel_map) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); if (channel_map != NULL) { g_object_ref (channel_map); } if (stream->priv->channel_map != NULL) { g_signal_handlers_disconnect_by_func (stream->priv->channel_map, on_channel_map_volume_changed, stream); g_object_unref (stream->priv->channel_map); } stream->priv->channel_map = channel_map; if (stream->priv->channel_map != NULL) { g_signal_connect (stream->priv->channel_map, "volume-changed", G_CALLBACK (on_channel_map_volume_changed), stream); g_object_notify (G_OBJECT (stream), "channel-map"); } return TRUE; } const char * gvc_mixer_stream_get_icon_name (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), NULL); return stream->priv->icon_name; } const char * gvc_mixer_stream_get_form_factor (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), NULL); return stream->priv->form_factor; } const char * gvc_mixer_stream_get_sysfs_path (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), NULL); return stream->priv->sysfs_path; } /** * gvc_mixer_stream_get_gicon: * @stream: a #GvcMixerStream * * Returns: (transfer full): a new #GIcon */ GIcon * gvc_mixer_stream_get_gicon (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), NULL); if (stream->priv->icon_name == NULL) return NULL; return g_themed_icon_new_with_default_fallbacks (stream->priv->icon_name); } gboolean gvc_mixer_stream_set_icon_name (GvcMixerStream *stream, const char *icon_name) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_free (stream->priv->icon_name); stream->priv->icon_name = g_strdup (icon_name); g_object_notify (G_OBJECT (stream), "icon-name"); return TRUE; } gboolean gvc_mixer_stream_set_form_factor (GvcMixerStream *stream, const char *form_factor) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_free (stream->priv->form_factor); stream->priv->form_factor = g_strdup (form_factor); g_object_notify (G_OBJECT (stream), "form-factor"); return TRUE; } gboolean gvc_mixer_stream_set_sysfs_path (GvcMixerStream *stream, const char *sysfs_path) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_free (stream->priv->sysfs_path); stream->priv->sysfs_path = g_strdup (sysfs_path); g_object_notify (G_OBJECT (stream), "sysfs-path"); return TRUE; } /** * gvc_mixer_stream_get_base_volume: * @stream: * * Returns: (type guint32) (transfer none): */ pa_volume_t gvc_mixer_stream_get_base_volume (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), 0); return stream->priv->base_volume; } /** * gvc_mixer_stream_set_base_volume: * @stream: * @base_volume: (type guint32): * * Returns: */ gboolean gvc_mixer_stream_set_base_volume (GvcMixerStream *stream, pa_volume_t base_volume) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); stream->priv->base_volume = base_volume; return TRUE; } const GvcMixerStreamPort * gvc_mixer_stream_get_port (GvcMixerStream *stream) { GList *l; g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), NULL); g_return_val_if_fail (stream->priv->ports != NULL, NULL); for (l = stream->priv->ports; l != NULL; l = l->next) { GvcMixerStreamPort *p = l->data; if (g_strcmp0 (stream->priv->port, p->port) == 0) { return p; } } g_assert_not_reached (); return NULL; } gboolean gvc_mixer_stream_set_port (GvcMixerStream *stream, const char *port) { GList *l; g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_return_val_if_fail (stream->priv->ports != NULL, FALSE); g_free (stream->priv->port); stream->priv->port = g_strdup (port); g_free (stream->priv->human_port); stream->priv->human_port = NULL; for (l = stream->priv->ports; l != NULL; l = l->next) { GvcMixerStreamPort *p = l->data; if (g_str_equal (stream->priv->port, p->port)) { stream->priv->human_port = g_strdup (p->human_port); break; } } g_object_notify (G_OBJECT (stream), "port"); return TRUE; } gboolean gvc_mixer_stream_change_port (GvcMixerStream *stream, const char *port) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); return GVC_MIXER_STREAM_GET_CLASS (stream)->change_port (stream, port); } /** * gvc_mixer_stream_get_ports: * * Return value: (transfer none) (element-type GvcMixerStreamPort): */ const GList * gvc_mixer_stream_get_ports (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), NULL); return stream->priv->ports; } static int sort_ports (GvcMixerStreamPort *a, GvcMixerStreamPort *b) { if (a->priority == b->priority) return 0; if (a->priority > b->priority) return 1; return -1; } /** * gvc_mixer_stream_set_ports: * @ports: (transfer full) (element-type GvcMixerStreamPort): */ gboolean gvc_mixer_stream_set_ports (GvcMixerStream *stream, GList *ports) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); g_return_val_if_fail (stream->priv->ports == NULL, FALSE); stream->priv->ports = g_list_sort (ports, (GCompareFunc) sort_ports); return TRUE; } gint gvc_mixer_stream_get_card_index (GvcMixerStream *stream) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), PA_INVALID_INDEX); return stream->priv->card_index; } gboolean gvc_mixer_stream_set_card_index (GvcMixerStream *stream, gint card_index) { g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); stream->priv->card_index = card_index; g_object_notify (G_OBJECT (stream), "card-index"); return TRUE; } static void gvc_mixer_stream_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GvcMixerStream *self = GVC_MIXER_STREAM (object); switch (prop_id) { case PROP_PA_CONTEXT: self->priv->pa_context = g_value_get_pointer (value); break; case PROP_INDEX: self->priv->index = g_value_get_ulong (value); break; case PROP_ID: self->priv->id = g_value_get_ulong (value); break; case PROP_CHANNEL_MAP: gvc_mixer_stream_set_channel_map (self, g_value_get_object (value)); break; case PROP_NAME: gvc_mixer_stream_set_name (self, g_value_get_string (value)); break; case PROP_DESCRIPTION: gvc_mixer_stream_set_description (self, g_value_get_string (value)); break; case PROP_APPLICATION_ID: gvc_mixer_stream_set_application_id (self, g_value_get_string (value)); break; case PROP_ICON_NAME: gvc_mixer_stream_set_icon_name (self, g_value_get_string (value)); break; case PROP_FORM_FACTOR: gvc_mixer_stream_set_form_factor (self, g_value_get_string (value)); break; case PROP_SYSFS_PATH: gvc_mixer_stream_set_sysfs_path (self, g_value_get_string (value)); break; case PROP_VOLUME: gvc_mixer_stream_set_volume (self, g_value_get_ulong (value)); break; case PROP_DECIBEL: gvc_mixer_stream_set_decibel (self, g_value_get_double (value)); break; case PROP_IS_MUTED: gvc_mixer_stream_set_is_muted (self, g_value_get_boolean (value)); break; case PROP_IS_EVENT_STREAM: gvc_mixer_stream_set_is_event_stream (self, g_value_get_boolean (value)); break; case PROP_IS_VIRTUAL: gvc_mixer_stream_set_is_virtual (self, g_value_get_boolean (value)); break; case PROP_CAN_DECIBEL: gvc_mixer_stream_set_can_decibel (self, g_value_get_boolean (value)); break; case PROP_PORT: gvc_mixer_stream_set_port (self, g_value_get_string (value)); break; case PROP_CARD_INDEX: self->priv->card_index = g_value_get_long (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gvc_mixer_stream_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GvcMixerStream *self = GVC_MIXER_STREAM (object); switch (prop_id) { case PROP_PA_CONTEXT: g_value_set_pointer (value, self->priv->pa_context); break; case PROP_INDEX: g_value_set_ulong (value, self->priv->index); break; case PROP_ID: g_value_set_ulong (value, self->priv->id); break; case PROP_CHANNEL_MAP: g_value_set_object (value, self->priv->channel_map); break; case PROP_NAME: g_value_set_string (value, self->priv->name); break; case PROP_DESCRIPTION: g_value_set_string (value, self->priv->description); break; case PROP_APPLICATION_ID: g_value_set_string (value, self->priv->application_id); break; case PROP_ICON_NAME: g_value_set_string (value, self->priv->icon_name); break; case PROP_FORM_FACTOR: g_value_set_string (value, self->priv->form_factor); break; case PROP_SYSFS_PATH: g_value_set_string (value, self->priv->sysfs_path); break; case PROP_VOLUME: g_value_set_ulong (value, pa_cvolume_max(gvc_channel_map_get_cvolume(self->priv->channel_map))); break; case PROP_DECIBEL: g_value_set_double (value, pa_sw_volume_to_dB(pa_cvolume_max(gvc_channel_map_get_cvolume(self->priv->channel_map)))); break; case PROP_IS_MUTED: g_value_set_boolean (value, self->priv->is_muted); break; case PROP_IS_EVENT_STREAM: g_value_set_boolean (value, self->priv->is_event_stream); break; case PROP_IS_VIRTUAL: g_value_set_boolean (value, self->priv->is_virtual); break; case PROP_CAN_DECIBEL: g_value_set_boolean (value, self->priv->can_decibel); break; case PROP_PORT: g_value_set_string (value, self->priv->port); break; case PROP_CARD_INDEX: g_value_set_long (value, self->priv->card_index); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static GObject * gvc_mixer_stream_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_params) { GObject *object; GvcMixerStream *self; object = G_OBJECT_CLASS (gvc_mixer_stream_parent_class)->constructor (type, n_construct_properties, construct_params); self = GVC_MIXER_STREAM (object); self->priv->id = get_next_stream_serial (); return object; } static gboolean gvc_mixer_stream_real_change_port (GvcMixerStream *stream, const char *port) { return FALSE; } static gboolean gvc_mixer_stream_real_push_volume (GvcMixerStream *stream, gpointer *op) { return FALSE; } static gboolean gvc_mixer_stream_real_change_is_muted (GvcMixerStream *stream, gboolean is_muted) { return FALSE; } gboolean gvc_mixer_stream_push_volume (GvcMixerStream *stream) { pa_operation *op; gboolean ret; g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); if (stream->priv->is_event_stream != FALSE) return TRUE; g_debug ("Pushing new volume to stream '%s' (%s)", stream->priv->description, stream->priv->name); ret = GVC_MIXER_STREAM_GET_CLASS (stream)->push_volume (stream, (gpointer *) &op); if (ret) { if (stream->priv->change_volume_op != NULL) pa_operation_unref (stream->priv->change_volume_op); stream->priv->change_volume_op = op; } return ret; } gboolean gvc_mixer_stream_change_is_muted (GvcMixerStream *stream, gboolean is_muted) { gboolean ret; g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE); ret = GVC_MIXER_STREAM_GET_CLASS (stream)->change_is_muted (stream, is_muted); return ret; } gboolean gvc_mixer_stream_is_running (GvcMixerStream *stream) { if (stream->priv->change_volume_op == NULL) return FALSE; if ((pa_operation_get_state(stream->priv->change_volume_op) == PA_OPERATION_RUNNING)) return TRUE; pa_operation_unref(stream->priv->change_volume_op); stream->priv->change_volume_op = NULL; return FALSE; } static void gvc_mixer_stream_class_init (GvcMixerStreamClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->constructor = gvc_mixer_stream_constructor; gobject_class->finalize = gvc_mixer_stream_finalize; gobject_class->set_property = gvc_mixer_stream_set_property; gobject_class->get_property = gvc_mixer_stream_get_property; klass->push_volume = gvc_mixer_stream_real_push_volume; klass->change_port = gvc_mixer_stream_real_change_port; klass->change_is_muted = gvc_mixer_stream_real_change_is_muted; g_object_class_install_property (gobject_class, PROP_INDEX, g_param_spec_ulong ("index", "Index", "The index for this stream", 0, G_MAXULONG, 0, G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (gobject_class, PROP_ID, g_param_spec_ulong ("id", "id", "The id for this stream", 0, G_MAXULONG, 0, G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (gobject_class, PROP_CHANNEL_MAP, g_param_spec_object ("channel-map", "channel map", "The channel map for this stream", GVC_TYPE_CHANNEL_MAP, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_PA_CONTEXT, g_param_spec_pointer ("pa-context", "PulseAudio context", "The PulseAudio context for this stream", G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (gobject_class, PROP_VOLUME, g_param_spec_ulong ("volume", "Volume", "The volume for this stream", 0, G_MAXULONG, 0, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_DECIBEL, g_param_spec_double ("decibel", "Decibel", "The decibel level for this stream", -G_MAXDOUBLE, G_MAXDOUBLE, 0, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_NAME, g_param_spec_string ("name", "Name", "Name to display for this stream", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_DESCRIPTION, g_param_spec_string ("description", "Description", "Description to display for this stream", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_APPLICATION_ID, g_param_spec_string ("application-id", "Application identifier", "Application identifier for this stream", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_ICON_NAME, g_param_spec_string ("icon-name", "Icon Name", "Name of icon to display for this stream", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_FORM_FACTOR, g_param_spec_string ("form-factor", "Form Factor", "Device form factor for this stream, as reported by PulseAudio", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_SYSFS_PATH, g_param_spec_string ("sysfs-path", "Sysfs path", "Sysfs path for the device associated with this stream", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_IS_MUTED, g_param_spec_boolean ("is-muted", "is muted", "Whether stream is muted", FALSE, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_CAN_DECIBEL, g_param_spec_boolean ("can-decibel", "can decibel", "Whether stream volume can be converted to decibel units", FALSE, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_IS_EVENT_STREAM, g_param_spec_boolean ("is-event-stream", "is event stream", "Whether stream's role is to play an event", FALSE, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_IS_VIRTUAL, g_param_spec_boolean ("is-virtual", "is virtual stream", "Whether the stream is virtual", FALSE, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_object_class_install_property (gobject_class, PROP_PORT, g_param_spec_string ("port", "Port", "The name of the current port for this stream", NULL, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_CARD_INDEX, g_param_spec_long ("card-index", "Card index", "The index of the card for this stream", PA_INVALID_INDEX, G_MAXLONG, PA_INVALID_INDEX, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); g_type_class_add_private (klass, sizeof (GvcMixerStreamPrivate)); } static void gvc_mixer_stream_init (GvcMixerStream *stream) { stream->priv = GVC_MIXER_STREAM_GET_PRIVATE (stream); } static void gvc_mixer_stream_finalize (GObject *object) { GvcMixerStream *mixer_stream; g_return_if_fail (object != NULL); g_return_if_fail (GVC_IS_MIXER_STREAM (object)); mixer_stream = GVC_MIXER_STREAM (object); g_return_if_fail (mixer_stream->priv != NULL); g_object_unref (mixer_stream->priv->channel_map); mixer_stream->priv->channel_map = NULL; g_free (mixer_stream->priv->name); mixer_stream->priv->name = NULL; g_free (mixer_stream->priv->description); mixer_stream->priv->description = NULL; g_free (mixer_stream->priv->application_id); mixer_stream->priv->application_id = NULL; g_free (mixer_stream->priv->icon_name); mixer_stream->priv->icon_name = NULL; g_free (mixer_stream->priv->form_factor); mixer_stream->priv->form_factor = NULL; g_free (mixer_stream->priv->sysfs_path); mixer_stream->priv->sysfs_path = NULL; g_free (mixer_stream->priv->port); mixer_stream->priv->port = NULL; g_free (mixer_stream->priv->human_port); mixer_stream->priv->human_port = NULL; g_list_foreach (mixer_stream->priv->ports, (GFunc) free_port, NULL); g_list_free (mixer_stream->priv->ports); mixer_stream->priv->ports = NULL; if (mixer_stream->priv->change_volume_op) { pa_operation_unref(mixer_stream->priv->change_volume_op); mixer_stream->priv->change_volume_op = NULL; } G_OBJECT_CLASS (gvc_mixer_stream_parent_class)->finalize (object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-stream.h0000664000175000017500000001607500000000000026702 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_MIXER_STREAM_H #define __GVC_MIXER_STREAM_H #include #include "gvc-pulseaudio-fake.h" #include "gvc-channel-map.h" #include G_BEGIN_DECLS #define GVC_TYPE_MIXER_STREAM (gvc_mixer_stream_get_type ()) #define GVC_MIXER_STREAM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GVC_TYPE_MIXER_STREAM, GvcMixerStream)) #define GVC_MIXER_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GVC_TYPE_MIXER_STREAM, GvcMixerStreamClass)) #define GVC_IS_MIXER_STREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GVC_TYPE_MIXER_STREAM)) #define GVC_IS_MIXER_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GVC_TYPE_MIXER_STREAM)) #define GVC_MIXER_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GVC_TYPE_MIXER_STREAM, GvcMixerStreamClass)) typedef struct GvcMixerStreamPrivate GvcMixerStreamPrivate; typedef struct { GObject parent; GvcMixerStreamPrivate *priv; } GvcMixerStream; typedef struct { GObjectClass parent_class; /* vtable */ gboolean (*push_volume) (GvcMixerStream *stream, gpointer *operation); gboolean (*change_is_muted) (GvcMixerStream *stream, gboolean is_muted); gboolean (*change_port) (GvcMixerStream *stream, const char *port); } GvcMixerStreamClass; typedef struct { char *port; char *human_port; guint priority; gboolean available; } GvcMixerStreamPort; GType gvc_mixer_stream_port_get_type (void) G_GNUC_CONST; GType gvc_mixer_stream_get_type (void) G_GNUC_CONST; guint gvc_mixer_stream_get_index (GvcMixerStream *stream); guint gvc_mixer_stream_get_id (GvcMixerStream *stream); const GvcChannelMap *gvc_mixer_stream_get_channel_map(GvcMixerStream *stream); const GvcMixerStreamPort *gvc_mixer_stream_get_port (GvcMixerStream *stream); const GList * gvc_mixer_stream_get_ports (GvcMixerStream *stream); gboolean gvc_mixer_stream_change_port (GvcMixerStream *stream, const char *port); pa_volume_t gvc_mixer_stream_get_volume (GvcMixerStream *stream); gdouble gvc_mixer_stream_get_decibel (GvcMixerStream *stream); gboolean gvc_mixer_stream_push_volume (GvcMixerStream *stream); pa_volume_t gvc_mixer_stream_get_base_volume (GvcMixerStream *stream); gboolean gvc_mixer_stream_get_is_muted (GvcMixerStream *stream); gboolean gvc_mixer_stream_get_can_decibel (GvcMixerStream *stream); gboolean gvc_mixer_stream_change_is_muted (GvcMixerStream *stream, gboolean is_muted); gboolean gvc_mixer_stream_is_running (GvcMixerStream *stream); const char * gvc_mixer_stream_get_name (GvcMixerStream *stream); const char * gvc_mixer_stream_get_icon_name (GvcMixerStream *stream); const char * gvc_mixer_stream_get_form_factor (GvcMixerStream *stream); const char * gvc_mixer_stream_get_sysfs_path (GvcMixerStream *stream); GIcon * gvc_mixer_stream_get_gicon (GvcMixerStream *stream); const char * gvc_mixer_stream_get_description (GvcMixerStream *stream); const char * gvc_mixer_stream_get_application_id (GvcMixerStream *stream); gboolean gvc_mixer_stream_is_event_stream (GvcMixerStream *stream); gboolean gvc_mixer_stream_is_virtual (GvcMixerStream *stream); gint gvc_mixer_stream_get_card_index (GvcMixerStream *stream); /* private */ gboolean gvc_mixer_stream_set_volume (GvcMixerStream *stream, pa_volume_t volume); gboolean gvc_mixer_stream_set_decibel (GvcMixerStream *stream, gdouble db); gboolean gvc_mixer_stream_set_is_muted (GvcMixerStream *stream, gboolean is_muted); gboolean gvc_mixer_stream_set_can_decibel (GvcMixerStream *stream, gboolean can_decibel); gboolean gvc_mixer_stream_set_name (GvcMixerStream *stream, const char *name); gboolean gvc_mixer_stream_set_description (GvcMixerStream *stream, const char *description); gboolean gvc_mixer_stream_set_icon_name (GvcMixerStream *stream, const char *name); gboolean gvc_mixer_stream_set_form_factor (GvcMixerStream *stream, const char *form_factor); gboolean gvc_mixer_stream_set_sysfs_path (GvcMixerStream *stream, const char *sysfs_path); gboolean gvc_mixer_stream_set_is_event_stream (GvcMixerStream *stream, gboolean is_event_stream); gboolean gvc_mixer_stream_set_is_virtual (GvcMixerStream *stream, gboolean is_event_stream); gboolean gvc_mixer_stream_set_application_id (GvcMixerStream *stream, const char *application_id); gboolean gvc_mixer_stream_set_base_volume (GvcMixerStream *stream, pa_volume_t base_volume); gboolean gvc_mixer_stream_set_port (GvcMixerStream *stream, const char *port); gboolean gvc_mixer_stream_set_ports (GvcMixerStream *stream, GList *ports); gboolean gvc_mixer_stream_set_card_index (GvcMixerStream *stream, gint card_index); G_END_DECLS #endif /* __GVC_MIXER_STREAM_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-ui-device.c0000664000175000017500000006025600000000000027254 0ustar00jeremyjeremy/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* * gvc-mixer-ui-device.c * Copyright (C) Conor Curran 2011 * Copyright (C) 2012 David Henningsson, Canonical Ltd. * * gvc-mixer-ui-device.c is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * gvc-mixer-ui-device.c is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #include #include "gvc-mixer-ui-device.h" #include "gvc-mixer-card.h" #define GVC_MIXER_UI_DEVICE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GVC_TYPE_MIXER_UI_DEVICE, GvcMixerUIDevicePrivate)) struct GvcMixerUIDevicePrivate { gchar *first_line_desc; gchar *second_line_desc; GvcMixerCard *card; gchar *port_name; gint stream_id; guint id; gboolean port_available; /* These two lists contain pointers to GvcMixerCardProfile objects. Those objects are owned by GvcMixerCard. * * TODO: Do we want to add a weak reference to the GvcMixerCard for this reason? */ GList *supported_profiles; /* all profiles supported by this port.*/ GList *profiles; /* profiles to be added to combobox, subset of supported_profiles. */ GvcMixerUIDeviceDirection type; gboolean disable_profile_swapping; gchar *user_preferred_profile; }; enum { PROP_0, PROP_DESC_LINE_1, PROP_DESC_LINE_2, PROP_CARD, PROP_PORT_NAME, PROP_STREAM_ID, PROP_UI_DEVICE_TYPE, PROP_PORT_AVAILABLE, }; static void gvc_mixer_ui_device_class_init (GvcMixerUIDeviceClass *klass); static void gvc_mixer_ui_device_init (GvcMixerUIDevice *device); static void gvc_mixer_ui_device_finalize (GObject *object); G_DEFINE_TYPE (GvcMixerUIDevice, gvc_mixer_ui_device, G_TYPE_OBJECT); static guint32 get_next_output_serial (void) { static guint32 output_serial = 1; guint32 serial; serial = output_serial++; if ((gint32)output_serial < 0) output_serial = 1; return serial; } static void gvc_mixer_ui_device_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { GvcMixerUIDevice *self = GVC_MIXER_UI_DEVICE (object); switch (property_id) { case PROP_DESC_LINE_1: g_value_set_string (value, self->priv->first_line_desc); break; case PROP_DESC_LINE_2: g_value_set_string (value, self->priv->second_line_desc); break; case PROP_CARD: g_value_set_pointer (value, self->priv->card); break; case PROP_PORT_NAME: g_value_set_string (value, self->priv->port_name); break; case PROP_STREAM_ID: g_value_set_int (value, self->priv->stream_id); break; case PROP_UI_DEVICE_TYPE: g_value_set_uint (value, (guint)self->priv->type); break; case PROP_PORT_AVAILABLE: g_value_set_boolean (value, self->priv->port_available); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void gvc_mixer_ui_device_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GvcMixerUIDevice *self = GVC_MIXER_UI_DEVICE (object); switch (property_id) { case PROP_DESC_LINE_1: g_free (self->priv->first_line_desc); self->priv->first_line_desc = g_value_dup_string (value); g_debug ("gvc-mixer-output-set-property - 1st line: %s\n", self->priv->first_line_desc); break; case PROP_DESC_LINE_2: g_free (self->priv->second_line_desc); self->priv->second_line_desc = g_value_dup_string (value); g_debug ("gvc-mixer-output-set-property - 2nd line: %s\n", self->priv->second_line_desc); break; case PROP_CARD: self->priv->card = g_value_get_pointer (value); g_debug ("gvc-mixer-output-set-property - card: %p\n", self->priv->card); break; case PROP_PORT_NAME: g_free (self->priv->port_name); self->priv->port_name = g_value_dup_string (value); g_debug ("gvc-mixer-output-set-property - card port name: %s\n", self->priv->port_name); break; case PROP_STREAM_ID: self->priv->stream_id = g_value_get_int (value); g_debug ("gvc-mixer-output-set-property - sink/source id: %i\n", self->priv->stream_id); break; case PROP_UI_DEVICE_TYPE: self->priv->type = (GvcMixerUIDeviceDirection) g_value_get_uint (value); break; case PROP_PORT_AVAILABLE: self->priv->port_available = g_value_get_boolean (value); g_debug ("gvc-mixer-output-set-property - port available %i, value passed in %i \n", self->priv->port_available, g_value_get_boolean (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static GObject * gvc_mixer_ui_device_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_params) { GObject *object; GvcMixerUIDevice *self; object = G_OBJECT_CLASS (gvc_mixer_ui_device_parent_class)->constructor (type, n_construct_properties, construct_params); self = GVC_MIXER_UI_DEVICE (object); self->priv->id = get_next_output_serial (); self->priv->stream_id = GVC_MIXER_UI_DEVICE_INVALID; return object; } static void gvc_mixer_ui_device_init (GvcMixerUIDevice *device) { device->priv = GVC_MIXER_UI_DEVICE_GET_PRIVATE (device); } static void gvc_mixer_ui_device_dispose (GObject *object) { GvcMixerUIDevice *device; g_return_if_fail (object != NULL); g_return_if_fail (GVC_MIXER_UI_DEVICE (object)); device = GVC_MIXER_UI_DEVICE (object); g_clear_pointer (&device->priv->port_name, g_free); g_clear_pointer (&device->priv->first_line_desc, g_free); g_clear_pointer (&device->priv->second_line_desc, g_free); g_clear_pointer (&device->priv->profiles, g_list_free); g_clear_pointer (&device->priv->supported_profiles, g_list_free); g_clear_pointer (&device->priv->user_preferred_profile, g_free); G_OBJECT_CLASS (gvc_mixer_ui_device_parent_class)->dispose (object); } static void gvc_mixer_ui_device_finalize (GObject *object) { G_OBJECT_CLASS (gvc_mixer_ui_device_parent_class)->finalize (object); } static void gvc_mixer_ui_device_class_init (GvcMixerUIDeviceClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); GParamSpec *pspec; object_class->constructor = gvc_mixer_ui_device_constructor; object_class->dispose = gvc_mixer_ui_device_dispose; object_class->finalize = gvc_mixer_ui_device_finalize; object_class->set_property = gvc_mixer_ui_device_set_property; object_class->get_property = gvc_mixer_ui_device_get_property; pspec = g_param_spec_string ("description", "Description construct prop", "Set first line description", "no-name-set", G_PARAM_READWRITE); g_object_class_install_property (object_class, PROP_DESC_LINE_1, pspec); pspec = g_param_spec_string ("origin", "origin construct prop", "Set second line description name", "no-name-set", G_PARAM_READWRITE); g_object_class_install_property (object_class, PROP_DESC_LINE_2, pspec); pspec = g_param_spec_pointer ("card", "Card from pulse", "Set/Get card", G_PARAM_READWRITE); g_object_class_install_property (object_class, PROP_CARD, pspec); pspec = g_param_spec_string ("port-name", "port-name construct prop", "Set port-name", NULL, G_PARAM_READWRITE); g_object_class_install_property (object_class, PROP_PORT_NAME, pspec); pspec = g_param_spec_int ("stream-id", "stream id assigned by gvc-stream", "Set/Get stream id", -1, G_MAXINT, GVC_MIXER_UI_DEVICE_INVALID, G_PARAM_READWRITE); g_object_class_install_property (object_class, PROP_STREAM_ID, pspec); pspec = g_param_spec_uint ("type", "ui-device type", "determine whether its an input and output", 0, 1, 0, G_PARAM_READWRITE); g_object_class_install_property (object_class, PROP_UI_DEVICE_TYPE, pspec); pspec = g_param_spec_boolean ("port-available", "available", "determine whether this port is available", FALSE, G_PARAM_READWRITE); g_object_class_install_property (object_class, PROP_PORT_AVAILABLE, pspec); g_type_class_add_private (klass, sizeof (GvcMixerUIDevicePrivate)); } /* Removes the part of the string that starts with skip_prefix * ie. corresponding to the other direction. * Normally either "input:" or "output:" * * Example: if given the input string "output:hdmi-stereo+input:analog-stereo" and * skip_prefix "input:", the resulting string is "output:hdmi-stereo". * * The returned string must be freed with g_free(). */ static gchar * get_profile_canonical_name (const gchar *profile_name, const gchar *skip_prefix) { gchar *result = NULL; gchar **s; int i; /* optimisation for the simple case. */ if (strstr (profile_name, skip_prefix) == NULL) return g_strdup (profile_name); s = g_strsplit (profile_name, "+", 0); for (i = 0; i < g_strv_length (s); i++) { if (g_str_has_prefix (s[i], skip_prefix)) continue; if (result == NULL) result = g_strdup (s[i]); else { gchar *c = g_strdup_printf("%s+%s", result, s[i]); g_free(result); result = c; } } g_strfreev(s); if (!result) return g_strdup("off"); return result; } const gchar * gvc_mixer_ui_device_get_matching_profile (GvcMixerUIDevice *device, const gchar *profile) { gchar *skip_prefix = device->priv->type == UIDeviceInput ? "output:" : "input:"; gchar *target_cname = get_profile_canonical_name (profile, skip_prefix); GList *l; gchar *result = NULL; for (l = device->priv->profiles; l != NULL; l = l->next) { gchar *canonical_name; GvcMixerCardProfile* p = l->data; canonical_name = get_profile_canonical_name (p->profile, skip_prefix); if (strcmp (canonical_name, target_cname) == 0) result = p->profile; g_free (canonical_name); } g_free (target_cname); g_debug ("Matching profile for '%s' is '%s'", profile, result ? result : "(null)"); return result; } static void add_canonical_names_of_profiles (GvcMixerUIDevice *device, const GList *in_profiles, GHashTable *added_profiles, const gchar *skip_prefix, gboolean only_canonical) { const GList *l; for (l = in_profiles; l != NULL; l = l->next) { gchar *canonical_name; GvcMixerCardProfile* p = l->data; canonical_name = get_profile_canonical_name (p->profile, skip_prefix); g_debug ("The canonical name for '%s' is '%s'", p->profile, canonical_name); /* Have we already added the canonical version of this profile? */ if (g_hash_table_contains (added_profiles, canonical_name)) { g_free (canonical_name); continue; } if (only_canonical && strcmp (p->profile, canonical_name) != 0) { g_free (canonical_name); continue; } g_free (canonical_name); g_debug ("Adding profile to combobox: '%s' - '%s'", p->profile, p->human_profile); g_hash_table_insert (added_profiles, g_strdup (p->profile), p); device->priv->profiles = g_list_append (device->priv->profiles, p); } } /** * gvc_mixer_ui_device_set_profiles: * @in_profiles: (element-type Gvc.MixerCardProfile): a list of GvcMixerCardProfile * * Assigns value to * - device->priv->profiles (profiles to be added to combobox) * - device->priv->supported_profiles (all profiles of this port) * - device->priv->disable_profile_swapping (whether to show the combobox) * * This method attempts to reduce the list of profiles visible to the user by figuring out * from the context of that device (whether it's an input or an output) what profiles * actually provide an alternative. * * It does this by the following. * - It ignores off profiles. * - It takes the canonical name of the profile. That name is what you get when you * ignore the other direction. * - In the first iteration, it only adds the names of canonical profiles - i e * when the other side is turned off. * - Normally the first iteration covers all cases, but sometimes (e g bluetooth) * it doesn't, so add other profiles whose canonical name isn't already added * in a second iteration. */ void gvc_mixer_ui_device_set_profiles (GvcMixerUIDevice *device, const GList *in_profiles) { GHashTable *added_profiles; gchar *skip_prefix = device->priv->type == UIDeviceInput ? "output:" : "input:"; g_debug ("Set profiles for '%s'", gvc_mixer_ui_device_get_description(device)); if (in_profiles == NULL) return; device->priv->supported_profiles = g_list_copy ((GList*) in_profiles); added_profiles = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); /* Run two iterations: First, add profiles which are canonical themselves, * Second, add profiles for which the canonical name is not added already. */ add_canonical_names_of_profiles(device, in_profiles, added_profiles, skip_prefix, TRUE); add_canonical_names_of_profiles(device, in_profiles, added_profiles, skip_prefix, FALSE); /* TODO: Consider adding the "Off" profile here */ device->priv->disable_profile_swapping = g_hash_table_size (added_profiles) <= 1; g_hash_table_destroy (added_profiles); } /** * gvc_mixer_ui_device_get_best_profile: * @selected: The selected profile or its canonical name or %NULL for any profile * @current: The currently selected profile * * Returns: (transfer none): a profile name, valid as long as the UI device profiles are. */ const gchar * gvc_mixer_ui_device_get_best_profile (GvcMixerUIDevice *device, const gchar *selected, const gchar *current) { GList *candidates, *l; const gchar *result; gchar *skip_prefix; gchar *canonical_name_selected; if (device->priv->type == UIDeviceInput) skip_prefix = "output:"; else skip_prefix = "input:"; /* First make a list of profiles acceptable to switch to */ canonical_name_selected = NULL; if (selected) canonical_name_selected = get_profile_canonical_name (selected, skip_prefix); candidates = NULL; for (l = device->priv->supported_profiles; l != NULL; l = l->next) { gchar *canonical_name; GvcMixerCardProfile* p = l->data; canonical_name = get_profile_canonical_name (p->profile, skip_prefix); if (!canonical_name_selected || strcmp (canonical_name, canonical_name_selected) == 0) { candidates = g_list_append (candidates, p); g_debug ("Candidate for profile switching: '%s'", p->profile); } } if (!candidates) { g_warning ("No suitable profile candidates for '%s'", selected ? selected : "(null)"); g_free (canonical_name_selected); return current; } /* 1) Maybe we can skip profile switching altogether? */ result = NULL; for (l = candidates; (result == NULL) && (l != NULL); l = l->next) { GvcMixerCardProfile* p = l->data; if (strcmp (current, p->profile) == 0) result = p->profile; } /* 2) Try to keep the other side unchanged if possible */ if (result == NULL) { guint prio = 0; gchar *skip_prefix_reverse = device->priv->type == UIDeviceInput ? "input:" : "output:"; gchar *current_reverse = get_profile_canonical_name (current, skip_prefix_reverse); for (l = candidates; l != NULL; l = l->next) { gchar *p_reverse; GvcMixerCardProfile* p = l->data; p_reverse = get_profile_canonical_name (p->profile, skip_prefix_reverse); g_debug ("Comparing '%s' (from '%s') with '%s', prio %d", p_reverse, p->profile, current_reverse, p->priority); if (strcmp (p_reverse, current_reverse) == 0 && (!result || p->priority > prio)) { result = p->profile; prio = p->priority; } g_free (p_reverse); } g_free (current_reverse); } /* 3) All right, let's just pick the profile with highest priority. * TODO: We could consider asking a GUI question if this stops streams * in the other direction */ if (result == NULL) { guint prio = 0; for (l = candidates; l != NULL; l = l->next) { GvcMixerCardProfile* p = l->data; if ((p->priority > prio) || !result) { result = p->profile; prio = p->priority; } } } g_list_free (candidates); g_free (canonical_name_selected); return result; } const gchar * gvc_mixer_ui_device_get_active_profile (GvcMixerUIDevice* device) { GvcMixerCardProfile *profile; g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL); if (device->priv->card == NULL) { g_warning ("Device did not have an appropriate card"); return NULL; } profile = gvc_mixer_card_get_profile (device->priv->card); return gvc_mixer_ui_device_get_matching_profile (device, profile->profile); } gboolean gvc_mixer_ui_device_should_profiles_be_hidden (GvcMixerUIDevice *device) { g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), FALSE); return device->priv->disable_profile_swapping; } /** * gvc_mixer_ui_device_get_profiles: * @device: * * Returns: (transfer none) (element-type Gvc.MixerCardProfile): */ GList* gvc_mixer_ui_device_get_profiles (GvcMixerUIDevice *device) { g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL); return device->priv->profiles; } /** * gvc_mixer_ui_device_get_supported_profiles: * @device: * * Returns: (transfer none) (element-type Gvc.MixerCardProfile): */ GList* gvc_mixer_ui_device_get_supported_profiles (GvcMixerUIDevice *device) { g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL); return device->priv->supported_profiles; } guint gvc_mixer_ui_device_get_id (GvcMixerUIDevice *device) { g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), 0); return device->priv->id; } gint gvc_mixer_ui_device_get_stream_id (GvcMixerUIDevice *device) { g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), 0); return device->priv->stream_id; } void gvc_mixer_ui_device_invalidate_stream (GvcMixerUIDevice *self) { g_return_if_fail (GVC_IS_MIXER_UI_DEVICE (self)); self->priv->stream_id = GVC_MIXER_UI_DEVICE_INVALID; } const gchar * gvc_mixer_ui_device_get_description (GvcMixerUIDevice *device) { g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL); return device->priv->first_line_desc; } const gchar * gvc_mixer_ui_device_get_origin (GvcMixerUIDevice *device) { g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL); return device->priv->second_line_desc; } const gchar* gvc_mixer_ui_device_get_user_preferred_profile (GvcMixerUIDevice *device) { g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL); return device->priv->user_preferred_profile; } const gchar * gvc_mixer_ui_device_get_top_priority_profile (GvcMixerUIDevice *device) { GList *last; GvcMixerCardProfile *profile; g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL); last = g_list_last (device->priv->supported_profiles); profile = last->data; return profile->profile; } void gvc_mixer_ui_device_set_user_preferred_profile (GvcMixerUIDevice *device, const gchar *profile) { g_return_if_fail (GVC_IS_MIXER_UI_DEVICE (device)); g_free (device->priv->user_preferred_profile); device->priv->user_preferred_profile = g_strdup (profile); } const gchar * gvc_mixer_ui_device_get_port (GvcMixerUIDevice *device) { g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), NULL); return device->priv->port_name; } gboolean gvc_mixer_ui_device_has_ports (GvcMixerUIDevice *device) { g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), FALSE); return (device->priv->port_name != NULL); } gboolean gvc_mixer_ui_device_is_output (GvcMixerUIDevice *device) { g_return_val_if_fail (GVC_IS_MIXER_UI_DEVICE (device), FALSE); return (device->priv->type == UIDeviceOutput); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-mixer-ui-device.h0000664000175000017500000001012700000000000027251 0ustar00jeremyjeremy/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* * Copyright (C) Conor Curran 2011 * * This is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * gvc-mixer-ui-device.h is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #ifndef _GVC_MIXER_UI_DEVICE_H_ #define _GVC_MIXER_UI_DEVICE_H_ #include G_BEGIN_DECLS #define GVC_TYPE_MIXER_UI_DEVICE (gvc_mixer_ui_device_get_type ()) #define GVC_MIXER_UI_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVC_TYPE_MIXER_UI_DEVICE, GvcMixerUIDevice)) #define GVC_MIXER_UI_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVC_TYPE_MIXER_UI_DEVICE, GvcMixerUIDeviceClass)) #define GVC_IS_MIXER_UI_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVC_TYPE_MIXER_UI_DEVICE)) #define GVC_IS_MIXER_UI_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVC_TYPE_MIXER_UI_DEVICE)) #define GVC_MIXER_UI_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVC_TYPE_MIXER_UI_DEVICE, GvcMixerUIDeviceClass)) #define GVC_MIXER_UI_DEVICE_INVALID -1 typedef struct GvcMixerUIDevicePrivate GvcMixerUIDevicePrivate; typedef struct { GObjectClass parent_class; } GvcMixerUIDeviceClass; typedef struct { GObject parent_instance; GvcMixerUIDevicePrivate *priv; } GvcMixerUIDevice; typedef enum { UIDeviceInput, UIDeviceOutput, } GvcMixerUIDeviceDirection; GType gvc_mixer_ui_device_get_type (void) G_GNUC_CONST; guint gvc_mixer_ui_device_get_id (GvcMixerUIDevice *device); gint gvc_mixer_ui_device_get_stream_id (GvcMixerUIDevice *device); const gchar * gvc_mixer_ui_device_get_description (GvcMixerUIDevice *device); const gchar * gvc_mixer_ui_device_get_origin (GvcMixerUIDevice *device); const gchar * gvc_mixer_ui_device_get_port (GvcMixerUIDevice *device); const gchar * gvc_mixer_ui_device_get_best_profile (GvcMixerUIDevice *device, const gchar *selected, const gchar *current); const gchar * gvc_mixer_ui_device_get_active_profile (GvcMixerUIDevice* device); const gchar * gvc_mixer_ui_device_get_matching_profile (GvcMixerUIDevice *device, const gchar *profile); const gchar * gvc_mixer_ui_device_get_user_preferred_profile (GvcMixerUIDevice *device); const gchar * gvc_mixer_ui_device_get_top_priority_profile (GvcMixerUIDevice *device); GList * gvc_mixer_ui_device_get_profiles (GvcMixerUIDevice *device); GList * gvc_mixer_ui_device_get_supported_profiles (GvcMixerUIDevice *device); gboolean gvc_mixer_ui_device_should_profiles_be_hidden (GvcMixerUIDevice *device); void gvc_mixer_ui_device_set_profiles (GvcMixerUIDevice *device, const GList *in_profiles); void gvc_mixer_ui_device_set_user_preferred_profile (GvcMixerUIDevice *device, const gchar *profile); void gvc_mixer_ui_device_invalidate_stream (GvcMixerUIDevice *device); gboolean gvc_mixer_ui_device_has_ports (GvcMixerUIDevice *device); gboolean gvc_mixer_ui_device_is_output (GvcMixerUIDevice *device); G_END_DECLS #endif /* _GVC_MIXER_UI_DEVICE_H_ */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/gvc/gvc-pulseaudio-fake.h0000664000175000017500000000216700000000000027340 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GVC_PULSEAUDIO_FAKE_H #define __GVC_PULSEAUDIO_FAKE_H #ifdef WITH_INTROSPECTION #ifndef PA_API_VERSION #define pa_channel_position_t int #define pa_volume_t guint32 #define pa_context gpointer #endif /* PA_API_VERSION */ #endif /* WITH_INTROSPECTION */ #endif /* __GVC_PULSEAUDIO_FAKE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/media-keys.gnome-settings-plugin.in0000664000175000017500000000026100000000000031364 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=media-keys IAge=0 # Default Priority # Priority=100 _Name=Media keys _Description=Media keys plugin Authors= Copyright=Copyright © 2007 Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/org.gnome.ShellKeyGrabber.xml0000664000175000017500000000147400000000000030176 0ustar00jeremyjeremy ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/shell-keybinding-modes.h0000664000175000017500000000324300000000000027257 0ustar00jeremyjeremy/** * ShellKeyBindingMode: * @SHELL_KEYBINDING_MODE_NONE: block keybinding * @SHELL_KEYBINDING_MODE_NORMAL: allow keybinding when in window mode, * e.g. when the focus is in an application window * @SHELL_KEYBINDING_MODE_OVERVIEW: allow keybinding while the overview * is active * @SHELL_KEYBINDING_MODE_LOCK_SCREEN: allow keybinding when the screen * is locked, e.g. when the screen shield is shown * @SHELL_KEYBINDING_MODE_UNLOCK_SCREEN: allow keybinding in the unlock * dialog * @SHELL_KEYBINDING_MODE_LOGIN_SCREEN: allow keybinding in the login screen * @SHELL_KEYBINDING_MODE_MESSAGE_TRAY: allow keybinding while the message * tray is popped up * @SHELL_KEYBINDING_MODE_SYSTEM_MODAL: allow keybinding when a system modal * dialog (e.g. authentification or session dialogs) is open * @SHELL_KEYBINDING_MODE_LOOKING_GLASS: allow keybinding in looking glass * @SHELL_KEYBINDING_MODE_TOPBAR_POPUP: allow keybinding while a top bar menu * is open * @SHELL_KEYBINDING_MODE_ALL: always allow keybinding * * Controls in which GNOME Shell states a keybinding should be handled. */ typedef enum { SHELL_KEYBINDING_MODE_NONE = 0, SHELL_KEYBINDING_MODE_NORMAL = 1 << 0, SHELL_KEYBINDING_MODE_OVERVIEW = 1 << 1, SHELL_KEYBINDING_MODE_LOCK_SCREEN = 1 << 2, SHELL_KEYBINDING_MODE_UNLOCK_SCREEN = 1 << 3, SHELL_KEYBINDING_MODE_LOGIN_SCREEN = 1 << 4, SHELL_KEYBINDING_MODE_MESSAGE_TRAY = 1 << 5, SHELL_KEYBINDING_MODE_SYSTEM_MODAL = 1 << 6, SHELL_KEYBINDING_MODE_LOOKING_GLASS = 1 << 7, SHELL_KEYBINDING_MODE_TOPBAR_POPUP = 1 << 8, SHELL_KEYBINDING_MODE_ALL = ~SHELL_KEYBINDING_MODE_NONE } ShellKeyBindingMode; ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/shortcuts-list.h0000664000175000017500000002340400000000000025732 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2001 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ #ifndef __SHORTCUTS_LIST_H__ #define __SHORTCUTS_LIST_H__ #include "shell-keybinding-modes.h" #include "gsd-keygrab.h" #define SETTINGS_BINDING_DIR "com.canonical.unity.settings-daemon.plugins.media-keys" #define INPUT_SETTINGS_BINDING_DIR "org.gnome.desktop.wm.keybindings" typedef enum { TOUCHPAD_KEY, TOUCHPAD_ON_KEY, TOUCHPAD_OFF_KEY, MUTE_KEY, VOLUME_DOWN_KEY, VOLUME_UP_KEY, MUTE_QUIET_KEY, VOLUME_DOWN_QUIET_KEY, VOLUME_UP_QUIET_KEY, MIC_MUTE_KEY, LOGOUT_KEY, EJECT_KEY, HOME_KEY, MEDIA_KEY, CALCULATOR_KEY, SEARCH_KEY, EMAIL_KEY, SCREENSAVER_KEY, HELP_KEY, SCREENSHOT_KEY, WINDOW_SCREENSHOT_KEY, AREA_SCREENSHOT_KEY, SCREENSHOT_CLIP_KEY, WINDOW_SCREENSHOT_CLIP_KEY, AREA_SCREENSHOT_CLIP_KEY, TERMINAL_KEY, WWW_KEY, PLAY_KEY, PAUSE_KEY, STOP_KEY, PREVIOUS_KEY, NEXT_KEY, REWIND_KEY, FORWARD_KEY, REPEAT_KEY, RANDOM_KEY, VIDEO_OUT_KEY, ROTATE_VIDEO_KEY, MAGNIFIER_KEY, SCREENREADER_KEY, ON_SCREEN_KEYBOARD_KEY, INCREASE_TEXT_KEY, DECREASE_TEXT_KEY, TOGGLE_CONTRAST_KEY, MAGNIFIER_ZOOM_IN_KEY, MAGNIFIER_ZOOM_OUT_KEY, POWER_KEY, SLEEP_KEY, SUSPEND_KEY, HIBERNATE_KEY, POWER_KEY_NO_DIALOG, SLEEP_KEY_NO_DIALOG, SUSPEND_KEY_NO_DIALOG, HIBERNATE_KEY_NO_DIALOG, SCREEN_BRIGHTNESS_UP_KEY, SCREEN_BRIGHTNESS_DOWN_KEY, KEYBOARD_BRIGHTNESS_UP_KEY, KEYBOARD_BRIGHTNESS_DOWN_KEY, KEYBOARD_BRIGHTNESS_TOGGLE_KEY, BATTERY_KEY, SWITCH_INPUT_SOURCE_KEY, SWITCH_INPUT_SOURCE_BACKWARD_KEY, CUSTOM_KEY } MediaKeyType; #define GSD_KEYBINDING_MODE_LAUNCHER (SHELL_KEYBINDING_MODE_NORMAL | \ SHELL_KEYBINDING_MODE_OVERVIEW) #define SCREENSAVER_MODE SHELL_KEYBINDING_MODE_ALL & ~SHELL_KEYBINDING_MODE_UNLOCK_SCREEN #define POWER_KEYS_MODE (SHELL_KEYBINDING_MODE_NORMAL | \ SHELL_KEYBINDING_MODE_OVERVIEW | \ SHELL_KEYBINDING_MODE_LOGIN_SCREEN) #define POWER_KEYS_MODE_NO_DIALOG (SHELL_KEYBINDING_MODE_LOCK_SCREEN | \ SHELL_KEYBINDING_MODE_UNLOCK_SCREEN) static struct { MediaKeyType key_type; const char *settings_key; const char *key_name; const char *hard_coded; ShellKeyBindingMode modes; } media_keys[] = { { TOUCHPAD_KEY, NULL, N_("Touchpad toggle") ,"XF86TouchpadToggle", SHELL_KEYBINDING_MODE_ALL }, { TOUCHPAD_ON_KEY, NULL, N_("Touchpad On"), "XF86TouchpadOn", SHELL_KEYBINDING_MODE_ALL }, { TOUCHPAD_OFF_KEY, NULL, N_("Touchpad Off"), "XF86TouchpadOff", SHELL_KEYBINDING_MODE_ALL }, { MUTE_KEY, "volume-mute", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { VOLUME_DOWN_KEY, "volume-down", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { VOLUME_UP_KEY, "volume-up", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { MIC_MUTE_KEY, NULL, N_("Microphone Mute"), "F20", SHELL_KEYBINDING_MODE_ALL }, { MIC_MUTE_KEY, NULL, N_("Microphone Mute"), "XF86AudioMicMute", SHELL_KEYBINDING_MODE_ALL }, { MUTE_QUIET_KEY, NULL, N_("Quiet Volume Mute"), "XF86AudioMute", SHELL_KEYBINDING_MODE_ALL }, { VOLUME_DOWN_QUIET_KEY, NULL, N_("Quiet Volume Down"), "XF86AudioLowerVolume", SHELL_KEYBINDING_MODE_ALL }, { VOLUME_UP_QUIET_KEY, NULL, N_("Quiet Volume Up"), "XF86AudioRaiseVolume", SHELL_KEYBINDING_MODE_ALL }, { LOGOUT_KEY, "logout", NULL, NULL, GSD_KEYBINDING_MODE_LAUNCHER }, { EJECT_KEY, "eject", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { HOME_KEY, "home", NULL, NULL, GSD_KEYBINDING_MODE_LAUNCHER }, { MEDIA_KEY, "media", NULL, NULL, GSD_KEYBINDING_MODE_LAUNCHER }, { CALCULATOR_KEY, "calculator", NULL, NULL, GSD_KEYBINDING_MODE_LAUNCHER }, { SEARCH_KEY, "search", NULL, NULL, GSD_KEYBINDING_MODE_LAUNCHER }, { EMAIL_KEY, "email", NULL, NULL, GSD_KEYBINDING_MODE_LAUNCHER }, { SCREENSAVER_KEY, "screensaver", NULL, NULL, SCREENSAVER_MODE }, { SCREENSAVER_KEY, NULL, N_("Lock Screen"), "XF86ScreenSaver", SCREENSAVER_MODE }, { HELP_KEY, "help", NULL, NULL, GSD_KEYBINDING_MODE_LAUNCHER }, { SCREENSHOT_KEY, "screenshot", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { WINDOW_SCREENSHOT_KEY, "window-screenshot", NULL, NULL, SHELL_KEYBINDING_MODE_NORMAL }, { AREA_SCREENSHOT_KEY, "area-screenshot", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { SCREENSHOT_CLIP_KEY, "screenshot-clip", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { WINDOW_SCREENSHOT_CLIP_KEY, "window-screenshot-clip", NULL, NULL, SHELL_KEYBINDING_MODE_NORMAL }, { AREA_SCREENSHOT_CLIP_KEY, "area-screenshot-clip", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { TERMINAL_KEY, "terminal", NULL, NULL, GSD_KEYBINDING_MODE_LAUNCHER }, { WWW_KEY, "www", NULL, NULL, GSD_KEYBINDING_MODE_LAUNCHER }, { PLAY_KEY, "play", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { PAUSE_KEY, "pause", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { STOP_KEY, "stop", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { PREVIOUS_KEY, "previous", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { NEXT_KEY, "next", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { REWIND_KEY, NULL, N_("Rewind"), "XF86AudioRewind", SHELL_KEYBINDING_MODE_ALL }, { FORWARD_KEY, NULL, N_("Forward"), "XF86AudioForward", SHELL_KEYBINDING_MODE_ALL }, { REPEAT_KEY, NULL, N_("Repeat"), "XF86AudioRepeat", SHELL_KEYBINDING_MODE_ALL }, { RANDOM_KEY, NULL, N_("Random Play"), "XF86AudioRandomPlay", SHELL_KEYBINDING_MODE_ALL }, { VIDEO_OUT_KEY, NULL, N_("Video Out"), "p", SHELL_KEYBINDING_MODE_ALL }, /* Key code of the XF86Display key (Fn-F7 on Thinkpads, Fn-F4 on HP machines, etc.) */ { VIDEO_OUT_KEY, NULL, N_("Video Out"), "XF86Display", SHELL_KEYBINDING_MODE_ALL }, /* Key code of the XF86RotateWindows key (present on some tablets) */ { ROTATE_VIDEO_KEY, NULL, N_("Rotate Screen"), "XF86RotateWindows", SHELL_KEYBINDING_MODE_NORMAL }, { MAGNIFIER_KEY, "magnifier", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { SCREENREADER_KEY, "screenreader", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { ON_SCREEN_KEYBOARD_KEY, "on-screen-keyboard", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { INCREASE_TEXT_KEY, "increase-text-size", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { DECREASE_TEXT_KEY, "decrease-text-size", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { TOGGLE_CONTRAST_KEY, "toggle-contrast", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { MAGNIFIER_ZOOM_IN_KEY, "magnifier-zoom-in", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { MAGNIFIER_ZOOM_OUT_KEY, "magnifier-zoom-out", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { POWER_KEY, NULL, N_("Power Off"), "XF86PowerOff", POWER_KEYS_MODE }, /* the kernel / Xorg names really are like this... */ /* translators: "Sleep" means putting the machine to sleep, either through hibernate or suspend */ { SLEEP_KEY, NULL, N_("Sleep"), "XF86Suspend", POWER_KEYS_MODE }, { SUSPEND_KEY, NULL, N_("Suspend"), "XF86Sleep", POWER_KEYS_MODE }, { HIBERNATE_KEY, NULL, N_("Hibernate"), "XF86Hibernate", POWER_KEYS_MODE }, { POWER_KEY_NO_DIALOG, NULL, N_("Power Off"), "XF86PowerOff", POWER_KEYS_MODE_NO_DIALOG }, /* the kernel / Xorg names really are like this... */ /* translators: "Sleep" means putting the machine to sleep, either through hibernate or suspend */ { SLEEP_KEY_NO_DIALOG, NULL, N_("Sleep"), "XF86Suspend", POWER_KEYS_MODE_NO_DIALOG }, { SUSPEND_KEY_NO_DIALOG, NULL, N_("Suspend"), "XF86Sleep", POWER_KEYS_MODE_NO_DIALOG }, { HIBERNATE_KEY_NO_DIALOG, NULL, N_("Hibernate"), "XF86Hibernate", POWER_KEYS_MODE_NO_DIALOG }, { SCREEN_BRIGHTNESS_UP_KEY, NULL, N_("Brightness Up"), "XF86MonBrightnessUp", SHELL_KEYBINDING_MODE_ALL }, { SCREEN_BRIGHTNESS_DOWN_KEY, NULL, N_("Brightness Down"), "XF86MonBrightnessDown", SHELL_KEYBINDING_MODE_ALL }, { KEYBOARD_BRIGHTNESS_UP_KEY, NULL, N_("Keyboard Brightness Up"), "XF86KbdBrightnessUp", SHELL_KEYBINDING_MODE_ALL }, { KEYBOARD_BRIGHTNESS_DOWN_KEY, NULL, N_("Keyboard Brightness Down"), "XF86KbdBrightnessDown", SHELL_KEYBINDING_MODE_ALL }, { KEYBOARD_BRIGHTNESS_TOGGLE_KEY, NULL, N_("Keyboard Brightness Toggle"), "XF86KbdLightOnOff", SHELL_KEYBINDING_MODE_ALL }, { BATTERY_KEY, NULL, N_("Battery Status"), "XF86Battery", GSD_KEYBINDING_MODE_LAUNCHER }, { SWITCH_INPUT_SOURCE_KEY, "switch-input-source", NULL, NULL, SHELL_KEYBINDING_MODE_ALL }, { SWITCH_INPUT_SOURCE_BACKWARD_KEY, "switch-input-source-backward", NULL, NULL, SHELL_KEYBINDING_MODE_ALL } }; #undef SCREENSAVER_MODE #endif /* __SHORTCUTS_LIST_H__ */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/test-media-keys.c0000664000175000017500000000033500000000000025721 0ustar00jeremyjeremy#define NEW gsd_media_keys_manager_new #define START gsd_media_keys_manager_start #define STOP gsd_media_keys_manager_stop #define MANAGER GsdMediaKeysManager #include "gsd-media-keys-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1644246191.587767 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/what-did-you-plug-in/0000775000175000017500000000000000000000000026433 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/what-did-you-plug-in/dialog-window.c0000664000175000017500000001131500000000000031344 0ustar00jeremyjeremy#include #include #include #include #include #include "dialog-window.h" typedef struct dialog_window { GtkWidget *dialog; GtkWidget *ca_box; GtkWidget *v_box; GtkWidget *icon_box; GtkWidget *btn_box; GtkWidget *label; GtkWidget *cancel_btn; GtkWidget *settings_btn; GtkWidget *hp_btn; GtkWidget *hs_btn; GtkWidget *mic_btn; int button_response; wdypi_dialog_cb cb; void *cb_userdata; } dialog_window; /* It's okay to have a global here - we should never show more than one dialog */ dialog_window dlg; void wdypi_dialog_kill() { dialog_window *d = &dlg; if (d->dialog) { gtk_widget_destroy(d->dialog); d->dialog = NULL; } } static void on_iconbtn_clicked (GtkWidget *widget, gpointer data) { dialog_window *d = &dlg; d->button_response = (ssize_t) data; gtk_dialog_response(GTK_DIALOG(d->dialog), GTK_RESPONSE_OK); } static void on_response (GtkWidget *widget, gint response_id, gpointer data) { int resp; dialog_window *d = data; if (!d->cb) return; switch (response_id) { case GTK_RESPONSE_YES: resp = WDYPI_DIALOG_SOUND_SETTINGS; break; case GTK_RESPONSE_OK: resp = d->button_response; break; default: resp = WDYPI_DIALOG_CANCELLED; } d->cb(resp, d->cb_userdata); wdypi_dialog_kill(); } static GtkWidget * create_icon_button(int response, const char *name, const char *icon) { GtkWidget *btn = gtk_button_new(); GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); GtkWidget *lbl = gtk_label_new(name); GtkWidget *img = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_DIALOG); gtk_box_pack_end(GTK_BOX(box), lbl, FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(box), img, FALSE, FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(box), 6); gtk_container_add(GTK_CONTAINER(btn), box); g_signal_connect(btn, "clicked", G_CALLBACK(on_iconbtn_clicked), (void*) (ssize_t) response); return btn; } static void dialog_create(dialog_window *d, bool show_headset, bool show_mic) { guint32 timestamp; d->dialog = gtk_dialog_new(); gtk_window_set_title(GTK_WINDOW(d->dialog), _("Unknown Audio Device")); gtk_container_set_border_width(GTK_CONTAINER(d->dialog), 6); gtk_window_set_icon_name(GTK_WINDOW(d->dialog), "audio-headphones"); gtk_window_set_resizable(GTK_WINDOW(d->dialog), FALSE); d->ca_box = gtk_dialog_get_content_area(GTK_DIALOG(d->dialog)); d->v_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width(GTK_CONTAINER(d->v_box), 5); d->icon_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_set_homogeneous(GTK_BOX(d->icon_box), TRUE); d->label = gtk_label_new(_("What kind of device did you plug in?")); gtk_misc_set_alignment(GTK_MISC(d->label), 0.5, 0.5); gtk_box_pack_start(GTK_CONTAINER(d->v_box), d->label, FALSE, FALSE, 6); d->hp_btn = create_icon_button(WDYPI_DIALOG_HEADPHONES, _("Headphones"), "audio-headphones"); gtk_box_pack_start(GTK_BOX(d->icon_box), d->hp_btn, FALSE, TRUE, 0); if (show_headset) { d->hs_btn = create_icon_button(WDYPI_DIALOG_HEADSET, _("Headset"), "audio-headset"); gtk_box_pack_start(GTK_BOX(d->icon_box), d->hs_btn, FALSE, TRUE, 0); } if (show_mic) { d->mic_btn = create_icon_button(WDYPI_DIALOG_MICROPHONE, _("Microphone"), "audio-input-microphone"); gtk_box_pack_start(GTK_BOX(d->icon_box), d->mic_btn, FALSE, TRUE, 0); } gtk_box_pack_start(GTK_CONTAINER(d->v_box), d->icon_box, FALSE, FALSE, 6); d->cancel_btn = gtk_dialog_add_button(GTK_DIALOG(d->dialog), _("Cancel"), GTK_RESPONSE_CANCEL); d->settings_btn = gtk_dialog_add_button(GTK_DIALOG(d->dialog), _("Sound Settings…"), GTK_RESPONSE_YES); gtk_container_add(GTK_CONTAINER(d->ca_box), d->v_box); g_signal_connect(d->dialog, "response", G_CALLBACK(on_response), d); gtk_widget_show_all(d->dialog); /* This event did not originate from a pointer or key movement, so we can't use GDK_CURRENT_TIME (or just gtk_window_present) here. There is also no other source timestamp to rely on. Without a timestamp, the dialog would often show up behind other windows. */ timestamp = gdk_x11_get_server_time(gtk_widget_get_window(GTK_WIDGET(d->dialog))); gtk_window_present_with_time(GTK_WINDOW(d->dialog), timestamp); } void wdypi_dialog_run(bool show_headset, bool show_mic, wdypi_dialog_cb cb, void *cb_userdata) { dialog_window *d = &dlg; wdypi_dialog_kill(); d->cb = cb; d->cb_userdata = cb_userdata; dialog_create(d, show_headset, show_mic); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/what-did-you-plug-in/dialog-window.h0000664000175000017500000000067500000000000031360 0ustar00jeremyjeremy#ifndef __DIALOG_WINDOW_H__ #define __DIALOG_WINDOW_H__ #include #define WDYPI_DIALOG_CANCELLED 0 #define WDYPI_DIALOG_HEADPHONES 1 #define WDYPI_DIALOG_HEADSET 2 #define WDYPI_DIALOG_MICROPHONE 3 #define WDYPI_DIALOG_SOUND_SETTINGS 4 typedef void (*wdypi_dialog_cb)(int response, void *userdata); void wdypi_dialog_run(bool show_headset, bool show_mic, wdypi_dialog_cb cb, void *cb_userdata); void wdypi_dialog_kill(); #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/what-did-you-plug-in/pa-backend.c0000664000175000017500000001644600000000000030577 0ustar00jeremyjeremy#include #include #include #include #include #include #include "pa-backend.h" struct pa_backend { const pa_context *context; pa_backend_cb dialog_cb; void *cb_userdata; int headset_card; bool headset_plugged_in; bool has_headsetmic; bool has_headphonemic; const char *sink_port_name_to_set; const char *source_port_name_to_set; }; void pa_backend_set_context(pa_backend *p, const pa_context *c) { p->context = c; } pa_backend *pa_backend_new(pa_backend_cb cb, void *cb_userdata) { pa_backend *p = calloc(1, sizeof(*p)); if (!p) return NULL; p->headset_card = -1; p->dialog_cb = cb; p->cb_userdata = cb_userdata; return p; } typedef struct headset_ports { const pa_card_port_info *headphones, *headsetmic, *headphonemic; } headset_ports; /* TODO: Check if we still need this with the changed PA port names In PulseAudio ports will show up with the following names: Headphones - analog-output-headphones Headset mic - analog-input-headset-mic (was: analog-input-microphone-headset) Jack in mic-in mode - analog-input-headphone-mic (was: analog-input-microphone) However, since regular mics also show up as analog-input-microphone, we need to check for certain controls on alsa mixer level too, to know if we deal with a separate mic jack, or a multi-function jack with a mic-in mode (also called "headphone mic"). We check for the following names: Headphone Mic Jack - indicates headphone and mic-in mode share the same jack, i e, not two separate jacks. Hardware cannot distinguish between a headphone and a mic. Headset Mic Phantom Jack - indicates headset jack where hardware can not distinguish between headphones and headsets Headset Mic Jack - indicates headset jack where hardware can distinguish between headphones and headsets. There is no use popping up a dialog in this case, unless we already need to do this for the mic-in mode. */ static headset_ports get_headset_ports(const pa_card_info *c) { headset_ports h = {NULL, NULL, NULL}; int i; for (i = 0; i < c->n_ports; i++) { pa_card_port_info *p = c->ports[i]; if (!strcmp(p->name, "analog-output-headphones")) h.headphones = p; else if (!strcmp(p->name, "analog-input-headset-mic")) h.headsetmic = p; else if (!strcmp(p->name, "analog-input-headphone-mic")) h.headphonemic = p; } return h; } static bool verify_alsa_card(int cardindex, bool *headsetmic, bool *headphonemic) { char ctlstr[20]; snd_hctl_t *hctl; snd_ctl_elem_id_t *id; int err; *headsetmic = false; *headphonemic = false; snprintf(ctlstr, sizeof(ctlstr), "hw:%i", cardindex); if ((err = snd_hctl_open(&hctl, ctlstr, 0)) < 0) { g_warning("snd_hctl_open failed: %s", snd_strerror(err)); return false; } if ((err = snd_hctl_load(hctl)) < 0) { g_warning("snd_hctl_load failed: %s", snd_strerror(err)); snd_hctl_close(hctl); return false; } snd_ctl_elem_id_alloca(&id); snd_ctl_elem_id_clear(id); snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_CARD); snd_ctl_elem_id_set_name(id, "Headphone Mic Jack"); if (snd_hctl_find_elem(hctl, id)) *headphonemic = true; snd_ctl_elem_id_clear(id); snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_CARD); snd_ctl_elem_id_set_name(id, "Headset Mic Phantom Jack"); if (snd_hctl_find_elem(hctl, id)) *headsetmic = true; if (*headphonemic) { snd_ctl_elem_id_clear(id); snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_CARD); snd_ctl_elem_id_set_name(id, "Headset Mic Jack"); if (snd_hctl_find_elem(hctl, id)) *headsetmic = true; } snd_hctl_close(hctl); return *headsetmic || *headphonemic; } void pa_backend_card_changed(pa_backend *p, const pa_card_info *i) { headset_ports h; bool start_dialog = false, stop_dialog = false; h = get_headset_ports(i); if (!h.headphones || (!h.headsetmic && !h.headphonemic)) return; /* Not a headset jack */ if (p->headset_card != (int) i->index) { int cardindex = 0; bool hsmic, hpmic; const char *s = pa_proplist_gets(i->proplist, "alsa.card"); if (!s) return; cardindex = strtol(s, NULL, 10); if (cardindex == 0 && strcmp(s, "0")) return; if (!verify_alsa_card(cardindex, &hsmic, &hpmic)) return; p->headset_card = (int) i->index; p->has_headsetmic = hsmic && h.headsetmic; p->has_headphonemic = hpmic && h.headphonemic; } else { start_dialog = p->dialog_cb && (h.headphones->available != PA_PORT_AVAILABLE_NO) && !p->headset_plugged_in; stop_dialog = p->dialog_cb && (h.headphones->available == PA_PORT_AVAILABLE_NO) && p->headset_plugged_in; } p->headset_plugged_in = h.headphones->available != PA_PORT_AVAILABLE_NO; if (start_dialog) p->dialog_cb(p->has_headsetmic, p->has_headphonemic, p->cb_userdata); else if (stop_dialog) p->dialog_cb(false, false, p->cb_userdata); } /* We need to re-enumerate sources and sinks every time the user makes a choice, because they can change due to use interaction in other software (or policy changes inside PulseAudio). Enumeration means PulseAudio will do a series of callbacks, one for every source/sink. Set the port when we find the correct source/sink. */ static void sink_info_cb(pa_context *c, const pa_sink_info *i, int eol, void *userdata) { pa_backend *p = userdata; pa_operation *o; int j; const char *s = p->sink_port_name_to_set; if (eol) return; if (i->card != p->headset_card) return; if (i->active_port && !strcmp(i->active_port->name, s)) return; for (j = 0; j < i->n_ports; j++) if (!strcmp(i->ports[j]->name, s)) break; if (j >= i->n_ports) return; o = pa_context_set_sink_port_by_index(c, i->index, s, NULL, NULL); if (o) pa_operation_unref(o); } static void source_info_cb(pa_context *c, const pa_source_info *i, int eol, void *userdata) { pa_backend *p = userdata; pa_operation *o; int j; const char *s = p->source_port_name_to_set; if (eol) return; if (i->card != p->headset_card) return; if (i->active_port && !strcmp(i->active_port->name, s)) return; for (j = 0; j < i->n_ports; j++) if (!strcmp(i->ports[j]->name, s)) break; if (j >= i->n_ports) return; o = pa_context_set_source_port_by_index(c, i->index, s, NULL, NULL); if (o) pa_operation_unref(o); } void pa_backend_set_port(pa_backend *p, const char *portname, bool is_output) { pa_operation *o; if (is_output) { p->sink_port_name_to_set = portname; o = pa_context_get_sink_info_list(p->context, sink_info_cb, p); } else { p->source_port_name_to_set = portname; o = pa_context_get_source_info_list(p->context, source_info_cb, p); } if (o) { pa_operation_unref(o); } } void pa_backend_free(pa_backend *p) { if (!p) return; free(p); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/media-keys/what-did-you-plug-in/pa-backend.h0000664000175000017500000000105100000000000030566 0ustar00jeremyjeremy#ifndef __PA_BACKEND_H__ #define __PA_BACKEND_H__ #include #include typedef struct pa_backend pa_backend; typedef void (*pa_backend_cb)(bool headsetmic, bool headphonemic, void *userdata); pa_backend *pa_backend_new(pa_backend_cb cb, void *cb_userdata); void pa_backend_free(pa_backend *p); void pa_backend_card_changed(pa_backend *p, const pa_card_info *i); void pa_backend_set_context(pa_backend *p, const pa_context *c); void pa_backend_set_port(pa_backend *p, const char *portname, bool is_output); #endif ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1644246191.587767 unity-settings-daemon-15.04.1+21.10.20220207/plugins/mouse/0000775000175000017500000000000000000000000021647 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/mouse/Makefile.am0000664000175000017500000000374100000000000023710 0ustar00jeremyjeremyplugin_name = mouse plugin_LTLIBRARIES = libmouse.la libmouse_la_SOURCES = \ gsd-mouse-plugin.c \ gsd-mouse-manager.h \ gsd-mouse-manager.c libmouse_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common/ \ -I$(top_srcdir)/data/ \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ $(AM_CPPFLAGS) libmouse_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(MOUSE_CFLAGS) \ $(AM_CFLAGS) libmouse_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) libmouse_la_LIBADD = \ $(MOUSE_LIBS) \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(SETTINGS_PLUGIN_LIBS) plugin_in_files = mouse.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) libexec_PROGRAMS = usd-locate-pointer usd_locate_pointer_SOURCES = \ gsd-locate-pointer.h \ gsd-locate-pointer.c \ gsd-timeline.h \ gsd-timeline.c usd_locate_pointer_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(MOUSE_CFLAGS) \ $(AM_CFLAGS) usd_locate_pointer_LDADD = \ $(SETTINGS_PLUGIN_LIBS) \ $(MOUSE_LIBS) \ -lm libexec_PROGRAMS += usd-test-mouse usd_test_mouse_SOURCES = \ test-mouse.c \ gsd-mouse-manager.c \ gsd-mouse-manager.h usd_test_mouse_CPPFLAGS = \ -I$(top_srcdir)/data/ \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ $(AM_CPPFLAGS) usd_test_mouse_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(MOUSE_CFLAGS) \ $(AM_CFLAGS) usd_test_mouse_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(SETTINGS_DAEMON_LIBS) \ $(SETTINGS_PLUGIN_LIBS) \ $(MOUSE_LIBS) \ -lm EXTRA_DIST = $(plugin_in_files) CLEANFILES = $(plugin_DATA) DISTCLEANFILES = $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/mouse/gsd-locate-pointer.c0000664000175000017500000003572000000000000025522 0ustar00jeremyjeremy/* gsd-locate-pointer.c * * Copyright (C) 2008 Carlos Garnacho * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ #include #include "gsd-timeline.h" #include "gsd-locate-pointer.h" #include #include #include #define ANIMATION_LENGTH 750 #define WINDOW_SIZE 101 #define N_CIRCLES 4 /* All circles are supposed to be moving when progress * reaches 0.5, and each of them are supposed to long * for half of the progress, hence the need of 0.5 to * get the circles interval, and the multiplication * by 2 to know a circle progress */ #define CIRCLES_PROGRESS_INTERVAL (0.5 / N_CIRCLES) #define CIRCLE_PROGRESS(p) (MIN (1., ((gdouble) (p) * 2.))) typedef struct GsdLocatePointerData GsdLocatePointerData; struct GsdLocatePointerData { GsdTimeline *timeline; GtkWidget *widget; GdkWindow *window; gdouble progress; }; static GsdLocatePointerData *data = NULL; static void locate_pointer_paint (GsdLocatePointerData *data, cairo_t *cr, gboolean composite) { GdkRGBA color; gdouble progress, circle_progress; gint width, height, i; GtkStyleContext *context; progress = data->progress; width = gdk_window_get_width (data->window); height = gdk_window_get_height (data->window); context = gtk_widget_get_style_context (data->widget); gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &color); cairo_set_source_rgba (cr, 1., 1., 1., 0.); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); for (i = 0; i <= N_CIRCLES; i++) { if (progress < 0.) break; circle_progress = MIN (1., (progress * 2)); progress -= CIRCLES_PROGRESS_INTERVAL; if (circle_progress >= 1.) continue; if (composite) { cairo_set_source_rgba (cr, color.red, color.green, color.blue, 1 - circle_progress); cairo_arc (cr, width / 2, height / 2, circle_progress * width / 2, 0, 2 * G_PI); cairo_fill (cr); } else { cairo_set_source_rgb (cr, 0., 0., 0.); cairo_set_line_width (cr, 3.); cairo_arc (cr, width / 2, height / 2, circle_progress * width / 2, 0, 2 * G_PI); cairo_stroke (cr); cairo_set_source_rgb (cr, 1., 1., 1.); cairo_set_line_width (cr, 1.); cairo_arc (cr, width / 2, height / 2, circle_progress * width / 2, 0, 2 * G_PI); cairo_stroke (cr); } } } static gboolean locate_pointer_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data) { GsdLocatePointerData *data = (GsdLocatePointerData *) user_data; if (gtk_cairo_should_draw_window (cr, data->window)) locate_pointer_paint (data, cr, gtk_widget_is_composited (data->widget)); return TRUE; } static void update_shape (GsdLocatePointerData *data) { cairo_t *cr; cairo_region_t *region; cairo_surface_t *mask; mask = cairo_image_surface_create (CAIRO_FORMAT_A1, WINDOW_SIZE, WINDOW_SIZE); cr = cairo_create (mask); locate_pointer_paint (data, cr, FALSE); region = gdk_cairo_region_create_from_surface (mask); gdk_window_shape_combine_region (data->window, region, 0, 0); cairo_region_destroy (region); cairo_destroy (cr); cairo_surface_destroy (mask); } static void timeline_frame_cb (GsdTimeline *timeline, gdouble progress, gpointer user_data) { GsdLocatePointerData *data = (GsdLocatePointerData *) user_data; GdkScreen *screen; gint cursor_x, cursor_y; if (gtk_widget_is_composited (data->widget)) { gdk_window_invalidate_rect (data->window, NULL, FALSE); data->progress = progress; } else if (progress >= data->progress + CIRCLES_PROGRESS_INTERVAL) { /* only invalidate window each circle interval */ update_shape (data); gdk_window_invalidate_rect (data->window, NULL, FALSE); data->progress += CIRCLES_PROGRESS_INTERVAL; } screen = gdk_window_get_screen (data->window); gdk_window_get_pointer (gdk_screen_get_root_window (screen), &cursor_x, &cursor_y, NULL); gdk_window_move (data->window, cursor_x - WINDOW_SIZE / 2, cursor_y - WINDOW_SIZE / 2); } static void set_transparent_shape (GdkWindow *window) { cairo_region_t *region; region = cairo_region_create (); gdk_window_shape_combine_region (data->window, region, 0, 0); cairo_region_destroy (region); } static void unset_transparent_shape (GdkWindow *window) { gdk_window_shape_combine_region (data->window, NULL, 0, 0); } static void composited_changed (GtkWidget *widget, GsdLocatePointerData *data) { if (!gtk_widget_is_composited (widget)) set_transparent_shape (data->window); else unset_transparent_shape (data->window); } static void timeline_finished_cb (GsdTimeline *timeline, gpointer user_data) { GsdLocatePointerData *data = (GsdLocatePointerData *) user_data; /* set transparent shape and hide window */ if (!gtk_widget_is_composited (data->widget)) set_transparent_shape (data->window); gtk_widget_hide (data->widget); gdk_window_hide (data->window); } static void create_window (GsdLocatePointerData *data, GdkScreen *screen) { GdkVisual *visual; GdkWindowAttr attributes; gint attributes_mask; visual = gdk_screen_get_rgba_visual (screen); if (visual == NULL) visual = gdk_screen_get_system_visual (screen); attributes_mask = GDK_WA_X | GDK_WA_Y; if (visual != NULL) attributes_mask = attributes_mask | GDK_WA_VISUAL; attributes.window_type = GDK_WINDOW_TEMP; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = visual; attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK; attributes.width = 1; attributes.height = 1; data->window = gdk_window_new (gdk_screen_get_root_window (screen), &attributes, attributes_mask); gdk_window_set_user_data (data->window, data->widget); } static GsdLocatePointerData * gsd_locate_pointer_data_new (GdkScreen *screen) { GsdLocatePointerData *data; data = g_new0 (GsdLocatePointerData, 1); /* this widget will never be shown, it's * mainly used to get signals/events from */ data->widget = gtk_invisible_new (); gtk_widget_realize (data->widget); g_signal_connect (G_OBJECT (data->widget), "draw", G_CALLBACK (locate_pointer_draw), data); data->timeline = gsd_timeline_new (ANIMATION_LENGTH); g_signal_connect (data->timeline, "frame", G_CALLBACK (timeline_frame_cb), data); g_signal_connect (data->timeline, "finished", G_CALLBACK (timeline_finished_cb), data); create_window (data, screen); return data; } static void move_locate_pointer_window (GsdLocatePointerData *data, GdkScreen *screen) { cairo_region_t *region; gint cursor_x, cursor_y; gdk_window_get_pointer (gdk_screen_get_root_window (screen), &cursor_x, &cursor_y, NULL); gdk_window_move_resize (data->window, cursor_x - WINDOW_SIZE / 2, cursor_y - WINDOW_SIZE / 2, WINDOW_SIZE, WINDOW_SIZE); /* allow events to happen through the window */ region = cairo_region_create (); gdk_window_input_shape_combine_region (data->window, region, 0, 0); cairo_region_destroy (region); } void gsd_locate_pointer (GdkScreen *screen) { if (!data) data = gsd_locate_pointer_data_new (screen); gsd_timeline_pause (data->timeline); gsd_timeline_rewind (data->timeline); /* Create again the window if it is not for the current screen */ if (gdk_screen_get_number (screen) != gdk_screen_get_number (gdk_window_get_screen (data->window))) { gdk_window_set_user_data (data->window, NULL); gdk_window_destroy (data->window); create_window (data, screen); } data->progress = 0.; g_signal_connect (data->widget, "composited-changed", G_CALLBACK (composited_changed), data); move_locate_pointer_window (data, screen); composited_changed (data->widget, data); gdk_window_show (data->window); gtk_widget_show (data->widget); gsd_timeline_start (data->timeline); } #define KEYBOARD_GROUP_SHIFT 13 #define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14)) /* Owen magic */ static GdkFilterReturn filter (GdkXEvent *xevent, GdkEvent *event, gpointer data) { XEvent *xev = (XEvent *) xevent; guint keyval; gint group; GdkScreen *screen = (GdkScreen *)data; if (xev->type == ButtonPress) { XAllowEvents (xev->xbutton.display, ReplayPointer, xev->xbutton.time); XUngrabButton (xev->xbutton.display, AnyButton, AnyModifier, xev->xbutton.window); XUngrabKeyboard (xev->xbutton.display, xev->xbutton.time); } if (xev->type == KeyPress || xev->type == KeyRelease) { /* get the keysym */ group = (xev->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT; gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (), xev->xkey.keycode, xev->xkey.state, group, &keyval, NULL, NULL, NULL); if (keyval == GDK_KEY_Control_L || keyval == GDK_KEY_Control_R) { if (xev->type == KeyPress) { XAllowEvents (xev->xkey.display, SyncKeyboard, xev->xkey.time); XGrabButton (xev->xkey.display, AnyButton, AnyModifier, xev->xkey.window, False, ButtonPressMask, GrabModeSync, GrabModeAsync, None, None); } else { XUngrabButton (xev->xkey.display, AnyButton, AnyModifier, xev->xkey.window); XAllowEvents (xev->xkey.display, AsyncKeyboard, xev->xkey.time); gsd_locate_pointer (screen); } } else { XAllowEvents (xev->xkey.display, ReplayKeyboard, xev->xkey.time); XUngrabButton (xev->xkey.display, AnyButton, AnyModifier, xev->xkey.window); XUngrabKeyboard (xev->xkey.display, xev->xkey.time); } } return GDK_FILTER_CONTINUE; } static void set_locate_pointer (void) { GdkKeymapKey *keys; GdkDisplay *display; int n_screens; int n_keys; gboolean has_entries; static const guint keyvals[] = { GDK_KEY_Control_L, GDK_KEY_Control_R }; unsigned j; display = gdk_display_get_default (); n_screens = gdk_display_get_n_screens (display); for (j = 0 ; j < G_N_ELEMENTS (keyvals) ; j++) { has_entries = gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), keyvals[j], &keys, &n_keys); if (has_entries) { gint i, j; for (i = 0; i < n_keys; i++) { for (j = 0; j < n_screens; j++) { GdkScreen *screen; Window xroot; screen = gdk_display_get_screen (display, j); xroot = gdk_x11_window_get_xid (gdk_screen_get_root_window (screen)); gdk_x11_display_error_trap_push (display); XGrabKey (GDK_DISPLAY_XDISPLAY (display), keys[i].keycode, 0, xroot, False, GrabModeAsync, GrabModeSync); XGrabKey (GDK_DISPLAY_XDISPLAY (display), keys[i].keycode, LockMask, xroot, False, GrabModeAsync, GrabModeSync); XGrabKey (GDK_DISPLAY_XDISPLAY (display), keys[i].keycode, Mod2Mask, xroot, False, GrabModeAsync, GrabModeSync); XGrabKey (GDK_DISPLAY_XDISPLAY (display), keys[i].keycode, Mod4Mask, xroot, False, GrabModeAsync, GrabModeSync); gdk_x11_display_error_trap_pop_ignored (display); } } g_free (keys); for (i = 0; i < n_screens; i++) { GdkScreen *screen; screen = gdk_display_get_screen (display, i); gdk_window_add_filter (gdk_screen_get_root_window (screen), filter, screen); } } } } int main (int argc, char *argv[]) { gdk_disable_multidevice (); gtk_init (&argc, &argv); set_locate_pointer (); gtk_main (); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/mouse/gsd-locate-pointer.h0000664000175000017500000000153300000000000025522 0ustar00jeremyjeremy/* * Copyright 2001 Jonathan Blandford * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of Red Hat not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. Red Hat makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * Authors: Jonathan Blandford */ #ifndef LOCATE_POINTER_H #define LOCATE_POINTER_H #include void gsd_locate_pointer (GdkScreen *screen); #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/mouse/gsd-mouse-manager.c0000664000175000017500000015230200000000000025331 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #ifdef __linux #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include "gnome-settings-profile.h" #include "gsd-mouse-manager.h" #include "gsd-input-helper.h" #include "gsd-enums.h" #include "gsd-settings-migrate.h" #define GSD_MOUSE_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_MOUSE_MANAGER, GsdMouseManagerPrivate)) #define GNOME_DESKTOP_INTERFACE_DIR "org.gnome.desktop.interface" #define GSETTINGS_MOUSE_SCHEMA "org.gnome.desktop.peripherals.mouse" #define GSETTINGS_TOUCHPAD_SCHEMA "org.gnome.desktop.peripherals.touchpad" #define USD_TOUCHPAD_SCHEMA "com.canonical.unity.settings-daemon.peripherals.touchpad" /* Keys for both touchpad and mouse */ #define KEY_LEFT_HANDED "left-handed" /* a boolean for mouse, an enum for touchpad */ #define KEY_SPEED "speed" /* Touchpad settings */ #define KEY_SCROLL_METHOD "scroll-method" #define KEY_TAP_TO_CLICK "tap-to-click" #define KEY_SEND_EVENTS "send-events" #define KEY_NATURAL_SCROLL_ENABLED "natural-scroll" /* Mouse settings */ #define KEY_LOCATE_POINTER "locate-pointer" #define KEY_DWELL_CLICK_ENABLED "dwell-click-enabled" #define KEY_SECONDARY_CLICK_ENABLED "secondary-click-enabled" struct GsdMouseManagerPrivate { guint start_idle_id; GSettings *touchpad_settings; GSettings *usd_touchpad_settings; GSettings *mouse_settings; GSettings *mouse_a11y_settings; GSettings *interface_settings; GdkDeviceManager *device_manager; guint device_added_id; guint device_removed_id; GHashTable *blacklist; gboolean mousetweaks_daemon_running; gboolean syndaemon_spawned; GPid syndaemon_pid; gboolean locate_pointer_spawned; GPid locate_pointer_pid; }; static void gsd_mouse_manager_class_init (GsdMouseManagerClass *klass); static void gsd_mouse_manager_init (GsdMouseManager *mouse_manager); static void gsd_mouse_manager_finalize (GObject *object); static void set_tap_to_click (GdkDevice *device, gboolean state, gboolean left_handed); static void set_natural_scroll (GsdMouseManager *manager, GdkDevice *device, gboolean natural_scroll); G_DEFINE_TYPE (GsdMouseManager, gsd_mouse_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static GObject * gsd_mouse_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { GsdMouseManager *mouse_manager; mouse_manager = GSD_MOUSE_MANAGER (G_OBJECT_CLASS (gsd_mouse_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); return G_OBJECT (mouse_manager); } static void gsd_mouse_manager_dispose (GObject *object) { G_OBJECT_CLASS (gsd_mouse_manager_parent_class)->dispose (object); } static void gsd_mouse_manager_class_init (GsdMouseManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructor = gsd_mouse_manager_constructor; object_class->dispose = gsd_mouse_manager_dispose; object_class->finalize = gsd_mouse_manager_finalize; g_type_class_add_private (klass, sizeof (GsdMouseManagerPrivate)); } static XDevice * open_gdk_device (GdkDevice *device) { XDevice *xdevice; int id; g_object_get (G_OBJECT (device), "device-id", &id, NULL); gdk_error_trap_push (); xdevice = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), id); if (gdk_error_trap_pop () != 0) return NULL; return xdevice; } static gboolean device_is_blacklisted (GsdMouseManager *manager, GdkDevice *device) { int id; g_object_get (G_OBJECT (device), "device-id", &id, NULL); if (g_hash_table_lookup (manager->priv->blacklist, GINT_TO_POINTER (id)) != NULL) { g_debug ("device %s (%d) is blacklisted", gdk_device_get_name (device), id); return TRUE; } return FALSE; } static gboolean device_is_ignored (GsdMouseManager *manager, GdkDevice *device) { GdkInputSource source; const char *name; if (device_is_blacklisted (manager, device)) return TRUE; source = gdk_device_get_source (device); if (source != GDK_SOURCE_MOUSE && source != GDK_SOURCE_TOUCHPAD && source != GDK_SOURCE_CURSOR) return TRUE; name = gdk_device_get_name (device); if (name != NULL && g_str_equal ("Virtual core XTEST pointer", name)) return TRUE; return FALSE; } static void configure_button_layout (guchar *buttons, gint n_buttons, gboolean left_handed) { const gint left_button = 1; gint right_button; gint i; /* if the button is higher than 2 (3rd button) then it's * probably one direction of a scroll wheel or something else * uninteresting */ right_button = MIN (n_buttons, 3); /* If we change things we need to make sure we only swap buttons. * If we end up with multiple physical buttons assigned to the same * logical button the server will complain. This code assumes physical * button 0 is the physical left mouse button, and that the physical * button other than 0 currently assigned left_button or right_button * is the physical right mouse button. */ /* check if the current mapping satisfies the above assumptions */ if (buttons[left_button - 1] != left_button && buttons[left_button - 1] != right_button) /* The current mapping is weird. Swapping buttons is probably not a * good idea. */ return; /* check if we are left_handed and currently not swapped */ if (left_handed && buttons[left_button - 1] == left_button) { /* find the right button */ for (i = 0; i < n_buttons; i++) { if (buttons[i] == right_button) { buttons[i] = left_button; break; } } /* swap the buttons */ buttons[left_button - 1] = right_button; } /* check if we are not left_handed but are swapped */ else if (!left_handed && buttons[left_button - 1] == right_button) { /* find the right button */ for (i = 0; i < n_buttons; i++) { if (buttons[i] == left_button) { buttons[i] = right_button; break; } } /* swap the buttons */ buttons[left_button - 1] = left_button; } } static gboolean xinput_device_has_buttons (GdkDevice *device) { int i; XAnyClassInfo *class_info; /* FIXME can we use the XDevice's classes here instead? */ XDeviceInfo *device_info, *info; gint n_devices; int id; /* Find the XDeviceInfo for the GdkDevice */ g_object_get (G_OBJECT (device), "device-id", &id, NULL); device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &n_devices); if (device_info == NULL) return FALSE; info = NULL; for (i = 0; i < n_devices; i++) { if (device_info[i].id == id) { info = &device_info[i]; break; } } if (info == NULL) goto bail; class_info = info->inputclassinfo; for (i = 0; i < info->num_classes; i++) { if (class_info->class == ButtonClass) { XButtonInfo *button_info; button_info = (XButtonInfo *) class_info; if (button_info->num_buttons > 0) { XFreeDeviceList (device_info); return TRUE; } } class_info = (XAnyClassInfo *) (((guchar *) class_info) + class_info->length); } bail: XFreeDeviceList (device_info); return FALSE; } static gboolean touchpad_has_single_button (XDevice *device) { Atom type, prop; int format; unsigned long nitems, bytes_after; unsigned char *data; gboolean is_single_button = FALSE; int rc; prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Capabilities", False); if (!prop) return FALSE; gdk_error_trap_push (); rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device, prop, 0, 1, False, XA_INTEGER, &type, &format, &nitems, &bytes_after, &data); if (rc == Success && type == XA_INTEGER && format == 8 && nitems >= 3) is_single_button = (data[0] == 1 && data[1] == 0 && data[2] == 0); if (rc == Success) XFree (data); gdk_error_trap_pop_ignored (); return is_single_button; } static void set_left_handed (GsdMouseManager *manager, GdkDevice *device, gboolean mouse_left_handed, gboolean touchpad_left_handed) { XDevice *xdevice; guchar *buttons; gsize buttons_capacity = 16; gboolean left_handed; gint n_buttons; if (!xinput_device_has_buttons (device)) return; xdevice = open_gdk_device (device); if (xdevice == NULL) return; g_debug ("setting handedness on %s", gdk_device_get_name (device)); buttons = g_new (guchar, buttons_capacity); /* If the device is a touchpad, swap tap buttons * around too, otherwise a tap would be a right-click */ if (device_is_touchpad (xdevice)) { gboolean tap = g_settings_get_boolean (manager->priv->touchpad_settings, KEY_TAP_TO_CLICK); gboolean single_button = touchpad_has_single_button (xdevice); left_handed = touchpad_left_handed; if (tap && !single_button) set_tap_to_click (device, tap, left_handed); if (single_button) goto out; } else { left_handed = mouse_left_handed; } gdk_error_trap_push (); n_buttons = XGetDeviceButtonMapping (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, buttons, buttons_capacity); while (n_buttons > buttons_capacity) { buttons_capacity = n_buttons; buttons = (guchar *) g_realloc (buttons, buttons_capacity * sizeof (guchar)); n_buttons = XGetDeviceButtonMapping (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, buttons, buttons_capacity); } configure_button_layout (buttons, n_buttons, left_handed); XSetDeviceButtonMapping (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, buttons, n_buttons); gdk_error_trap_pop_ignored (); out: xdevice_close (xdevice); g_free (buttons); } static void set_motion (GsdMouseManager *manager, GdkDevice *device) { XDevice *xdevice; XPtrFeedbackControl feedback; XFeedbackState *states, *state; int num_feedbacks; int numerator, denominator; gfloat motion_acceleration; int motion_threshold; GSettings *settings; gdouble speed; guint i; xdevice = open_gdk_device (device); if (xdevice == NULL) return; g_debug ("setting motion on %s", gdk_device_get_name (device)); if (device_is_touchpad (xdevice)) settings = manager->priv->touchpad_settings; else settings = manager->priv->mouse_settings; speed = g_settings_get_double (settings, KEY_SPEED); /* Calculate acceleration and threshold */ motion_acceleration = (speed + 1) * 5; /* speed is [-1..1], map to [0..10] */ motion_threshold = CLAMP (10 - floor (motion_acceleration), 1, 10); if (motion_acceleration >= 1.0) { /* we want to get the acceleration, with a resolution of 0.5 */ if ((motion_acceleration - floor (motion_acceleration)) < 0.25) { numerator = floor (motion_acceleration); denominator = 1; } else if ((motion_acceleration - floor (motion_acceleration)) < 0.5) { numerator = ceil (2.0 * motion_acceleration); denominator = 2; } else if ((motion_acceleration - floor (motion_acceleration)) < 0.75) { numerator = floor (2.0 *motion_acceleration); denominator = 2; } else { numerator = ceil (motion_acceleration); denominator = 1; } } else if (motion_acceleration < 1.0 && motion_acceleration > 0) { /* This we do to 1/10ths */ numerator = floor (motion_acceleration * 10) + 1; denominator= 10; } else { numerator = -1; denominator = -1; } gdk_error_trap_push (); /* Get the list of feedbacks for the device */ states = XGetFeedbackControl (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, &num_feedbacks); if (states == NULL) goto out; state = (XFeedbackState *) states; for (i = 0; i < num_feedbacks; i++) { if (state->class == PtrFeedbackClass) { /* And tell the device */ feedback.class = PtrFeedbackClass; feedback.length = sizeof (XPtrFeedbackControl); feedback.id = state->id; feedback.threshold = motion_threshold; feedback.accelNum = numerator; feedback.accelDenom = denominator; g_debug ("Setting accel %d/%d, threshold %d for device '%s'", numerator, denominator, motion_threshold, gdk_device_get_name (device)); XChangeFeedbackControl (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, DvAccelNum | DvAccelDenom | DvThreshold, (XFeedbackControl *) &feedback); break; } state = (XFeedbackState *) ((char *) state + state->length); } if (gdk_error_trap_pop ()) g_warning ("Error setting acceleration on \"%s\"", gdk_device_get_name (device)); XFreeFeedbackList (states); out: xdevice_close (xdevice); } /* Ensure that syndaemon dies together with us, to avoid running several of * them */ static void setup_syndaemon (gpointer user_data) { #ifdef __linux prctl (PR_SET_PDEATHSIG, SIGHUP); #endif } static gboolean have_program_in_path (const char *name) { gchar *path; gboolean result; path = g_find_program_in_path (name); result = (path != NULL); g_free (path); return result; } static void syndaemon_died (GPid pid, gint status, gpointer user_data) { GsdMouseManager *manager = GSD_MOUSE_MANAGER (user_data); g_debug ("syndaemon stopped with status %i", status); g_spawn_close_pid (pid); manager->priv->syndaemon_spawned = FALSE; } static int set_disable_w_typing (GsdMouseManager *manager, gboolean state) { if (state && touchpad_is_present ()) { GError *error = NULL; GPtrArray *args; if (manager->priv->syndaemon_spawned) return 0; if (!have_program_in_path ("syndaemon")) return 0; args = g_ptr_array_new (); g_ptr_array_add (args, "syndaemon"); g_ptr_array_add (args, "-i"); g_ptr_array_add (args, "1.0"); g_ptr_array_add (args, "-t"); g_ptr_array_add (args, "-K"); g_ptr_array_add (args, "-R"); g_ptr_array_add (args, NULL); /* we must use G_SPAWN_DO_NOT_REAP_CHILD to avoid * double-forking, otherwise syndaemon will immediately get * killed again through (PR_SET_PDEATHSIG when the intermediate * process dies */ g_spawn_async (g_get_home_dir (), (char **) args->pdata, NULL, G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD, setup_syndaemon, NULL, &manager->priv->syndaemon_pid, &error); manager->priv->syndaemon_spawned = (error == NULL); g_ptr_array_free (args, FALSE); if (error) { g_warning ("Failed to launch syndaemon: %s", error->message); g_error_free (error); } else { g_child_watch_add (manager->priv->syndaemon_pid, syndaemon_died, manager); g_debug ("Launched syndaemon"); } } else if (manager->priv->syndaemon_spawned) { kill (manager->priv->syndaemon_pid, SIGHUP); g_spawn_close_pid (manager->priv->syndaemon_pid); manager->priv->syndaemon_spawned = FALSE; g_debug ("Killed syndaemon"); } return 0; } static void set_tap_to_click (GdkDevice *device, gboolean state, gboolean left_handed) { int format, rc; unsigned long nitems, bytes_after; XDevice *xdevice; unsigned char* data; Atom prop, type; prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Tap Action", False); if (!prop) return; xdevice = open_gdk_device (device); if (xdevice == NULL) return; if (!device_is_touchpad (xdevice)) { xdevice_close (xdevice); return; } g_debug ("setting tap to click on %s", gdk_device_get_name (device)); gdk_error_trap_push (); rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, 0, 2, False, XA_INTEGER, &type, &format, &nitems, &bytes_after, &data); if (rc == Success && type == XA_INTEGER && format == 8 && nitems >= 7) { /* Set MR mapping for corner tapping on the right side*/ data[0] = (state) ? 2 : 0; data[1] = (state) ? 3 : 0; /* Set RLM mapping for 1/2/3 fingers*/ data[4] = (state) ? ((left_handed) ? 3 : 1) : 0; data[5] = (state) ? ((left_handed) ? 1 : 3) : 0; data[6] = 0; /* Disable three touch tap so gestures work */ XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, XA_INTEGER, 8, PropModeReplace, data, nitems); } if (rc == Success) XFree (data); if (gdk_error_trap_pop ()) g_warning ("Error in setting tap to click on \"%s\"", gdk_device_get_name (device)); xdevice_close (xdevice); } static void set_horiz_scroll (GdkDevice *device, gboolean state) { int rc; XDevice *xdevice; Atom act_type, prop_edge, prop_twofinger; int act_format; unsigned long nitems, bytes_after; unsigned char *data; prop_edge = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Edge Scrolling", False); prop_twofinger = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Two-Finger Scrolling", False); if (!prop_edge || !prop_twofinger) return; xdevice = open_gdk_device (device); if (xdevice == NULL) return; if (!device_is_touchpad (xdevice)) { xdevice_close (xdevice); return; } g_debug ("setting horiz scroll on %s", gdk_device_get_name (device)); gdk_error_trap_push (); rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop_edge, 0, 1, False, XA_INTEGER, &act_type, &act_format, &nitems, &bytes_after, &data); if (rc == Success && act_type == XA_INTEGER && act_format == 8 && nitems >= 2) { data[1] = (state && data[0]); XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop_edge, XA_INTEGER, 8, PropModeReplace, data, nitems); } XFree (data); rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop_twofinger, 0, 1, False, XA_INTEGER, &act_type, &act_format, &nitems, &bytes_after, &data); if (rc == Success && act_type == XA_INTEGER && act_format == 8 && nitems >= 2) { data[1] = (state && data[0]); XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop_twofinger, XA_INTEGER, 8, PropModeReplace, data, nitems); } if (gdk_error_trap_pop ()) g_warning ("Error in setting horiz scroll on \"%s\"", gdk_device_get_name (device)); if (rc == Success) XFree (data); xdevice_close (xdevice); } static void set_scroll_method (GsdMouseManager *manager, GdkDevice *device, GsdTouchpadScrollMethod method) { int rc; XDevice *xdevice; Atom act_type, prop, prop_edge, prop_twofinger; int act_format; unsigned long nitems, bytes_after; unsigned char *data; prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Capabilities", True); prop_edge = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Edge Scrolling", False); prop_twofinger = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Two-Finger Scrolling", False); if (!prop_edge || !prop_twofinger || !prop) return; xdevice = open_gdk_device (device); if (xdevice == NULL) return; if (!device_is_touchpad (xdevice)) { xdevice_close (xdevice); return; } g_debug ("setting edge scroll on %s", gdk_device_get_name (device)); gdk_error_trap_push (); rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, 0, 2, False, XA_INTEGER, &act_type, &act_format, &nitems, &bytes_after, &data); if (rc == Success && act_type != None) { if (!(data[3]) && method == GSD_TOUCHPAD_SCROLL_METHOD_TWO_FINGER_SCROLLING) { g_warning ("Two finger scroll is not supported by %s", gdk_device_get_name (device)); method = GSD_TOUCHPAD_SCROLL_METHOD_EDGE_SCROLLING; g_settings_set_enum (manager->priv->usd_touchpad_settings, KEY_SCROLL_METHOD, method); } XFree (data); } rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop_edge, 0, 1, False, XA_INTEGER, &act_type, &act_format, &nitems, &bytes_after, &data); if (rc == Success && act_type == XA_INTEGER && act_format == 8 && nitems >= 2) { data[0] = (method == GSD_TOUCHPAD_SCROLL_METHOD_EDGE_SCROLLING) ? 1 : 0; XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop_edge, XA_INTEGER, 8, PropModeReplace, data, nitems); } XFree (data); rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop_twofinger, 0, 1, False, XA_INTEGER, &act_type, &act_format, &nitems, &bytes_after, &data); if (rc == Success && act_type == XA_INTEGER && act_format == 8 && nitems >= 2) { data[0] = (method == GSD_TOUCHPAD_SCROLL_METHOD_TWO_FINGER_SCROLLING) ? 1 : 0; XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop_twofinger, XA_INTEGER, 8, PropModeReplace, data, nitems); } if (gdk_error_trap_pop ()) g_warning ("Error in setting edge scroll on \"%s\"", gdk_device_get_name (device)); if (rc == Success) XFree (data); xdevice_close (xdevice); } static void set_touchpad_disabled (GdkDevice *device) { int id; XDevice *xdevice; g_object_get (G_OBJECT (device), "device-id", &id, NULL); g_debug ("Trying to set device disabled for \"%s\" (%d)", gdk_device_get_name (device), id); xdevice = open_gdk_device (device); if (xdevice == NULL) return; if (!device_is_touchpad (xdevice)) { xdevice_close (xdevice); return; } if (set_device_enabled (id, FALSE) == FALSE) g_warning ("Error disabling device \"%s\" (%d)", gdk_device_get_name (device), id); else g_debug ("Disabled device \"%s\" (%d)", gdk_device_get_name (device), id); xdevice_close (xdevice); } static void set_touchpad_enabled (int id) { XDevice *xdevice; g_debug ("Trying to set device enabled for %d", id); gdk_error_trap_push (); xdevice = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), id); if (gdk_error_trap_pop () != 0) return; if (!device_is_touchpad (xdevice)) { xdevice_close (xdevice); return; } if (set_device_enabled (id, TRUE) == FALSE) g_warning ("Error enabling device \"%d\"", id); else g_debug ("Enabled device %d", id); xdevice_close (xdevice); } static void set_locate_pointer (GsdMouseManager *manager, gboolean state) { if (state) { GError *error = NULL; char *args[2]; if (manager->priv->locate_pointer_spawned) return; args[0] = LIBEXECDIR "/usd-locate-pointer"; args[1] = NULL; g_spawn_async (NULL, args, NULL, 0, NULL, NULL, &manager->priv->locate_pointer_pid, &error); manager->priv->locate_pointer_spawned = (error == NULL); if (error) { g_settings_set_boolean (manager->priv->interface_settings, KEY_LOCATE_POINTER, FALSE); g_error_free (error); } } else if (manager->priv->locate_pointer_spawned) { kill (manager->priv->locate_pointer_pid, SIGHUP); g_spawn_close_pid (manager->priv->locate_pointer_pid); manager->priv->locate_pointer_spawned = FALSE; } } static void set_mousetweaks_daemon (GsdMouseManager *manager, gboolean dwell_click_enabled, gboolean secondary_click_enabled) { GError *error = NULL; gchar *comm; gboolean run_daemon = dwell_click_enabled || secondary_click_enabled; if (run_daemon || manager->priv->mousetweaks_daemon_running) comm = g_strdup_printf ("mousetweaks %s", run_daemon ? "" : "-s"); else return; if (run_daemon) manager->priv->mousetweaks_daemon_running = TRUE; if (! g_spawn_command_line_async (comm, &error)) { if (error->code == G_SPAWN_ERROR_NOENT && run_daemon) { GtkWidget *dialog; if (dwell_click_enabled) { g_settings_set_boolean (manager->priv->mouse_a11y_settings, KEY_DWELL_CLICK_ENABLED, FALSE); } else if (secondary_click_enabled) { g_settings_set_boolean (manager->priv->mouse_a11y_settings, KEY_SECONDARY_CLICK_ENABLED, FALSE); } dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Could not enable mouse accessibility features")); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("Mouse accessibility requires Mousetweaks " "to be installed on your system.")); gtk_window_set_title (GTK_WINDOW (dialog), _("Universal Access")); gtk_window_set_icon_name (GTK_WINDOW (dialog), "preferences-desktop-accessibility"); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } g_error_free (error); } g_free (comm); } static gboolean get_touchpad_handedness (GsdMouseManager *manager, gboolean mouse_left_handed) { switch (g_settings_get_enum (manager->priv->touchpad_settings, KEY_LEFT_HANDED)) { case GSD_TOUCHPAD_HANDEDNESS_RIGHT: return FALSE; case GSD_TOUCHPAD_HANDEDNESS_LEFT: return TRUE; case GSD_TOUCHPAD_HANDEDNESS_MOUSE: return mouse_left_handed; default: g_assert_not_reached (); } } static gboolean get_touchpad_enabled (GsdMouseManager *manager) { GDesktopDeviceSendEvents send_events; send_events = g_settings_get_enum (manager->priv->touchpad_settings, KEY_SEND_EVENTS); if (send_events == G_DESKTOP_DEVICE_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE) { /* FIXME: mouse_is_present() also finds internal ones... */ return (!mouse_is_present () && !trackball_is_present ()); } return send_events == G_DESKTOP_DEVICE_SEND_EVENTS_ENABLED ? TRUE : FALSE; } static void set_mouse_settings (GsdMouseManager *manager, GdkDevice *device) { gboolean mouse_left_handed, touchpad_left_handed; mouse_left_handed = g_settings_get_boolean (manager->priv->mouse_settings, KEY_LEFT_HANDED); touchpad_left_handed = get_touchpad_handedness (manager, mouse_left_handed); set_left_handed (manager, device, mouse_left_handed, touchpad_left_handed); set_motion (manager, device); set_tap_to_click (device, g_settings_get_boolean (manager->priv->touchpad_settings, KEY_TAP_TO_CLICK), touchpad_left_handed); set_scroll_method (manager, device, g_settings_get_enum (manager->priv->usd_touchpad_settings, KEY_SCROLL_METHOD)); set_horiz_scroll (device, TRUE); set_natural_scroll (manager, device, g_settings_get_boolean (manager->priv->touchpad_settings, KEY_NATURAL_SCROLL_ENABLED)); if (!get_touchpad_enabled (manager)) set_touchpad_disabled (device); } static void set_natural_scroll (GsdMouseManager *manager, GdkDevice *device, gboolean natural_scroll) { XDevice *xdevice; Atom scrolling_distance, act_type; int rc, act_format; unsigned long nitems, bytes_after; unsigned char *data; glong *ptr; xdevice = open_gdk_device (device); if (xdevice == NULL) return; if (!device_is_touchpad (xdevice)) { xdevice_close (xdevice); return; } g_debug ("Trying to set %s for \"%s\"", natural_scroll ? "natural (reverse) scroll" : "normal scroll", gdk_device_get_name (device)); scrolling_distance = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Scrolling Distance", False); gdk_error_trap_push (); rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, scrolling_distance, 0, 2, False, XA_INTEGER, &act_type, &act_format, &nitems, &bytes_after, &data); if (rc == Success && act_type == XA_INTEGER && act_format == 32 && nitems >= 2) { ptr = (glong *) data; if (natural_scroll) { ptr[0] = -abs(ptr[0]); ptr[1] = -abs(ptr[1]); } else { ptr[0] = abs(ptr[0]); ptr[1] = abs(ptr[1]); } XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, scrolling_distance, XA_INTEGER, act_format, PropModeReplace, data, nitems); } if (gdk_error_trap_pop ()) g_warning ("Error setting %s for \"%s\"", natural_scroll ? "natural (reverse) scroll" : "normal scroll", gdk_device_get_name (device)); if (rc == Success) XFree (data); xdevice_close (xdevice); } static void mouse_callback (GSettings *settings, const gchar *key, GsdMouseManager *manager) { GList *devices, *l; if (g_str_equal (key, KEY_DWELL_CLICK_ENABLED) || g_str_equal (key, KEY_SECONDARY_CLICK_ENABLED)) { set_mousetweaks_daemon (manager, g_settings_get_boolean (settings, KEY_DWELL_CLICK_ENABLED), g_settings_get_boolean (settings, KEY_SECONDARY_CLICK_ENABLED)); return; } else if (g_str_equal (key, KEY_LOCATE_POINTER)) { set_locate_pointer (manager, g_settings_get_boolean (settings, KEY_LOCATE_POINTER)); return; } devices = gdk_device_manager_list_devices (manager->priv->device_manager, GDK_DEVICE_TYPE_SLAVE); for (l = devices; l != NULL; l = l->next) { GdkDevice *device = l->data; if (device_is_ignored (manager, device)) continue; if (g_str_equal (key, KEY_LEFT_HANDED)) { gboolean mouse_left_handed; mouse_left_handed = g_settings_get_boolean (settings, KEY_LEFT_HANDED); set_left_handed (manager, device, mouse_left_handed, get_touchpad_handedness (manager, mouse_left_handed)); } else if (g_str_equal (key, KEY_SPEED)) { set_motion (manager, device); } } g_list_free (devices); } static void touchpad_callback (GSettings *settings, const gchar *key, GsdMouseManager *manager) { GList *devices, *l; devices = gdk_device_manager_list_devices (manager->priv->device_manager, GDK_DEVICE_TYPE_SLAVE); for (l = devices; l != NULL; l = l->next) { GdkDevice *device = l->data; if (device_is_ignored (manager, device)) continue; if (g_str_equal (key, KEY_TAP_TO_CLICK)) { gboolean mouse_left_handed; mouse_left_handed = g_settings_get_boolean (manager->priv->mouse_settings, KEY_LEFT_HANDED); set_tap_to_click (device, g_settings_get_boolean (manager->priv->touchpad_settings, key), get_touchpad_handedness (manager, mouse_left_handed)); } else if (g_str_equal (key, KEY_SCROLL_METHOD)) { set_scroll_method (manager, device, g_settings_get_enum (manager->priv->usd_touchpad_settings, key)); set_horiz_scroll (device, TRUE); } else if (g_str_equal (key, KEY_SEND_EVENTS)) { if (!get_touchpad_enabled (manager)) set_touchpad_disabled (device); else set_touchpad_enabled (gdk_x11_device_get_id (device)); } else if (g_str_equal (key, KEY_SPEED)) { set_motion (manager, device); } else if (g_str_equal (key, KEY_LEFT_HANDED)) { gboolean mouse_left_handed; mouse_left_handed = g_settings_get_boolean (manager->priv->mouse_settings, KEY_LEFT_HANDED); set_left_handed (manager, device, mouse_left_handed, get_touchpad_handedness (manager, mouse_left_handed)); } else if (g_str_equal (key, KEY_NATURAL_SCROLL_ENABLED)) { set_natural_scroll (manager, device, g_settings_get_boolean (manager->priv->touchpad_settings, key)); } } g_list_free (devices); if (g_str_equal (key, KEY_SEND_EVENTS) && get_touchpad_enabled (manager)) { devices = get_disabled_devices (manager->priv->device_manager); for (l = devices; l != NULL; l = l->next) { int device_id; device_id = GPOINTER_TO_INT (l->data); set_touchpad_enabled (device_id); } g_list_free (devices); } } /* Re-enable touchpad when any other pointing device isn't present. */ static void ensure_touchpad_active (GsdMouseManager *manager) { GList *devices, *l; if (get_touchpad_enabled (manager)) { devices = get_disabled_devices (manager->priv->device_manager); for (l = devices; l != NULL; l = l->next) { int device_id; device_id = GPOINTER_TO_INT (l->data); set_touchpad_enabled (device_id); } g_list_free (devices); } else { devices = gdk_device_manager_list_devices (manager->priv->device_manager, GDK_DEVICE_TYPE_SLAVE); for (l = devices; l != NULL; l = l->next) { GdkDevice *device = l->data; if (device_is_ignored (manager, device)) continue; if (gdk_device_get_source (device) != GDK_SOURCE_TOUCHPAD) continue; set_touchpad_disabled (device); } g_list_free (devices); } } static void device_added_cb (GdkDeviceManager *device_manager, GdkDevice *device, GsdMouseManager *manager) { if (device_is_ignored (manager, device) == FALSE) { if (run_custom_command (device, COMMAND_DEVICE_ADDED) == FALSE) { set_mouse_settings (manager, device); } else { int id; g_object_get (G_OBJECT (device), "device-id", &id, NULL); g_hash_table_insert (manager->priv->blacklist, GINT_TO_POINTER (id), GINT_TO_POINTER (1)); } /* If a touchpad was to appear... */ set_disable_w_typing (manager, TRUE); /* If a mouse was to appear... */ ensure_touchpad_active (manager); } } static void device_removed_cb (GdkDeviceManager *device_manager, GdkDevice *device, GsdMouseManager *manager) { int id; /* Remove the device from the hash table so that * device_is_ignored () doesn't check for blacklisted devices */ g_object_get (G_OBJECT (device), "device-id", &id, NULL); g_hash_table_remove (manager->priv->blacklist, GINT_TO_POINTER (id)); if (device_is_ignored (manager, device) == FALSE) { run_custom_command (device, COMMAND_DEVICE_REMOVED); /* If a touchpad was to disappear... */ set_disable_w_typing (manager, TRUE); if (gdk_device_get_source (device) != GDK_SOURCE_TOUCHPAD) ensure_touchpad_active (manager); } } static void set_devicepresence_handler (GsdMouseManager *manager) { GdkDeviceManager *device_manager; device_manager = gdk_display_get_device_manager (gdk_display_get_default ()); manager->priv->device_added_id = g_signal_connect (G_OBJECT (device_manager), "device-added", G_CALLBACK (device_added_cb), manager); manager->priv->device_removed_id = g_signal_connect (G_OBJECT (device_manager), "device-removed", G_CALLBACK (device_removed_cb), manager); manager->priv->device_manager = device_manager; } static void gsd_mouse_manager_init (GsdMouseManager *manager) { manager->priv = GSD_MOUSE_MANAGER_GET_PRIVATE (manager); manager->priv->blacklist = g_hash_table_new (g_direct_hash, g_direct_equal); } static gboolean gsd_mouse_manager_idle_cb (GsdMouseManager *manager) { GList *devices, *l; gnome_settings_profile_start (NULL); set_devicepresence_handler (manager); manager->priv->interface_settings = g_settings_new (GNOME_DESKTOP_INTERFACE_DIR); g_signal_connect (manager->priv->interface_settings, "changed", G_CALLBACK (mouse_callback), manager); manager->priv->mouse_a11y_settings = g_settings_new ("org.gnome.desktop.a11y.mouse"); g_signal_connect (manager->priv->mouse_a11y_settings, "changed", G_CALLBACK (mouse_callback), manager); manager->priv->mouse_settings = g_settings_new (GSETTINGS_MOUSE_SCHEMA); g_signal_connect (manager->priv->mouse_settings, "changed", G_CALLBACK (mouse_callback), manager); manager->priv->touchpad_settings = g_settings_new (GSETTINGS_TOUCHPAD_SCHEMA); g_signal_connect (manager->priv->touchpad_settings, "changed", G_CALLBACK (touchpad_callback), manager); manager->priv->usd_touchpad_settings = g_settings_new (USD_TOUCHPAD_SCHEMA); g_signal_connect (manager->priv->usd_touchpad_settings, "changed", G_CALLBACK (touchpad_callback), manager); manager->priv->syndaemon_spawned = FALSE; set_locate_pointer (manager, g_settings_get_boolean (manager->priv->interface_settings, KEY_LOCATE_POINTER)); set_mousetweaks_daemon (manager, g_settings_get_boolean (manager->priv->mouse_a11y_settings, KEY_DWELL_CLICK_ENABLED), g_settings_get_boolean (manager->priv->mouse_a11y_settings, KEY_SECONDARY_CLICK_ENABLED)); set_disable_w_typing (manager, TRUE); devices = gdk_device_manager_list_devices (manager->priv->device_manager, GDK_DEVICE_TYPE_SLAVE); for (l = devices; l != NULL; l = l->next) { GdkDevice *device = l->data; if (device_is_ignored (manager, device)) continue; if (run_custom_command (device, COMMAND_DEVICE_PRESENT) == FALSE) { set_mouse_settings (manager, device); } else { int id; g_object_get (G_OBJECT (device), "device-id", &id, NULL); g_hash_table_insert (manager->priv->blacklist, GINT_TO_POINTER (id), GINT_TO_POINTER (1)); } } g_list_free (devices); ensure_touchpad_active (manager); if (get_touchpad_enabled (manager)) { devices = get_disabled_devices (manager->priv->device_manager); for (l = devices; l != NULL; l = l->next) { int device_id; device_id = GPOINTER_TO_INT (l->data); set_touchpad_enabled (device_id); } g_list_free (devices); } gnome_settings_profile_end (NULL); manager->priv->start_idle_id = 0; return FALSE; } gboolean gsd_mouse_manager_start (GsdMouseManager *manager, GError **error) { gnome_settings_profile_start (NULL); if (!supports_xinput_devices ()) { g_debug ("XInput is not supported, not applying any settings"); return TRUE; } manager->priv->start_idle_id = g_idle_add ((GSourceFunc) gsd_mouse_manager_idle_cb, manager); gnome_settings_profile_end (NULL); return TRUE; } void gsd_mouse_manager_stop (GsdMouseManager *manager) { GsdMouseManagerPrivate *p = manager->priv; g_debug ("Stopping mouse manager"); if (manager->priv->start_idle_id != 0) { g_source_remove (manager->priv->start_idle_id); manager->priv->start_idle_id = 0; } if (p->device_manager != NULL) { g_signal_handler_disconnect (p->device_manager, p->device_added_id); g_signal_handler_disconnect (p->device_manager, p->device_removed_id); p->device_manager = NULL; } g_clear_object (&p->mouse_a11y_settings); g_clear_object (&p->mouse_settings); g_clear_object (&p->touchpad_settings); g_clear_object (&p->usd_touchpad_settings); set_locate_pointer (manager, FALSE); g_clear_object (&p->interface_settings); } static void gsd_mouse_manager_finalize (GObject *object) { GsdMouseManager *mouse_manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_MOUSE_MANAGER (object)); mouse_manager = GSD_MOUSE_MANAGER (object); g_return_if_fail (mouse_manager->priv != NULL); gsd_mouse_manager_stop (mouse_manager); if (mouse_manager->priv->blacklist != NULL) g_hash_table_destroy (mouse_manager->priv->blacklist); G_OBJECT_CLASS (gsd_mouse_manager_parent_class)->finalize (object); } static GVariant * map_speed (GVariant *variant) { gdouble value; value = g_variant_get_double (variant); /* Remap from [0..10] to [-1..1] */ value = (value / 5) - 1; return g_variant_new_double (value); } static GVariant * map_send_events (GVariant *variant) { gboolean enabled; enabled = g_variant_get_boolean (variant); if (enabled) { return g_variant_new_string ("enabled"); } else { return g_variant_new_string ("disabled"); } } static void migrate_mouse_settings (void) { GsdSettingsMigrateEntry trackball_entries[] = { { "scroll-wheel-emulation-button", "scroll-wheel-emulation-button", NULL } }; GsdSettingsMigrateEntry mouse_entries[] = { { "left-handed", "left-handed", NULL }, { "motion-acceleration", "speed", map_speed }, { "motion-threshold", NULL, NULL }, { "middle-button-enabled", NULL, NULL }, }; GsdSettingsMigrateEntry touchpad_entries[] = { { "disable-while-typing", NULL, NULL }, { "horiz-scroll-enabled", NULL, NULL }, { "tap-to-click", "tap-to-click", NULL }, { "touchpad-enabled", "send-events", map_send_events }, { "left-handed", "left-handed", NULL }, { "motion-acceleration", "speed", map_speed }, { "motion-threshold", NULL, NULL }, { "natural-scroll", "natural-scroll", NULL } }; gsd_settings_migrate_check ("com.canonical.unity.settings-daemon.peripherals.trackball.deprecated", "/com/canonical/unity/settings-daemon/peripherals/trackball/", "org.gnome.desktop.peripherals.trackball", "/org/gnome/desktop/peripherals/trackball/", trackball_entries, G_N_ELEMENTS (trackball_entries)); gsd_settings_migrate_check ("com.canonical.unity.settings-daemon.peripherals.mouse.deprecated", "/com/canonical/unity/settings-daemon/peripherals/mouse/", "org.gnome.desktop.peripherals.mouse", "/org/gnome/desktop/peripherals/mouse/", mouse_entries, G_N_ELEMENTS (mouse_entries)); gsd_settings_migrate_check ("com.canonical.unity.settings-daemon.peripherals.touchpad.deprecated", "/com/canonical/unity/settings-daemon/peripherals/touchpad/", "org.gnome.desktop.peripherals.touchpad", "/org/gnome/desktop/peripherals/touchpad/", touchpad_entries, G_N_ELEMENTS (touchpad_entries)); } GsdMouseManager * gsd_mouse_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { migrate_mouse_settings (); manager_object = g_object_new (GSD_TYPE_MOUSE_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_MOUSE_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/mouse/gsd-mouse-manager.h0000664000175000017500000000437000000000000025337 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_MOUSE_MANAGER_H #define __GSD_MOUSE_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_MOUSE_MANAGER (gsd_mouse_manager_get_type ()) #define GSD_MOUSE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_MOUSE_MANAGER, GsdMouseManager)) #define GSD_MOUSE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_MOUSE_MANAGER, GsdMouseManagerClass)) #define GSD_IS_MOUSE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_MOUSE_MANAGER)) #define GSD_IS_MOUSE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_MOUSE_MANAGER)) #define GSD_MOUSE_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_MOUSE_MANAGER, GsdMouseManagerClass)) typedef struct GsdMouseManagerPrivate GsdMouseManagerPrivate; typedef struct { GObject parent; GsdMouseManagerPrivate *priv; } GsdMouseManager; typedef struct { GObjectClass parent_class; } GsdMouseManagerClass; GType gsd_mouse_manager_get_type (void); GsdMouseManager * gsd_mouse_manager_new (void); gboolean gsd_mouse_manager_start (GsdMouseManager *manager, GError **error); void gsd_mouse_manager_stop (GsdMouseManager *manager); G_END_DECLS #endif /* __GSD_MOUSE_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/mouse/gsd-mouse-plugin.c0000664000175000017500000000201500000000000025210 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-mouse-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdMouse, gsd_mouse) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/mouse/gsd-timeline.c0000664000175000017500000004730200000000000024402 0ustar00jeremyjeremy/* gsd-timeline.c * * Copyright (C) 2008 Carlos Garnacho * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include "gsd-timeline.h" #define GSD_TIMELINE_GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSD_TYPE_TIMELINE, GsdTimelinePriv)) #define MSECS_PER_SEC 1000 #define FRAME_INTERVAL(nframes) (MSECS_PER_SEC / nframes) #define DEFAULT_FPS 30 typedef struct GsdTimelinePriv GsdTimelinePriv; struct GsdTimelinePriv { guint duration; guint fps; guint source_id; GTimer *timer; GdkScreen *screen; GsdTimelineProgressType progress_type; GsdTimelineProgressFunc progress_func; guint loop : 1; guint direction : 1; }; enum { PROP_0, PROP_FPS, PROP_DURATION, PROP_LOOP, PROP_DIRECTION, PROP_SCREEN, PROP_PROGRESS_TYPE, }; enum { STARTED, PAUSED, FINISHED, FRAME, LAST_SIGNAL }; static guint signals [LAST_SIGNAL] = { 0, }; static void gsd_timeline_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); static void gsd_timeline_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); static void gsd_timeline_finalize (GObject *object); G_DEFINE_TYPE (GsdTimeline, gsd_timeline, G_TYPE_OBJECT) GType gsd_timeline_direction_get_type (void) { static GType type = 0; if (G_UNLIKELY (type == 0)) { static const GEnumValue values[] = { { GSD_TIMELINE_DIRECTION_FORWARD, "GSD_TIMELINE_DIRECTION_FORWARD", "forward" }, { GSD_TIMELINE_DIRECTION_BACKWARD, "GSD_TIMELINE_DIRECTION_BACKWARD", "backward" }, { 0, NULL, NULL } }; type = g_enum_register_static (g_intern_static_string ("GsdTimelineDirection"), values); } return type; } GType gsd_timeline_progress_type_get_type (void) { static GType type = 0; if (G_UNLIKELY (type == 0)) { static const GEnumValue values[] = { { GSD_TIMELINE_PROGRESS_LINEAR, "GSD_TIMELINE_PROGRESS_LINEAR", "linear" }, { GSD_TIMELINE_PROGRESS_SINUSOIDAL, "GSD_TIMELINE_PROGRESS_SINUSOIDAL", "sinusoidal" }, { GSD_TIMELINE_PROGRESS_EXPONENTIAL, "GSD_TIMELINE_PROGRESS_EXPONENTIAL", "exponential" }, { 0, NULL, NULL } }; type = g_enum_register_static (g_intern_static_string ("GsdTimelineProgressType"), values); } return type; } static void gsd_timeline_class_init (GsdTimelineClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); object_class->set_property = gsd_timeline_set_property; object_class->get_property = gsd_timeline_get_property; object_class->finalize = gsd_timeline_finalize; g_object_class_install_property (object_class, PROP_FPS, g_param_spec_uint ("fps", "FPS", "Frames per second for the timeline", 1, G_MAXUINT, DEFAULT_FPS, G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_DURATION, g_param_spec_uint ("duration", "Animation Duration", "Animation Duration", 0, G_MAXUINT, 0, G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_LOOP, g_param_spec_boolean ("loop", "Loop", "Whether the timeline loops or not", FALSE, G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_DIRECTION, g_param_spec_enum ("direction", "Direction", "Whether the timeline moves forward or backward in time", GSD_TYPE_TIMELINE_DIRECTION, GSD_TIMELINE_DIRECTION_FORWARD, G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_DIRECTION, g_param_spec_enum ("progress-type", "Progress type", "Type of progress through the timeline", GSD_TYPE_TIMELINE_PROGRESS_TYPE, GSD_TIMELINE_PROGRESS_LINEAR, G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_SCREEN, g_param_spec_object ("screen", "Screen", "Screen to get the settings from", GDK_TYPE_SCREEN, G_PARAM_READWRITE)); signals[STARTED] = g_signal_new ("started", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GsdTimelineClass, started), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); signals[PAUSED] = g_signal_new ("paused", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GsdTimelineClass, paused), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); signals[FINISHED] = g_signal_new ("finished", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GsdTimelineClass, finished), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); signals[FRAME] = g_signal_new ("frame", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GsdTimelineClass, frame), NULL, NULL, g_cclosure_marshal_VOID__DOUBLE, G_TYPE_NONE, 1, G_TYPE_DOUBLE); g_type_class_add_private (class, sizeof (GsdTimelinePriv)); } static void gsd_timeline_init (GsdTimeline *timeline) { GsdTimelinePriv *priv; priv = GSD_TIMELINE_GET_PRIV (timeline); priv->fps = DEFAULT_FPS; priv->duration = 0; priv->direction = GSD_TIMELINE_DIRECTION_FORWARD; priv->screen = gdk_screen_get_default (); } static void gsd_timeline_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GsdTimeline *timeline; timeline = GSD_TIMELINE (object); switch (prop_id) { case PROP_FPS: gsd_timeline_set_fps (timeline, g_value_get_uint (value)); break; case PROP_DURATION: gsd_timeline_set_duration (timeline, g_value_get_uint (value)); break; case PROP_LOOP: gsd_timeline_set_loop (timeline, g_value_get_boolean (value)); break; case PROP_DIRECTION: gsd_timeline_set_direction (timeline, g_value_get_enum (value)); break; case PROP_SCREEN: gsd_timeline_set_screen (timeline, GDK_SCREEN (g_value_get_object (value))); break; case PROP_PROGRESS_TYPE: gsd_timeline_set_progress_type (timeline, g_value_get_enum (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void gsd_timeline_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GsdTimeline *timeline; GsdTimelinePriv *priv; timeline = GSD_TIMELINE (object); priv = GSD_TIMELINE_GET_PRIV (timeline); switch (prop_id) { case PROP_FPS: g_value_set_uint (value, priv->fps); break; case PROP_DURATION: g_value_set_uint (value, priv->duration); break; case PROP_LOOP: g_value_set_boolean (value, priv->loop); break; case PROP_DIRECTION: g_value_set_enum (value, priv->direction); break; case PROP_SCREEN: g_value_set_object (value, priv->screen); break; case PROP_PROGRESS_TYPE: g_value_set_enum (value, priv->progress_type); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void gsd_timeline_finalize (GObject *object) { GsdTimelinePriv *priv; priv = GSD_TIMELINE_GET_PRIV (object); if (priv->source_id) { g_source_remove (priv->source_id); priv->source_id = 0; } if (priv->timer) g_timer_destroy (priv->timer); G_OBJECT_CLASS (gsd_timeline_parent_class)->finalize (object); } /* Sinusoidal progress */ static gdouble sinusoidal_progress (gdouble progress) { return (sinf ((progress * G_PI) / 2)); } static gdouble exponential_progress (gdouble progress) { return progress * progress; } static GsdTimelineProgressFunc progress_type_to_func (GsdTimelineProgressType type) { if (type == GSD_TIMELINE_PROGRESS_SINUSOIDAL) return sinusoidal_progress; else if (type == GSD_TIMELINE_PROGRESS_EXPONENTIAL) return exponential_progress; return NULL; } static gboolean gsd_timeline_run_frame (GsdTimeline *timeline, gboolean enable_animations) { GsdTimelinePriv *priv; gdouble linear_progress, progress; guint elapsed_time; GsdTimelineProgressFunc progress_func = NULL; priv = GSD_TIMELINE_GET_PRIV (timeline); if (enable_animations) { elapsed_time = (guint) (g_timer_elapsed (priv->timer, NULL) * 1000); linear_progress = (gdouble) elapsed_time / priv->duration; if (priv->direction == GSD_TIMELINE_DIRECTION_BACKWARD) linear_progress = 1 - linear_progress; linear_progress = CLAMP (linear_progress, 0., 1.); if (priv->progress_func) progress_func = priv->progress_func; else if (priv->progress_type) progress_func = progress_type_to_func (priv->progress_type); if (progress_func) progress = (progress_func) (linear_progress); else progress = linear_progress; } else progress = (priv->direction == GSD_TIMELINE_DIRECTION_FORWARD) ? 1.0 : 0.0; g_signal_emit (timeline, signals [FRAME], 0, CLAMP (progress, 0.0, 1.0)); if ((priv->direction == GSD_TIMELINE_DIRECTION_FORWARD && progress >= 1.0) || (priv->direction == GSD_TIMELINE_DIRECTION_BACKWARD && progress <= 0.0)) { if (!priv->loop) { if (priv->source_id) { g_source_remove (priv->source_id); priv->source_id = 0; } g_signal_emit (timeline, signals [FINISHED], 0); return FALSE; } else gsd_timeline_rewind (timeline); } return TRUE; } static gboolean gsd_timeline_frame_idle_func (GsdTimeline *timeline) { return gsd_timeline_run_frame (timeline, TRUE); } /** * gsd_timeline_new: * @duration: duration in milliseconds for the timeline * * Creates a new #GsdTimeline with the specified number of frames. * * Return Value: the newly created #GsdTimeline **/ GsdTimeline * gsd_timeline_new (guint duration) { return g_object_new (GSD_TYPE_TIMELINE, "duration", duration, NULL); } GsdTimeline * gsd_timeline_new_for_screen (guint duration, GdkScreen *screen) { return g_object_new (GSD_TYPE_TIMELINE, "duration", duration, "screen", screen, NULL); } /** * gsd_timeline_start: * @timeline: A #GsdTimeline * * Runs the timeline from the current frame. **/ void gsd_timeline_start (GsdTimeline *timeline) { GsdTimelinePriv *priv; GtkSettings *settings; gboolean enable_animations = FALSE; g_return_if_fail (GSD_IS_TIMELINE (timeline)); priv = GSD_TIMELINE_GET_PRIV (timeline); if (priv->screen) { settings = gtk_settings_get_for_screen (priv->screen); g_object_get (settings, "gtk-enable-animations", &enable_animations, NULL); } if (enable_animations) { if (!priv->source_id) { if (priv->timer) g_timer_continue (priv->timer); else priv->timer = g_timer_new (); /* sanity check */ g_assert (priv->fps > 0); g_signal_emit (timeline, signals [STARTED], 0); priv->source_id = gdk_threads_add_timeout (FRAME_INTERVAL (priv->fps), (GSourceFunc) gsd_timeline_frame_idle_func, timeline); } } else { /* If animations are not enabled, only run the last frame, * it take us instantaneously to the last state of the animation. * The only potential flaw happens when people use the ::finished * signal to trigger another animation, or even worse, finally * loop into this animation again. */ g_signal_emit (timeline, signals [STARTED], 0); gsd_timeline_run_frame (timeline, FALSE); } } /** * gsd_timeline_pause: * @timeline: A #GsdTimeline * * Pauses the timeline. **/ void gsd_timeline_pause (GsdTimeline *timeline) { GsdTimelinePriv *priv; g_return_if_fail (GSD_IS_TIMELINE (timeline)); priv = GSD_TIMELINE_GET_PRIV (timeline); if (priv->source_id) { g_source_remove (priv->source_id); priv->source_id = 0; g_timer_stop (priv->timer); g_signal_emit (timeline, signals [PAUSED], 0); } } /** * gsd_timeline_rewind: * @timeline: A #GsdTimeline * * Rewinds the timeline. **/ void gsd_timeline_rewind (GsdTimeline *timeline) { GsdTimelinePriv *priv; g_return_if_fail (GSD_IS_TIMELINE (timeline)); priv = GSD_TIMELINE_GET_PRIV (timeline); /* destroy and re-create timer if neccesary */ if (priv->timer) { g_timer_destroy (priv->timer); if (gsd_timeline_is_running (timeline)) priv->timer = g_timer_new (); else priv->timer = NULL; } } /** * gsd_timeline_is_running: * @timeline: A #GsdTimeline * * Returns whether the timeline is running or not. * * Return Value: %TRUE if the timeline is running **/ gboolean gsd_timeline_is_running (GsdTimeline *timeline) { GsdTimelinePriv *priv; g_return_val_if_fail (GSD_IS_TIMELINE (timeline), FALSE); priv = GSD_TIMELINE_GET_PRIV (timeline); return (priv->source_id != 0); } /** * gsd_timeline_get_fps: * @timeline: A #GsdTimeline * * Returns the number of frames per second. * * Return Value: frames per second **/ guint gsd_timeline_get_fps (GsdTimeline *timeline) { GsdTimelinePriv *priv; g_return_val_if_fail (GSD_IS_TIMELINE (timeline), 1); priv = GSD_TIMELINE_GET_PRIV (timeline); return priv->fps; } /** * gsd_timeline_set_fps: * @timeline: A #GsdTimeline * @fps: frames per second * * Sets the number of frames per second that * the timeline will play. **/ void gsd_timeline_set_fps (GsdTimeline *timeline, guint fps) { GsdTimelinePriv *priv; g_return_if_fail (GSD_IS_TIMELINE (timeline)); g_return_if_fail (fps > 0); priv = GSD_TIMELINE_GET_PRIV (timeline); priv->fps = fps; if (gsd_timeline_is_running (timeline)) { g_source_remove (priv->source_id); priv->source_id = gdk_threads_add_timeout (FRAME_INTERVAL (priv->fps), (GSourceFunc) gsd_timeline_run_frame, timeline); } g_object_notify (G_OBJECT (timeline), "fps"); } /** * gsd_timeline_get_loop: * @timeline: A #GsdTimeline * * Returns whether the timeline loops to the * beginning when it has reached the end. * * Return Value: %TRUE if the timeline loops **/ gboolean gsd_timeline_get_loop (GsdTimeline *timeline) { GsdTimelinePriv *priv; g_return_val_if_fail (GSD_IS_TIMELINE (timeline), FALSE); priv = GSD_TIMELINE_GET_PRIV (timeline); return priv->loop; } /** * gsd_timeline_set_loop: * @timeline: A #GsdTimeline * @loop: %TRUE to make the timeline loop * * Sets whether the timeline loops to the beginning * when it has reached the end. **/ void gsd_timeline_set_loop (GsdTimeline *timeline, gboolean loop) { GsdTimelinePriv *priv; g_return_if_fail (GSD_IS_TIMELINE (timeline)); priv = GSD_TIMELINE_GET_PRIV (timeline); priv->loop = loop; g_object_notify (G_OBJECT (timeline), "loop"); } void gsd_timeline_set_duration (GsdTimeline *timeline, guint duration) { GsdTimelinePriv *priv; g_return_if_fail (GSD_IS_TIMELINE (timeline)); priv = GSD_TIMELINE_GET_PRIV (timeline); priv->duration = duration; g_object_notify (G_OBJECT (timeline), "duration"); } guint gsd_timeline_get_duration (GsdTimeline *timeline) { GsdTimelinePriv *priv; g_return_val_if_fail (GSD_IS_TIMELINE (timeline), 0); priv = GSD_TIMELINE_GET_PRIV (timeline); return priv->duration; } /** * gsd_timeline_get_direction: * @timeline: A #GsdTimeline * * Returns the direction of the timeline. * * Return Value: direction **/ GsdTimelineDirection gsd_timeline_get_direction (GsdTimeline *timeline) { GsdTimelinePriv *priv; g_return_val_if_fail (GSD_IS_TIMELINE (timeline), GSD_TIMELINE_DIRECTION_FORWARD); priv = GSD_TIMELINE_GET_PRIV (timeline); return priv->direction; } /** * gsd_timeline_set_direction: * @timeline: A #GsdTimeline * @direction: direction * * Sets the direction of the timeline. **/ void gsd_timeline_set_direction (GsdTimeline *timeline, GsdTimelineDirection direction) { GsdTimelinePriv *priv; g_return_if_fail (GSD_IS_TIMELINE (timeline)); priv = GSD_TIMELINE_GET_PRIV (timeline); priv->direction = direction; g_object_notify (G_OBJECT (timeline), "direction"); } GdkScreen * gsd_timeline_get_screen (GsdTimeline *timeline) { GsdTimelinePriv *priv; g_return_val_if_fail (GSD_IS_TIMELINE (timeline), NULL); priv = GSD_TIMELINE_GET_PRIV (timeline); return priv->screen; } void gsd_timeline_set_screen (GsdTimeline *timeline, GdkScreen *screen) { GsdTimelinePriv *priv; g_return_if_fail (GSD_IS_TIMELINE (timeline)); g_return_if_fail (GDK_IS_SCREEN (screen)); priv = GSD_TIMELINE_GET_PRIV (timeline); if (priv->screen) g_object_unref (priv->screen); priv->screen = g_object_ref (screen); g_object_notify (G_OBJECT (timeline), "screen"); } void gsd_timeline_set_progress_type (GsdTimeline *timeline, GsdTimelineProgressType type) { GsdTimelinePriv *priv; g_return_if_fail (GSD_IS_TIMELINE (timeline)); priv = GSD_TIMELINE_GET_PRIV (timeline); priv->progress_type = type; g_object_notify (G_OBJECT (timeline), "progress-type"); } GsdTimelineProgressType gsd_timeline_get_progress_type (GsdTimeline *timeline) { GsdTimelinePriv *priv; g_return_val_if_fail (GSD_IS_TIMELINE (timeline), GSD_TIMELINE_PROGRESS_LINEAR); priv = GSD_TIMELINE_GET_PRIV (timeline); if (priv->progress_func) return GSD_TIMELINE_PROGRESS_LINEAR; return priv->progress_type; } /** * gsd_timeline_set_progress_func: * @timeline: A #GsdTimeline * @progress_func: progress function * * Sets the progress function. This function will be used to calculate * a different progress to pass to the ::frame signal based on the * linear progress through the timeline. Setting progress_func * to %NULL will make the timeline use the default function, * which is just a linear progress. * * All progresses are in the [0.0, 1.0] range. **/ void gsd_timeline_set_progress_func (GsdTimeline *timeline, GsdTimelineProgressFunc progress_func) { GsdTimelinePriv *priv; g_return_if_fail (GSD_IS_TIMELINE (timeline)); priv = GSD_TIMELINE_GET_PRIV (timeline); priv->progress_func = progress_func; } gdouble gsd_timeline_get_progress (GsdTimeline *timeline) { GsdTimelinePriv *priv; GsdTimelineProgressFunc progress_func = NULL; gdouble linear_progress, progress; guint elapsed_time; g_return_val_if_fail (GSD_IS_TIMELINE (timeline), 0.0); priv = GSD_TIMELINE_GET_PRIV (timeline); if (!priv->timer) return 0.; elapsed_time = (guint) (g_timer_elapsed (priv->timer, NULL) * 1000); linear_progress = (gdouble) elapsed_time / priv->duration; if (priv->direction == GSD_TIMELINE_DIRECTION_BACKWARD) linear_progress = 1 - linear_progress; linear_progress = CLAMP (linear_progress, 0., 1.); if (priv->progress_func) progress_func = priv->progress_func; else if (priv->progress_type) progress_func = progress_type_to_func (priv->progress_type); if (progress_func) progress = (progress_func) (linear_progress); else progress = linear_progress; return CLAMP (progress, 0., 1.); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/mouse/gsd-timeline.h0000664000175000017500000001210200000000000024375 0ustar00jeremyjeremy/* gsdtimeline.c * * Copyright (C) 2008 Carlos Garnacho * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __GSD_TIMELINE_H__ #define __GSD_TIMELINE_H__ #include #include G_BEGIN_DECLS #define GSD_TYPE_TIMELINE_DIRECTION (gsd_timeline_direction_get_type ()) #define GSD_TYPE_TIMELINE_PROGRESS_TYPE (gsd_timeline_progress_type_get_type ()) #define GSD_TYPE_TIMELINE (gsd_timeline_get_type ()) #define GSD_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_TIMELINE, GsdTimeline)) #define GSD_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_TIMELINE, GsdTimelineClass)) #define GSD_IS_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_TIMELINE)) #define GSD_IS_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_TIMELINE)) #define GSD_TIMELINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_TIMELINE, GsdTimelineClass)) typedef enum { GSD_TIMELINE_DIRECTION_FORWARD, GSD_TIMELINE_DIRECTION_BACKWARD } GsdTimelineDirection; typedef enum { GSD_TIMELINE_PROGRESS_LINEAR, GSD_TIMELINE_PROGRESS_SINUSOIDAL, GSD_TIMELINE_PROGRESS_EXPONENTIAL } GsdTimelineProgressType; typedef struct GsdTimeline GsdTimeline; typedef struct GsdTimelineClass GsdTimelineClass; struct GsdTimeline { GObject parent_instance; }; struct GsdTimelineClass { GObjectClass parent_class; void (* started) (GsdTimeline *timeline); void (* finished) (GsdTimeline *timeline); void (* paused) (GsdTimeline *timeline); void (* frame) (GsdTimeline *timeline, gdouble progress); void (* __gsd_reserved1) (void); void (* __gsd_reserved2) (void); void (* __gsd_reserved3) (void); void (* __gsd_reserved4) (void); }; typedef gdouble (*GsdTimelineProgressFunc) (gdouble progress); GType gsd_timeline_get_type (void) G_GNUC_CONST; GType gsd_timeline_direction_get_type (void) G_GNUC_CONST; GType gsd_timeline_progress_type_get_type (void) G_GNUC_CONST; GsdTimeline *gsd_timeline_new (guint duration); GsdTimeline *gsd_timeline_new_for_screen (guint duration, GdkScreen *screen); void gsd_timeline_start (GsdTimeline *timeline); void gsd_timeline_pause (GsdTimeline *timeline); void gsd_timeline_rewind (GsdTimeline *timeline); gboolean gsd_timeline_is_running (GsdTimeline *timeline); guint gsd_timeline_get_fps (GsdTimeline *timeline); void gsd_timeline_set_fps (GsdTimeline *timeline, guint fps); gboolean gsd_timeline_get_loop (GsdTimeline *timeline); void gsd_timeline_set_loop (GsdTimeline *timeline, gboolean loop); guint gsd_timeline_get_duration (GsdTimeline *timeline); void gsd_timeline_set_duration (GsdTimeline *timeline, guint duration); GdkScreen *gsd_timeline_get_screen (GsdTimeline *timeline); void gsd_timeline_set_screen (GsdTimeline *timeline, GdkScreen *screen); GsdTimelineDirection gsd_timeline_get_direction (GsdTimeline *timeline); void gsd_timeline_set_direction (GsdTimeline *timeline, GsdTimelineDirection direction); GsdTimelineProgressType gsd_timeline_get_progress_type (GsdTimeline *timeline); void gsd_timeline_set_progress_type (GsdTimeline *timeline, GsdTimelineProgressType type); void gsd_timeline_get_progress_func (GsdTimeline *timeline); void gsd_timeline_set_progress_func (GsdTimeline *timeline, GsdTimelineProgressFunc progress_func); gdouble gsd_timeline_get_progress (GsdTimeline *timeline); G_END_DECLS #endif /* __GSD_TIMELINE_H__ */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/mouse/mouse.gnome-settings-plugin.in0000664000175000017500000000021400000000000027562 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=mouse IAge=0 Priority=7 _Name=Mouse _Description=Mouse plugin Authors= Copyright=Copyright © 2007 Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/mouse/test-mouse.c0000664000175000017500000000030500000000000024116 0ustar00jeremyjeremy#define NEW gsd_mouse_manager_new #define START gsd_mouse_manager_start #define STOP gsd_mouse_manager_stop #define MANAGER GsdMouseManager #include "gsd-mouse-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1644246191.587767 unity-settings-daemon-15.04.1+21.10.20220207/plugins/orientation/0000775000175000017500000000000000000000000023052 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/orientation/Makefile.am0000664000175000017500000000320300000000000025104 0ustar00jeremyjeremyplugin_name = orientation libexec_PROGRAMS = usd-test-orientation usd_test_orientation_SOURCES = \ gsd-orientation-manager.h \ gsd-orientation-manager.c \ test-orientation.c usd_test_orientation_CFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(ORIENTATION_CFLAGS) \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) usd_test_orientation_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(ORIENTATION_LIBS) \ $(SETTINGS_PLUGIN_LIBS) plugin_LTLIBRARIES = liborientation.la liborientation_la_SOURCES = \ gsd-orientation-plugin.c \ gsd-orientation-manager.h \ gsd-orientation-manager.c liborientation_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common/ \ -I$(top_srcdir)/data/ \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ $(AM_CPPFLAGS) liborientation_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(ORIENTATION_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) liborientation_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) liborientation_la_LIBADD = \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(ORIENTATION_LIBS) \ $(SETTINGS_PLUGIN_LIBS) plugin_in_files = orientation.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = $(plugin_in_files) CLEANFILES = $(plugin_DATA) DISTCLEANFILES = $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/orientation/gsd-orientation-manager.c0000664000175000017500000004766700000000000027760 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * Copyright (C) 2010,2011 Red Hat, Inc. * * Author: Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include "gsd-input-helper.h" #include "gnome-settings-plugin.h" #include "gnome-settings-profile.h" #include "gsd-orientation-manager.h" #include "gsd-rr.h" typedef enum { ORIENTATION_UNDEFINED, ORIENTATION_NORMAL, ORIENTATION_BOTTOM_UP, ORIENTATION_LEFT_UP, ORIENTATION_RIGHT_UP } OrientationUp; #define GSD_ORIENTATION_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_ORIENTATION_MANAGER, GsdOrientationManagerPrivate)) struct GsdOrientationManagerPrivate { guint start_idle_id; guint name_id; /* Accelerometer */ char *sysfs_path; OrientationUp prev_orientation; /* DBus */ GDBusNodeInfo *introspection_data; GDBusConnection *connection; GDBusProxy *xrandr_proxy; GCancellable *cancellable; /* Notifications */ GUdevClient *client; GSettings *settings; gboolean orientation_lock; }; #define CONF_SCHEMA "com.canonical.unity.settings-daemon.peripherals.touchscreen" #define ORIENTATION_LOCK_KEY "orientation-lock" #define GSD_ORIENTATION_DBUS_NAME GSD_DBUS_NAME ".Orientation" #define GSD_ORIENTATION_DBUS_PATH GSD_DBUS_PATH "/Orientation" static const gchar introspection_xml[] = "" " " " " " " ""; static void gsd_orientation_manager_class_init (GsdOrientationManagerClass *klass); static void gsd_orientation_manager_init (GsdOrientationManager *orientation_manager); static void gsd_orientation_manager_finalize (GObject *object); G_DEFINE_TYPE (GsdOrientationManager, gsd_orientation_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; #define MPU_THRESHOLD 12000 #define MPU_POLL_INTERVAL 1 static gboolean is_mpu6050 = FALSE; static char *mpu6050_accel_x = NULL; static char *mpu6050_accel_y = NULL; static gboolean mpu_timer(GsdOrientationManager *manager); static GObject * gsd_orientation_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { GsdOrientationManager *orientation_manager; orientation_manager = GSD_ORIENTATION_MANAGER (G_OBJECT_CLASS (gsd_orientation_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); return G_OBJECT (orientation_manager); } static void gsd_orientation_manager_dispose (GObject *object) { G_OBJECT_CLASS (gsd_orientation_manager_parent_class)->dispose (object); } static void gsd_orientation_manager_class_init (GsdOrientationManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructor = gsd_orientation_manager_constructor; object_class->dispose = gsd_orientation_manager_dispose; object_class->finalize = gsd_orientation_manager_finalize; g_type_class_add_private (klass, sizeof (GsdOrientationManagerPrivate)); } static void gsd_orientation_manager_init (GsdOrientationManager *manager) { manager->priv = GSD_ORIENTATION_MANAGER_GET_PRIVATE (manager); manager->priv->prev_orientation = ORIENTATION_UNDEFINED; } static GsdRRRotation orientation_to_rotation (OrientationUp orientation) { switch (orientation) { case ORIENTATION_NORMAL: return GSD_RR_ROTATION_0; case ORIENTATION_BOTTOM_UP: return GSD_RR_ROTATION_180; case ORIENTATION_LEFT_UP: return GSD_RR_ROTATION_90; case ORIENTATION_RIGHT_UP: return GSD_RR_ROTATION_270; default: g_assert_not_reached (); } } static OrientationUp orientation_from_string (const char *orientation) { if (g_strcmp0 (orientation, "normal") == 0) return ORIENTATION_NORMAL; if (g_strcmp0 (orientation, "bottom-up") == 0) return ORIENTATION_BOTTOM_UP; if (g_strcmp0 (orientation, "left-up") == 0) return ORIENTATION_LEFT_UP; if (g_strcmp0 (orientation, "right-up") == 0) return ORIENTATION_RIGHT_UP; return ORIENTATION_UNDEFINED; } static const char * orientation_to_string (OrientationUp o) { switch (o) { case ORIENTATION_UNDEFINED: return "undefined"; case ORIENTATION_NORMAL: return "normal"; case ORIENTATION_BOTTOM_UP: return "bottom-up"; case ORIENTATION_LEFT_UP: return "left-up"; case ORIENTATION_RIGHT_UP: return "right-up"; default: g_assert_not_reached (); } } static OrientationUp get_orientation_from_device (GUdevDevice *dev) { const char *value; value = g_udev_device_get_property (dev, "ID_INPUT_ACCELEROMETER_ORIENTATION"); if (value == NULL) { g_debug ("Couldn't find orientation for accelerometer %s", g_udev_device_get_sysfs_path (dev)); return ORIENTATION_UNDEFINED; } g_debug ("Found orientation '%s' for accelerometer %s", value, g_udev_device_get_sysfs_path (dev)); return orientation_from_string (value); } static void on_xrandr_action_call_finished (GObject *source_object, GAsyncResult *res, GsdOrientationManager *manager) { GError *error = NULL; GVariant *variant; variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); g_object_unref (manager->priv->cancellable); manager->priv->cancellable = NULL; if (error != NULL) { g_warning ("Unable to call 'RotateTo': %s", error->message); g_error_free (error); } else { g_variant_unref (variant); } } static void do_xrandr_action (GsdOrientationManager *manager, GsdRRRotation rotation) { GsdOrientationManagerPrivate *priv = manager->priv; GTimeVal tv; gint64 timestamp; if (priv->connection == NULL || priv->xrandr_proxy == NULL) { g_warning ("No existing D-Bus connection trying to handle XRANDR keys"); return; } if (priv->cancellable != NULL) { g_debug ("xrandr action already in flight"); return; } g_get_current_time (&tv); timestamp = tv.tv_sec * 1000 + tv.tv_usec / 1000; priv->cancellable = g_cancellable_new (); g_dbus_proxy_call (priv->xrandr_proxy, "RotateTo", g_variant_new ("(ix)", rotation, timestamp), G_DBUS_CALL_FLAGS_NONE, -1, priv->cancellable, (GAsyncReadyCallback) on_xrandr_action_call_finished, manager); } static void do_rotation (GsdOrientationManager *manager) { GsdRRRotation rotation; if (manager->priv->orientation_lock) { g_debug ("Orientation changed, but we are locked"); return; } if (manager->priv->prev_orientation == ORIENTATION_UNDEFINED) { g_debug ("Not trying to rotate, orientation is undefined"); return; } rotation = orientation_to_rotation (manager->priv->prev_orientation); do_xrandr_action (manager, rotation); } static void client_uevent_cb (GUdevClient *client, gchar *action, GUdevDevice *device, GsdOrientationManager *manager) { const char *sysfs_path; OrientationUp orientation; sysfs_path = g_udev_device_get_sysfs_path (device); g_debug ("Received uevent '%s' from '%s'", action, sysfs_path); if (manager->priv->orientation_lock) return; if (g_str_equal (action, "change") == FALSE) return; if (g_strcmp0 (manager->priv->sysfs_path, sysfs_path) != 0) return; g_debug ("Received an event from the accelerometer"); orientation = get_orientation_from_device (device); if (orientation != manager->priv->prev_orientation) { manager->priv->prev_orientation = orientation; g_debug ("Orientation changed to '%s', switching screen rotation", orientation_to_string (manager->priv->prev_orientation)); do_rotation (manager); } } static void orientation_lock_changed_cb (GSettings *settings, gchar *key, GsdOrientationManager *manager) { gboolean new; new = g_settings_get_boolean (settings, key); if (new == manager->priv->orientation_lock) return; manager->priv->orientation_lock = new; if (new == FALSE) { if (is_mpu6050) { g_timeout_add_seconds(MPU_POLL_INTERVAL, (GSourceFunc) mpu_timer, manager); } /* Handle the rotations that could have occurred while * we were locked */ do_rotation (manager); } } static void xrandr_ready_cb (GObject *source_object, GAsyncResult *res, GsdOrientationManager *manager) { GError *error = NULL; manager->priv->xrandr_proxy = g_dbus_proxy_new_finish (res, &error); if (manager->priv->xrandr_proxy == NULL) { g_warning ("Failed to get proxy for XRandR operations: %s", error->message); g_error_free (error); } } static void on_bus_gotten (GObject *source_object, GAsyncResult *res, GsdOrientationManager *manager) { GDBusConnection *connection; GError *error = NULL; connection = g_bus_get_finish (res, &error); if (connection == NULL) { g_warning ("Could not get session bus: %s", error->message); g_error_free (error); return; } manager->priv->connection = connection; g_dbus_connection_register_object (connection, GSD_ORIENTATION_DBUS_PATH, manager->priv->introspection_data->interfaces[0], NULL, NULL, NULL, NULL); g_dbus_proxy_new (manager->priv->connection, G_DBUS_PROXY_FLAGS_NONE, NULL, GSD_DBUS_NAME ".XRANDR", GSD_DBUS_PATH "/XRANDR", GSD_DBUS_BASE_INTERFACE ".XRANDR_2", NULL, (GAsyncReadyCallback) xrandr_ready_cb, manager); manager->priv->name_id = g_bus_own_name_on_connection (connection, GSD_ORIENTATION_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL); } static GUdevDevice * get_accelerometer (GUdevClient *client) { GList *list, *listiio, *l; GUdevDevice *ret, *parent; /* Look for a device with the ID_INPUT_ACCELEROMETER=1 property */ ret = NULL; list = g_udev_client_query_by_subsystem (client, "input"); listiio = g_udev_client_query_by_subsystem (client, "iio"); list = g_list_concat(list, listiio); for (l = list; l != NULL; l = l->next) { GUdevDevice *dev; dev = l->data; if (g_udev_device_get_property_as_boolean (dev, "ID_INPUT_ACCELEROMETER")) { ret = dev; continue; } g_object_unref (dev); } g_list_free (list); if (ret == NULL) return NULL; /* Now walk up to the parent */ parent = g_udev_device_get_parent (ret); if (parent == NULL) return ret; if (g_udev_device_get_property_as_boolean (parent, "ID_INPUT_ACCELEROMETER")) { g_object_unref (ret); ret = parent; } else { g_object_unref (parent); } return ret; } static int read_sysfs_attr_as_int(const char *filename) { int i, c; char buf[40]; int fd = open(filename, O_RDONLY); if (fd < 0) return 0; c = read(fd, buf, 40); if (c < 0) return 0; close(fd); sscanf(buf, "%d", &i); return i; } static gboolean mpu_timer(GsdOrientationManager *manager) { int x, y; static gboolean first = TRUE; OrientationUp orientation = manager->priv->prev_orientation; if (manager->priv->xrandr_proxy == NULL) return TRUE; x = read_sysfs_attr_as_int(mpu6050_accel_x); y = read_sysfs_attr_as_int(mpu6050_accel_y); if (x > MPU_THRESHOLD) orientation = ORIENTATION_NORMAL; if (x < -MPU_THRESHOLD) orientation = ORIENTATION_BOTTOM_UP; if (y > MPU_THRESHOLD) orientation = ORIENTATION_RIGHT_UP; if (y < -MPU_THRESHOLD) orientation = ORIENTATION_LEFT_UP; if (orientation != manager->priv->prev_orientation || first) { first = FALSE; manager->priv->prev_orientation = orientation; g_debug ("Orientation changed to '%s', switching screen rotation", orientation_to_string (manager->priv->prev_orientation)); do_rotation (manager); } return !manager->priv->orientation_lock; } static gboolean gsd_orientation_manager_idle_cb (GsdOrientationManager *manager) { const char * const subsystems[] = { "input", NULL }; GUdevDevice *dev; gnome_settings_profile_start (NULL); manager->priv->start_idle_id = 0; manager->priv->settings = g_settings_new (CONF_SCHEMA); g_signal_connect (G_OBJECT (manager->priv->settings), "changed::orientation-lock", G_CALLBACK (orientation_lock_changed_cb), manager); manager->priv->orientation_lock = g_settings_get_boolean (manager->priv->settings, ORIENTATION_LOCK_KEY); manager->priv->client = g_udev_client_new (subsystems); dev = get_accelerometer (manager->priv->client); if (dev == NULL) { g_debug ("Did not find an accelerometer"); gnome_settings_profile_end (NULL); return FALSE; } manager->priv->sysfs_path = g_strdup (g_udev_device_get_sysfs_path (dev)); g_debug ("Found accelerometer at sysfs path '%s'", manager->priv->sysfs_path); manager->priv->prev_orientation = get_orientation_from_device (dev); /* Poll the sysfs attributes exposed by MPU6050 as it is not an uevent based input driver */ if (g_strcmp0 (g_udev_device_get_sysfs_attr (dev, "name"), "mpu6050") == 0) { manager->priv->prev_orientation = ORIENTATION_NORMAL; g_timeout_add_seconds(MPU_POLL_INTERVAL, (GSourceFunc) mpu_timer, manager); mpu6050_accel_x = g_build_filename(manager->priv->sysfs_path, "in_accel_x_raw", NULL); mpu6050_accel_y = g_build_filename(manager->priv->sysfs_path, "in_accel_y_raw", NULL); is_mpu6050 = TRUE; } g_object_unref (dev); /* Start process of owning a D-Bus name */ g_bus_get (G_BUS_TYPE_SESSION, NULL, (GAsyncReadyCallback) on_bus_gotten, manager); g_signal_connect (G_OBJECT (manager->priv->client), "uevent", G_CALLBACK (client_uevent_cb), manager); gnome_settings_profile_end (NULL); return FALSE; } gboolean gsd_orientation_manager_start (GsdOrientationManager *manager, GError **error) { gnome_settings_profile_start (NULL); manager->priv->start_idle_id = g_idle_add ((GSourceFunc) gsd_orientation_manager_idle_cb, manager); manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (manager->priv->introspection_data != NULL); gnome_settings_profile_end (NULL); return TRUE; } void gsd_orientation_manager_stop (GsdOrientationManager *manager) { GsdOrientationManagerPrivate *p = manager->priv; g_debug ("Stopping orientation manager"); if (p->settings) { g_object_unref (p->settings); p->settings = NULL; } if (p->sysfs_path) { g_free (p->sysfs_path); p->sysfs_path = NULL; } if (p->introspection_data) { g_dbus_node_info_unref (p->introspection_data); p->introspection_data = NULL; } if (p->client) { g_object_unref (p->client); p->client = NULL; } } static void gsd_orientation_manager_finalize (GObject *object) { GsdOrientationManager *orientation_manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_ORIENTATION_MANAGER (object)); orientation_manager = GSD_ORIENTATION_MANAGER (object); g_return_if_fail (orientation_manager->priv != NULL); if (orientation_manager->priv->start_idle_id != 0) g_source_remove (orientation_manager->priv->start_idle_id); if (orientation_manager->priv->name_id != 0) g_bus_unown_name (orientation_manager->priv->name_id); G_OBJECT_CLASS (gsd_orientation_manager_parent_class)->finalize (object); } GsdOrientationManager * gsd_orientation_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_ORIENTATION_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_ORIENTATION_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/orientation/gsd-orientation-manager.h0000664000175000017500000000472000000000000027744 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * Copyright (C) 2010 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_ORIENTATION_MANAGER_H #define __GSD_ORIENTATION_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_ORIENTATION_MANAGER (gsd_orientation_manager_get_type ()) #define GSD_ORIENTATION_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_ORIENTATION_MANAGER, GsdOrientationManager)) #define GSD_ORIENTATION_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_ORIENTATION_MANAGER, GsdOrientationManagerClass)) #define GSD_IS_ORIENTATION_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_ORIENTATION_MANAGER)) #define GSD_IS_ORIENTATION_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_ORIENTATION_MANAGER)) #define GSD_ORIENTATION_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_ORIENTATION_MANAGER, GsdOrientationManagerClass)) typedef struct GsdOrientationManagerPrivate GsdOrientationManagerPrivate; typedef struct { GObject parent; GsdOrientationManagerPrivate *priv; } GsdOrientationManager; typedef struct { GObjectClass parent_class; } GsdOrientationManagerClass; GType gsd_orientation_manager_get_type (void); GsdOrientationManager * gsd_orientation_manager_new (void); gboolean gsd_orientation_manager_start (GsdOrientationManager *manager, GError **error); void gsd_orientation_manager_stop (GsdOrientationManager *manager); G_END_DECLS #endif /* __GSD_ORIENTATION_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/orientation/gsd-orientation-plugin.c0000664000175000017500000000210300000000000027614 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * Copyright (C) 2010 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-orientation-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdOrientation, gsd_orientation) ././@PaxHeader0000000000000000000000000000021300000000000010211 xustar00111 path=unity-settings-daemon-15.04.1+21.10.20220207/plugins/orientation/orientation.gnome-settings-plugin.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/orientation/orientation.gnome-settings-plugin.i0000664000175000017500000000030200000000000032010 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=orientation IAge=0 # Default Priority # Priority=100 _Name=Orientation _Description=Orientation plugin Authors=Peter Hutterer Copyright=Copyright © 2010 Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/orientation/test-orientation.c0000664000175000017500000000034300000000000026526 0ustar00jeremyjeremy#define NEW gsd_orientation_manager_new #define START gsd_orientation_manager_start #define STOP gsd_orientation_manager_stop #define MANAGER GsdOrientationManager #include "gsd-orientation-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5917668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/0000775000175000017500000000000000000000000021653 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/Makefile.am0000664000175000017500000001266400000000000023720 0ustar00jeremyjeremyBUILT_SOURCES = plugin_name = power plugin_LTLIBRARIES = \ libpower.la libpower_la_SOURCES = \ gpm-common.c \ gpm-common.h \ gsd-backlight-linux.c \ gsd-backlight-linux.h \ gsd-power-manager.c \ gsd-power-manager.h \ gsm-inhibitor-flag.h \ gsm-presence-flag.h \ gsm-manager-logout-mode.h \ gsd-power-constants.h \ gsd-power-plugin.c libpower_la_CPPFLAGS = \ -I$(top_srcdir)/data/ \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DGTKBUILDERDIR=\""$(pkgdatadir)"\" \ -DSBINDIR=\"$(sbindir)\" \ -DLIBEXECDIR=\"$(libexecdir)\" \ $(AM_CPPFLAGS) libpower_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(POWER_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) libpower_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) libpower_la_LIBADD = \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(POWER_LIBS) \ $(SETTINGS_PLUGIN_LIBS) plugin_in_files = \ power.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) com.ubuntu.unity-settings-daemon.plugins.power.policy.in: com.ubuntu.unity-settings-daemon.plugins.power.policy.in.in Makefile $(AM_V_GEN) sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ @INTLTOOL_POLICY_RULE@ polkit_policydir = $(datadir)/polkit-1/actions polkit_policy_in_files = com.ubuntu.unity-settings-daemon.plugins.power.policy.in polkit_policy_DATA = $(polkit_policy_in_files:.policy.in=.policy) # so it always gets included in the tarball usd_backlight_helper_SOURCES = \ gsd-backlight-linux.c \ gsd-backlight-linux.h \ gsd-backlight-helper.c noinst_PROGRAMS = usd-test-power usd_test_power_SOURCES = \ gpm-common.c \ gpm-common.h \ gsd-backlight-linux.c \ gsd-backlight-linux.h \ gsd-power-manager.c \ gsd-power-manager.h \ gsm-inhibitor-flag.h \ gsm-presence-flag.h \ gsm-manager-logout-mode.h \ test-power.c usd_test_power_CFLAGS = $(libpower_la_CFLAGS) usd_test_power_CPPFLAGS = $(libpower_la_CPPFLAGS) -DGSD_MOCK=1 -DGSD_ACTION_DELAY=1 usd_test_power_LDADD = \ -lm \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(POWER_LIBS) \ $(SETTINGS_PLUGIN_LIBS) EXTRA_DIST = \ $(plugin_in_files) \ $(gsd_backlight_helper_SOURCES) \ $(NULL) if HAVE_GUDEV libexec_PROGRAMS = usd-backlight-helper usd_backlight_helper_LDFLAGS = \ $(BACKLIGHT_HELPER_LIBS) \ -lm usd_backlight_helper_CFLAGS = \ $(BACKLIGHT_HELPER_CFLAGS) EXTRA_DIST += \ com.ubuntu.unity-settings-daemon.plugins.power.policy.in.in endif # Enums GSD_POWER_ENUM_FILES = gsd-power-enums.c gsd-power-enums.h gsd-power-enums.h: gsm-inhibitor-flag.h gsm-presence-flag.h Makefile $(AM_V_GEN)($(GLIB_MKENUMS) \ --fhead "#ifndef GSD_POWER_ENUMS_H\n#define GSD_POWER_ENUMS_H\n\n#include \n\nG_BEGIN_DECLS\n" \ --fprod "/* enumerations from \"@filename@\" */\n" \ --vhead "GType @enum_name@_get_type (void) G_GNUC_CONST;\n#define GSD_POWER_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \ --ftail "G_END_DECLS\n\n#endif /* !GSD_POWER_ENUMS_H */" $(srcdir)/gsm-inhibitor-flag.h $(srcdir)/gsm-presence-flag.h > $@) gsd-power-enums.c: gsd-power-constants.h gsm-inhibitor-flag.h gsm-presence-flag.h Makefile gsd-power-enums.h $(AM_V_GEN)($(GLIB_MKENUMS) \ --fhead "#include \"gsm-inhibitor-flag.h\"\n#include \"gsm-presence-flag.h\"\n#include \"gsd-power-enums.h\"" \ --fprod "\n/* enumerations from \"@filename@\" */" \ --vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \ --vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \ --vtail " { 0, NULL, NULL }\n };\n etype = g_@type@_register_static (\"@EnumName@\", values);\n }\n return etype;\n}\n" \ $(srcdir)/gsm-inhibitor-flag.h $(srcdir)/gsm-presence-flag.h > $@) BUILT_SOURCES += $(GSD_POWER_ENUM_FILES) gsdpowerconstants.py: gsd-power-constants-update.pl gsd-power-constants.h $(AM_V_GEN) $(srcdir)/gsd-power-constants-update.pl gsdpowerenums.py: gsd-power-enums-update gsd-power-enums.h gsd-power-enums.c $(AM_V_GEN) $(builddir)/gsd-power-enums-update > $@ noinst_PROGRAMS += gsd-power-enums-update gsd_power_enums_update_SOURCES = \ gsd-power-enums-update.c \ gsd-power-enums.h \ gsd-power-enums.c gsd_power_enums_update_CFLAGS = $(libpower_la_CFLAGS) gsd_power_enums_update_CPPFLAGS = $(libpower_la_CPPFLAGS) -I$(top_builddir)/plugins/power gsd_power_enums_update_LDFLAGS = $(POWER_LIBS) EXTRA_DIST += gsd-power-constants-update.pl gsdpowerconstants.py gsdpowerenums.py test.py check-local: $(top_builddir)/tests/shiftkey usd-test-power test.py gsdpowerconstants.py gsdpowerenums.py # This is how you run a single test # BUILDDIR=$(builddir) TOP_BUILDDIR=$(top_builddir) ${PYTHON} $(srcdir)/test.py PowerPluginTest.test_sleep_inactive_blank BUILDDIR=$(builddir) TOP_BUILDDIR=$(top_builddir) ${PYTHON} $(srcdir)/test.py clean-local: rm -f *~ CLEANFILES = \ $(plugin_DATA) \ $(GSD_POWER_ENUM_FILES) \ gsdpowerenums.py \ com.ubuntu.unity-settings-daemon.plugins.power.policy \ com.ubuntu.unity-settings-daemon.plugins.power.policy.in @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000023400000000000010214 xustar00128 path=unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/com.ubuntu.unity-settings-daemon.plugins.power.policy.in.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/com.ubuntu.unity-settings-daemon.plugins.0000664000175000017500000000223000000000000031676 0ustar00jeremyjeremy Unity Settings Daemon http://git.gnome.org/browse/gnome-settings-daemon battery <_description>Modify the laptop brightness <_message>Authentication is required to modify the laptop brightness no no yes @libexecdir@/usd-backlight-helper ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gpm-common.c0000664000175000017500000020245200000000000024075 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2005-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include "gpm-common.h" #include "gsd-power-constants.h" #include "gsd-power-manager.h" #include "gsd-backlight-linux.h" #include "gsd-rr.h" #define XSCREENSAVER_WATCHDOG_TIMEOUT 120 /* seconds */ #define UPS_SOUND_LOOP_ID 99 #define GSD_POWER_MANAGER_CRITICAL_ALERT_TIMEOUT 5 /* seconds */ /* take a discrete value with offset and convert to percentage */ int gsd_power_backlight_abs_to_percentage (int min, int max, int value) { g_return_val_if_fail (max > min, -1); g_return_val_if_fail (value >= min, -1); g_return_val_if_fail (value <= max, -1); return (((value - min) * 100) / (max - min)); } #define GPM_UP_TIME_PRECISION 5*60 #define GPM_UP_TEXT_MIN_TIME 120 /** * Return value: The time string, e.g. "2 hours 3 minutes" **/ gchar * gpm_get_timestring (guint time_secs) { char* timestring = NULL; gint hours; gint minutes; /* Add 0.5 to do rounding */ minutes = (int) ( ( time_secs / 60.0 ) + 0.5 ); if (minutes == 0) { timestring = g_strdup (_("Unknown time")); return timestring; } if (minutes < 60) { timestring = g_strdup_printf (ngettext ("%i minute", "%i minutes", minutes), minutes); return timestring; } hours = minutes / 60; minutes = minutes % 60; if (minutes == 0) timestring = g_strdup_printf (ngettext ( "%i hour", "%i hours", hours), hours); else /* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes" * Swap order with "%2$s %2$i %1$s %1$i if needed */ timestring = g_strdup_printf (_("%i %s %i %s"), hours, ngettext ("hour", "hours", hours), minutes, ngettext ("minute", "minutes", minutes)); return timestring; } static const gchar * gpm_upower_get_device_icon_index (UpDevice *device) { gdouble percentage; /* get device properties */ g_object_get (device, "percentage", &percentage, NULL); if (percentage < 10) return "000"; else if (percentage < 30) return "020"; else if (percentage < 50) return "040"; else if (percentage < 70) return "060"; else if (percentage < 90) return "080"; return "100"; } static const gchar * gpm_upower_get_device_icon_suffix (UpDevice *device) { gdouble percentage; /* get device properties */ g_object_get (device, "percentage", &percentage, NULL); if (percentage < 10) return "caution"; else if (percentage < 30) return "low"; else if (percentage < 60) return "good"; return "full"; } GIcon * gpm_upower_get_device_icon (UpDevice *device, gboolean use_symbolic) { GString *filename; gchar **iconnames; const gchar *kind_str; const gchar *suffix_str; const gchar *index_str; UpDeviceKind kind; UpDeviceState state; gboolean is_present; gdouble percentage; GIcon *icon = NULL; g_return_val_if_fail (device != NULL, NULL); /* get device properties */ g_object_get (device, "kind", &kind, "state", &state, "percentage", &percentage, "is-present", &is_present, NULL); /* get correct icon prefix */ filename = g_string_new (NULL); /* get the icon from some simple rules */ if (kind == UP_DEVICE_KIND_LINE_POWER) { if (use_symbolic) g_string_append (filename, "ac-adapter-symbolic;"); g_string_append (filename, "ac-adapter;"); } else if (kind == UP_DEVICE_KIND_MONITOR) { if (use_symbolic) g_string_append (filename, "gpm-monitor-symbolic;"); g_string_append (filename, "gpm-monitor;"); } else { kind_str = up_device_kind_to_string (kind); if (!is_present) { if (use_symbolic) g_string_append (filename, "battery-missing-symbolic;"); g_string_append_printf (filename, "gpm-%s-missing;", kind_str); g_string_append_printf (filename, "gpm-%s-000;", kind_str); g_string_append (filename, "battery-missing;"); } else { switch (state) { case UP_DEVICE_STATE_EMPTY: if (use_symbolic) g_string_append (filename, "battery-empty-symbolic;"); g_string_append_printf (filename, "gpm-%s-empty;", kind_str); g_string_append_printf (filename, "gpm-%s-000;", kind_str); g_string_append (filename, "battery-empty;"); break; case UP_DEVICE_STATE_FULLY_CHARGED: if (use_symbolic) { g_string_append (filename, "battery-full-charged-symbolic;"); g_string_append (filename, "battery-full-charging-symbolic;"); } g_string_append_printf (filename, "gpm-%s-full;", kind_str); g_string_append_printf (filename, "gpm-%s-100;", kind_str); g_string_append (filename, "battery-full-charged;"); g_string_append (filename, "battery-full-charging;"); break; case UP_DEVICE_STATE_CHARGING: case UP_DEVICE_STATE_PENDING_CHARGE: suffix_str = gpm_upower_get_device_icon_suffix (device); index_str = gpm_upower_get_device_icon_index (device); if (use_symbolic) g_string_append_printf (filename, "battery-%s-charging-symbolic;", suffix_str); g_string_append_printf (filename, "gpm-%s-%s-charging;", kind_str, index_str); g_string_append_printf (filename, "battery-%s-charging;", suffix_str); break; case UP_DEVICE_STATE_DISCHARGING: case UP_DEVICE_STATE_PENDING_DISCHARGE: suffix_str = gpm_upower_get_device_icon_suffix (device); index_str = gpm_upower_get_device_icon_index (device); if (use_symbolic) g_string_append_printf (filename, "battery-%s-symbolic;", suffix_str); g_string_append_printf (filename, "gpm-%s-%s;", kind_str, index_str); g_string_append_printf (filename, "battery-%s;", suffix_str); break; default: if (use_symbolic) g_string_append (filename, "battery-missing-symbolic;"); g_string_append (filename, "gpm-battery-missing;"); g_string_append (filename, "battery-missing;"); } } } /* nothing matched */ if (filename->len == 0) { g_warning ("nothing matched, falling back to default icon"); g_string_append (filename, "dialog-warning;"); } g_debug ("got filename: %s", filename->str); iconnames = g_strsplit (filename->str, ";", -1); icon = g_themed_icon_new_from_names (iconnames, -1); g_strfreev (iconnames); g_string_free (filename, TRUE); return icon; } /** * gpm_precision_round_down: * @value: The input value * @smallest: The smallest increment allowed * * 101, 10 100 * 95, 10 90 * 0, 10 0 * 112, 10 110 * 100, 10 100 **/ static gint gpm_precision_round_down (gfloat value, gint smallest) { gfloat division; if (fabs (value) < 0.01) return 0; if (smallest == 0) { g_warning ("divisor zero"); return 0; } division = (gfloat) value / (gfloat) smallest; division = floorf (division); division *= smallest; return (gint) division; } gchar * gpm_upower_get_device_summary (UpDevice *device) { const gchar *kind_desc = NULL; const gchar *device_desc = NULL; GString *description; guint time_to_full_round; guint time_to_empty_round; gchar *time_to_full_str = NULL; gchar *time_to_empty_str = NULL; UpDeviceKind kind; UpDeviceState state; gdouble percentage; gboolean is_present; gint64 time_to_full; gint64 time_to_empty; /* get device properties */ g_object_get (device, "kind", &kind, "state", &state, "percentage", &percentage, "is-present", &is_present, "time-to-full", &time_to_full, "time-to-empty", &time_to_empty, NULL); description = g_string_new (NULL); kind_desc = gpm_device_kind_to_localised_string (kind, 1); device_desc = gpm_device_to_localised_string (device); /* not installed */ if (!is_present) { g_string_append (description, device_desc); goto out; } /* don't display all the extra stuff for keyboards and mice */ if (kind == UP_DEVICE_KIND_MOUSE || kind == UP_DEVICE_KIND_KEYBOARD || kind == UP_DEVICE_KIND_PDA) { g_string_append (description, kind_desc); g_string_append_printf (description, " (%.0f%%)", percentage); goto out; } /* we care if we are on AC */ if (kind == UP_DEVICE_KIND_PHONE) { if (state == UP_DEVICE_STATE_CHARGING || !(state == UP_DEVICE_STATE_DISCHARGING)) { g_string_append (description, device_desc); g_string_append_printf (description, " (%.0f%%)", percentage); goto out; } g_string_append (description, kind_desc); g_string_append_printf (description, " (%.0f%%)", percentage); goto out; } /* precalculate so we don't get Unknown time remaining */ time_to_full_round = gpm_precision_round_down (time_to_full, GPM_UP_TIME_PRECISION); time_to_empty_round = gpm_precision_round_down (time_to_empty, GPM_UP_TIME_PRECISION); /* we always display "Laptop battery 16 minutes remaining" as we need to clarify what device we are refering to */ if (state == UP_DEVICE_STATE_FULLY_CHARGED) { g_string_append (description, device_desc); if (kind == UP_DEVICE_KIND_BATTERY && time_to_empty_round > GPM_UP_TEXT_MIN_TIME) { time_to_empty_str = gpm_get_timestring (time_to_empty_round); g_string_append (description, " - "); /* TRANSLATORS: The laptop battery is charged, and we know a time. * The parameter is the time, e.g. 7 hours 6 minutes */ g_string_append_printf (description, _("provides %s laptop runtime"), time_to_empty_str); } goto out; } if (state == UP_DEVICE_STATE_DISCHARGING) { if (time_to_empty_round > GPM_UP_TEXT_MIN_TIME) { time_to_empty_str = gpm_get_timestring (time_to_empty_round); /* TRANSLATORS: the device is discharging, and we have a time remaining * The first parameter is the device type, e.g. "Laptop battery" and * the second is the time, e.g. 7 hours 6 minutes */ g_string_append_printf (description, _("%s %s remaining"), kind_desc, time_to_empty_str); g_string_append_printf (description, " (%.0f%%)", percentage); } else { g_string_append (description, device_desc); g_string_append_printf (description, " (%.0f%%)", percentage); } goto out; } if (state == UP_DEVICE_STATE_CHARGING) { if (time_to_full_round > GPM_UP_TEXT_MIN_TIME && time_to_empty_round > GPM_UP_TEXT_MIN_TIME) { /* display both discharge and charge time */ time_to_full_str = gpm_get_timestring (time_to_full_round); time_to_empty_str = gpm_get_timestring (time_to_empty_round); /* TRANSLATORS: device is charging, and we have a time to full and a percentage * The first parameter is the device type, e.g. "Laptop battery" and * the second is the time, e.g. "7 hours 6 minutes" */ g_string_append_printf (description, _("%s %s until charged"), kind_desc, time_to_full_str); g_string_append_printf (description, " (%.0f%%)", percentage); g_string_append (description, " - "); /* TRANSLATORS: the device is charging, and we have a time to full and empty. * The parameter is a time string, e.g. "7 hours 6 minutes" */ g_string_append_printf (description, _("provides %s battery runtime"), time_to_empty_str); } else if (time_to_full_round > GPM_UP_TEXT_MIN_TIME) { /* display only charge time */ time_to_full_str = gpm_get_timestring (time_to_full_round); /* TRANSLATORS: device is charging, and we have a time to full and a percentage. * The first parameter is the device type, e.g. "Laptop battery" and * the second is the time, e.g. "7 hours 6 minutes" */ g_string_append_printf (description, _("%s %s until charged"), kind_desc, time_to_full_str); g_string_append_printf (description, " (%.0f%%)", percentage); } else { g_string_append (description, device_desc); g_string_append_printf (description, " (%.0f%%)", percentage); } goto out; } if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) { g_string_append (description, device_desc); g_string_append_printf (description, " (%.0f%%)", percentage); goto out; } if (state == UP_DEVICE_STATE_PENDING_CHARGE) { g_string_append (description, device_desc); g_string_append_printf (description, " (%.0f%%)", percentage); goto out; } if (state == UP_DEVICE_STATE_EMPTY) { g_string_append (description, device_desc); goto out; } /* fallback */ g_warning ("in an undefined state we are not charging or " "discharging and the batteries are also not charged"); g_string_append (description, device_desc); g_string_append_printf (description, " (%.0f%%)", percentage); out: g_free (time_to_full_str); g_free (time_to_empty_str); return g_string_free (description, FALSE); } gchar * gpm_upower_get_device_description (UpDevice *device) { GString *details; const gchar *text; gchar *time_str; UpDeviceKind kind; UpDeviceState state; UpDeviceTechnology technology; gdouble percentage; gdouble capacity; gdouble energy; gdouble energy_full; gdouble energy_full_design; gdouble energy_rate; gboolean is_present; gint64 time_to_full; gint64 time_to_empty; gchar *vendor = NULL; gchar *serial = NULL; gchar *model = NULL; g_return_val_if_fail (device != NULL, NULL); /* get device properties */ g_object_get (device, "kind", &kind, "state", &state, "percentage", &percentage, "is-present", &is_present, "time-to-full", &time_to_full, "time-to-empty", &time_to_empty, "technology", &technology, "capacity", &capacity, "energy", &energy, "energy-full", &energy_full, "energy-full-design", &energy_full_design, "energy-rate", &energy_rate, "vendor", &vendor, "serial", &serial, "model", &model, NULL); details = g_string_new (""); text = gpm_device_kind_to_localised_string (kind, 1); /* TRANSLATORS: the type of data, e.g. Laptop battery */ g_string_append_printf (details, "%s %s\n", _("Product:"), text); if (!is_present) { /* TRANSLATORS: device is missing */ g_string_append_printf (details, "%s %s\n", _("Status:"), _("Missing")); } else if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* TRANSLATORS: device is charged */ g_string_append_printf (details, "%s %s\n", _("Status:"), _("Charged")); } else if (state == UP_DEVICE_STATE_CHARGING) { /* TRANSLATORS: device is charging */ g_string_append_printf (details, "%s %s\n", _("Status:"), _("Charging")); } else if (state == UP_DEVICE_STATE_DISCHARGING) { /* TRANSLATORS: device is discharging */ g_string_append_printf (details, "%s %s\n", _("Status:"), _("Discharging")); } if (percentage >= 0) { /* TRANSLATORS: percentage */ g_string_append_printf (details, "%s %.1f%%\n", _("Percentage charge:"), percentage); } if (vendor) { /* TRANSLATORS: manufacturer */ g_string_append_printf (details, "%s %s\n", _("Vendor:"), vendor); } if (technology != UP_DEVICE_TECHNOLOGY_UNKNOWN) { text = gpm_device_technology_to_localised_string (technology); /* TRANSLATORS: how the battery is made, e.g. Lithium Ion */ g_string_append_printf (details, "%s %s\n", _("Technology:"), text); } if (serial) { /* TRANSLATORS: serial number of the battery */ g_string_append_printf (details, "%s %s\n", _("Serial number:"), serial); } if (model) { /* TRANSLATORS: model number of the battery */ g_string_append_printf (details, "%s %s\n", _("Model:"), model); } if (time_to_full > 0) { time_str = gpm_get_timestring (time_to_full); /* TRANSLATORS: time to fully charged */ g_string_append_printf (details, "%s %s\n", _("Charge time:"), time_str); g_free (time_str); } if (time_to_empty > 0) { time_str = gpm_get_timestring (time_to_empty); /* TRANSLATORS: time to empty */ g_string_append_printf (details, "%s %s\n", _("Discharge time:"), time_str); g_free (time_str); } if (capacity > 0) { const gchar *condition; if (capacity > 99) { /* TRANSLATORS: Excellent, Good, Fair and Poor are all related to battery Capacity */ condition = _("Excellent"); } else if (capacity > 90) { condition = _("Good"); } else if (capacity > 70) { condition = _("Fair"); } else { condition = _("Poor"); } /* TRANSLATORS: %.1f is a percentage and %s the condition (Excellent, Good, ...) */ g_string_append_printf (details, "%s %.1f%% (%s)\n", _("Capacity:"), capacity, condition); } if (kind == UP_DEVICE_KIND_BATTERY) { if (energy > 0) { /* TRANSLATORS: current charge */ g_string_append_printf (details, "%s %.1f Wh\n", _("Current charge:"), energy); } if (energy_full > 0 && energy_full_design != energy_full) { /* TRANSLATORS: last full is the charge the battery was seen to charge to */ g_string_append_printf (details, "%s %.1f Wh\n", _("Last full charge:"), energy_full); } if (energy_full_design > 0) { /* Translators: */ /* TRANSLATORS: Design charge is the amount of charge the battery is designed to have when brand new */ g_string_append_printf (details, "%s %.1f Wh\n", _("Design charge:"), energy_full_design); } if (energy_rate > 0) { /* TRANSLATORS: the charge or discharge rate */ g_string_append_printf (details, "%s %.1f W\n", _("Charge rate:"), energy_rate); } } if (kind == UP_DEVICE_KIND_MOUSE || kind == UP_DEVICE_KIND_KEYBOARD) { if (energy > 0) { /* TRANSLATORS: the current charge for CSR devices */ g_string_append_printf (details, "%s %.0f/7\n", _("Current charge:"), energy); } if (energy_full_design > 0) { /* TRANSLATORS: the design charge for CSR devices */ g_string_append_printf (details, "%s %.0f/7\n", _("Design charge:"), energy_full_design); } } /* remove the last \n */ g_string_truncate (details, details->len-1); g_free (vendor); g_free (serial); g_free (model); return g_string_free (details, FALSE); } const gchar * gpm_device_kind_to_localised_string (UpDeviceKind kind, guint number) { const gchar *text = NULL; switch (kind) { case UP_DEVICE_KIND_LINE_POWER: /* TRANSLATORS: system power cord */ text = ngettext ("AC adapter", "AC adapters", number); break; case UP_DEVICE_KIND_BATTERY: /* TRANSLATORS: laptop primary battery */ text = ngettext ("Laptop battery", "Laptop batteries", number); break; case UP_DEVICE_KIND_UPS: /* TRANSLATORS: battery-backed AC power source */ text = ngettext ("UPS", "UPSs", number); break; case UP_DEVICE_KIND_MONITOR: /* TRANSLATORS: a monitor is a device to measure voltage and current */ text = ngettext ("Monitor", "Monitors", number); break; case UP_DEVICE_KIND_MOUSE: /* TRANSLATORS: wireless mice with internal batteries */ text = ngettext ("Mouse", "Mice", number); break; case UP_DEVICE_KIND_KEYBOARD: /* TRANSLATORS: wireless keyboard with internal battery */ text = ngettext ("Keyboard", "Keyboards", number); break; case UP_DEVICE_KIND_PDA: /* TRANSLATORS: portable device */ text = ngettext ("PDA", "PDAs", number); break; case UP_DEVICE_KIND_PHONE: /* TRANSLATORS: cell phone (mobile...) */ text = ngettext ("Cell phone", "Cell phones", number); break; #if UP_CHECK_VERSION(0,9,5) case UP_DEVICE_KIND_MEDIA_PLAYER: /* TRANSLATORS: media player, mp3 etc */ text = ngettext ("Media player", "Media players", number); break; case UP_DEVICE_KIND_TABLET: /* TRANSLATORS: tablet device */ text = ngettext ("Tablet", "Tablets", number); break; case UP_DEVICE_KIND_COMPUTER: /* TRANSLATORS: tablet device */ text = ngettext ("Computer", "Computers", number); break; #endif default: g_warning ("enum unrecognised: %i", kind); text = up_device_kind_to_string (kind); } return text; } const gchar * gpm_device_kind_to_icon (UpDeviceKind kind) { const gchar *icon = NULL; switch (kind) { case UP_DEVICE_KIND_LINE_POWER: icon = "ac-adapter"; break; case UP_DEVICE_KIND_BATTERY: icon = "battery"; break; case UP_DEVICE_KIND_UPS: icon = "network-wired"; break; case UP_DEVICE_KIND_MONITOR: icon = "application-certificate"; break; case UP_DEVICE_KIND_MOUSE: icon = "input-mouse"; break; case UP_DEVICE_KIND_KEYBOARD: icon = "input-keyboard"; break; case UP_DEVICE_KIND_PDA: icon = "pda"; break; case UP_DEVICE_KIND_PHONE: icon = "phone"; break; #if UP_CHECK_VERSION(0,9,5) case UP_DEVICE_KIND_MEDIA_PLAYER: icon = "multimedia-player"; break; case UP_DEVICE_KIND_TABLET: icon = "input-tablet"; break; case UP_DEVICE_KIND_COMPUTER: icon = "computer-apple-ipad"; break; #endif default: g_warning ("enum unrecognised: %i", kind); icon = "gtk-help"; } return icon; } const gchar * gpm_device_technology_to_localised_string (UpDeviceTechnology technology_enum) { const gchar *technology = NULL; switch (technology_enum) { case UP_DEVICE_TECHNOLOGY_LITHIUM_ION: /* TRANSLATORS: battery technology */ technology = _("Lithium Ion"); break; case UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER: /* TRANSLATORS: battery technology */ technology = _("Lithium Polymer"); break; case UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE: /* TRANSLATORS: battery technology */ technology = _("Lithium Iron Phosphate"); break; case UP_DEVICE_TECHNOLOGY_LEAD_ACID: /* TRANSLATORS: battery technology */ technology = _("Lead acid"); break; case UP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM: /* TRANSLATORS: battery technology */ technology = _("Nickel Cadmium"); break; case UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE: /* TRANSLATORS: battery technology */ technology = _("Nickel metal hydride"); break; case UP_DEVICE_TECHNOLOGY_UNKNOWN: /* TRANSLATORS: battery technology */ technology = _("Unknown technology"); break; default: g_assert_not_reached (); break; } return technology; } const gchar * gpm_device_state_to_localised_string (UpDeviceState state) { const gchar *state_string = NULL; switch (state) { case UP_DEVICE_STATE_CHARGING: /* TRANSLATORS: battery state */ state_string = _("Charging"); break; case UP_DEVICE_STATE_DISCHARGING: /* TRANSLATORS: battery state */ state_string = _("Discharging"); break; case UP_DEVICE_STATE_EMPTY: /* TRANSLATORS: battery state */ state_string = _("Empty"); break; case UP_DEVICE_STATE_FULLY_CHARGED: /* TRANSLATORS: battery state */ state_string = _("Charged"); break; case UP_DEVICE_STATE_PENDING_CHARGE: /* TRANSLATORS: battery state */ state_string = _("Waiting to charge"); break; case UP_DEVICE_STATE_PENDING_DISCHARGE: /* TRANSLATORS: battery state */ state_string = _("Waiting to discharge"); break; default: g_assert_not_reached (); break; } return state_string; } const gchar * gpm_device_to_localised_string (UpDevice *device) { UpDeviceState state; UpDeviceKind kind; gboolean present; /* get device parameters */ g_object_get (device, "is-present", &present, "kind", &kind, "state", &state, NULL); /* laptop battery */ if (kind == UP_DEVICE_KIND_BATTERY) { if (!present) { /* TRANSLATORS: device not present */ return _("Laptop battery not present"); } if (state == UP_DEVICE_STATE_CHARGING) { /* TRANSLATORS: battery state */ return _("Laptop battery is charging"); } if (state == UP_DEVICE_STATE_DISCHARGING) { /* TRANSLATORS: battery state */ return _("Laptop battery is discharging"); } if (state == UP_DEVICE_STATE_EMPTY) { /* TRANSLATORS: battery state */ return _("Laptop battery is empty"); } if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* TRANSLATORS: battery state */ return _("Laptop battery is charged"); } if (state == UP_DEVICE_STATE_PENDING_CHARGE) { /* TRANSLATORS: battery state */ return _("Laptop battery is waiting to charge"); } if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) { /* TRANSLATORS: battery state */ return _("Laptop battery is waiting to discharge"); } } /* UPS */ if (kind == UP_DEVICE_KIND_UPS) { if (state == UP_DEVICE_STATE_CHARGING) { /* TRANSLATORS: battery state */ return _("UPS is charging"); } if (state == UP_DEVICE_STATE_DISCHARGING) { /* TRANSLATORS: battery state */ return _("UPS is discharging"); } if (state == UP_DEVICE_STATE_EMPTY) { /* TRANSLATORS: battery state */ return _("UPS is empty"); } if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* TRANSLATORS: battery state */ return _("UPS is charged"); } } /* mouse */ if (kind == UP_DEVICE_KIND_MOUSE) { if (state == UP_DEVICE_STATE_CHARGING) { /* TRANSLATORS: battery state */ return _("Mouse is charging"); } if (state == UP_DEVICE_STATE_DISCHARGING) { /* TRANSLATORS: battery state */ return _("Mouse is discharging"); } if (state == UP_DEVICE_STATE_EMPTY) { /* TRANSLATORS: battery state */ return _("Mouse is empty"); } if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* TRANSLATORS: battery state */ return _("Mouse is charged"); } } /* keyboard */ if (kind == UP_DEVICE_KIND_KEYBOARD) { if (state == UP_DEVICE_STATE_CHARGING) { /* TRANSLATORS: battery state */ return _("Keyboard is charging"); } if (state == UP_DEVICE_STATE_DISCHARGING) { /* TRANSLATORS: battery state */ return _("Keyboard is discharging"); } if (state == UP_DEVICE_STATE_EMPTY) { /* TRANSLATORS: battery state */ return _("Keyboard is empty"); } if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* TRANSLATORS: battery state */ return _("Keyboard is charged"); } } /* PDA */ if (kind == UP_DEVICE_KIND_PDA) { if (state == UP_DEVICE_STATE_CHARGING) { /* TRANSLATORS: battery state */ return _("PDA is charging"); } if (state == UP_DEVICE_STATE_DISCHARGING) { /* TRANSLATORS: battery state */ return _("PDA is discharging"); } if (state == UP_DEVICE_STATE_EMPTY) { /* TRANSLATORS: battery state */ return _("PDA is empty"); } if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* TRANSLATORS: battery state */ return _("PDA is charged"); } } /* phone */ if (kind == UP_DEVICE_KIND_PHONE) { if (state == UP_DEVICE_STATE_CHARGING) { /* TRANSLATORS: battery state */ return _("Cell phone is charging"); } if (state == UP_DEVICE_STATE_DISCHARGING) { /* TRANSLATORS: battery state */ return _("Cell phone is discharging"); } if (state == UP_DEVICE_STATE_EMPTY) { /* TRANSLATORS: battery state */ return _("Cell phone is empty"); } if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* TRANSLATORS: battery state */ return _("Cell phone is charged"); } } #if UP_CHECK_VERSION(0,9,5) /* media player */ if (kind == UP_DEVICE_KIND_MEDIA_PLAYER) { if (state == UP_DEVICE_STATE_CHARGING) { /* TRANSLATORS: battery state */ return _("Media player is charging"); } if (state == UP_DEVICE_STATE_DISCHARGING) { /* TRANSLATORS: battery state */ return _("Media player is discharging"); } if (state == UP_DEVICE_STATE_EMPTY) { /* TRANSLATORS: battery state */ return _("Media player is empty"); } if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* TRANSLATORS: battery state */ return _("Media player is charged"); } } /* tablet */ if (kind == UP_DEVICE_KIND_TABLET) { if (state == UP_DEVICE_STATE_CHARGING) { /* TRANSLATORS: battery state */ return _("Tablet is charging"); } if (state == UP_DEVICE_STATE_DISCHARGING) { /* TRANSLATORS: battery state */ return _("Tablet is discharging"); } if (state == UP_DEVICE_STATE_EMPTY) { /* TRANSLATORS: battery state */ return _("Tablet is empty"); } if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* TRANSLATORS: battery state */ return _("Tablet is charged"); } } /* computer */ if (kind == UP_DEVICE_KIND_COMPUTER) { if (state == UP_DEVICE_STATE_CHARGING) { /* TRANSLATORS: battery state */ return _("Computer is charging"); } if (state == UP_DEVICE_STATE_DISCHARGING) { /* TRANSLATORS: battery state */ return _("Computer is discharging"); } if (state == UP_DEVICE_STATE_EMPTY) { /* TRANSLATORS: battery state */ return _("Computer is empty"); } if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* TRANSLATORS: battery state */ return _("Computer is charged"); } } #endif return gpm_device_kind_to_localised_string (kind, 1); } static gboolean parse_vm_kernel_cmdline (gboolean *is_virtual_machine) { gboolean ret = FALSE; GRegex *regex; GMatchInfo *match; char *contents; char *word; const char *arg; if (!g_file_get_contents ("/proc/cmdline", &contents, NULL, NULL)) return ret; regex = g_regex_new ("gnome.is_vm=(\\S+)", 0, G_REGEX_MATCH_NOTEMPTY, NULL); if (!g_regex_match (regex, contents, G_REGEX_MATCH_NOTEMPTY, &match)) goto out; word = g_match_info_fetch (match, 0); g_debug ("Found command-line match '%s'", word); arg = word + strlen ("gnome.is_vm="); if (*arg != '0' && *arg != '1') { g_warning ("Invalid value '%s' for gnome.is_vm passed in kernel command line.\n", arg); } else { *is_virtual_machine = atoi (arg); ret = TRUE; } g_free (word); out: g_match_info_free (match); g_regex_unref (regex); g_free (contents); if (ret) g_debug ("Kernel command-line parsed to %d", *is_virtual_machine); return ret; } gboolean gsd_power_is_hardware_a_vm (void) { const gchar *str; gboolean ret = FALSE; GError *error = NULL; GVariant *inner; GVariant *variant = NULL; GDBusConnection *connection; if (parse_vm_kernel_cmdline (&ret)) return ret; connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (connection == NULL) { g_warning ("system bus not available: %s", error->message); g_error_free (error); goto out; } variant = g_dbus_connection_call_sync (connection, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.DBus.Properties", "Get", g_variant_new ("(ss)", "org.freedesktop.systemd1.Manager", "Virtualization"), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (variant == NULL) { g_debug ("Failed to get property '%s': %s", "Virtualization", error->message); g_error_free (error); goto out; } /* on bare-metal hardware this is the empty string, * otherwise an identifier such as "kvm", "vmware", etc. */ g_variant_get (variant, "(v)", &inner); str = g_variant_get_string (inner, NULL); if (str != NULL && str[0] != '\0') ret = TRUE; out: if (connection != NULL) g_object_unref (connection); if (variant != NULL) g_variant_unref (variant); return ret; } /* This timer goes off every few minutes, whether the user is idle or not, to try and clean up anything that has gone wrong. It calls disable_builtin_screensaver() so that if xset has been used, or some other program (like xlock) has messed with the XSetScreenSaver() settings, they will be set back to sensible values (if a server extension is in use, messing with xlock can cause the screensaver to never get a wakeup event, and could cause monitor power-saving to occur, and all manner of heinousness.) This code was originally part of gnome-screensaver, see http://git.gnome.org/browse/gnome-screensaver/tree/src/gs-watcher-x11.c?id=fec00b12ec46c86334cfd36b37771cc4632f0d4d#n530 */ static gboolean disable_builtin_screensaver (gpointer unused) { int current_server_timeout, current_server_interval; int current_prefer_blank, current_allow_exp; int desired_server_timeout, desired_server_interval; int desired_prefer_blank, desired_allow_exp; XGetScreenSaver (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), ¤t_server_timeout, ¤t_server_interval, ¤t_prefer_blank, ¤t_allow_exp); desired_server_timeout = current_server_timeout; desired_server_interval = current_server_interval; desired_prefer_blank = current_prefer_blank; desired_allow_exp = current_allow_exp; desired_server_interval = 0; /* I suspect (but am not sure) that DontAllowExposures might have something to do with powering off the monitor as well, at least on some systems that don't support XDPMS? Who know... */ desired_allow_exp = AllowExposures; /* When we're not using an extension, set the server-side timeout to 0, so that the server never gets involved with screen blanking, and we do it all ourselves. (However, when we *are* using an extension, we tell the server when to notify us, and rather than blanking the screen, the server will send us an X event telling us to blank.) */ desired_server_timeout = 0; if (desired_server_timeout != current_server_timeout || desired_server_interval != current_server_interval || desired_prefer_blank != current_prefer_blank || desired_allow_exp != current_allow_exp) { g_debug ("disabling server builtin screensaver:" " (xset s %d %d; xset s %s; xset s %s)", desired_server_timeout, desired_server_interval, (desired_prefer_blank ? "blank" : "noblank"), (desired_allow_exp ? "expose" : "noexpose")); XSetScreenSaver (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), desired_server_timeout, desired_server_interval, desired_prefer_blank, desired_allow_exp); XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), FALSE); } return TRUE; } guint gsd_power_enable_screensaver_watchdog (void) { int dummy; /* Make sure that Xorg's DPMS extension never gets in our * way. The defaults are now applied in Fedora 20 from * being "0" by default to being "600" by default */ gdk_error_trap_push (); if (DPMSQueryExtension(GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &dummy, &dummy)) DPMSSetTimeouts (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), 0, 0, 0); gdk_error_trap_pop_ignored (); return g_timeout_add_seconds (XSCREENSAVER_WATCHDOG_TIMEOUT, disable_builtin_screensaver, NULL); } static GsdRROutput * get_primary_output (GsdRRScreen *rr_screen) { GsdRROutput *output = NULL; GsdRROutput **outputs; guint i; /* search all X11 outputs for the device id */ outputs = gsd_rr_screen_list_outputs (rr_screen); if (outputs == NULL) goto out; for (i = 0; outputs[i] != NULL; i++) { if (gsd_rr_output_is_connected (outputs[i]) && gsd_rr_output_is_laptop (outputs[i]) && gsd_rr_output_get_backlight_min (outputs[i]) >= 0 && gsd_rr_output_get_backlight_max (outputs[i]) > 0) { output = outputs[i]; break; } } out: return output; } #ifdef GSD_MOCK static void backlight_set_mock_value (gint value) { const char *filename; char *contents; g_debug ("Settings mock brightness: %d", value); filename = "GSD_MOCK_brightness"; contents = g_strdup_printf ("%d", value); g_file_set_contents (filename, contents, -1, NULL); g_free (contents); } static gint64 backlight_get_mock_value (const char *argument) { const char *filename; char *contents; gint64 ret; if (g_str_equal (argument, "get-max-brightness")) { g_debug ("Returning max mock brightness: %d", GSD_MOCK_MAX_BRIGHTNESS); return GSD_MOCK_MAX_BRIGHTNESS; } if (g_str_equal (argument, "get-brightness")) { filename = "GSD_MOCK_brightness"; ret = GSD_MOCK_DEFAULT_BRIGHTNESS; } else { g_assert_not_reached (); } if (g_file_get_contents (filename, &contents, NULL, NULL)) { ret = g_ascii_strtoll (contents, NULL, 0); g_free (contents); g_debug ("Returning mock brightness: %"G_GINT64_FORMAT, ret); } else { ret = GSD_MOCK_DEFAULT_BRIGHTNESS; backlight_set_mock_value (GSD_MOCK_DEFAULT_BRIGHTNESS); g_debug ("Returning default mock brightness: %"G_GINT64_FORMAT, ret); } return ret; } #endif /* GSD_MOCK */ gboolean backlight_available (GsdRRScreen *rr_screen) { char *path; #ifdef GSD_MOCK return TRUE; #endif if (get_primary_output (rr_screen) != NULL) return TRUE; path = gsd_backlight_helper_get_best_backlight (NULL); if (path == NULL) return FALSE; g_free (path); return TRUE; } /** * backlight_helper_get_value: * * Gets a brightness value from the PolicyKit helper. * * Return value: the signed integer value from the helper, or -1 * for failure. If -1 then @error is set. **/ static gint64 backlight_helper_get_value (const gchar *argument, GError **error) { gboolean ret; gchar *stdout_data = NULL; gint exit_status = 0; gint64 value = -1; gchar *command = NULL; gchar *endptr = NULL; #ifdef GSD_MOCK return backlight_get_mock_value (argument); #endif #ifndef __linux__ /* non-Linux platforms won't have /sys/class/backlight */ g_set_error_literal (error, GSD_POWER_MANAGER_ERROR, GSD_POWER_MANAGER_ERROR_FAILED, "The sysfs backlight helper is only for Linux"); goto out; #endif /* get the data */ command = g_strdup_printf (LIBEXECDIR "/usd-backlight-helper --%s", argument); ret = g_spawn_command_line_sync (command, &stdout_data, NULL, &exit_status, error); g_debug ("executed %s retval: %i", command, exit_status); if (!ret) goto out; if (WEXITSTATUS (exit_status) != 0) { g_set_error (error, GSD_POWER_MANAGER_ERROR, GSD_POWER_MANAGER_ERROR_FAILED, "usd-backlight-helper failed: %s", stdout_data ? stdout_data : "No reason"); goto out; } /* parse */ value = g_ascii_strtoll (stdout_data, &endptr, 10); /* parsing error */ if (endptr == stdout_data) { value = -1; g_set_error (error, GSD_POWER_MANAGER_ERROR, GSD_POWER_MANAGER_ERROR_FAILED, "failed to parse value: %s", stdout_data); goto out; } /* out of range */ if (value > G_MAXINT) { value = -1; g_set_error (error, GSD_POWER_MANAGER_ERROR, GSD_POWER_MANAGER_ERROR_FAILED, "value out of range: %s", stdout_data); goto out; } /* Fetching the value failed, for some other reason */ if (value < 0) { g_set_error (error, GSD_POWER_MANAGER_ERROR, GSD_POWER_MANAGER_ERROR_FAILED, "value negative, but helper did not fail: %s", stdout_data); goto out; } out: g_free (command); g_free (stdout_data); return value; } /** * backlight_helper_set_value: * * Sets a brightness value using the PolicyKit helper. * * Return value: Success. If FALSE then @error is set. **/ static gboolean backlight_helper_set_value (const gchar *argument, gint value, GError **error) { gboolean ret = FALSE; gint exit_status = 0; gchar *command = NULL; #ifdef GSD_MOCK backlight_set_mock_value (value); return TRUE; #endif #ifndef __linux__ /* non-Linux platforms won't have /sys/class/backlight */ g_set_error_literal (error, GSD_POWER_MANAGER_ERROR, GSD_POWER_MANAGER_ERROR_FAILED, "The sysfs backlight helper is only for Linux"); goto out; #endif /* get the data */ command = g_strdup_printf ("pkexec " LIBEXECDIR "/usd-backlight-helper --%s %i", argument, value); ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, error); g_debug ("executed %s retval: %i", command, exit_status); if (!ret || WEXITSTATUS (exit_status) != 0) goto out; out: g_free (command); return ret; } int backlight_get_abs (GsdRRScreen *rr_screen, GError **error) { GsdRROutput *output; /* prefer xbacklight */ output = get_primary_output (rr_screen); if (output != NULL) { return gsd_rr_output_get_backlight (output, error); } /* fall back to the polkit helper */ return backlight_helper_get_value ("get-brightness", error); } int backlight_get_percentage (GsdRRScreen *rr_screen, GError **error) { GsdRROutput *output; gint now; gint value = -1; gint min = 0; gint max; /* prefer xbacklight */ output = get_primary_output (rr_screen); if (output != NULL) { min = gsd_rr_output_get_backlight_min (output); max = gsd_rr_output_get_backlight_max (output); now = gsd_rr_output_get_backlight (output, error); if (now < 0) goto out; value = ABS_TO_PERCENTAGE (min, max, now); goto out; } /* fall back to the polkit helper */ max = backlight_helper_get_value ("get-max-brightness", error); if (max < 0) goto out; now = backlight_helper_get_value ("get-brightness", error); if (now < 0) goto out; value = ABS_TO_PERCENTAGE (min, max, now); out: return value; } int backlight_get_min (GsdRRScreen *rr_screen) { GsdRROutput *output; /* if we have no xbacklight device, then hardcode zero as sysfs * offsets everything to 0 as min */ output = get_primary_output (rr_screen); if (output == NULL) return 0; /* get xbacklight value, which maybe non-zero */ return gsd_rr_output_get_backlight_min (output); } int backlight_get_max (GsdRRScreen *rr_screen, GError **error) { gint value; GsdRROutput *output; /* prefer xbacklight */ output = get_primary_output (rr_screen); if (output != NULL) { value = gsd_rr_output_get_backlight_max (output); if (value < 0) { g_set_error (error, GSD_POWER_MANAGER_ERROR, GSD_POWER_MANAGER_ERROR_FAILED, "failed to get backlight max"); } return value; } /* fall back to the polkit helper */ return backlight_helper_get_value ("get-max-brightness", error); } gboolean backlight_set_percentage (GsdRRScreen *rr_screen, guint value, GError **error) { GsdRROutput *output; gboolean ret = FALSE; gint min = 0; gint max; guint discrete; /* prefer xbacklight */ output = get_primary_output (rr_screen); if (output != NULL) { min = gsd_rr_output_get_backlight_min (output); max = gsd_rr_output_get_backlight_max (output); if (min < 0 || max < 0) { g_warning ("no xrandr backlight capability"); return ret; } discrete = PERCENTAGE_TO_ABS (min, max, value); ret = gsd_rr_output_set_backlight (output, discrete, error); return ret; } /* fall back to the polkit helper */ max = backlight_helper_get_value ("get-max-brightness", error); if (max < 0) return ret; discrete = PERCENTAGE_TO_ABS (min, max, value); ret = backlight_helper_set_value ("set-brightness", discrete, error); return ret; } int backlight_step_up (GsdRRScreen *rr_screen, GError **error) { GsdRROutput *output; gboolean ret = FALSE; gint percentage_value = -1; gint min = 0; gint max; gint now; gint step; guint discrete; GsdRRCrtc *crtc; /* prefer xbacklight */ output = get_primary_output (rr_screen); if (output != NULL) { crtc = gsd_rr_output_get_crtc (output); if (crtc == NULL) { g_set_error (error, GSD_POWER_MANAGER_ERROR, GSD_POWER_MANAGER_ERROR_FAILED, "no crtc for %s", gsd_rr_output_get_name (output)); return percentage_value; } min = gsd_rr_output_get_backlight_min (output); max = gsd_rr_output_get_backlight_max (output); now = gsd_rr_output_get_backlight (output, error); if (now < 0) return percentage_value; step = BRIGHTNESS_STEP_AMOUNT (max - min + 1); discrete = MIN (now + step, max); ret = gsd_rr_output_set_backlight (output, discrete, error); if (ret) percentage_value = ABS_TO_PERCENTAGE (min, max, discrete); return percentage_value; } /* fall back to the polkit helper */ now = backlight_helper_get_value ("get-brightness", error); if (now < 0) return percentage_value; max = backlight_helper_get_value ("get-max-brightness", error); if (max < 0) return percentage_value; step = BRIGHTNESS_STEP_AMOUNT (max - min + 1); discrete = MIN (now + step, max); ret = backlight_helper_set_value ("set-brightness", discrete, error); if (ret) percentage_value = ABS_TO_PERCENTAGE (min, max, discrete); return percentage_value; } int backlight_step_down (GsdRRScreen *rr_screen, GError **error) { GsdRROutput *output; gboolean ret = FALSE; gint percentage_value = -1; gint min = 0; gint max; gint now; gint step; guint discrete; GsdRRCrtc *crtc; /* prefer xbacklight */ output = get_primary_output (rr_screen); if (output != NULL) { crtc = gsd_rr_output_get_crtc (output); if (crtc == NULL) { g_set_error (error, GSD_POWER_MANAGER_ERROR, GSD_POWER_MANAGER_ERROR_FAILED, "no crtc for %s", gsd_rr_output_get_name (output)); return percentage_value; } min = gsd_rr_output_get_backlight_min (output); max = gsd_rr_output_get_backlight_max (output); now = gsd_rr_output_get_backlight (output, error); if (now < 0) return percentage_value; step = BRIGHTNESS_STEP_AMOUNT (max - min + 1); discrete = MAX (now - step, 0); ret = gsd_rr_output_set_backlight (output, discrete, error); if (ret) percentage_value = ABS_TO_PERCENTAGE (min, max, discrete); return percentage_value; } /* fall back to the polkit helper */ now = backlight_helper_get_value ("get-brightness", error); if (now < 0) return percentage_value; max = backlight_helper_get_value ("get-max-brightness", error); if (max < 0) return percentage_value; step = BRIGHTNESS_STEP_AMOUNT (max - min + 1); discrete = MAX (now - step, 0); ret = backlight_helper_set_value ("set-brightness", discrete, error); if (ret) percentage_value = ABS_TO_PERCENTAGE (min, max, discrete); return percentage_value; } int backlight_set_abs (GsdRRScreen *rr_screen, guint value, GError **error) { GsdRROutput *output; gboolean ret = FALSE; /* prefer xbacklight */ output = get_primary_output (rr_screen); if (output != NULL) { ret = gsd_rr_output_set_backlight (output, value, error); return ret; } /* fall back to the polkit helper */ ret = backlight_helper_set_value ("set-brightness", value, error); return ret; } void reset_idletime (void) { static gboolean inited = FALSE; static KeyCode keycode1, keycode2; static gboolean first_keycode = FALSE; if (inited == FALSE) { keycode1 = XKeysymToKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_KEY_Shift_L); keycode2 = XKeysymToKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_KEY_Shift_R); } gdk_error_trap_push (); /* send a left or right alt key; first press, then release */ XTestFakeKeyEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), first_keycode ? keycode1 : keycode2, True, CurrentTime); XTestFakeKeyEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), first_keycode ? keycode1 : keycode2, False, CurrentTime); first_keycode = !first_keycode; gdk_error_trap_pop_ignored (); } static gboolean randr_output_is_on (GsdRROutput *output) { GsdRRCrtc *crtc; crtc = gsd_rr_output_get_crtc (output); if (!crtc) return FALSE; return gsd_rr_crtc_get_current_mode (crtc) != NULL; } gboolean external_monitor_is_connected (GsdRRScreen *screen) { GsdRROutput **outputs; guint i; #ifdef GSD_MOCK char *mock_external_monitor_contents; if (g_file_get_contents ("GSD_MOCK_EXTERNAL_MONITOR", &mock_external_monitor_contents, NULL, NULL)) { if (mock_external_monitor_contents[0] == '1') { g_free (mock_external_monitor_contents); return TRUE; } else if (mock_external_monitor_contents[0] == '0') { g_free (mock_external_monitor_contents); return FALSE; } g_warning ("Unhandled value for GSD_MOCK_EXTERNAL_MONITOR contents: %s", mock_external_monitor_contents); g_free (mock_external_monitor_contents); } #endif /* GSD_MOCK */ /* see if we have more than one screen plugged in */ outputs = gsd_rr_screen_list_outputs (screen); for (i = 0; outputs[i] != NULL; i++) { if (randr_output_is_on (outputs[i]) && !gsd_rr_output_is_laptop (outputs[i])) return TRUE; } return FALSE; } static void play_sound (void) { ca_context_play (ca_gtk_context_get (), UPS_SOUND_LOOP_ID, CA_PROP_EVENT_ID, "battery-caution", CA_PROP_EVENT_DESCRIPTION, _("Battery is critically low"), NULL); } static gboolean play_loop_timeout_cb (gpointer user_data) { play_sound (); return TRUE; } void play_loop_start (guint *id) { if (*id != 0) return; *id = g_timeout_add_seconds (GSD_POWER_MANAGER_CRITICAL_ALERT_TIMEOUT, (GSourceFunc) play_loop_timeout_cb, NULL); play_sound (); } void play_loop_stop (guint *id) { if (*id == 0) return; ca_context_cancel (ca_gtk_context_get (), UPS_SOUND_LOOP_ID); g_source_remove (*id); *id = 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gpm-common.h0000664000175000017500000000771100000000000024103 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2005-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __GPMCOMMON_H #define __GPMCOMMON_H #include #include #include "gsd-rr.h" G_BEGIN_DECLS /* UPower helpers */ gchar *gpm_get_timestring (guint time); const gchar *gpm_device_to_localised_string (UpDevice *device); const gchar *gpm_device_kind_to_localised_string (UpDeviceKind kind, guint number); const gchar *gpm_device_kind_to_icon (UpDeviceKind kind); const gchar *gpm_device_technology_to_localised_string (UpDeviceTechnology technology_enum); const gchar *gpm_device_state_to_localised_string (UpDeviceState state); GIcon *gpm_upower_get_device_icon (UpDevice *device, gboolean use_symbolic); gchar *gpm_upower_get_device_summary (UpDevice *device); gchar *gpm_upower_get_device_description (UpDevice *device); /* Power helpers */ gboolean gsd_power_is_hardware_a_vm (void); guint gsd_power_enable_screensaver_watchdog (void); void reset_idletime (void); /* Backlight helpers */ /* on ACPI machines we have 4-16 levels, on others it's ~150 */ #define BRIGHTNESS_STEP_AMOUNT(max) ((max) < 20 ? 1 : (max) / 20) #define ABS_TO_PERCENTAGE(min, max, value) gsd_power_backlight_abs_to_percentage(min, max, value) #define PERCENTAGE_TO_ABS(min, max, value) (min + (((max - min) * value) / 100)) int gsd_power_backlight_abs_to_percentage (int min, int max, int value); gboolean backlight_available (GsdRRScreen *rr_screen); int backlight_get_abs (GsdRRScreen *rr_screen, GError **error); int backlight_get_percentage (GsdRRScreen *rr_screen, GError **error); int backlight_get_min (GsdRRScreen *rr_screen); int backlight_get_max (GsdRRScreen *rr_screen, GError **error); gboolean backlight_set_percentage (GsdRRScreen *rr_screen, guint value, GError **error); int backlight_step_up (GsdRRScreen *rr_screen, GError **error); int backlight_step_down (GsdRRScreen *rr_screen, GError **error); int backlight_set_abs (GsdRRScreen *rr_screen, guint value, GError **error); /* RandR helpers */ gboolean external_monitor_is_connected (GsdRRScreen *screen); /* Sound helpers */ void play_loop_start (guint *id); void play_loop_stop (guint *id); G_END_DECLS #endif /* __GPMCOMMON_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsd-backlight-helper.c0000664000175000017500000001623400000000000026005 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2010-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #include #include #include #include #include #include #include #include "gsd-backlight-linux.h" #define GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS 0 #define GSD_BACKLIGHT_HELPER_EXIT_CODE_FAILED 1 #define GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID 3 #define GSD_BACKLIGHT_HELPER_EXIT_CODE_INVALID_USER 4 #define GSD_BACKLIGHT_HELPER_EXIT_CODE_NO_DEVICES 5 static gboolean gsd_backlight_helper_write (const gchar *filename, gint value, GError **error) { gchar *filename_path = NULL; gchar *text = NULL; gint retval; gint length; gint fd = -1; gboolean ret = TRUE; filename_path = g_build_filename (filename, "brightness", NULL); fd = open (filename_path, O_WRONLY); if (fd < 0) { ret = FALSE; g_set_error (error, 1, 0, "failed to open filename: %s", filename); goto out; } /* convert to text */ text = g_strdup_printf ("%i", value); length = strlen (text); /* write to device file */ retval = write (fd, text, length); if (retval != length) { ret = FALSE; g_set_error (error, 1, 0, "writing '%s' to %s failed", text, filename); goto out; } out: if (fd >= 0) close (fd); g_free (text); g_free (filename_path); return ret; } static gint gsd_backlight_helper_read_value (const gchar *filename, GError **error) { gchar *contents = NULL; gint value; if (g_file_get_contents (filename, &contents, NULL, error)) value = atoi (contents); else value = -1; g_free (contents); if (value < 0 && *error == NULL) g_set_error (error, 1, 0, "got invalid backlight value from %s", filename); return value; } static gint gsd_backlight_helper_get (const gchar *filename, GError **error) { gchar *filename_path = NULL; gint value; filename_path = g_build_filename (filename, "brightness", NULL); value = gsd_backlight_helper_read_value (filename_path, error); g_free (filename_path); return value; } static gint gsd_backlight_helper_get_max (const gchar *filename, GError **error) { gchar *filename_path = NULL; gint value; filename_path = g_build_filename (filename, "max_brightness", NULL); value = gsd_backlight_helper_read_value (filename_path, error); g_free (filename_path); return value; } static gint clamp_minimum (gint max, gint value) { gint minimum; /* If the interface has less than 100 possible values, it's * likely that 0 doesn't turn the backlight off so we let 0 be * set in that case. */ if (max > 99) minimum = 1; else minimum = 0; return MAX (value, minimum); } int main (int argc, char *argv[]) { GOptionContext *context; gint uid; gint euid; guint retval = 0; GError *error = NULL; gint set_brightness = -1; gboolean get_brightness = FALSE; gboolean get_max_brightness = FALSE; gchar *filename = NULL; GsdBacklightType type; const GOptionEntry options[] = { { "set-brightness", '\0', 0, G_OPTION_ARG_INT, &set_brightness, /* command line argument */ "Set the current brightness", NULL }, { "get-brightness", '\0', 0, G_OPTION_ARG_NONE, &get_brightness, /* command line argument */ "Get the current brightness", NULL }, { "get-max-brightness", '\0', 0, G_OPTION_ARG_NONE, &get_max_brightness, /* command line argument */ "Get the number of brightness levels supported", NULL }, { NULL} }; context = g_option_context_new (NULL); g_option_context_set_summary (context, "GNOME Settings Daemon Backlight Helper"); g_option_context_add_main_entries (context, options, NULL); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); #ifndef __linux__ /* the g-s-d plugin should only call this helper on linux */ g_critical ("Attempting to call gsb-backlight-helper on non-Linux"); g_assert_not_reached (); #endif /* no input */ if (set_brightness == -1 && !get_brightness && !get_max_brightness) { g_print ("%s\n", "No valid option was specified"); retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID; goto out; } /* find device */ filename = gsd_backlight_helper_get_best_backlight (&type); if (filename == NULL) { retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_NO_DEVICES; g_print ("%s: %s\n", "Could not get or set the value of the backlight", "No backlight devices present"); goto out; } /* GetBrightness */ if (get_brightness) { gint value; value = gsd_backlight_helper_get (filename, &error); if (value < 0) { g_print ("%s: %s\n", "Could not get the value of the backlight", error->message); g_error_free (error); retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID; goto out; } /* just print the contents to stdout */ g_print ("%d", value); retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS; goto out; } /* GetSteps */ if (get_max_brightness) { gint value; value = gsd_backlight_helper_get_max (filename, &error); if (value < 0) { g_print ("%s: %s\n", "Could not get the maximum value of the backlight", error->message); g_error_free (error); retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID; goto out; } /* just print the contents to stdout */ g_print ("%d", value); retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS; goto out; } /* check calling UID */ uid = getuid (); euid = geteuid (); if (uid != 0 || euid != 0) { g_print ("%s\n", "This program can only be used by the root user"); retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID; goto out; } /* SetBrightness */ if (set_brightness != -1) { gboolean ret = FALSE; gint max = gsd_backlight_helper_get_max (filename, &error); if (max < 0) { g_print ("%s: %s\n", "Could not get the maximum value of the backlight", error->message); g_error_free (error); retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID; goto out; } if (type == GSD_BACKLIGHT_TYPE_RAW) set_brightness = clamp_minimum (max, set_brightness); ret = gsd_backlight_helper_write (filename, set_brightness, &error); if (!ret) { g_print ("%s: %s\n", "Could not set the value of the backlight", error->message); g_error_free (error); retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID; goto out; } } /* success */ retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_SUCCESS; out: g_free (filename); return retval; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsd-backlight-linux.c0000664000175000017500000000644100000000000025664 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2010-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include "config.h" #include "gsd-backlight-linux.h" #ifdef HAVE_GUDEV #include static gchar * gsd_backlight_helper_get_type (GList *devices, const gchar *type) { const gchar *type_tmp; GList *d; for (d = devices; d != NULL; d = d->next) { type_tmp = g_udev_device_get_sysfs_attr (d->data, "type"); if (g_strcmp0 (type_tmp, type) == 0) return g_strdup (g_udev_device_get_sysfs_path (d->data)); } return NULL; } /* * Search for a raw backlight interface, raw backlight interfaces registered * by the drm driver will have the drm-connector as their parent, check the * drm-connector's enabled sysfs attribute so that we pick the right LCD-panel * connector on laptops with hybrid-gfx. Fall back to just picking the first * raw backlight interface if no enabled interface is found. */ static gchar * gsd_backlight_helper_get_raw (GList *devices) { GUdevDevice *parent; const gchar *attr; GList *d; for (d = devices; d != NULL; d = d->next) { attr = g_udev_device_get_sysfs_attr (d->data, "type"); if (g_strcmp0 (attr, "raw") != 0) continue; parent = g_udev_device_get_parent (d->data); if (!parent) continue; attr = g_udev_device_get_sysfs_attr (parent, "enabled"); if (!attr || g_strcmp0 (attr, "enabled") != 0) continue; return g_strdup (g_udev_device_get_sysfs_path (d->data)); } return gsd_backlight_helper_get_type (devices, "raw"); } #endif /* HAVE_GUDEV */ char * gsd_backlight_helper_get_best_backlight (GsdBacklightType *type) { #ifdef HAVE_GUDEV gchar *path = NULL; GList *devices; GUdevClient *client; client = g_udev_client_new (NULL); devices = g_udev_client_query_by_subsystem (client, "backlight"); if (devices == NULL) goto out; /* search the backlight devices and prefer the types: * firmware -> platform -> raw */ path = gsd_backlight_helper_get_type (devices, "firmware"); if (path != NULL) { if (type) *type = GSD_BACKLIGHT_TYPE_FIRMWARE; goto out; } path = gsd_backlight_helper_get_type (devices, "platform"); if (path != NULL) { if (type) *type = GSD_BACKLIGHT_TYPE_PLATFORM; goto out; } path = gsd_backlight_helper_get_raw (devices); if (path != NULL) { if (type) *type = GSD_BACKLIGHT_TYPE_RAW; goto out; } out: g_object_unref (client); g_list_foreach (devices, (GFunc) g_object_unref, NULL); g_list_free (devices); return path; #endif /* HAVE_GUDEV */ return NULL; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsd-backlight-linux.h0000664000175000017500000000214000000000000025661 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2010-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ typedef enum { GSD_BACKLIGHT_TYPE_FIRMWARE, GSD_BACKLIGHT_TYPE_PLATFORM, GSD_BACKLIGHT_TYPE_RAW, } GsdBacklightType; char *gsd_backlight_helper_get_best_backlight (GsdBacklightType *type); ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsd-power-constants-update.pl0000775000175000017500000000254200000000000027417 0ustar00jeremyjeremy#!/usr/bin/env perl # Author : Simos Xenitellis . # Author : Bastien Nocera # Version : 1.2 # # Input : gsd-power-constants.h # Output : gsdpowerconstants.py # use strict; # Used for reading the keysymdef symbols. my @constantselements; die "Could not open file gsd-power-constants.h: $!\n" unless open(IN_CONSTANTS, "<:utf8", "gsd-power-constants.h"); # Output: gtk+/gdk/gdkkeysyms.h die "Could not open file gsdpowerconstants.py: $!\n" unless open(OUT_CONSTANTS, ">:utf8", "gsdpowerconstants.py"); print OUT_CONSTANTS<) { next if ( ! /^#define / ); @constantselements = split(/\s+/); die "Internal error, no \@constantselements: $_\n" unless @constantselements; my $constant = $constantselements[1]; my $value = $constantselements[2]; printf OUT_CONSTANTS "%s = %s;\n", $constant, $value; } close IN_CONSTANTS; printf "We just finished converting gsd-power-constants.h to gsdpowerconstants.py\nThank you\n"; ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsd-power-constants.h0000664000175000017500000000330500000000000025746 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2013 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ /* The blank delay when the screensaver is active */ #define SCREENSAVER_TIMEOUT_BLANK 15 /* seconds */ /* The dim delay when dimming on idle is requested but idle-delay * is set to "Never" */ #define IDLE_DIM_BLANK_DISABLED_MIN 60 /* seconds */ /* Which fraction of the idle-delay is the idle-dim delay */ #define IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER 4.0/5.0 /* The dim delay under which we do not bother dimming */ #define MINIMUM_IDLE_DIM_DELAY 10 /* seconds */ /* The amount of time we'll undim if the machine is idle when plugged in */ #define POWER_UP_TIME_ON_AC 15 /* seconds */ /* Default brightness values for the mock backlight used in the test suite */ #define GSD_MOCK_DEFAULT_BRIGHTNESS 50 #define GSD_MOCK_MAX_BRIGHTNESS 100 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsd-power-enums-update.c0000664000175000017500000000160600000000000026336 0ustar00jeremyjeremy#include #include static void output_enum_values (GType class_type) { GEnumClass *eclass; guint i; eclass = G_ENUM_CLASS (g_type_class_peek (class_type)); for (i = 0; i < eclass->n_values; i++) { GEnumValue *value = &(eclass->values[i]); g_print ("%s = %d;\n", value->value_name, value->value); } } static void output_flags_values (GType class_type) { GFlagsClass *fclass; guint i; fclass = G_FLAGS_CLASS (g_type_class_peek (class_type)); for (i = 0; i < fclass->n_values; i++) { GFlagsValue *value = &(fclass->values[i]); g_print ("%s = %d;\n", value->value_name, value->value); } } int main (int argc, char **argv) { g_type_class_ref (GSD_POWER_TYPE_INHIBITOR_FLAG); g_type_class_ref (GSD_POWER_TYPE_PRESENCE_STATUS); output_flags_values (GSD_POWER_TYPE_INHIBITOR_FLAG); output_enum_values (GSD_POWER_TYPE_PRESENCE_STATUS); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsd-power-manager.c0000664000175000017500000044113400000000000025345 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * Copyright (C) 2011-2012 Richard Hughes * Copyright (C) 2011 Ritesh Khadgaray * Copyright (C) 2012-2013 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #define UPOWER_ENABLE_DEPRECATED 1 #include #include #include #include #include #include #include "gsd-power-constants.h" #include "gsm-inhibitor-flag.h" #include "gsm-presence-flag.h" #include "gsm-manager-logout-mode.h" #include "gpm-common.h" #include "gnome-settings-plugin.h" #include "gnome-settings-profile.h" #include "gnome-settings-bus.h" #include "gsd-enums.h" #include "gsd-power-manager.h" #include "gsd-rr.h" #include "gsd-idle-monitor.h" #define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager" #define GNOME_SESSION_DBUS_PATH_PRESENCE "/org/gnome/SessionManager/Presence" #define GNOME_SESSION_DBUS_INTERFACE_PRESENCE "org.gnome.SessionManager.Presence" #define UPOWER_DBUS_NAME "org.freedesktop.UPower" #define UPOWER_DBUS_PATH "/org/freedesktop/UPower" #define UPOWER_DBUS_PATH_KBDBACKLIGHT "/org/freedesktop/UPower/KbdBacklight" #define UPOWER_DBUS_INTERFACE "org.freedesktop.UPower" #define UPOWER_DBUS_INTERFACE_KBDBACKLIGHT "org.freedesktop.UPower.KbdBacklight" #define GSD_POWER_SETTINGS_SCHEMA "com.canonical.unity.settings-daemon.plugins.power" #define GSD_XRANDR_SETTINGS_SCHEMA "com.canonical.unity.settings-daemon.plugins.xrandr" #define GSD_POWER_DBUS_NAME GSD_DBUS_NAME ".Power" #define GSD_POWER_DBUS_PATH GSD_DBUS_PATH "/Power" #define GSD_POWER_DBUS_INTERFACE GSD_DBUS_BASE_INTERFACE ".Power" #define GSD_POWER_DBUS_INTERFACE_SCREEN GSD_POWER_DBUS_INTERFACE ".Screen" #define GSD_POWER_DBUS_INTERFACE_KEYBOARD GSD_POWER_DBUS_INTERFACE ".Keyboard" #define GSD_POWER_MANAGER_NOTIFY_TIMEOUT_SHORT 10 * 1000 /* ms */ #define GSD_POWER_MANAGER_NOTIFY_TIMEOUT_LONG 30 * 1000 /* ms */ #define GSD_POWER_MANAGER_LID_CLOSE_SAFETY_TIMEOUT 30 /* seconds */ #define SYSTEMD_DBUS_NAME "org.freedesktop.login1" #define SYSTEMD_DBUS_PATH "/org/freedesktop/login1" #define SYSTEMD_DBUS_INTERFACE "org.freedesktop.login1.Manager" /* Keep this in sync with gnome-shell */ #define SCREENSAVER_FADE_TIME 10 /* seconds */ /* Time between notifying the user about a critical action and executing it. * This can be changed with the GSD_ACTION_DELAY constant. */ #ifndef GSD_ACTION_DELAY #define GSD_ACTION_DELAY 20 #endif /* !GSD_ACTION_DELAY */ static const gchar introspection_xml[] = "" " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " ""; #define GSD_POWER_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_POWER_MANAGER, GsdPowerManagerPrivate)) typedef enum { GSD_POWER_IDLE_MODE_NORMAL, GSD_POWER_IDLE_MODE_DIM, GSD_POWER_IDLE_MODE_BLANK, GSD_POWER_IDLE_MODE_SLEEP } GsdPowerIdleMode; struct GsdPowerManagerPrivate { /* D-Bus */ GsdSessionManager *session; guint name_id; GDBusNodeInfo *introspection_data; GDBusConnection *connection; GCancellable *bus_cancellable; GDBusProxy *session_presence_proxy; /* Settings */ GSettings *settings; GSettings *settings_bus; GSettings *settings_screensaver; GSettings *settings_xrandr; gboolean use_time_primary; guint action_percentage; guint action_time; guint critical_percentage; guint critical_time; guint low_percentage; guint low_time; /* Screensaver */ GsdScreenSaver *screensaver_proxy; gboolean screensaver_active; /* State */ gboolean lid_is_closed; UpClient *up_client; gchar *previous_summary; GIcon *previous_icon; GPtrArray *devices_array; UpDevice *device_composite; GsdRRScreen *rr_screen; NotifyNotification *notification_ups_discharging; NotifyNotification *notification_low; NotifyNotification *notification_sleep_warning; NotifyNotification *notification_logout_warning; GsdPowerActionType sleep_action_type; gboolean battery_is_low; /* laptop battery low, or UPS discharging */ /* Brightness */ gboolean backlight_available; gint pre_dim_brightness; /* level, not percentage */ /* Keyboard */ GDBusProxy *upower_kdb_proxy; gint kbd_brightness_max; gint kbd_brightness_old; gint kbd_brightness_pre_dim; /* Sound */ guint32 critical_alert_timeout_id; /* systemd stuff */ GDBusProxy *logind_proxy; gint inhibit_lid_switch_fd; gboolean inhibit_lid_switch_taken; gboolean inhibit_lid_switch_action; gint inhibit_suspend_fd; gboolean inhibit_suspend_taken; guint inhibit_lid_switch_timer_id; gboolean is_virtual_machine; /* Idles */ GsdIdleMonitor *idle_monitor; guint idle_dim_id; guint idle_blank_id; guint idle_sleep_warning_id; guint idle_sleep_id; GsdPowerIdleMode current_idle_mode; guint temporary_unidle_on_ac_id; GsdPowerIdleMode previous_idle_mode; guint xscreensaver_watchdog_timer_id; }; enum { PROP_0, }; static void gsd_power_manager_class_init (GsdPowerManagerClass *klass); static void gsd_power_manager_init (GsdPowerManager *power_manager); static UpDevice *engine_get_composite_device (GsdPowerManager *manager, UpDevice *original_device); static UpDevice *engine_update_composite_device (GsdPowerManager *manager, UpDevice *original_device); static GIcon *engine_get_icon (GsdPowerManager *manager); static gchar *engine_get_summary (GsdPowerManager *manager); static gdouble engine_get_percentage (GsdPowerManager *manager); static void do_power_action_type (GsdPowerManager *manager, GsdPowerActionType action_type); static void do_lid_closed_action (GsdPowerManager *manager); static void inhibit_lid_switch (GsdPowerManager *manager); static void uninhibit_lid_switch (GsdPowerManager *manager); static void main_battery_or_ups_low_changed (GsdPowerManager *manager, gboolean is_low); static void device_properties_changed_cb (UpDevice *device, GParamSpec *pspec, GsdPowerManager *manager); static gboolean idle_is_session_inhibited (GsdPowerManager *manager, guint mask, gboolean *is_inhibited); static void idle_set_mode (GsdPowerManager *manager, GsdPowerIdleMode mode); static void idle_triggered_idle_cb (GsdIdleMonitor *monitor, guint watch_id, gpointer user_data); static void idle_became_active_cb (GsdIdleMonitor *monitor, guint watch_id, gpointer user_data); G_DEFINE_TYPE (GsdPowerManager, gsd_power_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; GQuark gsd_power_manager_error_quark (void) { static GQuark quark = 0; if (!quark) quark = g_quark_from_static_string ("gsd_power_manager_error"); return quark; } static void notify_close_if_showing (NotifyNotification **notification) { if (*notification == NULL) return; notify_notification_close (*notification, NULL); g_clear_object (notification); } typedef enum { WARNING_NONE = 0, WARNING_DISCHARGING = 1, WARNING_LOW = 2, WARNING_CRITICAL = 3, WARNING_ACTION = 4 } GsdPowerManagerWarning; static GVariant * engine_get_icon_property_variant (GsdPowerManager *manager) { GIcon *icon; GVariant *retval; icon = engine_get_icon (manager); if (icon != NULL) { char *str; str = g_icon_to_string (icon); g_object_unref (icon); retval = g_variant_new_string (str); g_free (str); } else { retval = g_variant_new_string (""); } return retval; } static GVariant * engine_get_tooltip_property_variant (GsdPowerManager *manager) { char *tooltip; GVariant *retval; tooltip = engine_get_summary (manager); retval = g_variant_new_string (tooltip != NULL ? tooltip : ""); g_free (tooltip); return retval; } static void engine_emit_changed (GsdPowerManager *manager, gboolean icon_changed, gboolean state_changed) { GVariantBuilder props_builder; GVariant *props_changed = NULL; GError *error = NULL; /* not yet connected to the bus */ if (manager->priv->connection == NULL) return; g_variant_builder_init (&props_builder, G_VARIANT_TYPE ("a{sv}")); if (icon_changed) g_variant_builder_add (&props_builder, "{sv}", "Icon", engine_get_icon_property_variant (manager)); if (state_changed) g_variant_builder_add (&props_builder, "{sv}", "Tooltip", engine_get_tooltip_property_variant (manager)); g_variant_builder_add (&props_builder, "{sv}", "Percentage", g_variant_new_double (engine_get_percentage (manager))); props_changed = g_variant_new ("(s@a{sv}@as)", GSD_POWER_DBUS_INTERFACE, g_variant_builder_end (&props_builder), g_variant_new_strv (NULL, 0)); g_variant_ref_sink (props_changed); if (!g_dbus_connection_emit_signal (manager->priv->connection, NULL, GSD_POWER_DBUS_PATH, "org.freedesktop.DBus.Properties", "PropertiesChanged", props_changed, &error)) goto out; out: if (error) { g_warning ("%s", error->message); g_clear_error (&error); } if (props_changed) g_variant_unref (props_changed); } static GsdPowerManagerWarning engine_get_warning_csr (GsdPowerManager *manager, UpDevice *device) { gdouble percentage; /* get device properties */ g_object_get (device, "percentage", &percentage, NULL); if (percentage < 26.0f) return WARNING_LOW; else if (percentage < 13.0f) return WARNING_CRITICAL; return WARNING_NONE; } static GsdPowerManagerWarning engine_get_warning_percentage (GsdPowerManager *manager, UpDevice *device) { gdouble percentage; /* get device properties */ g_object_get (device, "percentage", &percentage, NULL); if (percentage <= manager->priv->action_percentage) return WARNING_ACTION; if (percentage <= manager->priv->critical_percentage) return WARNING_CRITICAL; if (percentage <= manager->priv->low_percentage) return WARNING_LOW; return WARNING_NONE; } static GsdPowerManagerWarning engine_get_warning_time (GsdPowerManager *manager, UpDevice *device) { UpDeviceKind kind; gint64 time_to_empty; /* get device properties */ g_object_get (device, "kind", &kind, "time-to-empty", &time_to_empty, NULL); /* this is probably an error condition */ if (time_to_empty == 0) { g_debug ("time zero, falling back to percentage for %s", up_device_kind_to_string (kind)); return engine_get_warning_percentage (manager, device); } if (time_to_empty <= manager->priv->action_time) return WARNING_ACTION; if (time_to_empty <= manager->priv->critical_time) return WARNING_CRITICAL; if (time_to_empty <= manager->priv->low_time) return WARNING_LOW; return WARNING_NONE; } /** * This gets the possible engine state for the device according to the * policy, which could be per-percent, or per-time. **/ static GsdPowerManagerWarning engine_get_warning (GsdPowerManager *manager, UpDevice *device) { UpDeviceKind kind; UpDeviceState state; GsdPowerManagerWarning warning_type; /* get device properties */ g_object_get (device, "kind", &kind, "state", &state, NULL); /* default to no engine */ warning_type = WARNING_NONE; /* if the device in question is on ac, don't give a warning */ if (state == UP_DEVICE_STATE_CHARGING) goto out; if (kind == UP_DEVICE_KIND_MOUSE || kind == UP_DEVICE_KIND_KEYBOARD) { warning_type = engine_get_warning_csr (manager, device); } else if (kind == UP_DEVICE_KIND_UPS || kind == UP_DEVICE_KIND_MEDIA_PLAYER || kind == UP_DEVICE_KIND_TABLET || kind == UP_DEVICE_KIND_COMPUTER || kind == UP_DEVICE_KIND_PDA) { warning_type = engine_get_warning_percentage (manager, device); } else if (kind == UP_DEVICE_KIND_PHONE) { warning_type = engine_get_warning_percentage (manager, device); } else if (kind == UP_DEVICE_KIND_BATTERY) { /* only use the time when it is accurate, and settings is not disabled */ if (manager->priv->use_time_primary) warning_type = engine_get_warning_time (manager, device); else warning_type = engine_get_warning_percentage (manager, device); } /* If we have no important engines, we should test for discharging */ if (warning_type == WARNING_NONE) { if (state == UP_DEVICE_STATE_DISCHARGING) warning_type = WARNING_DISCHARGING; } out: return warning_type; } static gchar * engine_get_summary (GsdPowerManager *manager) { guint i; GPtrArray *array; UpDevice *device; UpDeviceState state; GString *tooltip = NULL; gchar *part; gboolean is_present; /* need to get AC state */ tooltip = g_string_new (""); /* do we have specific device types? */ array = manager->priv->devices_array; for (i=0;ilen;i++) { device = g_ptr_array_index (array, i); g_object_get (device, "is-present", &is_present, "state", &state, NULL); if (!is_present) continue; if (state == UP_DEVICE_STATE_EMPTY) continue; part = gpm_upower_get_device_summary (device); if (part != NULL) g_string_append_printf (tooltip, "%s\n", part); g_free (part); } /* remove the last \n */ g_string_truncate (tooltip, tooltip->len-1); g_debug ("tooltip: %s", tooltip->str); return g_string_free (tooltip, FALSE); } static gdouble engine_get_percentage (GsdPowerManager *manager) { guint i; GPtrArray *array; UpDevice *device; UpDeviceKind kind; gboolean is_present; gdouble percentage; array = manager->priv->devices_array; for (i = 0; i < array->len ; i++) { device = g_ptr_array_index (array, i); /* get device properties */ g_object_get (device, "kind", &kind, "is-present", &is_present, NULL); /* if battery then use composite device to cope with multiple batteries */ if (kind == UP_DEVICE_KIND_BATTERY) device = engine_get_composite_device (manager, device); if (is_present) { /* Doing it here as it could be a composite device */ g_object_get (device, "percentage", &percentage, NULL); return percentage; } } return -1; } static GIcon * engine_get_icon_priv (GsdPowerManager *manager, UpDeviceKind device_kind, GsdPowerManagerWarning warning, gboolean use_state) { guint i; GPtrArray *array; UpDevice *device; GsdPowerManagerWarning warning_temp; UpDeviceKind kind; UpDeviceState state; gboolean is_present; /* do we have specific device types? */ array = manager->priv->devices_array; for (i=0;ilen;i++) { device = g_ptr_array_index (array, i); /* get device properties */ g_object_get (device, "kind", &kind, "state", &state, "is-present", &is_present, NULL); /* if battery then use composite device to cope with multiple batteries */ if (kind == UP_DEVICE_KIND_BATTERY) device = engine_get_composite_device (manager, device); warning_temp = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(device), "engine-warning-old")); if (kind == device_kind && is_present) { if (warning != WARNING_NONE) { if (warning_temp == warning) return gpm_upower_get_device_icon (device, TRUE); continue; } if (use_state) { if (state == UP_DEVICE_STATE_CHARGING || state == UP_DEVICE_STATE_DISCHARGING) return gpm_upower_get_device_icon (device, TRUE); continue; } return gpm_upower_get_device_icon (device, TRUE); } } return NULL; } static GIcon * engine_get_icon (GsdPowerManager *manager) { GIcon *icon = NULL; /* we try CRITICAL: BATTERY, UPS, MOUSE, KEYBOARD */ icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_BATTERY, WARNING_CRITICAL, FALSE); if (icon != NULL) return icon; icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_UPS, WARNING_CRITICAL, FALSE); if (icon != NULL) return icon; icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_MOUSE, WARNING_CRITICAL, FALSE); if (icon != NULL) return icon; icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_KEYBOARD, WARNING_CRITICAL, FALSE); if (icon != NULL) return icon; /* we try CRITICAL: BATTERY, UPS, MOUSE, KEYBOARD */ icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_BATTERY, WARNING_LOW, FALSE); if (icon != NULL) return icon; icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_UPS, WARNING_LOW, FALSE); if (icon != NULL) return icon; icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_MOUSE, WARNING_LOW, FALSE); if (icon != NULL) return icon; icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_KEYBOARD, WARNING_LOW, FALSE); if (icon != NULL) return icon; /* we try (DIS)CHARGING: BATTERY, UPS */ icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_BATTERY, WARNING_NONE, TRUE); if (icon != NULL) return icon; icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_UPS, WARNING_NONE, TRUE); if (icon != NULL) return icon; /* we try PRESENT: BATTERY, UPS */ icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_BATTERY, WARNING_NONE, FALSE); if (icon != NULL) return icon; icon = engine_get_icon_priv (manager, UP_DEVICE_KIND_UPS, WARNING_NONE, FALSE); if (icon != NULL) return icon; /* do not show an icon */ return NULL; } static gboolean engine_recalculate_state_icon (GsdPowerManager *manager) { GIcon *icon; /* show a different icon if we are disconnected */ icon = engine_get_icon (manager); if (g_icon_equal (icon, manager->priv->previous_icon)) { g_clear_object (&icon); return FALSE; } g_clear_object (&manager->priv->previous_icon); manager->priv->previous_icon = icon; g_debug ("Icon changed"); return TRUE; } static gboolean engine_recalculate_state_summary (GsdPowerManager *manager) { char *summary; summary = engine_get_summary (manager); if (g_strcmp0 (manager->priv->previous_summary, summary) == 0) { g_free (summary); return FALSE; } g_free (manager->priv->previous_summary); manager->priv->previous_summary = summary; g_debug ("Summary changed"); return TRUE; } static void engine_recalculate_state (GsdPowerManager *manager) { gboolean icon_changed = FALSE; gboolean state_changed = FALSE; icon_changed = engine_recalculate_state_icon (manager); state_changed = engine_recalculate_state_summary (manager); /* only emit if the icon or summary has changed */ if (icon_changed || state_changed) engine_emit_changed (manager, icon_changed, state_changed); } static UpDevice * engine_get_composite_device (GsdPowerManager *manager, UpDevice *original_device) { guint battery_devices = 0; GPtrArray *array; UpDevice *device; UpDeviceKind kind; UpDeviceKind original_kind; guint i; /* get the type of the original device */ g_object_get (original_device, "kind", &original_kind, NULL); /* find out how many batteries in the system */ array = manager->priv->devices_array; for (i=0;ilen;i++) { device = g_ptr_array_index (array, i); g_object_get (device, "kind", &kind, NULL); if (kind == original_kind) battery_devices++; } /* just use the original device if only one primary battery */ if (battery_devices <= 1) return original_device; /* use the composite device */ device = manager->priv->device_composite; /* return composite device or original device */ return device; } static UpDevice * engine_update_composite_device (GsdPowerManager *manager, UpDevice *original_device) { guint i; gdouble percentage = 0.0; gdouble energy = 0.0; gdouble energy_full = 0.0; gdouble energy_rate = 0.0; gdouble energy_total = 0.0; gdouble energy_full_total = 0.0; gdouble energy_rate_total = 0.0; gint64 time_to_empty = 0; gint64 time_to_full = 0; guint battery_devices = 0; gboolean is_charging = FALSE; gboolean is_discharging = FALSE; gboolean is_fully_charged = TRUE; GPtrArray *array; UpDevice *device; UpDeviceState state; UpDeviceKind kind; UpDeviceKind original_kind; /* get the type of the original device */ g_object_get (original_device, "kind", &original_kind, NULL); /* update the composite device */ array = manager->priv->devices_array; for (i=0;ilen;i++) { device = g_ptr_array_index (array, i); g_object_get (device, "kind", &kind, "state", &state, "energy", &energy, "energy-full", &energy_full, "energy-rate", &energy_rate, NULL); if (kind != original_kind) continue; /* one of these will be charging or discharging */ if (state == UP_DEVICE_STATE_CHARGING) is_charging = TRUE; if (state == UP_DEVICE_STATE_DISCHARGING) is_discharging = TRUE; if (state != UP_DEVICE_STATE_FULLY_CHARGED) is_fully_charged = FALSE; /* sum up composite */ energy_total += energy; energy_full_total += energy_full; energy_rate_total += energy_rate; battery_devices++; } /* just use the original device if only one primary battery */ if (battery_devices == 1) { g_debug ("using original device as only one primary battery"); device = original_device; goto out; } /* use percentage weighted for each battery capacity */ if (energy_full_total > 0.0) percentage = 100.0 * energy_total / energy_full_total; /* set composite state */ if (is_charging) state = UP_DEVICE_STATE_CHARGING; else if (is_discharging) state = UP_DEVICE_STATE_DISCHARGING; else if (is_fully_charged) state = UP_DEVICE_STATE_FULLY_CHARGED; else state = UP_DEVICE_STATE_UNKNOWN; /* calculate a quick and dirty time remaining value */ if (energy_rate_total > 0) { if (state == UP_DEVICE_STATE_DISCHARGING) time_to_empty = 3600 * (energy_total / energy_rate_total); else if (state == UP_DEVICE_STATE_CHARGING) time_to_full = 3600 * ((energy_full_total - energy_total) / energy_rate_total); } /* okay, we can use the composite device */ device = manager->priv->device_composite; g_debug ("printing composite device"); g_object_set (device, "energy", energy, "energy-full", energy_full, "energy-rate", energy_rate, "time-to-empty", time_to_empty, "time-to-full", time_to_full, "percentage", percentage, "state", state, NULL); /* force update of icon */ if (engine_recalculate_state_icon (manager)) engine_emit_changed (manager, TRUE, FALSE); out: /* return composite device or original device */ return device; } static void engine_device_add (GsdPowerManager *manager, UpDevice *device) { GsdPowerManagerWarning warning; UpDeviceState state; UpDeviceKind kind; UpDevice *composite; /* assign warning */ warning = engine_get_warning (manager, device); g_object_set_data (G_OBJECT(device), "engine-warning-old", GUINT_TO_POINTER(warning)); /* get device properties */ g_object_get (device, "kind", &kind, "state", &state, NULL); /* add old state for transitions */ g_debug ("adding %s with state %s", up_device_get_object_path (device), up_device_state_to_string (state)); g_object_set_data (G_OBJECT(device), "engine-state-old", GUINT_TO_POINTER(state)); if (kind == UP_DEVICE_KIND_BATTERY) { g_debug ("updating because we added a device"); composite = engine_update_composite_device (manager, device); /* get the same values for the composite device */ warning = engine_get_warning (manager, composite); g_object_set_data (G_OBJECT(composite), "engine-warning-old", GUINT_TO_POINTER(warning)); g_object_get (composite, "state", &state, NULL); g_object_set_data (G_OBJECT(composite), "engine-state-old", GUINT_TO_POINTER(state)); } g_ptr_array_add (manager->priv->devices_array, g_object_ref(device)); g_signal_connect (device, "notify::state", G_CALLBACK (device_properties_changed_cb), manager); g_signal_connect (device, "notify::warning-level", G_CALLBACK (device_properties_changed_cb), manager); } static gboolean engine_coldplug (GsdPowerManager *manager) { guint i; GPtrArray *array = NULL; UpDevice *device; engine_recalculate_state (manager); /* add to database */ array = up_client_get_devices (manager->priv->up_client); if (array == NULL) goto out; for (i=0;ilen;i++) { device = g_ptr_array_index (array, i); engine_device_add (manager, device); } out: if (array != NULL) g_ptr_array_unref (array); /* never repeat */ return FALSE; } static void engine_device_added_cb (UpClient *client, UpDevice *device, GsdPowerManager *manager) { /* add to list */ g_ptr_array_add (manager->priv->devices_array, g_object_ref (device)); engine_recalculate_state (manager); } static void engine_device_removed_cb (UpClient *client, const char *object_path, GsdPowerManager *manager) { guint i; for (i = 0; i < manager->priv->devices_array->len; i++) { UpDevice *device = g_ptr_array_index (manager->priv->devices_array, i); if (g_strcmp0 (object_path, up_device_get_object_path (device)) == 0) { g_ptr_array_remove_index (manager->priv->devices_array, i); break; } } } static void on_notification_closed (NotifyNotification *notification, gpointer data) { g_object_unref (notification); } static const gchar * get_first_themed_icon_name (GIcon *icon) { const gchar* const *icon_names; const gchar *icon_name = NULL; /* no icon */ if (icon == NULL) goto out; /* just use the first icon */ icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (icon_names != NULL) icon_name = icon_names[0]; out: return icon_name; } static void create_notification (const char *summary, const char *body, GIcon *icon, NotifyNotification **weak_pointer_location) { NotifyNotification *notification; notification = notify_notification_new (summary, body, icon ? get_first_themed_icon_name (icon) : NULL); *weak_pointer_location = notification; g_object_add_weak_pointer (G_OBJECT (notification), (gpointer *) weak_pointer_location); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), NULL); } static void engine_ups_discharging (GsdPowerManager *manager, UpDevice *device) { const gchar *title; gchar *remaining_text = NULL; gdouble percentage; GIcon *icon = NULL; gint64 time_to_empty; GString *message; UpDeviceKind kind; /* get device properties */ g_object_get (device, "kind", &kind, "percentage", &percentage, "time-to-empty", &time_to_empty, NULL); if (kind != UP_DEVICE_KIND_UPS) return; main_battery_or_ups_low_changed (manager, TRUE); /* only show text if there is a valid time */ if (time_to_empty > 0) remaining_text = gpm_get_timestring (time_to_empty); /* TRANSLATORS: UPS is now discharging */ title = _("UPS Discharging"); message = g_string_new (""); if (remaining_text != NULL) { /* TRANSLATORS: tell the user how much time they have got */ g_string_append_printf (message, _("%s of UPS backup power remaining"), remaining_text); } else { g_string_append (message, gpm_device_to_localised_string (device)); } g_string_append_printf (message, " (%.0f%%)", percentage); icon = gpm_upower_get_device_icon (device, TRUE); /* close any existing notification of this class */ notify_close_if_showing (&manager->priv->notification_ups_discharging); /* create a new notification */ create_notification (title, message->str, icon, &manager->priv->notification_ups_discharging); notify_notification_set_timeout (manager->priv->notification_ups_discharging, GSD_POWER_MANAGER_NOTIFY_TIMEOUT_LONG); notify_notification_set_urgency (manager->priv->notification_ups_discharging, NOTIFY_URGENCY_NORMAL); /* TRANSLATORS: this is the notification application name */ notify_notification_set_app_name (manager->priv->notification_ups_discharging, _("Power")); notify_notification_set_hint (manager->priv->notification_ups_discharging, "transient", g_variant_new_boolean (TRUE)); notify_notification_show (manager->priv->notification_ups_discharging, NULL); g_string_free (message, TRUE); if (icon != NULL) g_object_unref (icon); g_free (remaining_text); } static GsdPowerActionType manager_critical_action_get (GsdPowerManager *manager, gboolean is_ups) { GsdPowerActionType policy; GVariant *result = NULL; policy = g_settings_get_enum (manager->priv->settings, "critical-battery-action"); if (policy == GSD_POWER_ACTION_SUSPEND) { if (is_ups == FALSE) { result = g_dbus_proxy_call_sync (manager->priv->logind_proxy, "CanSuspend", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); } } else if (policy == GSD_POWER_ACTION_HIBERNATE) { result = g_dbus_proxy_call_sync (manager->priv->logind_proxy, "CanHibernate", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); } else { /* Other actions need no check */ return policy; } if (result) { const char *s; g_variant_get (result, "(s)", &s); if (g_strcmp0 (s, "yes") != 0) policy = GSD_POWER_ACTION_SHUTDOWN; g_variant_unref (result); } else { policy = GSD_POWER_ACTION_SHUTDOWN; } return policy; } static gboolean manager_critical_action_do (GsdPowerManager *manager, gboolean is_ups) { GsdPowerActionType action_type; /* stop playing the alert as it's too late to do anything now */ play_loop_stop (&manager->priv->critical_alert_timeout_id); action_type = manager_critical_action_get (manager, is_ups); do_power_action_type (manager, action_type); return FALSE; } static gboolean manager_critical_action_do_cb (GsdPowerManager *manager) { manager_critical_action_do (manager, FALSE); return FALSE; } static gboolean manager_critical_ups_action_do_cb (GsdPowerManager *manager) { manager_critical_action_do (manager, TRUE); return FALSE; } static gboolean engine_just_laptop_battery (GsdPowerManager *manager) { UpDevice *device; UpDeviceKind kind; GPtrArray *array; gboolean ret = TRUE; guint i; /* find if there are any other device types that mean we have to * be more specific in our wording */ array = manager->priv->devices_array; for (i=0; ilen; i++) { device = g_ptr_array_index (array, i); g_object_get (device, "kind", &kind, NULL); if (kind != UP_DEVICE_KIND_BATTERY) { ret = FALSE; break; } } return ret; } static void engine_charge_low (GsdPowerManager *manager, UpDevice *device) { const gchar *title = NULL; gboolean ret; gchar *message = NULL; gchar *tmp; gchar *remaining_text; gdouble percentage; GIcon *icon = NULL; gint64 time_to_empty; UpDeviceKind kind; /* get device properties */ g_object_get (device, "kind", &kind, "percentage", &percentage, "time-to-empty", &time_to_empty, NULL); if (kind == UP_DEVICE_KIND_BATTERY) { /* if the user has no other batteries, drop the "Laptop" wording */ ret = engine_just_laptop_battery (manager); if (ret) { /* TRANSLATORS: laptop battery low, and we only have one battery */ title = _("Battery low"); } else { /* TRANSLATORS: laptop battery low, and we have more than one kind of battery */ title = _("Laptop battery low"); } tmp = gpm_get_timestring (time_to_empty); remaining_text = g_strconcat ("", tmp, "", NULL); g_free (tmp); /* TRANSLATORS: tell the user how much time they have got */ message = g_strdup_printf (_("Approximately %s remaining (%.0f%%)"), remaining_text, percentage); g_free (remaining_text); main_battery_or_ups_low_changed (manager, TRUE); } else if (kind == UP_DEVICE_KIND_UPS) { /* TRANSLATORS: UPS is starting to get a little low */ title = _("UPS low"); tmp = gpm_get_timestring (time_to_empty); remaining_text = g_strconcat ("", tmp, "", NULL); g_free (tmp); /* TRANSLATORS: tell the user how much time they have got */ message = g_strdup_printf (_("Approximately %s of remaining UPS backup power (%.0f%%)"), remaining_text, percentage); g_free (remaining_text); } else if (kind == UP_DEVICE_KIND_MOUSE) { /* TRANSLATORS: mouse is getting a little low */ title = _("Mouse battery low"); /* TRANSLATORS: tell user more details */ message = g_strdup_printf (_("Wireless mouse is low in power (%.0f%%)"), percentage); } else if (kind == UP_DEVICE_KIND_KEYBOARD) { /* TRANSLATORS: keyboard is getting a little low */ title = _("Keyboard battery low"); /* TRANSLATORS: tell user more details */ message = g_strdup_printf (_("Wireless keyboard is low in power (%.0f%%)"), percentage); } else if (kind == UP_DEVICE_KIND_PDA) { /* TRANSLATORS: PDA is getting a little low */ title = _("PDA battery low"); /* TRANSLATORS: tell user more details */ message = g_strdup_printf (_("PDA is low in power (%.0f%%)"), percentage); } else if (kind == UP_DEVICE_KIND_PHONE) { /* TRANSLATORS: cell phone (mobile) is getting a little low */ title = _("Cell phone battery low"); /* TRANSLATORS: tell user more details */ message = g_strdup_printf (_("Cell phone is low in power (%.0f%%)"), percentage); } else if (kind == UP_DEVICE_KIND_MEDIA_PLAYER) { /* TRANSLATORS: media player, e.g. mp3 is getting a little low */ title = _("Media player battery low"); /* TRANSLATORS: tell user more details */ message = g_strdup_printf (_("Media player is low in power (%.0f%%)"), percentage); } else if (kind == UP_DEVICE_KIND_TABLET) { /* TRANSLATORS: graphics tablet, e.g. wacom is getting a little low */ title = _("Tablet battery low"); /* TRANSLATORS: tell user more details */ message = g_strdup_printf (_("Tablet is low in power (%.0f%%)"), percentage); } else if (kind == UP_DEVICE_KIND_COMPUTER) { /* TRANSLATORS: computer, e.g. ipad is getting a little low */ title = _("Attached computer battery low"); /* TRANSLATORS: tell user more details */ message = g_strdup_printf (_("Attached computer is low in power (%.0f%%)"), percentage); } /* get correct icon */ icon = gpm_upower_get_device_icon (device, TRUE); /* close any existing notification of this class */ notify_close_if_showing (&manager->priv->notification_low); /* create a new notification */ create_notification (title, message, icon, &manager->priv->notification_low); notify_notification_set_timeout (manager->priv->notification_low, GSD_POWER_MANAGER_NOTIFY_TIMEOUT_LONG); notify_notification_set_urgency (manager->priv->notification_low, NOTIFY_URGENCY_NORMAL); notify_notification_set_app_name (manager->priv->notification_low, _("Power")); notify_notification_set_hint (manager->priv->notification_low, "transient", g_variant_new_boolean (TRUE)); notify_notification_show (manager->priv->notification_low, NULL); /* play the sound, using sounds from the naming spec */ ca_context_play (ca_gtk_context_get (), 0, CA_PROP_EVENT_ID, "battery-low", /* TRANSLATORS: this is the sound description */ CA_PROP_EVENT_DESCRIPTION, _("Battery is low"), NULL); if (icon != NULL) g_object_unref (icon); g_free (message); } static void engine_charge_critical (GsdPowerManager *manager, UpDevice *device) { const gchar *title = NULL; gboolean ret; gchar *message = NULL; gdouble percentage; GIcon *icon = NULL; gint64 time_to_empty; GsdPowerActionType policy; UpDeviceKind kind; /* get device properties */ g_object_get (device, "kind", &kind, "percentage", &percentage, "time-to-empty", &time_to_empty, NULL); if (kind == UP_DEVICE_KIND_BATTERY) { /* if the user has no other batteries, drop the "Laptop" wording */ ret = engine_just_laptop_battery (manager); if (ret) { /* TRANSLATORS: laptop battery critically low, and only have one kind of battery */ title = _("Battery critically low"); } else { /* TRANSLATORS: laptop battery critically low, and we have more than one type of battery */ title = _("Laptop battery critically low"); } /* we have to do different warnings depending on the policy */ policy = manager_critical_action_get (manager, FALSE); /* use different text for different actions */ if (policy == GSD_POWER_ACTION_NOTHING) { /* TRANSLATORS: tell the use to insert the plug, as we're not going to do anything */ message = g_strdup (_("Plug in your AC adapter to avoid losing data.")); } else if (policy == GSD_POWER_ACTION_SUSPEND) { /* TRANSLATORS: give the user a ultimatum */ message = g_strdup_printf (_("Computer will suspend very soon unless it is plugged in.")); } else if (policy == GSD_POWER_ACTION_HIBERNATE) { /* TRANSLATORS: give the user a ultimatum */ message = g_strdup_printf (_("Computer will hibernate very soon unless it is plugged in.")); } else if (policy == GSD_POWER_ACTION_SHUTDOWN) { /* TRANSLATORS: give the user a ultimatum */ message = g_strdup_printf (_("Computer will shutdown very soon unless it is plugged in.")); } main_battery_or_ups_low_changed (manager, TRUE); } else if (kind == UP_DEVICE_KIND_UPS) { gchar *remaining_text; gchar *tmp; /* TRANSLATORS: the UPS is very low */ title = _("UPS critically low"); tmp = gpm_get_timestring (time_to_empty); remaining_text = g_strconcat ("", tmp, "", NULL); g_free (tmp); /* TRANSLATORS: give the user a ultimatum */ message = g_strdup_printf (_("Approximately %s of remaining UPS power (%.0f%%). " "Restore AC power to your computer to avoid losing data."), remaining_text, percentage); g_free (remaining_text); } else if (kind == UP_DEVICE_KIND_MOUSE) { /* TRANSLATORS: the mouse battery is very low */ title = _("Mouse battery low"); /* TRANSLATORS: the device is just going to stop working */ message = g_strdup_printf (_("Wireless mouse is very low in power (%.0f%%). " "This device will soon stop functioning if not charged."), percentage); } else if (kind == UP_DEVICE_KIND_KEYBOARD) { /* TRANSLATORS: the keyboard battery is very low */ title = _("Keyboard battery low"); /* TRANSLATORS: the device is just going to stop working */ message = g_strdup_printf (_("Wireless keyboard is very low in power (%.0f%%). " "This device will soon stop functioning if not charged."), percentage); } else if (kind == UP_DEVICE_KIND_PDA) { /* TRANSLATORS: the PDA battery is very low */ title = _("PDA battery low"); /* TRANSLATORS: the device is just going to stop working */ message = g_strdup_printf (_("PDA is very low in power (%.0f%%). " "This device will soon stop functioning if not charged."), percentage); } else if (kind == UP_DEVICE_KIND_PHONE) { /* TRANSLATORS: the cell battery is very low */ title = _("Cell phone battery low"); /* TRANSLATORS: the device is just going to stop working */ message = g_strdup_printf (_("Cell phone is very low in power (%.0f%%). " "This device will soon stop functioning if not charged."), percentage); } else if (kind == UP_DEVICE_KIND_MEDIA_PLAYER) { /* TRANSLATORS: the cell battery is very low */ title = _("Cell phone battery low"); /* TRANSLATORS: the device is just going to stop working */ message = g_strdup_printf (_("Media player is very low in power (%.0f%%). " "This device will soon stop functioning if not charged."), percentage); } else if (kind == UP_DEVICE_KIND_TABLET) { /* TRANSLATORS: the cell battery is very low */ title = _("Tablet battery low"); /* TRANSLATORS: the device is just going to stop working */ message = g_strdup_printf (_("Tablet is very low in power (%.0f%%). " "This device will soon stop functioning if not charged."), percentage); } else if (kind == UP_DEVICE_KIND_COMPUTER) { /* TRANSLATORS: the cell battery is very low */ title = _("Attached computer battery low"); /* TRANSLATORS: the device is just going to stop working */ message = g_strdup_printf (_("Attached computer is very low in power (%.0f%%). " "The device will soon shutdown if not charged."), percentage); } /* get correct icon */ icon = gpm_upower_get_device_icon (device, TRUE); /* close any existing notification of this class */ notify_close_if_showing (&manager->priv->notification_low); /* create a new notification */ create_notification (title, message, icon, &manager->priv->notification_low); notify_notification_set_timeout (manager->priv->notification_low, NOTIFY_EXPIRES_DEFAULT); notify_notification_set_urgency (manager->priv->notification_low, NOTIFY_URGENCY_CRITICAL); notify_notification_set_app_name (manager->priv->notification_low, _("Power")); notify_notification_show (manager->priv->notification_low, NULL); switch (kind) { case UP_DEVICE_KIND_BATTERY: case UP_DEVICE_KIND_UPS: g_debug ("critical charge level reached, starting sound loop"); play_loop_start (&manager->priv->critical_alert_timeout_id); break; default: /* play the sound, using sounds from the naming spec */ ca_context_play (ca_gtk_context_get (), 0, CA_PROP_EVENT_ID, "battery-caution", /* TRANSLATORS: this is the sound description */ CA_PROP_EVENT_DESCRIPTION, _("Battery is critically low"), NULL); break; } if (icon != NULL) g_object_unref (icon); g_free (message); } static void engine_charge_action (GsdPowerManager *manager, UpDevice *device) { const gchar *title = NULL; gchar *message = NULL; GIcon *icon = NULL; GsdPowerActionType policy; guint timer_id; UpDeviceKind kind; /* get device properties */ g_object_get (device, "kind", &kind, NULL); if (kind == UP_DEVICE_KIND_BATTERY) { /* TRANSLATORS: laptop battery is really, really, low */ title = _("Laptop battery critically low"); /* we have to do different warnings depending on the policy */ policy = manager_critical_action_get (manager, FALSE); /* use different text for different actions */ if (policy == GSD_POWER_ACTION_NOTHING) { /* TRANSLATORS: computer will shutdown without saving data */ message = g_strdup (_("The battery is below the critical level and " "this computer will power-off when the " "battery becomes completely empty.")); } else if (policy == GSD_POWER_ACTION_SUSPEND) { /* TRANSLATORS: computer will suspend */ message = g_strdup (_("The battery is below the critical level and " "this computer is about to suspend.\n" "NOTE: A small amount of power is required " "to keep your computer in a suspended state.")); } else if (policy == GSD_POWER_ACTION_HIBERNATE) { /* TRANSLATORS: computer will hibernate */ message = g_strdup (_("The battery is below the critical level and " "this computer is about to hibernate.")); } else if (policy == GSD_POWER_ACTION_SHUTDOWN) { /* TRANSLATORS: computer will just shutdown */ message = g_strdup (_("The battery is below the critical level and " "this computer is about to shutdown.")); } /* wait 20 seconds for user-panic */ timer_id = g_timeout_add_seconds (GSD_ACTION_DELAY, (GSourceFunc) manager_critical_action_do_cb, manager); g_source_set_name_by_id (timer_id, "[GsdPowerManager] battery critical-action"); } else if (kind == UP_DEVICE_KIND_UPS) { /* TRANSLATORS: UPS is really, really, low */ title = _("UPS critically low"); /* we have to do different warnings depending on the policy */ policy = manager_critical_action_get (manager, TRUE); /* use different text for different actions */ if (policy == GSD_POWER_ACTION_NOTHING) { /* TRANSLATORS: computer will shutdown without saving data */ message = g_strdup (_("UPS is below the critical level and " "this computer will power-off when the " "UPS becomes completely empty.")); } else if (policy == GSD_POWER_ACTION_HIBERNATE) { /* TRANSLATORS: computer will hibernate */ message = g_strdup (_("UPS is below the critical level and " "this computer is about to hibernate.")); } else if (policy == GSD_POWER_ACTION_SHUTDOWN) { /* TRANSLATORS: computer will just shutdown */ message = g_strdup (_("UPS is below the critical level and " "this computer is about to shutdown.")); } /* wait 20 seconds for user-panic */ timer_id = g_timeout_add_seconds (GSD_ACTION_DELAY, (GSourceFunc) manager_critical_ups_action_do_cb, manager); g_source_set_name_by_id (timer_id, "[GsdPowerManager] ups critical-action"); } /* not all types have actions */ if (title == NULL) return; /* get correct icon */ icon = gpm_upower_get_device_icon (device, TRUE); /* close any existing notification of this class */ notify_close_if_showing (&manager->priv->notification_low); /* create a new notification */ create_notification (title, message, icon, &manager->priv->notification_low); notify_notification_set_timeout (manager->priv->notification_low, NOTIFY_EXPIRES_DEFAULT); notify_notification_set_urgency (manager->priv->notification_low, NOTIFY_URGENCY_CRITICAL); notify_notification_set_app_name (manager->priv->notification_low, _("Power")); /* try to show */ notify_notification_show (manager->priv->notification_low, NULL); /* play the sound, using sounds from the naming spec */ ca_context_play (ca_gtk_context_get (), 0, CA_PROP_EVENT_ID, "battery-caution", /* TRANSLATORS: this is the sound description */ CA_PROP_EVENT_DESCRIPTION, _("Battery is critically low"), NULL); if (icon != NULL) g_object_unref (icon); g_free (message); } static void device_properties_changed_cb (UpDevice *device, GParamSpec *pspec, GsdPowerManager *manager) { UpDeviceKind kind; UpDeviceState state; UpDeviceState state_old; GsdPowerManagerWarning warning_old; GsdPowerManagerWarning warning; /* get device properties */ g_object_get (device, "kind", &kind, NULL); /* if battery then use composite device to cope with multiple batteries */ if (kind == UP_DEVICE_KIND_BATTERY) { g_debug ("updating because %s changed", up_device_get_object_path (device)); device = engine_update_composite_device (manager, device); } /* get device properties (may be composite) */ g_object_get (device, "state", &state, NULL); g_debug ("%s state is now %s", up_device_get_object_path (device), up_device_state_to_string (state)); /* see if any interesting state changes have happened */ state_old = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(device), "engine-state-old")); if (state_old != state) { if (state == UP_DEVICE_STATE_DISCHARGING) { g_debug ("discharging"); engine_ups_discharging (manager, device); } else if (state == UP_DEVICE_STATE_FULLY_CHARGED || state == UP_DEVICE_STATE_CHARGING) { g_debug ("fully charged or charging, hiding notifications if any"); notify_close_if_showing (&manager->priv->notification_low); notify_close_if_showing (&manager->priv->notification_ups_discharging); main_battery_or_ups_low_changed (manager, FALSE); } /* save new state */ g_object_set_data (G_OBJECT(device), "engine-state-old", GUINT_TO_POINTER(state)); } /* check the warning state has not changed */ warning_old = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(device), "engine-warning-old")); warning = engine_get_warning (manager, device); if (warning != warning_old) { if (warning == WARNING_LOW) { g_debug ("** EMIT: charge-low"); engine_charge_low (manager, device); } else if (warning == WARNING_CRITICAL) { g_debug ("** EMIT: charge-critical"); engine_charge_critical (manager, device); } else if (warning == WARNING_ACTION) { g_debug ("charge-action"); engine_charge_action (manager, device); } /* save new state */ g_object_set_data (G_OBJECT(device), "engine-warning-old", GUINT_TO_POINTER(warning)); } engine_recalculate_state (manager); } static UpDevice * engine_get_primary_device (GsdPowerManager *manager) { guint i; UpDevice *device = NULL; UpDevice *device_tmp; UpDeviceKind kind; UpDeviceState state; gboolean is_present; for (i=0; ipriv->devices_array->len; i++) { device_tmp = g_ptr_array_index (manager->priv->devices_array, i); /* get device properties */ g_object_get (device_tmp, "kind", &kind, "state", &state, "is-present", &is_present, NULL); /* not present */ if (!is_present) continue; /* not discharging */ if (state != UP_DEVICE_STATE_DISCHARGING) continue; /* not battery */ if (kind != UP_DEVICE_KIND_BATTERY) continue; /* use composite device to cope with multiple batteries */ device = g_object_ref (engine_get_composite_device (manager, device_tmp)); break; } return device; } static void gnome_session_shutdown_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GVariant *result; GError *error = NULL; result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); if (result == NULL) { g_warning ("couldn't shutdown using gnome-session: %s", error->message); g_error_free (error); } else { g_variant_unref (result); } } static void gnome_session_shutdown (GsdPowerManager *manager) { g_dbus_proxy_call (G_DBUS_PROXY (manager->priv->session), "Shutdown", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, gnome_session_shutdown_cb, NULL); } static void gnome_session_logout_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GVariant *result; GError *error = NULL; result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); if (result == NULL) { g_warning ("couldn't log out using gnome-session: %s", error->message); g_error_free (error); } else { g_variant_unref (result); } } static void gnome_session_logout (GsdPowerManager *manager, guint logout_mode) { g_dbus_proxy_call (G_DBUS_PROXY (manager->priv->session), "Logout", g_variant_new ("(u)", logout_mode), G_DBUS_CALL_FLAGS_NONE, -1, NULL, gnome_session_logout_cb, NULL); } static void action_poweroff (GsdPowerManager *manager) { if (manager->priv->logind_proxy == NULL) { g_warning ("no systemd support"); return; } g_dbus_proxy_call (manager->priv->logind_proxy, "PowerOff", g_variant_new ("(b)", FALSE), G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, NULL, NULL); } static void action_suspend (GsdPowerManager *manager) { if (manager->priv->logind_proxy == NULL) { g_warning ("no systemd support"); return; } g_dbus_proxy_call (manager->priv->logind_proxy, "Suspend", g_variant_new ("(b)", FALSE), G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, NULL, NULL); } static void action_hibernate (GsdPowerManager *manager) { if (manager->priv->logind_proxy == NULL) { g_warning ("no systemd support"); return; } g_dbus_proxy_call (manager->priv->logind_proxy, "Hibernate", g_variant_new ("(b)", FALSE), G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, NULL, NULL); } static void backlight_enable (GsdPowerManager *manager) { gboolean ret; GError *error = NULL; ret = gsd_rr_screen_set_dpms_mode (manager->priv->rr_screen, GSD_RR_DPMS_ON, &error); if (!ret) { g_warning ("failed to turn the panel on: %s", error->message); g_error_free (error); } g_debug ("TESTSUITE: Unblanked screen"); } static void backlight_disable (GsdPowerManager *manager) { gboolean ret; GError *error = NULL; ret = gsd_rr_screen_set_dpms_mode (manager->priv->rr_screen, GSD_RR_DPMS_OFF, &error); if (!ret) { g_warning ("failed to turn the panel off: %s", error->message); g_error_free (error); } g_debug ("TESTSUITE: Blanked screen"); } static void do_power_action_type (GsdPowerManager *manager, GsdPowerActionType action_type) { switch (action_type) { case GSD_POWER_ACTION_SUSPEND: action_suspend (manager); break; case GSD_POWER_ACTION_INTERACTIVE: gnome_session_shutdown (manager); break; case GSD_POWER_ACTION_HIBERNATE: action_hibernate (manager); break; case GSD_POWER_ACTION_SHUTDOWN: /* this is only used on critically low battery where * hibernate is not available and is marginally better * than just powering down the computer mid-write */ action_poweroff (manager); break; case GSD_POWER_ACTION_BLANK: backlight_disable (manager); break; case GSD_POWER_ACTION_NOTHING: break; case GSD_POWER_ACTION_LOGOUT: gnome_session_logout (manager, GSM_MANAGER_LOGOUT_MODE_FORCE); break; } } static GsmInhibitorFlag get_idle_inhibitors_for_action (GsdPowerActionType action_type) { switch (action_type) { case GSD_POWER_ACTION_BLANK: case GSD_POWER_ACTION_SHUTDOWN: case GSD_POWER_ACTION_INTERACTIVE: return GSM_INHIBITOR_FLAG_IDLE; case GSD_POWER_ACTION_HIBERNATE: case GSD_POWER_ACTION_SUSPEND: return GSM_INHIBITOR_FLAG_SUSPEND; /* in addition to idle */ case GSD_POWER_ACTION_NOTHING: return 0; case GSD_POWER_ACTION_LOGOUT: return GSM_INHIBITOR_FLAG_LOGOUT; /* in addition to idle */ } return 0; } static gboolean is_action_inhibited (GsdPowerManager *manager, GsdPowerActionType action_type) { GsmInhibitorFlag flag; gboolean is_inhibited; flag = get_idle_inhibitors_for_action (action_type); if (!flag) return FALSE; idle_is_session_inhibited (manager, flag, &is_inhibited); return is_inhibited; } static gboolean upower_kbd_get_brightness (GsdPowerManager *manager) { GVariant *k_now = NULL; GError *error = NULL; gint now; k_now = g_dbus_proxy_call_sync (manager->priv->upower_kdb_proxy, "GetBrightness", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (k_now == NULL) { if (error->domain != G_DBUS_ERROR || error->code != G_DBUS_ERROR_UNKNOWN_METHOD) { g_warning ("Failed to get brightness: %s", error->message); } g_error_free (error); return -1; } g_variant_get (k_now, "(i)", &now); g_variant_unref (k_now); return now; } static gboolean upower_kbd_set_brightness (GsdPowerManager *manager, guint value, GError **error) { GVariant *retval; /* update h/w value */ retval = g_dbus_proxy_call_sync (manager->priv->upower_kdb_proxy, "SetBrightness", g_variant_new ("(i)", (gint) value), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error); if (retval == NULL) return FALSE; g_variant_unref (retval); return TRUE; } static int upower_kbd_toggle (GsdPowerManager *manager, GError **error) { gboolean ret; int value = -1; if (manager->priv->kbd_brightness_old >= 0) { g_debug ("keyboard toggle off"); ret = upower_kbd_set_brightness (manager, manager->priv->kbd_brightness_old, error); if (ret) { /* succeeded, set to -1 since now no old value */ manager->priv->kbd_brightness_old = -1; value = 0; } } else { g_debug ("keyboard toggle on"); /* save the current value to restore later when untoggling */ manager->priv->kbd_brightness_old = upower_kbd_get_brightness (manager); ret = upower_kbd_set_brightness (manager, 0, error); if (!ret) { /* failed, reset back to -1 */ manager->priv->kbd_brightness_old = -1; } else { value = 0; } } if (ret) return value; return -1; } static gboolean suspend_on_lid_close (GsdPowerManager *manager) { GsdXrandrBootBehaviour val; if (manager->priv->inhibit_lid_switch_action) return FALSE; if (!external_monitor_is_connected (manager->priv->rr_screen)) return TRUE; val = g_settings_get_enum (manager->priv->settings_xrandr, "default-monitors-setup"); return val == GSD_XRANDR_BOOT_BEHAVIOUR_DO_NOTHING; } static gboolean inhibit_lid_switch_timer_cb (GsdPowerManager *manager) { if (suspend_on_lid_close (manager)) { g_debug ("no external monitors for a while; uninhibiting lid close"); uninhibit_lid_switch (manager); manager->priv->inhibit_lid_switch_timer_id = 0; return G_SOURCE_REMOVE; } g_debug ("external monitor still there; trying again later"); return G_SOURCE_CONTINUE; } /* Sets up a timer to be triggered some seconds after closing the laptop lid * when the laptop is *not* suspended for some reason. We'll check conditions * again in the timeout handler to see if we can suspend then. */ static void setup_inhibit_lid_switch_timer (GsdPowerManager *manager) { if (manager->priv->inhibit_lid_switch_timer_id != 0) { g_debug ("lid close safety timer already set up"); return; } g_debug ("setting up lid close safety timer"); manager->priv->inhibit_lid_switch_timer_id = g_timeout_add_seconds (GSD_POWER_MANAGER_LID_CLOSE_SAFETY_TIMEOUT, (GSourceFunc) inhibit_lid_switch_timer_cb, manager); g_source_set_name_by_id (manager->priv->inhibit_lid_switch_timer_id, "[GsdPowerManager] lid close safety timer"); } static void restart_inhibit_lid_switch_timer (GsdPowerManager *manager) { if (manager->priv->inhibit_lid_switch_timer_id != 0) { g_debug ("restarting lid close safety timer"); g_source_remove (manager->priv->inhibit_lid_switch_timer_id); manager->priv->inhibit_lid_switch_timer_id = 0; setup_inhibit_lid_switch_timer (manager); } } static void setup_lid_closed_action (GsdPowerManager *manager) { GsdPowerActionType policy; if (up_client_get_on_battery (manager->priv->up_client)) { policy = g_settings_get_enum (manager->priv->settings, "lid-close-battery-action"); } else { policy = g_settings_get_enum (manager->priv->settings, "lid-close-ac-action"); } if (policy == GSD_POWER_ACTION_NOTHING) { inhibit_lid_switch (manager); manager->priv->inhibit_lid_switch_action = TRUE; } else { uninhibit_lid_switch (manager); manager->priv->inhibit_lid_switch_action = FALSE; } } static void do_lid_open_action (GsdPowerManager *manager) { /* play a sound, using sounds from the naming spec */ ca_context_play (ca_gtk_context_get (), 0, CA_PROP_EVENT_ID, "lid-open", /* TRANSLATORS: this is the sound description */ CA_PROP_EVENT_DESCRIPTION, _("Lid has been opened"), NULL); /* This might already have happened when resuming, but * if we didn't sleep, we'll need to wake it up */ reset_idletime (); } static void lock_screensaver (GsdPowerManager *manager) { gboolean do_lock; do_lock = g_settings_get_boolean (manager->priv->settings_screensaver, "lock-enabled"); if (!do_lock) { g_dbus_proxy_call_sync (G_DBUS_PROXY (manager->priv->screensaver_proxy), "SetActive", g_variant_new ("(b)", TRUE), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); return; } g_dbus_proxy_call_sync (G_DBUS_PROXY (manager->priv->screensaver_proxy), "Lock", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); } static void do_lid_closed_action (GsdPowerManager *manager) { /* play a sound, using sounds from the naming spec */ ca_context_play (ca_gtk_context_get (), 0, CA_PROP_EVENT_ID, "lid-close", /* TRANSLATORS: this is the sound description */ CA_PROP_EVENT_DESCRIPTION, _("Lid has been closed"), NULL); /* refresh RANDR so we get an accurate view of what monitors are plugged in when the lid is closed */ gsd_rr_screen_refresh (manager->priv->rr_screen, NULL); /* NULL-GError */ restart_inhibit_lid_switch_timer (manager); if (suspend_on_lid_close (manager)) { gboolean is_inhibited; idle_is_session_inhibited (manager, GSM_INHIBITOR_FLAG_SUSPEND, &is_inhibited); if (is_inhibited) { g_debug ("Suspend is inhibited but lid is closed, locking the screen"); /* We put the screensaver on * as we're not suspending, * but the lid is closed */ lock_screensaver (manager); } } else { if (manager->priv->inhibit_lid_switch_action) lock_screensaver (manager); } } static void lid_state_changed_cb (UpClient *client, GParamSpec *pspec, GsdPowerManager *manager) { gboolean tmp; if (!up_client_get_on_battery (client)) { /* if we are playing a critical charge sound loop on AC, stop it */ play_loop_stop (&manager->priv->critical_alert_timeout_id); notify_close_if_showing (&manager->priv->notification_low); main_battery_or_ups_low_changed (manager, FALSE); } setup_lid_closed_action (manager); /* same state */ tmp = up_client_get_lid_is_closed (manager->priv->up_client); if (manager->priv->lid_is_closed == tmp) return; manager->priv->lid_is_closed = tmp; g_debug ("up changed: lid is now %s", tmp ? "closed" : "open"); if (manager->priv->lid_is_closed) do_lid_closed_action (manager); else do_lid_open_action (manager); } static const gchar * idle_mode_to_string (GsdPowerIdleMode mode) { if (mode == GSD_POWER_IDLE_MODE_NORMAL) return "normal"; if (mode == GSD_POWER_IDLE_MODE_DIM) return "dim"; if (mode == GSD_POWER_IDLE_MODE_BLANK) return "blank"; if (mode == GSD_POWER_IDLE_MODE_SLEEP) return "sleep"; return "unknown"; } static const char * idle_watch_id_to_string (GsdPowerManager *manager, guint id) { if (id == manager->priv->idle_dim_id) return "dim"; if (id == manager->priv->idle_blank_id) return "blank"; if (id == manager->priv->idle_sleep_id) return "sleep"; if (id == manager->priv->idle_sleep_warning_id) return "sleep-warning"; return NULL; } static void backlight_emit_changed (GsdPowerManager *manager) { gboolean ret; GError *error = NULL; /* not yet connected to the bus */ if (manager->priv->connection == NULL) return; ret = g_dbus_connection_emit_signal (manager->priv->connection, NULL, GSD_POWER_DBUS_PATH, GSD_POWER_DBUS_INTERFACE_SCREEN, "Changed", NULL, &error); if (!ret) { g_warning ("failed to emit Changed: %s", error->message); g_error_free (error); } } static gboolean display_backlight_dim (GsdPowerManager *manager, gint idle_percentage, GError **error) { gint min; gint max; gint now; gint idle; gboolean ret = FALSE; if (!manager->priv->backlight_available) return TRUE; now = backlight_get_abs (manager->priv->rr_screen, error); if (now < 0) { goto out; } /* is the dim brightness actually *dimmer* than the * brightness we have now? */ min = backlight_get_min (manager->priv->rr_screen); max = backlight_get_max (manager->priv->rr_screen, error); if (max < 0) { goto out; } idle = PERCENTAGE_TO_ABS (min, max, idle_percentage); if (idle > now) { g_debug ("brightness already now %i/%i, so " "ignoring dim to %i/%i", now, max, idle, max); ret = TRUE; goto out; } ret = backlight_set_abs (manager->priv->rr_screen, idle, error); if (!ret) { goto out; } /* save for undim */ manager->priv->pre_dim_brightness = now; out: return ret; } static gboolean kbd_backlight_dim (GsdPowerManager *manager, gint idle_percentage, GError **error) { gboolean ret; gint idle; gint max; gint now; if (manager->priv->upower_kdb_proxy == NULL) return TRUE; now = upower_kbd_get_brightness (manager); max = manager->priv->kbd_brightness_max; idle = PERCENTAGE_TO_ABS (0, max, idle_percentage); if (idle > now) { g_debug ("kbd brightness already now %i/%i, so " "ignoring dim to %i/%i", now, max, idle, max); return TRUE; } ret = upower_kbd_set_brightness (manager, idle, error); if (!ret) return FALSE; /* save for undim */ manager->priv->kbd_brightness_pre_dim = now; return TRUE; } static gboolean is_session_active (GsdPowerManager *manager) { GVariant *variant; gboolean is_session_active = FALSE; variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (manager->priv->session), "SessionIsActive"); if (variant) { is_session_active = g_variant_get_boolean (variant); g_variant_unref (variant); } return is_session_active; } static void idle_set_mode (GsdPowerManager *manager, GsdPowerIdleMode mode) { gboolean ret = FALSE; GError *error = NULL; gint idle_percentage; GsdPowerActionType action_type; gboolean is_active = FALSE; /* Ignore attempts to set "less idle" modes */ if (mode <= manager->priv->current_idle_mode && mode != GSD_POWER_IDLE_MODE_NORMAL) { g_debug ("Not going to 'less idle' mode %s (current: %s)", idle_mode_to_string (mode), idle_mode_to_string (manager->priv->current_idle_mode)); return; } /* ensure we're still on an active console */ is_active = is_session_active (manager); if (!is_active) { g_debug ("ignoring state transition to %s as inactive", idle_mode_to_string (mode)); return; } /* don't do any power saving if we're a VM */ if (manager->priv->is_virtual_machine) { g_debug ("ignoring state transition to %s as virtual machine", idle_mode_to_string (mode)); return; } manager->priv->current_idle_mode = mode; g_debug ("Doing a state transition: %s", idle_mode_to_string (mode)); /* if we're moving to an idle mode, make sure * we add a watch to take us back to normal */ if (mode != GSD_POWER_IDLE_MODE_NORMAL) { gsd_idle_monitor_add_user_active_watch (manager->priv->idle_monitor, idle_became_active_cb, manager, NULL); } /* save current brightness, and set dim level */ if (mode == GSD_POWER_IDLE_MODE_DIM) { /* display backlight */ idle_percentage = g_settings_get_int (manager->priv->settings, "idle-brightness"); ret = display_backlight_dim (manager, idle_percentage, &error); if (!ret) { g_warning ("failed to set dim backlight to %i%%: %s", idle_percentage, error->message); g_clear_error (&error); } /* keyboard backlight */ ret = kbd_backlight_dim (manager, idle_percentage, &error); if (!ret) { g_warning ("failed to set dim kbd backlight to %i%%: %s", idle_percentage, error->message); g_clear_error (&error); } /* turn off screen and kbd */ } else if (mode == GSD_POWER_IDLE_MODE_BLANK) { backlight_disable (manager); /* only toggle keyboard if present and not already toggled */ if (manager->priv->upower_kdb_proxy && manager->priv->kbd_brightness_old == -1) { if (upower_kbd_toggle (manager, &error) < 0) { g_warning ("failed to turn the kbd backlight off: %s", error->message); g_error_free (error); } } /* sleep */ } else if (mode == GSD_POWER_IDLE_MODE_SLEEP) { if (up_client_get_on_battery (manager->priv->up_client)) { action_type = g_settings_get_enum (manager->priv->settings, "sleep-inactive-battery-type"); } else { action_type = g_settings_get_enum (manager->priv->settings, "sleep-inactive-ac-type"); } do_power_action_type (manager, action_type); /* turn on screen and restore user-selected brightness level */ } else if (mode == GSD_POWER_IDLE_MODE_NORMAL) { backlight_enable (manager); /* reset brightness if we dimmed */ if (manager->priv->pre_dim_brightness >= 0) { ret = backlight_set_abs (manager->priv->rr_screen, manager->priv->pre_dim_brightness, &error); if (!ret) { g_warning ("failed to restore backlight to %i: %s", manager->priv->pre_dim_brightness, error->message); g_clear_error (&error); } else { manager->priv->pre_dim_brightness = -1; } } /* only toggle keyboard if present and already toggled off */ if (manager->priv->upower_kdb_proxy && manager->priv->kbd_brightness_old != -1) { if (upower_kbd_toggle (manager, &error) < 0) { g_warning ("failed to turn the kbd backlight on: %s", error->message); g_clear_error (&error); } } /* reset kbd brightness if we dimmed */ if (manager->priv->kbd_brightness_pre_dim >= 0) { ret = upower_kbd_set_brightness (manager, manager->priv->kbd_brightness_pre_dim, &error); if (!ret) { g_warning ("failed to restore kbd backlight to %i: %s", manager->priv->kbd_brightness_pre_dim, error->message); g_error_free (error); } manager->priv->kbd_brightness_pre_dim = -1; } } } static gboolean idle_is_session_inhibited (GsdPowerManager *manager, GsmInhibitorFlag mask, gboolean *is_inhibited) { GVariant *variant; GsmInhibitorFlag inhibited_actions; /* not yet connected to gnome-session */ if (manager->priv->session == NULL) return FALSE; variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (manager->priv->session), "InhibitedActions"); if (!variant) return FALSE; inhibited_actions = g_variant_get_uint32 (variant); g_variant_unref (variant); *is_inhibited = (inhibited_actions & mask); return TRUE; } static void clear_idle_watch (GsdIdleMonitor *monitor, guint *id) { if (*id == 0) return; gsd_idle_monitor_remove_watch (monitor, *id); *id = 0; } static void idle_configure (GsdPowerManager *manager) { gboolean is_idle_inhibited; GsdPowerActionType action_type; guint timeout_blank; guint timeout_sleep; guint timeout_dim; gboolean on_battery; if (!idle_is_session_inhibited (manager, GSM_INHIBITOR_FLAG_IDLE, &is_idle_inhibited)) { /* Session isn't available yet, postpone */ return; } /* are we inhibited from going idle */ if (!is_session_active (manager) || is_idle_inhibited) { g_debug ("inhibited or inactive, so using normal state"); idle_set_mode (manager, GSD_POWER_IDLE_MODE_NORMAL); clear_idle_watch (manager->priv->idle_monitor, &manager->priv->idle_blank_id); clear_idle_watch (manager->priv->idle_monitor, &manager->priv->idle_sleep_id); clear_idle_watch (manager->priv->idle_monitor, &manager->priv->idle_dim_id); clear_idle_watch (manager->priv->idle_monitor, &manager->priv->idle_sleep_warning_id); notify_close_if_showing (&manager->priv->notification_sleep_warning); return; } /* set up blank callback only when the screensaver is on, * as it's what will drive the blank */ on_battery = up_client_get_on_battery (manager->priv->up_client); timeout_blank = 0; if (manager->priv->screensaver_active) { /* The tail is wagging the dog. * The screensaver coming on will blank the screen. * If an event occurs while the screensaver is on, * the aggressive idle watch will handle it */ timeout_blank = SCREENSAVER_TIMEOUT_BLANK; } clear_idle_watch (manager->priv->idle_monitor, &manager->priv->idle_blank_id); if (timeout_blank != 0) { g_debug ("setting up blank callback for %is", timeout_blank); manager->priv->idle_blank_id = gsd_idle_monitor_add_idle_watch (manager->priv->idle_monitor, timeout_blank * 1000, idle_triggered_idle_cb, manager, NULL); } /* only do the sleep timeout when the session is idle * and we aren't inhibited from sleeping (or logging out, etc.) */ action_type = g_settings_get_enum (manager->priv->settings, on_battery ? "sleep-inactive-battery-type" : "sleep-inactive-ac-type"); timeout_sleep = 0; if (!is_action_inhibited (manager, action_type)) { timeout_sleep = g_settings_get_int (manager->priv->settings, on_battery ? "sleep-inactive-battery-timeout" : "sleep-inactive-ac-timeout"); } clear_idle_watch (manager->priv->idle_monitor, &manager->priv->idle_sleep_id); clear_idle_watch (manager->priv->idle_monitor, &manager->priv->idle_sleep_warning_id); if (timeout_sleep != 0) { g_debug ("setting up sleep callback %is", timeout_sleep); manager->priv->idle_sleep_id = gsd_idle_monitor_add_idle_watch (manager->priv->idle_monitor, timeout_sleep * 1000, idle_triggered_idle_cb, manager, NULL); if (action_type == GSD_POWER_ACTION_LOGOUT || action_type == GSD_POWER_ACTION_SUSPEND || action_type == GSD_POWER_ACTION_HIBERNATE) { guint timeout_sleep_warning; manager->priv->sleep_action_type = action_type; timeout_sleep_warning = timeout_sleep * IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER; if (timeout_sleep_warning < MINIMUM_IDLE_DIM_DELAY) timeout_sleep_warning = 0; g_debug ("setting up sleep warning callback %is", timeout_sleep_warning); manager->priv->idle_sleep_warning_id = gsd_idle_monitor_add_idle_watch (manager->priv->idle_monitor, timeout_sleep_warning * 1000, idle_triggered_idle_cb, manager, NULL); } } if (manager->priv->idle_sleep_warning_id == 0) notify_close_if_showing (&manager->priv->notification_sleep_warning); /* set up dim callback for when the screen lock is not active, * but only if we actually want to dim. */ timeout_dim = 0; if (manager->priv->screensaver_active) { /* Don't dim when the screen lock is active */ } else if (!on_battery) { /* Don't dim when charging */ } else if (manager->priv->battery_is_low) { /* Aggressively blank when battery is low */ timeout_dim = SCREENSAVER_TIMEOUT_BLANK; } else { if (g_settings_get_boolean (manager->priv->settings, "idle-dim")) { timeout_dim = g_settings_get_uint (manager->priv->settings_bus, "idle-delay"); if (timeout_dim == 0) { timeout_dim = IDLE_DIM_BLANK_DISABLED_MIN; } else { timeout_dim *= IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER; /* Don't bother dimming if the idle-delay is * too low, we'll do that when we bring down the * screen lock */ if (timeout_dim < MINIMUM_IDLE_DIM_DELAY) timeout_dim = 0; } } } clear_idle_watch (manager->priv->idle_monitor, &manager->priv->idle_dim_id); if (timeout_dim != 0) { g_debug ("setting up dim callback for %is", timeout_dim); manager->priv->idle_dim_id = gsd_idle_monitor_add_idle_watch (manager->priv->idle_monitor, timeout_dim * 1000, idle_triggered_idle_cb, manager, NULL); } } static void main_battery_or_ups_low_changed (GsdPowerManager *manager, gboolean is_low) { if (is_low == manager->priv->battery_is_low) return; manager->priv->battery_is_low = is_low; idle_configure (manager); } static gboolean temporary_unidle_done_cb (GsdPowerManager *manager) { idle_set_mode (manager, manager->priv->previous_idle_mode); manager->priv->temporary_unidle_on_ac_id = 0; return FALSE; } static void set_temporary_unidle_on_ac (GsdPowerManager *manager, gboolean enable) { if (!enable) { if (manager->priv->temporary_unidle_on_ac_id != 0) { g_source_remove (manager->priv->temporary_unidle_on_ac_id); manager->priv->temporary_unidle_on_ac_id = 0; idle_set_mode (manager, manager->priv->previous_idle_mode); } } else { /* Don't overwrite the previous idle mode when an unidle is * already on-going */ if (manager->priv->temporary_unidle_on_ac_id != 0) { g_source_remove (manager->priv->temporary_unidle_on_ac_id); } else { manager->priv->previous_idle_mode = manager->priv->current_idle_mode; idle_set_mode (manager, GSD_POWER_IDLE_MODE_NORMAL); } manager->priv->temporary_unidle_on_ac_id = g_timeout_add_seconds (POWER_UP_TIME_ON_AC, (GSourceFunc) temporary_unidle_done_cb, manager); } } static void up_client_on_battery_cb (UpClient *client, GParamSpec *pspec, GsdPowerManager *manager) { if (up_client_get_on_battery (manager->priv->up_client)) { ca_context_play (ca_gtk_context_get (), 0, CA_PROP_EVENT_ID, "power-unplug", /* TRANSLATORS: this is the sound description */ CA_PROP_EVENT_DESCRIPTION, _("On battery power"), NULL); } else { ca_context_play (ca_gtk_context_get (), 0, CA_PROP_EVENT_ID, "power-plug", /* TRANSLATORS: this is the sound description */ CA_PROP_EVENT_DESCRIPTION, _("On AC power"), NULL); } idle_configure (manager); if (manager->priv->lid_is_closed) return; if (manager->priv->current_idle_mode == GSD_POWER_IDLE_MODE_BLANK || manager->priv->current_idle_mode == GSD_POWER_IDLE_MODE_DIM || manager->priv->temporary_unidle_on_ac_id != 0) set_temporary_unidle_on_ac (manager, TRUE); } static void gsd_power_manager_finalize (GObject *object) { GsdPowerManager *manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_POWER_MANAGER (object)); manager = GSD_POWER_MANAGER (object); g_return_if_fail (manager->priv != NULL); g_clear_object (&manager->priv->connection); if (manager->priv->name_id != 0) g_bus_unown_name (manager->priv->name_id); G_OBJECT_CLASS (gsd_power_manager_parent_class)->finalize (object); } static void gsd_power_manager_class_init (GsdPowerManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_power_manager_finalize; g_type_class_add_private (klass, sizeof (GsdPowerManagerPrivate)); } static void session_presence_proxy_ready_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GError *error = NULL; GsdPowerManager *manager = GSD_POWER_MANAGER (user_data); manager->priv->session_presence_proxy = g_dbus_proxy_new_for_bus_finish (res, &error); if (manager->priv->session_presence_proxy == NULL) { g_warning ("Could not connect to gnome-sesson: %s", error->message); g_error_free (error); return; } } static void handle_screensaver_active (GsdPowerManager *manager, GVariant *parameters) { gboolean active; g_variant_get (parameters, "(b)", &active); g_debug ("Received screensaver ActiveChanged signal: %d (old: %d)", active, manager->priv->screensaver_active); if (manager->priv->screensaver_active != active) { manager->priv->screensaver_active = active; idle_configure (manager); /* Setup blank as soon as the screensaver comes on, * and its fade has finished. * * See also idle_configure() */ if (active) idle_set_mode (manager, GSD_POWER_IDLE_MODE_BLANK); } } static void screensaver_signal_cb (GDBusProxy *proxy, const gchar *sender_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { if (g_strcmp0 (signal_name, "ActiveChanged") == 0) handle_screensaver_active (GSD_POWER_MANAGER (user_data), parameters); } static void power_keyboard_proxy_ready_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GVariant *k_max = NULL; GError *error = NULL; GsdPowerManager *manager = GSD_POWER_MANAGER (user_data); manager->priv->upower_kdb_proxy = g_dbus_proxy_new_for_bus_finish (res, &error); if (manager->priv->upower_kdb_proxy == NULL) { g_warning ("Could not connect to UPower: %s", error->message); g_error_free (error); goto out; } k_max = g_dbus_proxy_call_sync (manager->priv->upower_kdb_proxy, "GetMaxBrightness", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (k_max == NULL) { if (error->domain != G_DBUS_ERROR || error->code != G_DBUS_ERROR_UNKNOWN_METHOD) { g_warning ("Failed to get max brightness: %s", error->message); } g_error_free (error); goto out; } g_variant_get (k_max, "(i)", &manager->priv->kbd_brightness_max); /* set brightness to max if not currently set so is something * sensible */ if (upower_kbd_get_brightness (manager) < 0) { gboolean ret; ret = upower_kbd_set_brightness (manager, manager->priv->kbd_brightness_max, &error); if (!ret) { g_warning ("failed to initialize kbd backlight to %i: %s", manager->priv->kbd_brightness_max, error->message); g_error_free (error); } } out: if (k_max != NULL) g_variant_unref (k_max); } static void show_sleep_warning (GsdPowerManager *manager) { /* close any existing notification of this class */ notify_close_if_showing (&manager->priv->notification_sleep_warning); /* create a new notification */ switch (manager->priv->sleep_action_type) { case GSD_POWER_ACTION_LOGOUT: create_notification (_("Automatic logout"), _("You will soon log out because of inactivity."), NULL, &manager->priv->notification_sleep_warning); break; case GSD_POWER_ACTION_SUSPEND: create_notification (_("Automatic suspend"), _("Computer will suspend very soon because of inactivity."), NULL, &manager->priv->notification_sleep_warning); break; case GSD_POWER_ACTION_HIBERNATE: create_notification (_("Automatic hibernation"), _("Computer will suspend very soon because of inactivity."), NULL, &manager->priv->notification_sleep_warning); break; default: g_assert_not_reached (); break; } notify_notification_set_timeout (manager->priv->notification_sleep_warning, NOTIFY_EXPIRES_DEFAULT); notify_notification_set_urgency (manager->priv->notification_sleep_warning, NOTIFY_URGENCY_CRITICAL); notify_notification_set_app_name (manager->priv->notification_sleep_warning, _("Power")); notify_notification_show (manager->priv->notification_sleep_warning, NULL); if (manager->priv->sleep_action_type == GSD_POWER_ACTION_LOGOUT) set_temporary_unidle_on_ac (manager, TRUE); } static void idle_triggered_idle_cb (GsdIdleMonitor *monitor, guint watch_id, gpointer user_data) { GsdPowerManager *manager = GSD_POWER_MANAGER (user_data); const char *id_name; id_name = idle_watch_id_to_string (manager, watch_id); if (id_name == NULL) g_debug ("idletime watch: %i", watch_id); else g_debug ("idletime watch: %s (%i)", id_name, watch_id); if (watch_id == manager->priv->idle_dim_id) { idle_set_mode (manager, GSD_POWER_IDLE_MODE_DIM); } else if (watch_id == manager->priv->idle_blank_id) { idle_set_mode (manager, GSD_POWER_IDLE_MODE_BLANK); } else if (watch_id == manager->priv->idle_sleep_id) { idle_set_mode (manager, GSD_POWER_IDLE_MODE_SLEEP); } else if (watch_id == manager->priv->idle_sleep_warning_id) { show_sleep_warning (manager); } } static void idle_became_active_cb (GsdIdleMonitor *monitor, guint watch_id, gpointer user_data) { GsdPowerManager *manager = GSD_POWER_MANAGER (user_data); g_debug ("idletime reset"); set_temporary_unidle_on_ac (manager, FALSE); /* close any existing notification about idleness */ notify_close_if_showing (&manager->priv->notification_sleep_warning); idle_set_mode (manager, GSD_POWER_IDLE_MODE_NORMAL); } static void engine_settings_key_changed_cb (GSettings *settings, const gchar *key, GsdPowerManager *manager) { if (g_strcmp0 (key, "use-time-for-policy") == 0) { manager->priv->use_time_primary = g_settings_get_boolean (settings, key); return; } if (g_str_has_prefix (key, "sleep-inactive") || g_str_equal (key, "idle-delay") || g_str_equal (key, "idle-dim")) { idle_configure (manager); return; } if (g_str_has_prefix (key, "lid-close")) { setup_lid_closed_action (manager); return; } } static void engine_session_properties_changed_cb (GDBusProxy *session, GVariant *changed, char **invalidated, GsdPowerManager *manager) { GVariant *v; v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN); if (v) { gboolean active; active = g_variant_get_boolean (v); g_debug ("Received session is active change: now %s", active ? "active" : "inactive"); /* when doing the fast-user-switch into a new account, * ensure the new account is undimmed and with the backlight on */ if (active) idle_set_mode (manager, GSD_POWER_IDLE_MODE_NORMAL); g_variant_unref (v); } v = g_variant_lookup_value (changed, "InhibitedActions", G_VARIANT_TYPE_UINT32); if (v) { g_variant_unref (v); g_debug ("Received gnome session inhibitor change"); idle_configure (manager); } } static void inhibit_lid_switch_done (GObject *source, GAsyncResult *result, gpointer user_data) { GDBusProxy *proxy = G_DBUS_PROXY (source); GsdPowerManager *manager = GSD_POWER_MANAGER (user_data); GError *error = NULL; GVariant *res; GUnixFDList *fd_list = NULL; gint idx; res = g_dbus_proxy_call_with_unix_fd_list_finish (proxy, &fd_list, result, &error); if (res == NULL) { g_warning ("Unable to inhibit lid switch: %s", error->message); g_error_free (error); } else { g_variant_get (res, "(h)", &idx); manager->priv->inhibit_lid_switch_fd = g_unix_fd_list_get (fd_list, idx, &error); if (manager->priv->inhibit_lid_switch_fd == -1) { g_warning ("Failed to receive system inhibitor fd: %s", error->message); g_error_free (error); } g_debug ("System inhibitor fd is %d", manager->priv->inhibit_lid_switch_fd); g_object_unref (fd_list); g_variant_unref (res); } } static void inhibit_lid_switch (GsdPowerManager *manager) { GVariant *params; if (manager->priv->inhibit_lid_switch_taken) { g_debug ("already inhibited lid-switch"); return; } g_debug ("Adding lid switch system inhibitor"); manager->priv->inhibit_lid_switch_taken = TRUE; params = g_variant_new ("(ssss)", "handle-lid-switch", g_get_user_name (), "Multiple displays attached", "block"); g_dbus_proxy_call_with_unix_fd_list (manager->priv->logind_proxy, "Inhibit", params, 0, G_MAXINT, NULL, NULL, inhibit_lid_switch_done, manager); } static void uninhibit_lid_switch (GsdPowerManager *manager) { if (manager->priv->inhibit_lid_switch_fd == -1) { g_debug ("no lid-switch inhibitor"); return; } g_debug ("Removing lid switch system inhibitor"); close (manager->priv->inhibit_lid_switch_fd); manager->priv->inhibit_lid_switch_fd = -1; manager->priv->inhibit_lid_switch_taken = FALSE; } static void inhibit_suspend_done (GObject *source, GAsyncResult *result, gpointer user_data) { GDBusProxy *proxy = G_DBUS_PROXY (source); GsdPowerManager *manager = GSD_POWER_MANAGER (user_data); GError *error = NULL; GVariant *res; GUnixFDList *fd_list = NULL; gint idx; res = g_dbus_proxy_call_with_unix_fd_list_finish (proxy, &fd_list, result, &error); if (res == NULL) { g_warning ("Unable to inhibit suspend: %s", error->message); g_error_free (error); } else { g_variant_get (res, "(h)", &idx); manager->priv->inhibit_suspend_fd = g_unix_fd_list_get (fd_list, idx, &error); if (manager->priv->inhibit_suspend_fd == -1) { g_warning ("Failed to receive system inhibitor fd: %s", error->message); g_error_free (error); } g_debug ("System inhibitor fd is %d", manager->priv->inhibit_suspend_fd); g_object_unref (fd_list); g_variant_unref (res); } } /* We take a delay inhibitor here, which causes logind to send a * PrepareForSleep signal, which gives us a chance to lock the screen * and do some other preparations. */ static void inhibit_suspend (GsdPowerManager *manager) { if (manager->priv->inhibit_suspend_taken) { g_debug ("already inhibited lid-switch"); return; } g_debug ("Adding suspend delay inhibitor"); manager->priv->inhibit_suspend_taken = TRUE; g_dbus_proxy_call_with_unix_fd_list (manager->priv->logind_proxy, "Inhibit", g_variant_new ("(ssss)", "sleep", g_get_user_name (), "GNOME needs to lock the screen", "delay"), 0, G_MAXINT, NULL, NULL, inhibit_suspend_done, manager); } static void uninhibit_suspend (GsdPowerManager *manager) { if (manager->priv->inhibit_suspend_fd == -1) { g_debug ("no suspend delay inhibitor"); return; } g_debug ("Removing suspend delay inhibitor"); close (manager->priv->inhibit_suspend_fd); manager->priv->inhibit_suspend_fd = -1; manager->priv->inhibit_suspend_taken = FALSE; } static void on_randr_event (GsdRRScreen *screen, gpointer user_data) { GsdPowerManager *manager = GSD_POWER_MANAGER (user_data); if (suspend_on_lid_close (manager)) { restart_inhibit_lid_switch_timer (manager); return; } /* when a second monitor is plugged in, we take the * handle-lid-switch inhibitor lock of logind to prevent * it from suspending. * * Uninhibiting is done in the inhibit_lid_switch_timer, * since we want to give users a few seconds when unplugging * and replugging an external monitor, not suspend right away. */ inhibit_lid_switch (manager); setup_inhibit_lid_switch_timer (manager); } #ifdef GSD_MOCK static gboolean received_sigusr2 (GsdPowerManager *manager) { on_randr_event (NULL, manager); return TRUE; } #endif /* GSD_MOCK */ static void handle_suspend_actions (GsdPowerManager *manager) { backlight_disable (manager); uninhibit_suspend (manager); } static void handle_resume_actions (GsdPowerManager *manager) { /* close existing notifications on resume, the system power * state is probably different now */ notify_close_if_showing (&manager->priv->notification_low); notify_close_if_showing (&manager->priv->notification_ups_discharging); main_battery_or_ups_low_changed (manager, FALSE); /* ensure we turn the panel back on after resume */ backlight_enable (manager); /* And work-around Xorg bug: * https://bugs.freedesktop.org/show_bug.cgi?id=59576 */ reset_idletime (); /* set up the delay again */ inhibit_suspend (manager); } static void logind_proxy_signal_cb (GDBusProxy *proxy, const gchar *sender_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { GsdPowerManager *manager = GSD_POWER_MANAGER (user_data); gboolean is_about_to_suspend; if (g_strcmp0 (signal_name, "PrepareForSleep") != 0) return; g_variant_get (parameters, "(b)", &is_about_to_suspend); if (is_about_to_suspend) { handle_suspend_actions (manager); } else { handle_resume_actions (manager); } } gboolean gsd_power_manager_start (GsdPowerManager *manager, GError **error) { g_debug ("Starting power manager"); gnome_settings_profile_start (NULL); /* coldplug the list of screens */ manager->priv->rr_screen = gsd_rr_screen_new (gdk_screen_get_default (), error); if (manager->priv->rr_screen == NULL) { g_debug ("Couldn't detect any screens, disabling plugin"); return FALSE; } /* Check for XTEST support */ if (supports_xtest () == FALSE) { g_debug ("XTEST extension required, disabling plugin"); return FALSE; } /* Set up the logind proxy */ manager->priv->logind_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, 0, NULL, SYSTEMD_DBUS_NAME, SYSTEMD_DBUS_PATH, SYSTEMD_DBUS_INTERFACE, NULL, error); if (manager->priv->logind_proxy == NULL) { g_debug ("No systemd (logind) support, disabling plugin"); return FALSE; } g_signal_connect (manager->priv->logind_proxy, "g-signal", G_CALLBACK (logind_proxy_signal_cb), manager); /* Set up a delay inhibitor to be informed about suspend attempts */ inhibit_suspend (manager); /* track the active session */ manager->priv->session = gnome_settings_bus_get_session_proxy (); g_signal_connect (manager->priv->session, "g-properties-changed", G_CALLBACK (engine_session_properties_changed_cb), manager); manager->priv->screensaver_proxy = gnome_settings_bus_get_screen_saver_proxy (); g_signal_connect (manager->priv->screensaver_proxy, "g-signal", G_CALLBACK (screensaver_signal_cb), manager); manager->priv->kbd_brightness_old = -1; manager->priv->kbd_brightness_pre_dim = -1; manager->priv->pre_dim_brightness = -1; manager->priv->settings = g_settings_new (GSD_POWER_SETTINGS_SCHEMA); g_signal_connect (manager->priv->settings, "changed", G_CALLBACK (engine_settings_key_changed_cb), manager); manager->priv->settings_screensaver = g_settings_new ("org.gnome.desktop.screensaver"); manager->priv->settings_bus = g_settings_new ("org.gnome.desktop.session"); g_signal_connect (manager->priv->settings_bus, "changed", G_CALLBACK (engine_settings_key_changed_cb), manager); manager->priv->settings_xrandr = g_settings_new (GSD_XRANDR_SETTINGS_SCHEMA); manager->priv->up_client = up_client_new (); manager->priv->lid_is_closed = up_client_get_lid_is_closed (manager->priv->up_client); g_signal_connect (manager->priv->up_client, "device-added", G_CALLBACK (engine_device_added_cb), manager); g_signal_connect (manager->priv->up_client, "device-removed", G_CALLBACK (engine_device_removed_cb), manager); g_signal_connect_after (manager->priv->up_client, "notify::lid-is-closed", G_CALLBACK (lid_state_changed_cb), manager); g_signal_connect (manager->priv->up_client, "notify::on-battery", G_CALLBACK (up_client_on_battery_cb), manager); g_signal_connect_after (manager->priv->up_client, "notify::on-battery", G_CALLBACK (lid_state_changed_cb), manager); /* connect to UPower for keyboard backlight control */ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, UPOWER_DBUS_NAME, UPOWER_DBUS_PATH_KBDBACKLIGHT, UPOWER_DBUS_INTERFACE_KBDBACKLIGHT, NULL, power_keyboard_proxy_ready_cb, manager); /* connect to the session */ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, 0, NULL, GNOME_SESSION_DBUS_NAME, GNOME_SESSION_DBUS_PATH_PRESENCE, GNOME_SESSION_DBUS_INTERFACE_PRESENCE, NULL, session_presence_proxy_ready_cb, manager); manager->priv->devices_array = g_ptr_array_new_with_free_func (g_object_unref); /* create a fake virtual composite battery */ manager->priv->device_composite = up_device_new (); g_object_set (manager->priv->device_composite, "kind", UP_DEVICE_KIND_BATTERY, "is-rechargeable", TRUE, "native-path", "dummy:composite_battery", "power-supply", TRUE, "is-present", TRUE, NULL); /* get percentage policy */ manager->priv->low_percentage = g_settings_get_int (manager->priv->settings, "percentage-low"); manager->priv->critical_percentage = g_settings_get_int (manager->priv->settings, "percentage-critical"); manager->priv->action_percentage = g_settings_get_int (manager->priv->settings, "percentage-action"); /* get time policy */ manager->priv->low_time = g_settings_get_int (manager->priv->settings, "time-low"); manager->priv->critical_time = g_settings_get_int (manager->priv->settings, "time-critical"); manager->priv->action_time = g_settings_get_int (manager->priv->settings, "time-action"); /* we can disable this if the time remaining is inaccurate or just plain wrong */ manager->priv->use_time_primary = g_settings_get_boolean (manager->priv->settings, "use-time-for-policy"); /* create IDLETIME watcher */ manager->priv->idle_monitor = g_object_ref (gsd_idle_monitor_get_core ()); /* set up the screens */ g_signal_connect (manager->priv->rr_screen, "changed", G_CALLBACK (on_randr_event), manager); on_randr_event (manager->priv->rr_screen, manager); #ifdef GSD_MOCK g_unix_signal_add (SIGUSR2, (GSourceFunc) received_sigusr2, manager); #endif /* GSD_MOCK */ /* check whether a backlight is available */ manager->priv->backlight_available = backlight_available (manager->priv->rr_screen); /* ensure the default dpms timeouts are cleared */ backlight_enable (manager); /* coldplug the engine */ engine_coldplug (manager); idle_configure (manager); manager->priv->xscreensaver_watchdog_timer_id = gsd_power_enable_screensaver_watchdog (); /* don't blank inside a VM */ manager->priv->is_virtual_machine = gsd_power_is_hardware_a_vm (); setup_lid_closed_action (manager); gnome_settings_profile_end (NULL); return TRUE; } void gsd_power_manager_stop (GsdPowerManager *manager) { GPtrArray *devices; int i; g_debug ("Stopping power manager"); if (manager->priv->inhibit_lid_switch_timer_id != 0) { g_source_remove (manager->priv->inhibit_lid_switch_timer_id); manager->priv->inhibit_lid_switch_timer_id = 0; } if (manager->priv->bus_cancellable != NULL) { g_cancellable_cancel (manager->priv->bus_cancellable); g_object_unref (manager->priv->bus_cancellable); manager->priv->bus_cancellable = NULL; } if (manager->priv->introspection_data) { g_dbus_node_info_unref (manager->priv->introspection_data); manager->priv->introspection_data = NULL; } g_signal_handlers_disconnect_by_data (manager->priv->up_client, manager); g_clear_object (&manager->priv->session); g_clear_object (&manager->priv->settings); g_clear_object (&manager->priv->settings_screensaver); g_clear_object (&manager->priv->settings_bus); g_clear_object (&manager->priv->up_client); if (manager->priv->inhibit_lid_switch_fd != -1) { close (manager->priv->inhibit_lid_switch_fd); manager->priv->inhibit_lid_switch_fd = -1; manager->priv->inhibit_lid_switch_taken = FALSE; manager->priv->inhibit_lid_switch_action = FALSE; } if (manager->priv->inhibit_suspend_fd != -1) { close (manager->priv->inhibit_suspend_fd); manager->priv->inhibit_suspend_fd = -1; manager->priv->inhibit_suspend_taken = FALSE; } g_clear_object (&manager->priv->logind_proxy); if (manager->priv->rr_screen) { g_signal_handlers_disconnect_by_data (manager->priv->rr_screen, manager); g_clear_object (&manager->priv->rr_screen); } devices = manager->priv->devices_array; if (devices != NULL) { for (i = 0; i < devices->len; i++) g_signal_handlers_disconnect_by_data (g_ptr_array_index (devices, i), manager); g_ptr_array_unref (devices); manager->priv->devices_array = NULL; } g_clear_object (&manager->priv->device_composite); g_clear_object (&manager->priv->previous_icon); g_clear_pointer (&manager->priv->previous_summary, g_free); g_clear_object (&manager->priv->session_presence_proxy); g_clear_object (&manager->priv->screensaver_proxy); play_loop_stop (&manager->priv->critical_alert_timeout_id); g_clear_object (&manager->priv->idle_monitor); if (manager->priv->xscreensaver_watchdog_timer_id > 0) { g_source_remove (manager->priv->xscreensaver_watchdog_timer_id); manager->priv->xscreensaver_watchdog_timer_id = 0; } } static void gsd_power_manager_init (GsdPowerManager *manager) { manager->priv = GSD_POWER_MANAGER_GET_PRIVATE (manager); manager->priv->inhibit_lid_switch_fd = -1; manager->priv->inhibit_suspend_fd = -1; manager->priv->inhibit_lid_switch_action = FALSE; manager->priv->bus_cancellable = g_cancellable_new (); } /* returns new level */ static void handle_method_call_keyboard (GsdPowerManager *manager, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation) { gint now; gint step; gint value = -1; gboolean ret; guint percentage; GError *error = NULL; if (g_strcmp0 (method_name, "StepUp") == 0) { g_debug ("keyboard step up"); now = upower_kbd_get_brightness (manager); step = BRIGHTNESS_STEP_AMOUNT (manager->priv->kbd_brightness_max); value = MIN (now + step, manager->priv->kbd_brightness_max); ret = upower_kbd_set_brightness (manager, value, &error); } else if (g_strcmp0 (method_name, "StepDown") == 0) { g_debug ("keyboard step down"); now = upower_kbd_get_brightness (manager); step = BRIGHTNESS_STEP_AMOUNT (manager->priv->kbd_brightness_max); value = MAX (now - step, 0); ret = upower_kbd_set_brightness (manager, value, &error); } else if (g_strcmp0 (method_name, "Toggle") == 0) { value = upower_kbd_toggle (manager, &error); ret = (value >= 0); } else { g_assert_not_reached (); } /* return value */ if (!ret) { g_dbus_method_invocation_take_error (invocation, error); } else { percentage = ABS_TO_PERCENTAGE (0, manager->priv->kbd_brightness_max, value); g_dbus_method_invocation_return_value (invocation, g_variant_new ("(u)", percentage)); } } static void handle_method_call_screen (GsdPowerManager *manager, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation) { gboolean ret = FALSE; gint value = -1; guint value_tmp; GError *error = NULL; if (!manager->priv->backlight_available) { g_set_error_literal (&error, GSD_POWER_MANAGER_ERROR, GSD_POWER_MANAGER_ERROR_FAILED, "Screen backlight not available"); goto out; } if (g_strcmp0 (method_name, "GetPercentage") == 0) { g_debug ("screen get percentage"); value = backlight_get_percentage (manager->priv->rr_screen, &error); } else if (g_strcmp0 (method_name, "SetPercentage") == 0) { g_debug ("screen set percentage"); g_variant_get (parameters, "(u)", &value_tmp); ret = backlight_set_percentage (manager->priv->rr_screen, value_tmp, &error); if (ret) { value = value_tmp; backlight_emit_changed (manager); } } else if (g_strcmp0 (method_name, "StepUp") == 0) { g_debug ("screen step up"); value = backlight_step_up (manager->priv->rr_screen, &error); if (value != -1) backlight_emit_changed (manager); } else if (g_strcmp0 (method_name, "StepDown") == 0) { g_debug ("screen step down"); value = backlight_step_down (manager->priv->rr_screen, &error); if (value != -1) backlight_emit_changed (manager); } else { g_assert_not_reached (); } out: /* return value */ if (value < 0) { g_dbus_method_invocation_take_error (invocation, error); } else { g_dbus_method_invocation_return_value (invocation, g_variant_new ("(u)", value)); } } static GVariant * device_to_variant_blob (UpDevice *device) { const gchar *object_path; gchar *device_icon; gdouble percentage; GIcon *icon; guint64 time_empty, time_full; guint64 time_state = 0; GVariant *value; UpDeviceKind kind; UpDeviceState state; icon = gpm_upower_get_device_icon (device, TRUE); device_icon = g_icon_to_string (icon); g_object_get (device, "kind", &kind, "percentage", &percentage, "state", &state, "time-to-empty", &time_empty, "time-to-full", &time_full, NULL); /* only return time for these simple states */ if (state == UP_DEVICE_STATE_DISCHARGING) time_state = time_empty; else if (state == UP_DEVICE_STATE_CHARGING) time_state = time_full; /* get an object path, even for the composite device */ object_path = up_device_get_object_path (device); if (object_path == NULL) object_path = GSD_DBUS_PATH; /* format complex object */ value = g_variant_new ("(susdut)", object_path, kind, device_icon, percentage, state, time_state); g_free (device_icon); g_object_unref (icon); return value; } static void handle_method_call_main (GsdPowerManager *manager, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation) { GPtrArray *array; guint i; GVariantBuilder *builder; GVariant *tuple = NULL; GVariant *value = NULL; UpDevice *device; /* return object */ if (g_strcmp0 (method_name, "GetPrimaryDevice") == 0) { /* get the virtual device */ device = engine_get_primary_device (manager); if (device == NULL) { g_dbus_method_invocation_return_dbus_error (invocation, "org.gnome.SettingsDaemon.Power.Failed", "There is no primary device."); return; } /* return the value */ value = device_to_variant_blob (device); tuple = g_variant_new_tuple (&value, 1); g_dbus_method_invocation_return_value (invocation, tuple); g_object_unref (device); return; } /* return array */ if (g_strcmp0 (method_name, "GetDevices") == 0) { /* create builder */ builder = g_variant_builder_new (G_VARIANT_TYPE("a(susdut)")); /* add each tuple to the array */ array = manager->priv->devices_array; for (i=0; ilen; i++) { device = g_ptr_array_index (array, i); value = device_to_variant_blob (device); g_variant_builder_add_value (builder, value); } /* return the value */ value = g_variant_builder_end (builder); tuple = g_variant_new_tuple (&value, 1); g_dbus_method_invocation_return_value (invocation, tuple); g_variant_builder_unref (builder); return; } g_assert_not_reached (); } static void handle_method_call (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { GsdPowerManager *manager = GSD_POWER_MANAGER (user_data); /* Check session pointer as a proxy for whether the manager is in the start or stop state */ if (manager->priv->session == NULL) { return; } g_debug ("Calling method '%s.%s' for Power", interface_name, method_name); if (g_strcmp0 (interface_name, GSD_POWER_DBUS_INTERFACE) == 0) { handle_method_call_main (manager, method_name, parameters, invocation); } else if (g_strcmp0 (interface_name, GSD_POWER_DBUS_INTERFACE_SCREEN) == 0) { handle_method_call_screen (manager, method_name, parameters, invocation); } else if (g_strcmp0 (interface_name, GSD_POWER_DBUS_INTERFACE_KEYBOARD) == 0) { handle_method_call_keyboard (manager, method_name, parameters, invocation); } else { g_warning ("not recognised interface: %s", interface_name); } } static GVariant * handle_get_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data) { GsdPowerManager *manager = GSD_POWER_MANAGER (user_data); GVariant *retval = NULL; /* Check session pointer as a proxy for whether the manager is in the start or stop state */ if (manager->priv->session == NULL) { return NULL; } if (g_strcmp0 (property_name, "Icon") == 0) { retval = engine_get_icon_property_variant (manager); } else if (g_strcmp0 (property_name, "Tooltip") == 0) { retval = engine_get_tooltip_property_variant (manager); } else if (g_strcmp0 (property_name, "Percentage") == 0) { gdouble percentage; percentage = engine_get_percentage (manager); if (percentage >= 0) retval = g_variant_new_double (percentage); } return retval; } static const GDBusInterfaceVTable interface_vtable = { handle_method_call, handle_get_property, NULL, /* SetProperty */ }; static void on_bus_gotten (GObject *source_object, GAsyncResult *res, GsdPowerManager *manager) { GDBusConnection *connection; GDBusInterfaceInfo **infos; GError *error = NULL; guint i; connection = g_bus_get_finish (res, &error); if (connection == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Could not get session bus: %s", error->message); g_error_free (error); return; } manager->priv->connection = connection; infos = manager->priv->introspection_data->interfaces; for (i = 0; infos[i] != NULL; i++) { g_dbus_connection_register_object (connection, GSD_POWER_DBUS_PATH, infos[i], &interface_vtable, manager, NULL, NULL); } manager->priv->name_id = g_bus_own_name_on_connection (connection, GSD_POWER_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL); } static void register_manager_dbus (GsdPowerManager *manager) { manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (manager->priv->introspection_data != NULL); g_bus_get (G_BUS_TYPE_SESSION, manager->priv->bus_cancellable, (GAsyncReadyCallback) on_bus_gotten, manager); } GsdPowerManager * gsd_power_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_POWER_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); register_manager_dbus (manager_object); } return GSD_POWER_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsd-power-manager.h0000664000175000017500000000467200000000000025354 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_POWER_MANAGER_H #define __GSD_POWER_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_POWER_MANAGER (gsd_power_manager_get_type ()) #define GSD_POWER_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_POWER_MANAGER, GsdPowerManager)) #define GSD_POWER_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_POWER_MANAGER, GsdPowerManagerClass)) #define GSD_IS_POWER_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_POWER_MANAGER)) #define GSD_IS_POWER_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_POWER_MANAGER)) #define GSD_POWER_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_POWER_MANAGER, GsdPowerManagerClass)) #define GSD_POWER_MANAGER_ERROR (gsd_power_manager_error_quark ()) typedef struct GsdPowerManagerPrivate GsdPowerManagerPrivate; typedef struct { GObject parent; GsdPowerManagerPrivate *priv; } GsdPowerManager; typedef struct { GObjectClass parent_class; } GsdPowerManagerClass; enum { GSD_POWER_MANAGER_ERROR_FAILED }; GType gsd_power_manager_get_type (void); GQuark gsd_power_manager_error_quark (void); GsdPowerManager * gsd_power_manager_new (void); gboolean gsd_power_manager_start (GsdPowerManager *manager, GError **error); void gsd_power_manager_stop (GsdPowerManager *manager); G_END_DECLS #endif /* __GSD_POWER_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsd-power-plugin.c0000664000175000017500000000201500000000000025220 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-power-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdPower, gsd_power) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsdpowerconstants.py0000664000175000017500000000113200000000000026011 0ustar00jeremyjeremy # File auto-generated from script http://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-power-constants-update.pl # Modified by the GTK+ Team and others 1997-2012. See the AUTHORS # file for a list of people on the GTK+ Team. See the ChangeLog # files for a list of changes. These files are distributed with # GTK+ at ftp://ftp.gtk.org/pub/gtk/. SCREENSAVER_TIMEOUT_BLANK = 15; IDLE_DIM_BLANK_DISABLED_MIN = 60; IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER = 4.0/5.0; MINIMUM_IDLE_DIM_DELAY = 10; POWER_UP_TIME_ON_AC = 15; GSD_MOCK_DEFAULT_BRIGHTNESS = 50; GSD_MOCK_MAX_BRIGHTNESS = 100; ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsm-inhibitor-flag.h0000664000175000017500000000240400000000000025506 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Red Hat, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #ifndef __GSM_INHIBITOR_FLAG_H__ #define __GSM_INHIBITOR_FLAG_H__ #include G_BEGIN_DECLS typedef enum { GSM_INHIBITOR_FLAG_LOGOUT = 1 << 0, GSM_INHIBITOR_FLAG_SWITCH_USER = 1 << 1, GSM_INHIBITOR_FLAG_SUSPEND = 1 << 2, GSM_INHIBITOR_FLAG_IDLE = 1 << 3, GSM_INHIBITOR_FLAG_AUTOMOUNT = 1 << 4 } GsmInhibitorFlag; G_END_DECLS #endif /* __GSM_INHIBITOR_FLAG_H__ */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsm-manager-logout-mode.h0000664000175000017500000000223300000000000026453 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSM_MANAGER_LOGOUT_MODE_H #define __GSM_MANAGER_LOGOUT_MODE_H G_BEGIN_DECLS typedef enum { GSM_MANAGER_LOGOUT_MODE_NORMAL = 0, GSM_MANAGER_LOGOUT_MODE_NO_CONFIRMATION, GSM_MANAGER_LOGOUT_MODE_FORCE } GsmManagerLogoutMode; G_END_DECLS #endif /* __GSM_MANAGER_LOGOUT_MODE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/gsm-presence-flag.h0000664000175000017500000000221200000000000025320 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2009 Red Hat, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #ifndef __GSM_PRESENCE_FLAG_H__ #define __GSM_PRESENCE_FLAG_H__ G_BEGIN_DECLS typedef enum { GSM_PRESENCE_STATUS_AVAILABLE = 0, GSM_PRESENCE_STATUS_INVISIBLE, GSM_PRESENCE_STATUS_BUSY, GSM_PRESENCE_STATUS_IDLE, } GsmPresenceStatus; G_END_DECLS #endif /* __GSM_PRESENCE_FLAG_H__ */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/power.gnome-settings-plugin.in0000664000175000017500000000025000000000000027572 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=power IAge=0 Priority=1 _Name=Power _Description=Power plugin Authors=Richard Hughes Copyright=Copyright © 2011 Richard Hughes Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/test-power.c0000664000175000017500000000030500000000000024126 0ustar00jeremyjeremy#define NEW gsd_power_manager_new #define START gsd_power_manager_start #define STOP gsd_power_manager_stop #define MANAGER GsdPowerManager #include "gsd-power-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/power/test.py0000775000175000017500000006617300000000000023224 0ustar00jeremyjeremy#!/usr/bin/env python '''GNOME settings daemon tests for power plugin.''' __author__ = 'Martin Pitt ' __copyright__ = '(C) 2013 Canonical Ltd.' __license__ = 'GPL v2 or later' import unittest import subprocess import sys import time import os import os.path import signal project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) builddir = os.environ.get('BUILDDIR', os.path.dirname(__file__)) sys.path.insert(0, os.path.join(project_root, 'tests')) sys.path.insert(0, builddir) import gsdtestcase import gsdpowerconstants import gsdpowerenums import dbus from gi.repository import Gio class PowerPluginTest(gsdtestcase.GSDTestCase): '''Test the power plugin''' def setUp(self): self.daemon_death_expected = False self.session_log_write = open(os.path.join(self.workdir, 'gnome-session.log'), 'wb') self.session = subprocess.Popen(['gnome-session', '-f', '-a', os.path.join(self.workdir, 'autostart'), '--session=dummy', '--debug'], stdout=self.session_log_write, stderr=subprocess.STDOUT) # wait until the daemon is on the bus try: self.wait_for_bus_object('org.gnome.SessionManager', '/org/gnome/SessionManager') except: # on failure, print log with open(self.session_log_write.name) as f: print('----- session log -----\n%s\n------' % f.read()) raise self.session_log = open(self.session_log_write.name) self.obj_session_mgr = self.session_bus_con.get_object( 'org.gnome.SessionManager', '/org/gnome/SessionManager') # start mock upowerd (self.upowerd, self.obj_upower) = self.spawn_server_template( 'upower', {'OnBattery': True, 'LidIsClosed': False}, stdout=subprocess.PIPE) gsdtestcase.set_nonblock(self.upowerd.stdout) # start mock gnome-shell screensaver (self.screensaver, self.obj_screensaver) = self.spawn_server_template( 'gnome_screensaver', stdout=subprocess.PIPE) gsdtestcase.set_nonblock(self.screensaver.stdout) self.start_logind() # Set up the gnome-session presence obj_session_presence = self.session_bus_con.get_object( 'org.gnome.SessionManager', '/org/gnome/SessionManager/Presence') self.obj_session_presence_props = dbus.Interface(obj_session_presence, dbus.PROPERTIES_IFACE) # ensure that our tests don't lock the screen when the screensaver # gets active self.settings_screensaver = Gio.Settings('org.gnome.desktop.screensaver') self.settings_screensaver['lock-enabled'] = False self.settings_gsd_power = Gio.Settings('com.canonical.unity.settings-daemon.plugins.power') # start power plugin self.settings_gsd_power['active'] = False Gio.Settings.sync() self.plugin_log_write = open(os.path.join(self.workdir, 'plugin_power.log'), 'wb') # avoid painfully long delays of actions for tests env = os.environ.copy() env['GSD_DISABLE_BACKLIGHT_HELPER'] = '1' self.daemon = subprocess.Popen( [os.path.join(builddir, 'usd-test-power')], # comment out this line if you want to see the logs in real time stdout=self.plugin_log_write, stderr=subprocess.STDOUT, env=env) # you can use this for reading the current daemon log in tests self.plugin_log = open(self.plugin_log_write.name) # wait until plugin is ready timeout = 100 while timeout > 0: time.sleep(0.1) timeout -= 1 log = self.plugin_log.read() if 'System inhibitor fd is' in log: break # always start with zero idle time self.reset_idle_timer() # flush notification log try: self.p_notify.stdout.read() except IOError: pass def tearDown(self): daemon_running = self.daemon.poll() == None if daemon_running: self.daemon.terminate() self.daemon.wait() self.plugin_log.close() self.plugin_log_write.flush() self.plugin_log_write.close() self.upowerd.terminate() self.upowerd.wait() self.screensaver.terminate() self.screensaver.wait() self.stop_session() self.stop_logind() # reset all changed gsettings, so that tests are independent from each # other for schema in [self.settings_gsd_power, self.settings_session, self.settings_screensaver]: for k in schema.list_keys(): schema.reset(k) Gio.Settings.sync() try: os.unlink('GSD_MOCK_EXTERNAL_MONITOR') except OSError: pass try: os.unlink('GSD_MOCK_brightness') except OSError: pass # we check this at the end so that the other cleanup always happens self.assertTrue(daemon_running or self.daemon_death_expected, 'daemon died during the test') def stop_session(self): '''Stop GNOME session''' assert self.session self.session.terminate() self.session.wait() self.session_log_write.flush() self.session_log_write.close() self.session_log.close() def get_status(self): return self.obj_session_presence_props.Get('org.gnome.SessionManager.Presence', 'status') def get_brightness(self): f = open('GSD_MOCK_brightness', 'r') ret = f.read() f.close() return int(ret) def set_has_external_monitor(self, external): f = open('GSD_MOCK_EXTERNAL_MONITOR', 'w') if external: f.write('1') else: f.write('0') f.close () os.kill(self.daemon.pid, signal.SIGUSR2) def check_for_logout(self, timeout): '''Check that logout is requested. Fail after the tiven timeout. ''' # check that it request suspend while timeout > 0: time.sleep(1) timeout -= 1 # check that it requested suspend try: log = self.session_log.read() except IOError: break if log and (b'GsmManager: requesting logout' in log): break else: self.fail('timed out waiting for gnome-session logout call') def check_no_logout(self, seconds): '''Check that no logout is requested in the given time''' # wait for specified time to ensure it didn't do anything time.sleep(seconds) # check that it did not logout log = self.session_log.read() if log: self.assertFalse(b'GsmManager: requesting logout' in log, 'unexpected logout request') def check_for_suspend(self, timeout): '''Check that Suspend() or Hibernate() is requested. Fail after the tiven timeout. ''' # check that it request suspend while timeout > 0: time.sleep(1) timeout -= 1 # check that it requested suspend try: log = self.logind.stdout.read() except IOError: break if log and (b' Suspend ' in log or b' Hibernate ' in log): break else: self.fail('timed out waiting for logind Suspend() call') def check_no_suspend(self, seconds): '''Check that no Suspend or Hibernate is requested in the given time''' # wait for specified time to ensure it didn't do anything time.sleep(seconds) # check that it did not suspend or hibernate log = self.logind.stdout.read() if log: self.assertFalse(b' Suspend' in log, 'unexpected Suspend request') self.assertFalse(b' Hibernate' in log, 'unexpected Hibernate request') def check_no_dim(self, seconds): '''Check that mode is not set to dim in the given time''' # wait for specified time to ensure it didn't do anything time.sleep(seconds) # check that we don't dim log = self.plugin_log.read() if log: self.assertFalse(b'Doing a state transition: dim' in log, 'unexpected dim request') def check_dim(self, timeout): '''Check that mode is set to dim in the given time''' # wait for specified time to ensure it didn't do anything while timeout > 0: time.sleep(1) timeout -= 1 # check that it requested dim log = self.plugin_log.read() if 'Doing a state transition: dim' in log: break else: self.fail('timed out waiting for dim') def check_undim(self, timeout): '''Check that mode is set to normal in the given time''' # wait for specified time to ensure it didn't do anything while timeout > 0: time.sleep(1) timeout -= 1 # check that it requested normal log = self.plugin_log.read() if 'Doing a state transition: normal' in log: break else: self.fail('timed out waiting for normal mode') def check_blank(self, timeout): '''Check that blank is requested. Fail after the given timeout. ''' # check that it request blank while timeout > 0: time.sleep(1) timeout -= 1 # check that it requested blank log = self.plugin_log.read() if 'TESTSUITE: Blanked screen' in log: break else: self.fail('timed out waiting for blank') def check_unblank(self, timeout): '''Check that unblank is requested. Fail after the given timeout. ''' # check that it request blank while timeout > 0: time.sleep(1) timeout -= 1 # check that it requested unblank log = self.plugin_log.read() if 'TESTSUITE: Unblanked screen' in log: break else: self.fail('timed out waiting for unblank') def check_no_blank(self, seconds): '''Check that no blank is requested in the given time''' # wait for specified time to ensure it didn't blank time.sleep(seconds) # check that it did not blank log = self.plugin_log.read() self.assertFalse('TESTSUITE: Blanked screen' in log, 'unexpected blank request') def test_sleep_inactive_blank(self): '''screensaver/blank interaction''' # create suspend inhibitor which should have no effect on the idle inhibit_id = self.obj_session_mgr.Inhibit( 'testsuite', dbus.UInt32(0), 'for testing', dbus.UInt32(gsdpowerenums.GSM_INHIBITOR_FLAG_SUSPEND)) self.obj_screensaver.SetActive(True) self.assertTrue(self.obj_screensaver.GetActive(), 'screensaver not turned on') # blank is supposed to happen straight away self.check_blank(2) # wiggle the mouse now and check for unblank; this is expected to pop up # the locked screen saver self.reset_idle_timer() self.check_unblank(2) self.assertTrue(self.get_brightness() == gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS , 'incorrect unblanked brightness') # Check for no blank before the normal blank timeout self.check_no_blank(gsdpowerconstants.SCREENSAVER_TIMEOUT_BLANK - 4) self.assertTrue(self.obj_screensaver.GetActive(), 'screensaver not turned on') # and check for blank after the blank timeout self.check_blank(10) # Drop inhibitor self.obj_session_mgr.Uninhibit(dbus.UInt32(inhibit_id)) def test_session_idle_delay(self): '''verify that session idle delay works as expected when changed''' # Verify that idle is set after 5 seconds self.settings_session['idle-delay'] = 5 self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_AVAILABLE) time.sleep(7) self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_IDLE) # Raise the idle delay, and see that we stop being idle # and get idle again after the timeout self.settings_session['idle-delay'] = 10 self.reset_idle_timer() time.sleep(5) os.kill(self.session.pid, signal.SIGUSR2) self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_AVAILABLE) time.sleep(10) self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_IDLE) # Lower the delay again, and see that we get idle as we should self.settings_session['idle-delay'] = 5 self.reset_idle_timer() time.sleep(2) os.kill(self.session.pid, signal.SIGUSR2) self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_AVAILABLE) time.sleep(5) self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_IDLE) def test_idle_time_reset_on_resume(self): '''Check that the IDLETIME is reset when resuming''' # Go idle self.settings_session['idle-delay'] = 5 self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_AVAILABLE) time.sleep(7) self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_IDLE) # Go to sleep self.obj_logind.EmitSignal('', 'PrepareForSleep', 'b', [True], dbus_interface='org.freedesktop.DBus.Mock') time.sleep(1) # Wake up self.obj_logind.EmitSignal('', 'PrepareForSleep', 'b', [False], dbus_interface='org.freedesktop.DBus.Mock') time.sleep(1) # And check we're not idle self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_AVAILABLE) def test_sleep_inactive_battery(self): '''sleep-inactive-battery-timeout''' self.settings_session['idle-delay'] = 2 self.settings_gsd_power['sleep-inactive-battery-timeout'] = 5 self.settings_gsd_power['sleep-inactive-battery-type'] = 'suspend' # wait for idle delay; should not yet suspend self.check_no_suspend(2) # suspend should happen after inactive sleep timeout + 1 s notification # delay + 1 s error margin self.check_for_suspend(7) def test_sleep_inhibition(self): '''Does not sleep under idle inhibition''' idle_delay = round(gsdpowerconstants.MINIMUM_IDLE_DIM_DELAY / gsdpowerconstants.IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER) self.settings_session['idle-delay'] = idle_delay self.settings_gsd_power['sleep-inactive-battery-timeout'] = 5 self.settings_gsd_power['sleep-inactive-battery-type'] = 'suspend' # create inhibitor inhibit_id = self.obj_session_mgr.Inhibit( 'testsuite', dbus.UInt32(0), 'for testing', dbus.UInt32(gsdpowerenums.GSM_INHIBITOR_FLAG_IDLE | gsdpowerenums.GSM_INHIBITOR_FLAG_SUSPEND)) self.check_no_suspend(idle_delay + 2) self.check_no_dim(0) # Check that we didn't go to idle either self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_AVAILABLE) self.obj_session_mgr.Uninhibit(dbus.UInt32(inhibit_id)) def test_lock_on_lid_close(self): '''Check that we do lock on lid closing, if the machine will not suspend''' self.settings_screensaver['lock-enabled'] = True # create inhibitor inhibit_id = self.obj_session_mgr.Inhibit( 'testsuite', dbus.UInt32(0), 'for testing', dbus.UInt32(gsdpowerenums.GSM_INHIBITOR_FLAG_SUSPEND)) # Close the lid self.obj_upower.Set('org.freedesktop.UPower', 'LidIsClosed', True) self.obj_upower.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') # Check that we've blanked time.sleep(2) self.assertTrue(self.obj_screensaver.GetActive(), 'screensaver not turned on') self.check_blank(2) # Drop the inhibit and see whether we suspend self.obj_session_mgr.Uninhibit(dbus.UInt32(inhibit_id)) self.check_for_suspend(5) def test_blank_on_lid_close(self): '''Check that we do blank on lid closing, if the machine will not suspend''' # create inhibitor inhibit_id = self.obj_session_mgr.Inhibit( 'testsuite', dbus.UInt32(0), 'for testing', dbus.UInt32(gsdpowerenums.GSM_INHIBITOR_FLAG_SUSPEND)) # Close the lid self.obj_upower.Set('org.freedesktop.UPower', 'LidIsClosed', True) self.obj_upower.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') # Check that we've blanked self.check_blank(4) # Drop the inhibit and see whether we suspend self.obj_session_mgr.Uninhibit(dbus.UInt32(inhibit_id)) self.check_for_suspend(5) def test_unblank_on_lid_open(self): '''Check that we do unblank on lid opening, if the machine will not suspend''' # create inhibitor inhibit_id = self.obj_session_mgr.Inhibit( 'testsuite', dbus.UInt32(0), 'for testing', dbus.UInt32(gsdpowerenums.GSM_INHIBITOR_FLAG_SUSPEND)) # Close the lid self.obj_upower.Set('org.freedesktop.UPower', 'LidIsClosed', True) self.obj_upower.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') # Check that we've blanked self.check_blank(2) # Reopen the lid self.obj_upower.Set('org.freedesktop.UPower', 'LidIsClosed', False) self.obj_upower.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') # Check for unblanking self.check_unblank(2) # Drop the inhibit self.obj_session_mgr.Uninhibit(dbus.UInt32(inhibit_id)) def test_dim(self): '''Check that we do go to dim''' idle_delay = round(gsdpowerconstants.MINIMUM_IDLE_DIM_DELAY / gsdpowerconstants.IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER) self.settings_session['idle-delay'] = idle_delay self.settings_gsd_power['sleep-inactive-battery-timeout'] = idle_delay + 1 self.settings_gsd_power['sleep-inactive-battery-type'] = 'suspend' # This is an absolute percentage, and our brightness is 0..100 dim_level = self.settings_gsd_power['idle-brightness']; # Check that we're not idle self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_AVAILABLE) # Wait and check we're not idle, but dimmed self.check_dim(gsdpowerconstants.MINIMUM_IDLE_DIM_DELAY) self.assertTrue(self.get_brightness() == dim_level, 'incorrect dim brightness') self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_AVAILABLE) # Bring down the screensaver self.obj_screensaver.SetActive(True) self.assertTrue(self.obj_screensaver.GetActive(), 'screensaver not turned on') # Check that we blank self.check_blank(2) # Go to sleep self.obj_logind.EmitSignal('', 'PrepareForSleep', 'b', [True], dbus_interface='org.freedesktop.DBus.Mock') time.sleep(1) # Wake up self.obj_logind.EmitSignal('', 'PrepareForSleep', 'b', [False], dbus_interface='org.freedesktop.DBus.Mock') time.sleep(1) # And check that we have the pre-dim brightness self.assertTrue(self.get_brightness() == gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS , 'incorrect unblanked brightness') def test_no_suspend_lid_close(self): '''Check that we don't suspend on lid close with an external monitor''' # Add an external monitor self.set_has_external_monitor(True) time.sleep (1) # Close the lid self.obj_upower.Set('org.freedesktop.UPower', 'LidIsClosed', True) self.obj_upower.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') # Check for no suspend, and for no screen blanking self.check_no_suspend (10) self.check_no_blank(0) # Unplug the external monitor self.set_has_external_monitor(False) self.check_for_suspend (10) def test_action_critical_battery(self): '''action on critical battery''' # add a fake battery with 30%/2 hours charge to upower bat_path = self.obj_upower.AddDischargingBattery('mock_BAT', 'Mock Bat', 30.0, 1200) obj_bat = self.system_bus_con.get_object('org.freedesktop.UPower', bat_path) self.obj_upower.EmitSignal('', 'DeviceAdded', 's', [bat_path], dbus_interface='org.freedesktop.DBus.Mock') time.sleep(1) # now change battery to critical charge obj_bat.Set('org.freedesktop.UPower.Device', 'TimeToEmpty', dbus.Int64(30, variant_level=1), dbus_interface=dbus.PROPERTIES_IFACE) obj_bat.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') self.obj_upower.EmitSignal('', 'DeviceChanged', 's', [obj_bat.object_path], dbus_interface='org.freedesktop.DBus.Mock') time.sleep(0.5) # we should have gotten a notification now notify_log = self.p_notify.stdout.read() self.check_for_suspend(5) # verify notification self.assertRegex(notify_log, b'[0-9.]+ Notify "Power" 0 "battery-.*" ".*battery critical.*"') def test_action_critical_battery_on_start(self): '''action on critical battery on startup''' # add a fake battery with 2%/1 minute charge to upower bat_path = self.obj_upower.AddDischargingBattery('mock_BAT', 'Mock Bat', 2.0, 60) obj_bat = self.system_bus_con.get_object('org.freedesktop.UPower', bat_path) self.obj_upower.EmitSignal('', 'DeviceAdded', 's', [bat_path], dbus_interface='org.freedesktop.DBus.Mock') time.sleep(5) # we should have gotten a notification now notify_log = self.p_notify.stdout.read() self.check_for_suspend(5) # verify notification self.assertRegex(notify_log, b'[0-9.]+ Notify "Power" 0 "battery-.*" ".*battery critical.*"') def test_action_multiple_batteries(self): '''critical actions for multiple batteries''' # add two fake batteries to upower bat1_path = self.obj_upower.AddDischargingBattery('mock_BAT1', 'Bat0', 30.0, 1200) obj_bat1 = self.system_bus_con.get_object('org.freedesktop.UPower', bat1_path) self.obj_upower.EmitSignal('', 'DeviceAdded', 's', [bat1_path], dbus_interface='org.freedesktop.DBus.Mock') bat2_path = self.obj_upower.AddDischargingBattery('mock_BAT2', 'Bat2', 40.0, 1600) obj_bat2 = self.system_bus_con.get_object('org.freedesktop.UPower', bat2_path) self.obj_upower.EmitSignal('', 'DeviceAdded', 's', [bat2_path], dbus_interface='org.freedesktop.DBus.Mock') time.sleep(1) # now change one battery to critical charge obj_bat1.Set('org.freedesktop.UPower.Device', 'TimeToEmpty', dbus.Int64(30, variant_level=1), dbus_interface=dbus.PROPERTIES_IFACE) obj_bat1.Set('org.freedesktop.UPower.Device', 'Energy', dbus.Double(0.5, variant_level=1), dbus_interface=dbus.PROPERTIES_IFACE) obj_bat1.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') self.obj_upower.EmitSignal('', 'DeviceChanged', 's', [bat1_path], dbus_interface='org.freedesktop.DBus.Mock') # wait long enough to ensure it didn't do anything (as we still have # the second battery) self.check_no_suspend(5) # now change the other battery to critical charge as well obj_bat2.Set('org.freedesktop.UPower.Device', 'TimeToEmpty', dbus.Int64(25, variant_level=1), dbus_interface=dbus.PROPERTIES_IFACE) obj_bat2.Set('org.freedesktop.UPower.Device', 'Energy', dbus.Double(0.4, variant_level=1), dbus_interface=dbus.PROPERTIES_IFACE) obj_bat2.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') self.obj_upower.EmitSignal('', 'DeviceChanged', 's', [bat2_path], dbus_interface='org.freedesktop.DBus.Mock') self.check_for_suspend(5) def test_forced_logout(self): '''Test forced logout''' self.daemon_death_expected = True idle_delay = round(gsdpowerconstants.MINIMUM_IDLE_DIM_DELAY / gsdpowerconstants.IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER) self.settings_session['idle-delay'] = idle_delay self.settings_gsd_power['sleep-inactive-battery-timeout'] = idle_delay + 1 self.settings_gsd_power['sleep-inactive-battery-type'] = 'logout' self.check_for_logout(idle_delay + 2) # The notification should have been received before the logout, but it's saved anyway notify_log = self.p_notify.stdout.read() self.assertTrue(b'You will soon log out because of inactivity.' in notify_log) def test_forced_logout_inhibition(self): '''Test we don't force logout when inhibited''' idle_delay = round(gsdpowerconstants.MINIMUM_IDLE_DIM_DELAY / gsdpowerconstants.IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER) self.settings_session['idle-delay'] = idle_delay self.settings_gsd_power['sleep-inactive-battery-timeout'] = idle_delay + 1 self.settings_gsd_power['sleep-inactive-battery-type'] = 'logout' # create suspend inhibitor which should stop us logging out inhibit_id = self.obj_session_mgr.Inhibit( 'testsuite', dbus.UInt32(0), 'for testing', dbus.UInt32(gsdpowerenums.GSM_INHIBITOR_FLAG_LOGOUT)) self.check_no_logout(idle_delay + 3) # Drop inhibitor self.obj_session_mgr.Uninhibit(dbus.UInt32(inhibit_id)) def test_unindle_on_ac_plug(self): idle_delay = round(gsdpowerconstants.MINIMUM_IDLE_DIM_DELAY / gsdpowerconstants.IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER) self.settings_session['idle-delay'] = idle_delay # Wait for idle self.check_dim(idle_delay + 2) # Plug in the AC self.obj_upower.Set('org.freedesktop.UPower', 'OnBattery', False) self.obj_upower.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') # Check that we undim self.check_undim(gsdpowerconstants.POWER_UP_TIME_ON_AC / 2) # And wait a little more to see us dim again self.check_dim(idle_delay + 2) # Unplug the AC self.obj_upower.Set('org.freedesktop.UPower', 'OnBattery', True) self.obj_upower.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') # Check that we undim self.check_undim(gsdpowerconstants.POWER_UP_TIME_ON_AC / 2) # And wait a little more to see us dim again self.check_dim(idle_delay + 2) # avoid writing to stderr unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2)) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5917668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/remote-display/0000775000175000017500000000000000000000000023455 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/remote-display/Makefile.am0000664000175000017500000000311600000000000025512 0ustar00jeremyjeremyplugin_name = remote-display plugin_LTLIBRARIES = libremote-display.la libremote_display_la_SOURCES = \ gsd-remote-display-manager.c \ gsd-remote-display-manager.h \ gsd-remote-display-plugin.c libremote_display_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) libremote_display_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) libremote_display_la_LDFLAGS = $(GSD_PLUGIN_LDFLAGS) libremote_display_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(SETTINGS_PLUGIN_LIBS) \ $(NULL) libexec_PROGRAMS = usd-test-remote-display usd_test_remote_display_SOURCES = \ test-remote-display.c \ gsd-remote-display-manager.c \ gsd-remote-display-manager.h usd_test_remote_display_CPPFLAGS = \ -I$(top_srcdir)/data/ \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ $(AM_CPPFLAGS) usd_test_remote_display_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) usd_test_remote_display_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(SETTINGS_DAEMON_LIBS) \ $(SETTINGS_PLUGIN_LIBS) plugin_in_files = remote-display.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = $(plugin_in_files) CLEANFILES = $(plugin_DATA) DISTCLEANFILES = $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/remote-display/gsd-remote-display-manager.c0000664000175000017500000001642100000000000030746 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2012 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "gnome-settings-bus.h" #include "gnome-settings-profile.h" #include "gsd-remote-display-manager.h" #define GSD_REMOTE_DISPLAY_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_REMOTE_DISPLAY_MANAGER, GsdRemoteDisplayManagerPrivate)) struct GsdRemoteDisplayManagerPrivate { GSettings *desktop_settings; GDBusProxy *vino_proxy; GCancellable *cancellable; guint vino_watch_id; gboolean vnc_in_use; }; static void gsd_remote_display_manager_class_init (GsdRemoteDisplayManagerClass *klass); static void gsd_remote_display_manager_init (GsdRemoteDisplayManager *remote_display_manager); G_DEFINE_TYPE (GsdRemoteDisplayManager, gsd_remote_display_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static void update_settings_from_variant (GsdRemoteDisplayManager *manager, GVariant *variant) { manager->priv->vnc_in_use = g_variant_get_boolean (variant); g_debug ("%s because of remote display status (vnc: %d)", !manager->priv->vnc_in_use ? "Enabling" : "Disabling", manager->priv->vnc_in_use); g_settings_set_boolean (manager->priv->desktop_settings, "enable-animations", !manager->priv->vnc_in_use); } static void props_changed (GDBusProxy *proxy, GVariant *changed_properties, GStrv invalidated_properties, GsdRemoteDisplayManager *manager) { GVariant *v; v = g_variant_lookup_value (changed_properties, "Connected", G_VARIANT_TYPE_BOOLEAN); if (v) { g_debug ("Received connected change"); update_settings_from_variant (manager, v); g_variant_unref (v); } } static void got_vino_proxy (GObject *source_object, GAsyncResult *res, GsdRemoteDisplayManager *manager) { GError *error = NULL; GVariant *v; manager->priv->vino_proxy = g_dbus_proxy_new_finish (res, &error); if (manager->priv->vino_proxy == NULL) { g_warning ("Failed to get Vino's D-Bus proxy: %s", error->message); g_error_free (error); return; } g_signal_connect (manager->priv->vino_proxy, "g-properties-changed", G_CALLBACK (props_changed), manager); v = g_dbus_proxy_get_cached_property (manager->priv->vino_proxy, "Connected"); if (v) { g_debug ("Setting original state"); update_settings_from_variant (manager, v); g_variant_unref (v); } } static void vino_appeared_cb (GDBusConnection *connection, const gchar *name, const gchar *name_owner, GsdRemoteDisplayManager *manager) { g_debug ("Vino appeared"); g_dbus_proxy_new (connection, G_DBUS_PROXY_FLAGS_NONE, NULL, name, "/org/gnome/vino/screens/0", "org.gnome.VinoScreen", manager->priv->cancellable, (GAsyncReadyCallback) got_vino_proxy, manager); } static void vino_vanished_cb (GDBusConnection *connection, const char *name, GsdRemoteDisplayManager *manager) { g_debug ("Vino vanished"); if (manager->priv->cancellable != NULL) { g_cancellable_cancel (manager->priv->cancellable); g_clear_object (&manager->priv->cancellable); } g_clear_object (&manager->priv->vino_proxy); /* And reset for us to have animations */ g_settings_set_boolean (manager->priv->desktop_settings, "enable-animations", TRUE); } static gboolean gsd_display_has_extension (const gchar *ext) { int op, event, error; return XQueryExtension (gdk_x11_get_default_xdisplay (), ext, &op, &event, &error); } gboolean gsd_remote_display_manager_start (GsdRemoteDisplayManager *manager, GError **error) { g_debug ("Starting remote-display manager"); gnome_settings_profile_start (NULL); manager->priv->desktop_settings = g_settings_new ("org.gnome.desktop.interface"); /* Check if spice is used: * https://bugzilla.gnome.org/show_bug.cgi?id=680195#c7 * This doesn't change at run-time, so it's to the point */ if (g_file_test ("/dev/virtio-ports/com.redhat.spice.0", G_FILE_TEST_EXISTS)) { g_debug ("Disabling animations because SPICE is in use"); g_settings_set_boolean (manager->priv->desktop_settings, "enable-animations", FALSE); goto out; } /* Xvnc exposes an extension named VNC-EXTENSION */ if (gsd_display_has_extension ("VNC-EXTENSION")) { g_debug ("Disabling animations because VNC-EXTENSION was detected"); g_settings_set_boolean (manager->priv->desktop_settings, "enable-animations", FALSE); goto out; } /* Monitor Vino's usage */ manager->priv->vino_watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION, "org.gnome.Vino", G_BUS_NAME_WATCHER_FLAGS_NONE, (GBusNameAppearedCallback) vino_appeared_cb, (GBusNameVanishedCallback) vino_vanished_cb, manager, NULL); out: gnome_settings_profile_end (NULL); return TRUE; } void gsd_remote_display_manager_stop (GsdRemoteDisplayManager *manager) { g_debug ("Stopping remote_display manager"); if (manager->priv->cancellable != NULL) { g_cancellable_cancel (manager->priv->cancellable); g_clear_object (&manager->priv->cancellable); } g_clear_object (&manager->priv->vino_proxy); if (manager->priv->desktop_settings) { g_settings_reset (manager->priv->desktop_settings, "enable-animations"); g_clear_object (&manager->priv->desktop_settings); } } static void gsd_remote_display_manager_class_init (GsdRemoteDisplayManagerClass *klass) { g_type_class_add_private (klass, sizeof (GsdRemoteDisplayManagerPrivate)); } static void gsd_remote_display_manager_init (GsdRemoteDisplayManager *manager) { manager->priv = GSD_REMOTE_DISPLAY_MANAGER_GET_PRIVATE (manager); } GsdRemoteDisplayManager * gsd_remote_display_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_REMOTE_DISPLAY_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_REMOTE_DISPLAY_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/remote-display/gsd-remote-display-manager.h0000664000175000017500000000503500000000000030752 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2012 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_REMOTE_DISPLAY_MANAGER_H #define __GSD_REMOTE_DISPLAY_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_REMOTE_DISPLAY_MANAGER (gsd_remote_display_manager_get_type ()) #define GSD_REMOTE_DISPLAY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_REMOTE_DISPLAY_MANAGER, GsdRemoteDisplayManager)) #define GSD_REMOTE_DISPLAY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_REMOTE_DISPLAY_MANAGER, GsdRemoteDisplayManagerClass)) #define GSD_IS_REMOTE_DISPLAY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_REMOTE_DISPLAY_MANAGER)) #define GSD_IS_REMOTE_DISPLAY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_REMOTE_DISPLAY_MANAGER)) #define GSD_REMOTE_DISPLAY_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_REMOTE_DISPLAY_MANAGER, GsdRemoteDisplayManagerClass)) typedef struct GsdRemoteDisplayManagerPrivate GsdRemoteDisplayManagerPrivate; typedef struct { GObject parent; GsdRemoteDisplayManagerPrivate *priv; } GsdRemoteDisplayManager; typedef struct { GObjectClass parent_class; } GsdRemoteDisplayManagerClass; GType gsd_remote_display_manager_get_type (void); GsdRemoteDisplayManager *gsd_remote_display_manager_new (void); gboolean gsd_remote_display_manager_start (GsdRemoteDisplayManager *manager, GError **error); void gsd_remote_display_manager_stop (GsdRemoteDisplayManager *manager); G_END_DECLS #endif /* __GSD_REMOTE_DISPLAY_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/remote-display/gsd-remote-display-plugin.c0000664000175000017500000000217300000000000030631 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2012 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-remote-display-manager.h" struct GsdRemoteDisplayPluginPrivate { GsdRemoteDisplayManager *manager; }; GNOME_SETTINGS_PLUGIN_REGISTER (GsdRemoteDisplay, gsd_remote_display) ././@PaxHeader0000000000000000000000000000022100000000000010210 xustar00117 path=unity-settings-daemon-15.04.1+21.10.20220207/plugins/remote-display/remote-display.gnome-settings-plugin.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/remote-display/remote-display.gnome-settings-pl0000664000175000017500000000032300000000000031707 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=remote-display IAge=0 Priority=8 _Name=Remote Display _Description=Disable animations on remote displays Authors=Bastien Nocera Copyright=Copyright © 2012 Bastien Nocera Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/remote-display/test-remote-display.c0000664000175000017500000000036100000000000027534 0ustar00jeremyjeremy#define NEW gsd_remote_display_manager_new #define START gsd_remote_display_manager_start #define STOP gsd_remote_display_manager_stop #define MANAGER GsdRemoteDisplayManager #include "gsd-remote-display-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5917668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/rfkill/0000775000175000017500000000000000000000000022002 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/rfkill/61-gnome-settings-daemon-rfkill.rules0000664000175000017500000000044400000000000030771 0ustar00jeremyjeremy# Get access to /dev/rfkill for users # See https://bugzilla.redhat.com/show_bug.cgi?id=514798 # # Simplified by Kay Sievers # https://bugzilla.redhat.com/show_bug.cgi?id=733326 # See also https://bugzilla.gnome.org/show_bug.cgi?id=711373 KERNEL=="rfkill", SUBSYSTEM=="misc", TAG+="uaccess" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/rfkill/Makefile.am0000664000175000017500000000327600000000000024046 0ustar00jeremyjeremyplugin_name = rfkill libexec_PROGRAMS = gsd-test-rfkill gsd_test_rfkill_SOURCES = \ gsd-rfkill-manager.h \ gsd-rfkill-manager.c \ rfkill-glib.c \ rfkill-glib.h \ rfkill.h \ test-rfkill.c gsd_test_rfkill_CFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_builddir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) gsd_test_rfkill_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(SETTINGS_PLUGIN_LIBS) plugin_LTLIBRARIES = librfkill.la librfkill_la_SOURCES = \ gsd-rfkill-plugin.c \ gsd-rfkill-manager.h \ gsd-rfkill-manager.c \ rfkill-glib.c \ rfkill-glib.h \ rfkill.h librfkill_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_builddir)/gnome-settings-daemon \ -I$(top_srcdir)/data/ \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ $(AM_CPPFLAGS) librfkill_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(RFKILL_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) librfkill_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) librfkill_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(RFKILL_LIBS) \ $(SETTINGS_PLUGIN_LIBS) plugin_in_files = rfkill.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) udevrulesdir = $(prefix)/lib/udev/rules.d udevrules_DATA = 61-gnome-settings-daemon-rfkill.rules EXTRA_DIST = $(plugin_in_files) $(udevrules_DATA) CLEANFILES = $(plugin_DATA) DISTCLEANFILES = $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/rfkill/gsd-rfkill-manager.c0000664000175000017500000006456000000000000025627 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * Copyright (C) 2010,2011 Red Hat, Inc. * * Author: Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gnome-settings-profile.h" #include "gsd-rfkill-manager.h" #include "rfkill-glib.h" #include "gnome-settings-bus.h" #define GSD_RFKILL_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_RFKILL_MANAGER, GsdRfkillManagerPrivate)) struct GsdRfkillManagerPrivate { GDBusNodeInfo *introspection_data; guint name_id; GDBusConnection *connection; GCancellable *cancellable; CcRfkillGlib *rfkill; GHashTable *killswitches; GHashTable *bt_killswitches; /* In addition to using the rfkill kernel subsystem (which is exposed by wlan, wimax, bluetooth, nfc, some platform drivers and some usb modems), we need to go through NetworkManager, which in turn will tell ModemManager to write the right commands in the USB bus to take external modems down, all from userspace. */ GDBusProxy *nm_client; gboolean wwan_enabled; GDBusObjectManager *mm_client; gboolean wwan_interesting; gchar *chassis_type; }; #define GSD_RFKILL_DBUS_NAME GSD_DBUS_NAME ".Rfkill" #define GSD_RFKILL_DBUS_PATH GSD_DBUS_PATH "/Rfkill" static const gchar introspection_xml[] = "" " " " " " " " " " " " " " " " " " " " " ""; static void gsd_rfkill_manager_class_init (GsdRfkillManagerClass *klass); static void gsd_rfkill_manager_init (GsdRfkillManager *rfkill_manager); static void gsd_rfkill_manager_finalize (GObject *object); G_DEFINE_TYPE (GsdRfkillManager, gsd_rfkill_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static void gsd_rfkill_manager_class_init (GsdRfkillManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_rfkill_manager_finalize; g_type_class_add_private (klass, sizeof (GsdRfkillManagerPrivate)); } static void gsd_rfkill_manager_init (GsdRfkillManager *manager) { manager->priv = GSD_RFKILL_MANAGER_GET_PRIVATE (manager); } static gboolean engine_get_airplane_mode_helper (GHashTable *killswitches) { GHashTableIter iter; gpointer key, value; if (g_hash_table_size (killswitches) == 0) return FALSE; g_hash_table_iter_init (&iter, killswitches); while (g_hash_table_iter_next (&iter, &key, &value)) { int state; state = GPOINTER_TO_INT (value); /* A single rfkill switch that's unblocked? Airplane mode is off */ if (state == RFKILL_STATE_UNBLOCKED) return FALSE; } return TRUE; } static gboolean engine_get_bluetooth_airplane_mode (GsdRfkillManager *manager) { return engine_get_airplane_mode_helper (manager->priv->bt_killswitches); } static gboolean engine_get_bluetooth_hardware_airplane_mode (GsdRfkillManager *manager) { GHashTableIter iter; gpointer key, value; /* If we have no killswitches, hw airplane mode is off. */ if (g_hash_table_size (manager->priv->bt_killswitches) == 0) return FALSE; g_hash_table_iter_init (&iter, manager->priv->bt_killswitches); while (g_hash_table_iter_next (&iter, &key, &value)) { int state; state = GPOINTER_TO_INT (value); /* A single rfkill switch that's not hw blocked? Hw airplane mode is off */ if (state != RFKILL_STATE_HARD_BLOCKED) { return FALSE; } } return TRUE; } static gboolean engine_get_has_bluetooth_airplane_mode (GsdRfkillManager *manager) { return (g_hash_table_size (manager->priv->bt_killswitches) > 0); } static gboolean engine_get_airplane_mode (GsdRfkillManager *manager) { if (!manager->priv->wwan_interesting) return engine_get_airplane_mode_helper (manager->priv->killswitches); /* wwan enabled? then airplane mode is off (because an USB modem could be on in this state) */ return engine_get_airplane_mode_helper (manager->priv->killswitches) && !manager->priv->wwan_enabled; } static gboolean engine_get_hardware_airplane_mode (GsdRfkillManager *manager) { GHashTableIter iter; gpointer key, value; /* If we have no killswitches, hw airplane mode is off. */ if (g_hash_table_size (manager->priv->killswitches) == 0) return FALSE; g_hash_table_iter_init (&iter, manager->priv->killswitches); while (g_hash_table_iter_next (&iter, &key, &value)) { int state; state = GPOINTER_TO_INT (value); /* A single rfkill switch that's not hw blocked? Hw airplane mode is off */ if (state != RFKILL_STATE_HARD_BLOCKED) { return FALSE; } } return TRUE; } static gboolean engine_get_has_airplane_mode (GsdRfkillManager *manager) { return (g_hash_table_size (manager->priv->killswitches) > 0) || manager->priv->wwan_interesting; } static gboolean engine_get_should_show_airplane_mode (GsdRfkillManager *manager) { return (g_strcmp0 (manager->priv->chassis_type, "desktop") != 0) && (g_strcmp0 (manager->priv->chassis_type, "server") != 0) && (g_strcmp0 (manager->priv->chassis_type, "vm") != 0) && (g_strcmp0 (manager->priv->chassis_type, "container") != 0); } static void engine_properties_changed (GsdRfkillManager *manager) { GVariantBuilder props_builder; GVariant *props_changed = NULL; /* not yet connected to the session bus */ if (manager->priv->connection == NULL) return; g_variant_builder_init (&props_builder, G_VARIANT_TYPE ("a{sv}")); g_variant_builder_add (&props_builder, "{sv}", "AirplaneMode", g_variant_new_boolean (engine_get_airplane_mode (manager))); g_variant_builder_add (&props_builder, "{sv}", "HardwareAirplaneMode", g_variant_new_boolean (engine_get_hardware_airplane_mode (manager))); g_variant_builder_add (&props_builder, "{sv}", "HasAirplaneMode", g_variant_new_boolean (engine_get_has_airplane_mode (manager))); g_variant_builder_add (&props_builder, "{sv}", "ShouldShowAirplaneMode", g_variant_new_boolean (engine_get_should_show_airplane_mode (manager))); g_variant_builder_add (&props_builder, "{sv}", "BluetoothAirplaneMode", g_variant_new_boolean (engine_get_bluetooth_airplane_mode (manager))); g_variant_builder_add (&props_builder, "{sv}", "BluetoothHardwareAirplaneMode", g_variant_new_boolean (engine_get_bluetooth_hardware_airplane_mode (manager))); g_variant_builder_add (&props_builder, "{sv}", "BluetoothHasAirplaneMode", g_variant_new_boolean (engine_get_has_bluetooth_airplane_mode (manager))); props_changed = g_variant_new ("(s@a{sv}@as)", GSD_RFKILL_DBUS_NAME, g_variant_builder_end (&props_builder), g_variant_new_strv (NULL, 0)); g_dbus_connection_emit_signal (manager->priv->connection, NULL, GSD_RFKILL_DBUS_PATH, "org.freedesktop.DBus.Properties", "PropertiesChanged", props_changed, NULL); } static void rfkill_changed (CcRfkillGlib *rfkill, GList *events, GsdRfkillManager *manager) { GList *l; int value; for (l = events; l != NULL; l = l->next) { struct rfkill_event *event = l->data; switch (event->op) { case RFKILL_OP_ADD: case RFKILL_OP_CHANGE: if (event->hard) value = RFKILL_STATE_HARD_BLOCKED; else if (event->soft) value = RFKILL_STATE_SOFT_BLOCKED; else value = RFKILL_STATE_UNBLOCKED; g_hash_table_insert (manager->priv->killswitches, GINT_TO_POINTER (event->idx), GINT_TO_POINTER (value)); if (event->type == RFKILL_TYPE_BLUETOOTH) g_hash_table_insert (manager->priv->bt_killswitches, GINT_TO_POINTER (event->idx), GINT_TO_POINTER (value)); g_debug ("%s %srfkill with ID %d", event->op == RFKILL_OP_ADD ? "Added" : "Changed", event->type == RFKILL_TYPE_BLUETOOTH ? "Bluetooth " : "", event->idx); break; case RFKILL_OP_DEL: g_hash_table_remove (manager->priv->killswitches, GINT_TO_POINTER (event->idx)); if (event->type == RFKILL_TYPE_BLUETOOTH) g_hash_table_remove (manager->priv->bt_killswitches, GINT_TO_POINTER (event->idx)); g_debug ("Removed %srfkill with ID %d", event->type == RFKILL_TYPE_BLUETOOTH ? "Bluetooth " : "", event->idx); break; } } engine_properties_changed (manager); } static void rfkill_set_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { gboolean ret; GError *error = NULL; ret = cc_rfkill_glib_send_change_all_event_finish (CC_RFKILL_GLIB (source_object), res, &error); if (!ret) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT)) g_debug ("Timed out waiting for blocked rfkills"); else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to set RFKill: %s", error->message); g_error_free (error); } } static void set_wwan_complete (GObject *object, GAsyncResult *result, gpointer user_data) { GError *error; GVariant *variant; error = NULL; variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), result, &error); if (variant == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to set WWAN power status: %s", error->message); g_error_free (error); } else { g_variant_unref (variant); } } static gboolean engine_set_bluetooth_airplane_mode (GsdRfkillManager *manager, gboolean enable) { cc_rfkill_glib_send_change_all_event (manager->priv->rfkill, RFKILL_TYPE_BLUETOOTH, enable, manager->priv->cancellable, rfkill_set_cb, manager); return TRUE; } static gboolean engine_set_airplane_mode (GsdRfkillManager *manager, gboolean enable) { cc_rfkill_glib_send_change_all_event (manager->priv->rfkill, RFKILL_TYPE_ALL, enable, manager->priv->cancellable, rfkill_set_cb, manager); /* Note: we set the the NM property even if there are no modems, so we don't need to resync when one is plugged in */ if (manager->priv->nm_client) { g_dbus_proxy_call (manager->priv->nm_client, "org.freedesktop.DBus.Properties.Set", g_variant_new ("(ssv)", "org.freedesktop.NetworkManager", "WwanEnabled", g_variant_new_boolean (!enable)), G_DBUS_CALL_FLAGS_NONE, -1, /* timeout */ manager->priv->cancellable, set_wwan_complete, NULL); } return TRUE; } static gboolean handle_set_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GVariant *value, GError **error, gpointer user_data) { GsdRfkillManager *manager = GSD_RFKILL_MANAGER (user_data); if (g_strcmp0 (property_name, "AirplaneMode") == 0) { gboolean airplane_mode; g_variant_get (value, "b", &airplane_mode); return engine_set_airplane_mode (manager, airplane_mode); } else if (g_strcmp0 (property_name, "BluetoothAirplaneMode") == 0) { gboolean airplane_mode; g_variant_get (value, "b", &airplane_mode); return engine_set_bluetooth_airplane_mode (manager, airplane_mode); } return FALSE; } static GVariant * handle_get_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data) { GsdRfkillManager *manager = GSD_RFKILL_MANAGER (user_data); /* Check session pointer as a proxy for whether the manager is in the start or stop state */ if (manager->priv->connection == NULL) { return NULL; } if (g_strcmp0 (property_name, "AirplaneMode") == 0) { gboolean airplane_mode; airplane_mode = engine_get_airplane_mode (manager); return g_variant_new_boolean (airplane_mode); } if (g_strcmp0 (property_name, "HardwareAirplaneMode") == 0) { gboolean hw_airplane_mode; hw_airplane_mode = engine_get_hardware_airplane_mode (manager); return g_variant_new_boolean (hw_airplane_mode); } if (g_strcmp0 (property_name, "ShouldShowAirplaneMode") == 0) { gboolean should_show_airplane_mode; should_show_airplane_mode = engine_get_should_show_airplane_mode (manager); return g_variant_new_boolean (should_show_airplane_mode); } if (g_strcmp0 (property_name, "HasAirplaneMode") == 0) { gboolean has_airplane_mode; has_airplane_mode = engine_get_has_airplane_mode (manager); return g_variant_new_boolean (has_airplane_mode); } if (g_strcmp0 (property_name, "BluetoothAirplaneMode") == 0) { gboolean airplane_mode; airplane_mode = engine_get_bluetooth_airplane_mode (manager); return g_variant_new_boolean (airplane_mode); } if (g_strcmp0 (property_name, "BluetoothHardwareAirplaneMode") == 0) { gboolean hw_airplane_mode; hw_airplane_mode = engine_get_bluetooth_hardware_airplane_mode (manager); return g_variant_new_boolean (hw_airplane_mode); } if (g_strcmp0 (property_name, "BluetoothHasAirplaneMode") == 0) { gboolean has_airplane_mode; has_airplane_mode = engine_get_has_bluetooth_airplane_mode (manager); return g_variant_new_boolean (has_airplane_mode); } return NULL; } static const GDBusInterfaceVTable interface_vtable = { NULL, handle_get_property, handle_set_property }; static void on_bus_gotten (GObject *source_object, GAsyncResult *res, GsdRfkillManager *manager) { GDBusConnection *connection; GError *error = NULL; connection = g_bus_get_finish (res, &error); if (connection == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Could not get session bus: %s", error->message); g_error_free (error); return; } manager->priv->connection = connection; g_dbus_connection_register_object (connection, GSD_RFKILL_DBUS_PATH, manager->priv->introspection_data->interfaces[0], &interface_vtable, manager, NULL, NULL); manager->priv->name_id = g_bus_own_name_on_connection (connection, GSD_RFKILL_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL); } static void sync_wwan_enabled (GsdRfkillManager *manager) { GVariant *property; property = g_dbus_proxy_get_cached_property (manager->priv->nm_client, "WwanEnabled"); if (property == NULL) { /* GDBus telling us NM went down */ return; } manager->priv->wwan_enabled = g_variant_get_boolean (property); engine_properties_changed (manager); g_variant_unref (property); } static void nm_signal (GDBusProxy *proxy, char *sender_name, char *signal_name, GVariant *parameters, gpointer user_data) { GsdRfkillManager *manager = user_data; GVariant *changed; GVariant *property; if (g_strcmp0 (signal_name, "PropertiesChanged") == 0) { changed = g_variant_get_child_value (parameters, 0); property = g_variant_lookup_value (changed, "WwanEnabled", G_VARIANT_TYPE ("b")); g_dbus_proxy_set_cached_property (proxy, "WwanEnabled", property); if (property != NULL) { sync_wwan_enabled (manager); g_variant_unref (property); } g_variant_unref (changed); } } static void on_nm_proxy_gotten (GObject *source, GAsyncResult *result, gpointer user_data) { GsdRfkillManager *manager = user_data; GDBusProxy *proxy; GError *error; error = NULL; proxy = g_dbus_proxy_new_for_bus_finish (result, &error); if (proxy == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) g_warning ("Failed to acquire NetworkManager proxy: %s", error->message); g_error_free (error); goto out; } manager->priv->nm_client = proxy; g_signal_connect (manager->priv->nm_client, "g-signal", G_CALLBACK (nm_signal), manager); sync_wwan_enabled (manager); out: g_object_unref (manager); } static void sync_wwan_interesting (GDBusObjectManager *object_manager, GDBusObject *object, GDBusInterface *interface, gpointer user_data) { GsdRfkillManager *manager = user_data; GList *objects; objects = g_dbus_object_manager_get_objects (object_manager); manager->priv->wwan_interesting = (objects != NULL); engine_properties_changed (manager); g_list_free_full (objects, g_object_unref); } static void on_mm_proxy_gotten (GObject *source, GAsyncResult *result, gpointer user_data) { GsdRfkillManager *manager = user_data; GDBusObjectManager *proxy; GError *error; error = NULL; proxy = g_dbus_object_manager_client_new_for_bus_finish (result, &error); if (proxy == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) g_warning ("Failed to acquire ModemManager proxy: %s", error->message); g_error_free (error); goto out; } manager->priv->mm_client = proxy; g_signal_connect (manager->priv->mm_client, "interface-added", G_CALLBACK (sync_wwan_interesting), manager); g_signal_connect (manager->priv->mm_client, "interface-removed", G_CALLBACK (sync_wwan_interesting), manager); sync_wwan_interesting (manager->priv->mm_client, NULL, NULL, manager); out: g_object_unref (manager); } gboolean gsd_rfkill_manager_start (GsdRfkillManager *manager, GError **error) { gnome_settings_profile_start (NULL); manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (manager->priv->introspection_data != NULL); manager->priv->killswitches = g_hash_table_new (g_direct_hash, g_direct_equal); manager->priv->bt_killswitches = g_hash_table_new (g_direct_hash, g_direct_equal); manager->priv->rfkill = cc_rfkill_glib_new (); g_signal_connect (G_OBJECT (manager->priv->rfkill), "changed", G_CALLBACK (rfkill_changed), manager); cc_rfkill_glib_open (manager->priv->rfkill); manager->priv->cancellable = g_cancellable_new (); manager->priv->chassis_type = gnome_settings_get_chassis_type (); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, /* g-interface-info */ "org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager", manager->priv->cancellable, on_nm_proxy_gotten, g_object_ref (manager)); g_dbus_object_manager_client_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, "org.freedesktop.ModemManager1", "/org/freedesktop/ModemManager1", NULL, NULL, NULL, /* get_proxy_type and closure */ manager->priv->cancellable, on_mm_proxy_gotten, g_object_ref (manager)); /* Start process of owning a D-Bus name */ g_bus_get (G_BUS_TYPE_SESSION, manager->priv->cancellable, (GAsyncReadyCallback) on_bus_gotten, manager); gnome_settings_profile_end (NULL); return TRUE; } void gsd_rfkill_manager_stop (GsdRfkillManager *manager) { GsdRfkillManagerPrivate *p = manager->priv; g_debug ("Stopping rfkill manager"); if (manager->priv->name_id != 0) { g_bus_unown_name (manager->priv->name_id); manager->priv->name_id = 0; } g_clear_pointer (&p->introspection_data, g_dbus_node_info_unref); g_clear_object (&p->connection); g_clear_object (&p->rfkill); g_clear_pointer (&p->killswitches, g_hash_table_destroy); g_clear_pointer (&p->bt_killswitches, g_hash_table_destroy); if (p->cancellable) { g_cancellable_cancel (p->cancellable); g_clear_object (&p->cancellable); } g_clear_object (&p->nm_client); g_clear_object (&p->mm_client); p->wwan_enabled = FALSE; p->wwan_interesting = FALSE; g_clear_pointer (&p->chassis_type, g_free); } static void gsd_rfkill_manager_finalize (GObject *object) { GsdRfkillManager *manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_RFKILL_MANAGER (object)); manager = GSD_RFKILL_MANAGER (object); g_return_if_fail (manager->priv != NULL); gsd_rfkill_manager_stop (manager); G_OBJECT_CLASS (gsd_rfkill_manager_parent_class)->finalize (object); } GsdRfkillManager * gsd_rfkill_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_RFKILL_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_RFKILL_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/rfkill/gsd-rfkill-manager.h0000664000175000017500000000436500000000000025631 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * Copyright (C) 2010 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . * */ #ifndef __GSD_RFKILL_MANAGER_H #define __GSD_RFKILL_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_RFKILL_MANAGER (gsd_rfkill_manager_get_type ()) #define GSD_RFKILL_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_RFKILL_MANAGER, GsdRfkillManager)) #define GSD_RFKILL_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_RFKILL_MANAGER, GsdRfkillManagerClass)) #define GSD_IS_RFKILL_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_RFKILL_MANAGER)) #define GSD_IS_RFKILL_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_RFKILL_MANAGER)) #define GSD_RFKILL_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_RFKILL_MANAGER, GsdRfkillManagerClass)) typedef struct GsdRfkillManagerPrivate GsdRfkillManagerPrivate; typedef struct { GObject parent; GsdRfkillManagerPrivate *priv; } GsdRfkillManager; typedef struct { GObjectClass parent_class; } GsdRfkillManagerClass; GType gsd_rfkill_manager_get_type (void); GsdRfkillManager * gsd_rfkill_manager_new (void); gboolean gsd_rfkill_manager_start (GsdRfkillManager *manager, GError **error); void gsd_rfkill_manager_stop (GsdRfkillManager *manager); G_END_DECLS #endif /* __GSD_RFKILL_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/rfkill/gsd-rfkill-plugin.c0000664000175000017500000000175700000000000025512 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * Copyright (C) 2010 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-rfkill-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdRfkill, gsd_rfkill) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/rfkill/rfkill-glib.c0000664000175000017500000003174300000000000024354 0ustar00jeremyjeremy/* * * gnome-bluetooth - Bluetooth integration for GNOME * * Copyright (C) 2012 Bastien Nocera * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include "rfkill-glib.h" enum { CHANGED, LAST_SIGNAL }; static int signals[LAST_SIGNAL] = { 0 }; #define CC_RFKILL_GLIB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ CC_RFKILL_TYPE_GLIB, CcRfkillGlibPrivate)) struct CcRfkillGlibPrivate { GOutputStream *stream; GIOChannel *channel; guint watch_id; /* Pending Bluetooth enablement */ guint change_all_timeout_id; struct rfkill_event *event; GSimpleAsyncResult *simple; GCancellable *cancellable; }; G_DEFINE_TYPE(CcRfkillGlib, cc_rfkill_glib, G_TYPE_OBJECT) #define CHANGE_ALL_TIMEOUT 500 static const char *type_to_string (unsigned int type); gboolean cc_rfkill_glib_send_event_finish (CcRfkillGlib *rfkill, GAsyncResult *res, GError **error) { GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res); g_return_val_if_fail (RFKILL_IS_GLIB (rfkill), FALSE); g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == cc_rfkill_glib_send_event); if (g_simple_async_result_propagate_error (simple, error)) return FALSE; return (g_simple_async_result_get_op_res_gssize (simple) >= 0); } static void write_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); GError *error = NULL; gssize ret; ret = g_output_stream_write_finish (G_OUTPUT_STREAM (source_object), res, &error); if (ret < 0) g_simple_async_result_take_error (simple, error); else g_simple_async_result_set_op_res_gssize (simple, ret); g_simple_async_result_complete_in_idle (simple); g_object_unref (simple); } void cc_rfkill_glib_send_event (CcRfkillGlib *rfkill, struct rfkill_event *event, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GSimpleAsyncResult *simple; g_return_if_fail (RFKILL_IS_GLIB (rfkill)); g_return_if_fail (rfkill->priv->stream); simple = g_simple_async_result_new (G_OBJECT (rfkill), callback, user_data, cc_rfkill_glib_send_event); g_output_stream_write_async (rfkill->priv->stream, event, sizeof(struct rfkill_event), G_PRIORITY_DEFAULT, cancellable, write_done_cb, simple); } gboolean cc_rfkill_glib_send_change_all_event_finish (CcRfkillGlib *rfkill, GAsyncResult *res, GError **error) { GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res); g_return_val_if_fail (RFKILL_IS_GLIB (rfkill), FALSE); g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == cc_rfkill_glib_send_change_all_event); if (g_simple_async_result_propagate_error (simple, error)) return FALSE; return g_simple_async_result_get_op_res_gboolean (simple); } static void write_change_all_again_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { CcRfkillGlib *rfkill = user_data; GError *error = NULL; gssize ret; g_debug ("Finished writing second RFKILL_OP_CHANGE_ALL event"); ret = g_output_stream_write_finish (G_OUTPUT_STREAM (source_object), res, &error); if (ret < 0) g_simple_async_result_take_error (rfkill->priv->simple, error); else g_simple_async_result_set_op_res_gboolean (rfkill->priv->simple, ret >= 0); g_simple_async_result_complete_in_idle (rfkill->priv->simple); g_clear_object (&rfkill->priv->simple); g_clear_pointer (&rfkill->priv->event, g_free); } static gboolean write_change_all_timeout_cb (CcRfkillGlib *rfkill) { g_assert (rfkill->priv->event); g_debug ("Sending second RFKILL_OP_CHANGE_ALL timed out"); g_simple_async_result_set_error (rfkill->priv->simple, G_IO_ERROR, G_IO_ERROR_TIMED_OUT, "Enabling rfkill for %s timed out", type_to_string (rfkill->priv->event->type)); g_simple_async_result_complete_in_idle (rfkill->priv->simple); g_clear_object (&rfkill->priv->simple); g_clear_pointer (&rfkill->priv->event, g_free); g_clear_object (&rfkill->priv->cancellable); rfkill->priv->change_all_timeout_id = 0; return G_SOURCE_REMOVE; } static void write_change_all_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { CcRfkillGlib *rfkill = user_data; GError *error = NULL; gssize ret; g_debug ("Sending original RFKILL_OP_CHANGE_ALL event done"); ret = g_output_stream_write_finish (G_OUTPUT_STREAM (source_object), res, &error); if (ret < 0) { g_simple_async_result_take_error (rfkill->priv->simple, error); goto bail; } else if (rfkill->priv->event->soft == 1 || rfkill->priv->event->type != RFKILL_TYPE_BLUETOOTH) { g_simple_async_result_set_op_res_gboolean (rfkill->priv->simple, ret >= 0); goto bail; } rfkill->priv->change_all_timeout_id = g_timeout_add (CHANGE_ALL_TIMEOUT, (GSourceFunc) write_change_all_timeout_cb, rfkill); return; bail: g_simple_async_result_complete_in_idle (rfkill->priv->simple); g_clear_object (&rfkill->priv->simple); g_clear_pointer (&rfkill->priv->event, g_free); g_clear_object (&rfkill->priv->cancellable); } void cc_rfkill_glib_send_change_all_event (CcRfkillGlib *rfkill, guint rfkill_type, gboolean enable, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GSimpleAsyncResult *simple; struct rfkill_event *event; g_return_if_fail (RFKILL_IS_GLIB (rfkill)); g_return_if_fail (rfkill->priv->stream); simple = g_simple_async_result_new (G_OBJECT (rfkill), callback, user_data, cc_rfkill_glib_send_change_all_event); if (rfkill->priv->change_all_timeout_id > 0) { g_source_remove (rfkill->priv->change_all_timeout_id); rfkill->priv->change_all_timeout_id = 0; write_change_all_timeout_cb (rfkill); } event = g_new0 (struct rfkill_event, 1); event->op = RFKILL_OP_CHANGE_ALL; event->type = rfkill_type; event->soft = enable ? 1 : 0; rfkill->priv->event = event; rfkill->priv->simple = simple; rfkill->priv->cancellable = cancellable ? g_object_ref (cancellable) : NULL; rfkill->priv->change_all_timeout_id = 0; g_output_stream_write_async (rfkill->priv->stream, event, sizeof(struct rfkill_event), G_PRIORITY_DEFAULT, cancellable, write_change_all_done_cb, rfkill); } static const char * type_to_string (unsigned int type) { switch (type) { case RFKILL_TYPE_ALL: return "ALL"; case RFKILL_TYPE_WLAN: return "WLAN"; case RFKILL_TYPE_BLUETOOTH: return "BLUETOOTH"; case RFKILL_TYPE_UWB: return "UWB"; case RFKILL_TYPE_WIMAX: return "WIMAX"; case RFKILL_TYPE_WWAN: return "WWAN"; default: return "UNKNOWN"; } } static const char * op_to_string (unsigned int op) { switch (op) { case RFKILL_OP_ADD: return "ADD"; case RFKILL_OP_DEL: return "DEL"; case RFKILL_OP_CHANGE: return "CHANGE"; case RFKILL_OP_CHANGE_ALL: return "CHANGE_ALL"; default: g_assert_not_reached (); } } static void print_event (struct rfkill_event *event) { g_debug ("RFKILL event: idx %u type %u (%s) op %u (%s) soft %u hard %u", event->idx, event->type, type_to_string (event->type), event->op, op_to_string (event->op), event->soft, event->hard); } static gboolean got_change_event (GList *events) { GList *l; g_assert (events != NULL); for (l = events ; l != NULL; l = l->next) { struct rfkill_event *event = l->data; if (event->op == RFKILL_OP_CHANGE) return TRUE; } return FALSE; } static void emit_changed_signal_and_free (CcRfkillGlib *rfkill, GList *events) { if (events == NULL) return; g_signal_emit (G_OBJECT (rfkill), signals[CHANGED], 0, events); if (rfkill->priv->change_all_timeout_id > 0 && got_change_event (events)) { g_debug ("Received a change event after a RFKILL_OP_CHANGE_ALL event, re-sending RFKILL_OP_CHANGE_ALL"); g_output_stream_write_async (rfkill->priv->stream, rfkill->priv->event, sizeof(struct rfkill_event), G_PRIORITY_DEFAULT, rfkill->priv->cancellable, write_change_all_again_done_cb, rfkill); g_source_remove (rfkill->priv->change_all_timeout_id); rfkill->priv->change_all_timeout_id = 0; } g_list_free_full (events, g_free); } static gboolean event_cb (GIOChannel *source, GIOCondition condition, CcRfkillGlib *rfkill) { GList *events; events = NULL; if (condition & G_IO_IN) { GIOStatus status; struct rfkill_event event; gsize read; status = g_io_channel_read_chars (source, (char *) &event, sizeof(event), &read, NULL); while (status == G_IO_STATUS_NORMAL && read == sizeof(event)) { struct rfkill_event *event_ptr; print_event (&event); event_ptr = g_memdup (&event, sizeof(event)); events = g_list_prepend (events, event_ptr); status = g_io_channel_read_chars (source, (char *) &event, sizeof(event), &read, NULL); } events = g_list_reverse (events); } else { g_debug ("Something unexpected happened on rfkill fd"); return FALSE; } emit_changed_signal_and_free (rfkill, events); return TRUE; } static void cc_rfkill_glib_init (CcRfkillGlib *rfkill) { CcRfkillGlibPrivate *priv; priv = CC_RFKILL_GLIB_GET_PRIVATE (rfkill); rfkill->priv = priv; } int cc_rfkill_glib_open (CcRfkillGlib *rfkill) { CcRfkillGlibPrivate *priv; int fd; int ret; GList *events; g_return_val_if_fail (RFKILL_IS_GLIB (rfkill), -1); g_return_val_if_fail (rfkill->priv->stream == NULL, -1); priv = rfkill->priv; fd = open("/dev/rfkill", O_RDWR); if (fd < 0) { if (errno == EACCES) g_warning ("Could not open RFKILL control device, please verify your installation"); return fd; } ret = fcntl(fd, F_SETFL, O_NONBLOCK); if (ret < 0) { g_debug ("Can't set RFKILL control device to non-blocking"); close(fd); return ret; } events = NULL; while (1) { struct rfkill_event event; struct rfkill_event *event_ptr; ssize_t len; len = read(fd, &event, sizeof(event)); if (len < 0) { if (errno == EAGAIN) break; g_debug ("Reading of RFKILL events failed"); break; } if (len != RFKILL_EVENT_SIZE_V1) { g_warning ("Wrong size of RFKILL event\n"); continue; } if (event.op != RFKILL_OP_ADD) continue; g_debug ("Read killswitch of type '%s' (idx=%d): soft %d hard %d", type_to_string (event.type), event.idx, event.soft, event.hard); event_ptr = g_memdup (&event, sizeof(event)); events = g_list_prepend (events, event_ptr); } /* Setup monitoring */ priv->channel = g_io_channel_unix_new (fd); priv->watch_id = g_io_add_watch (priv->channel, G_IO_IN | G_IO_HUP | G_IO_ERR, (GIOFunc) event_cb, rfkill); if (events) { events = g_list_reverse (events); emit_changed_signal_and_free (rfkill, events); } else { g_debug ("No rfkill device available on startup"); } /* Setup write stream */ priv->stream = g_unix_output_stream_new (fd, TRUE); return fd; } static void cc_rfkill_glib_finalize (GObject *object) { CcRfkillGlib *rfkill; CcRfkillGlibPrivate *priv; rfkill = CC_RFKILL_GLIB (object); priv = rfkill->priv; if (priv->change_all_timeout_id > 0) write_change_all_timeout_cb (rfkill); /* cleanup monitoring */ if (priv->watch_id > 0) { g_source_remove (priv->watch_id); priv->watch_id = 0; g_io_channel_shutdown (priv->channel, FALSE, NULL); g_io_channel_unref (priv->channel); } g_clear_object (&priv->stream); G_OBJECT_CLASS(cc_rfkill_glib_parent_class)->finalize(object); } static void cc_rfkill_glib_class_init(CcRfkillGlibClass *klass) { GObjectClass *object_class = (GObjectClass *) klass; g_type_class_add_private(klass, sizeof(CcRfkillGlibPrivate)); object_class->finalize = cc_rfkill_glib_finalize; signals[CHANGED] = g_signal_new ("changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (CcRfkillGlibClass, changed), NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_POINTER); } CcRfkillGlib * cc_rfkill_glib_new (void) { return CC_RFKILL_GLIB (g_object_new (CC_RFKILL_TYPE_GLIB, NULL)); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/rfkill/rfkill-glib.h0000664000175000017500000000556100000000000024360 0ustar00jeremyjeremy/* * * gnome-bluetooth - Bluetooth integration for GNOME * * Copyright (C) 2012 Bastien Nocera * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef __CC_RFKILL_GLIB_H #define __CC_RFKILL_GLIB_H #include #include #include "rfkill.h" G_BEGIN_DECLS #define CC_RFKILL_TYPE_GLIB (cc_rfkill_glib_get_type()) #define CC_RFKILL_GLIB(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ CC_RFKILL_TYPE_GLIB, CcRfkillGlib)) #define CC_RFKILL_GLIB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ CC_RFKILL_TYPE_GLIB, CcRfkillGlibClass)) #define RFKILL_IS_GLIB(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ CC_RFKILL_TYPE_GLIB)) #define RFKILL_IS_GLIB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ CC_RFKILL_TYPE_GLIB)) #define RFKILL_GET_GLIB_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ CC_RFKILL_TYPE_GLIB, CcRfkillGlibClass)) typedef struct CcRfkillGlibPrivate CcRfkillGlibPrivate; typedef struct _CcRfkillGlib { GObject parent; CcRfkillGlibPrivate *priv; } CcRfkillGlib; typedef struct _CcRfkillGlibClass { GObjectClass parent_class; void (*changed) (CcRfkillGlib *rfkill, GList *events); } CcRfkillGlibClass; GType cc_rfkill_glib_get_type (void); CcRfkillGlib *cc_rfkill_glib_new (void); int cc_rfkill_glib_open (CcRfkillGlib *rfkill); void cc_rfkill_glib_send_event (CcRfkillGlib *rfkill, struct rfkill_event *event, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean cc_rfkill_glib_send_event_finish (CcRfkillGlib *rfkill, GAsyncResult *res, GError **error); void cc_rfkill_glib_send_change_all_event (CcRfkillGlib *rfkill, guint rfkill_type, gboolean enable, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean cc_rfkill_glib_send_change_all_event_finish (CcRfkillGlib *rfkill, GAsyncResult *res, GError **error); G_END_DECLS #endif /* __CC_RFKILL_GLIB_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/rfkill/rfkill.gnome-settings-plugin.in0000664000175000017500000000026300000000000030054 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=rfkill IAge=0 # Default Priority # Priority=100 _Name=Rfkill _Description=Rfkill plugin Authors=Bastien Nocera Copyright=Copyright © 2013 Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/rfkill/rfkill.h0000664000175000017500000000667400000000000023453 0ustar00jeremyjeremy#ifndef __RFKILL_H #define __RFKILL_H /* * Copyright (C) 2006 - 2007 Ivo van Doorn * Copyright (C) 2007 Dmitry Torokhov * Copyright 2009 Johannes Berg * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include /* define userspace visible states */ #define RFKILL_STATE_SOFT_BLOCKED 0 #define RFKILL_STATE_UNBLOCKED 1 #define RFKILL_STATE_HARD_BLOCKED 2 /** * enum rfkill_type - type of rfkill switch. * * @RFKILL_TYPE_ALL: toggles all switches (requests only - not a switch type) * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. * @RFKILL_TYPE_UWB: switch is on a ultra wideband device. * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device. * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device. * @RFKILL_TYPE_GPS: switch is on a GPS device. * @RFKILL_TYPE_FM: switch is on a FM radio device. * @NUM_RFKILL_TYPES: number of defined rfkill types */ enum rfkill_type { RFKILL_TYPE_ALL = 0, RFKILL_TYPE_WLAN, RFKILL_TYPE_BLUETOOTH, RFKILL_TYPE_UWB, RFKILL_TYPE_WIMAX, RFKILL_TYPE_WWAN, RFKILL_TYPE_GPS, RFKILL_TYPE_FM, NUM_RFKILL_TYPES, }; /** * enum rfkill_operation - operation types * @RFKILL_OP_ADD: a device was added * @RFKILL_OP_DEL: a device was removed * @RFKILL_OP_CHANGE: a device's state changed -- userspace changes one device * @RFKILL_OP_CHANGE_ALL: userspace changes all devices (of a type, or all) */ enum rfkill_operation { RFKILL_OP_ADD = 0, RFKILL_OP_DEL, RFKILL_OP_CHANGE, RFKILL_OP_CHANGE_ALL, }; /** * struct rfkill_event - events for userspace on /dev/rfkill * @idx: index of dev rfkill * @type: type of the rfkill struct * @op: operation code * @hard: hard state (0/1) * @soft: soft state (0/1) * * Structure used for userspace communication on /dev/rfkill, * used for events from the kernel and control to the kernel. */ struct rfkill_event { __u32 idx; __u8 type; __u8 op; __u8 soft, hard; } __attribute__((packed)); /* * We are planning to be backward and forward compatible with changes * to the event struct, by adding new, optional, members at the end. * When reading an event (whether the kernel from userspace or vice * versa) we need to accept anything that's at least as large as the * version 1 event size, but might be able to accept other sizes in * the future. * * One exception is the kernel -- we already have two event sizes in * that we've made the 'hard' member optional since our only option * is to ignore it anyway. */ #define RFKILL_EVENT_SIZE_V1 8 /* ioctl for turning off rfkill-input (if present) */ #define RFKILL_IOC_MAGIC 'R' #define RFKILL_IOC_NOINPUT 1 #define RFKILL_IOCTL_NOINPUT _IO(RFKILL_IOC_MAGIC, RFKILL_IOC_NOINPUT) /* and that's all userspace gets */ #endif /* RFKILL_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/rfkill/test-rfkill.c0000664000175000017500000000031200000000000024402 0ustar00jeremyjeremy#define NEW gsd_rfkill_manager_new #define START gsd_rfkill_manager_start #define STOP gsd_rfkill_manager_stop #define MANAGER GsdRfkillManager #include "gsd-rfkill-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5917668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/screensaver-proxy/0000775000175000017500000000000000000000000024216 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/screensaver-proxy/Makefile.am0000664000175000017500000000331400000000000026253 0ustar00jeremyjeremyplugin_name = screensaver-proxy plugin_LTLIBRARIES = libscreensaver-proxy.la libscreensaver_proxy_la_SOURCES = \ gsd-screensaver-proxy-manager.c \ gsd-screensaver-proxy-manager.h \ gsd-screensaver-proxy-plugin.c libscreensaver_proxy_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) libscreensaver_proxy_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) libscreensaver_proxy_la_LDFLAGS = $(GSD_PLUGIN_LDFLAGS) libscreensaver_proxy_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(SETTINGS_PLUGIN_LIBS) \ $(NULL) libexec_PROGRAMS = usd-test-screensaver-proxy usd_test_screensaver_proxy_SOURCES = \ test-screensaver-proxy.c \ gsd-screensaver-proxy-manager.c \ gsd-screensaver-proxy-manager.h usd_test_screensaver_proxy_CPPFLAGS = \ -I$(top_srcdir)/data/ \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ $(AM_CPPFLAGS) usd_test_screensaver_proxy_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) usd_test_screensaver_proxy_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(SETTINGS_DAEMON_LIBS) \ $(SETTINGS_PLUGIN_LIBS) plugin_in_files = screensaver-proxy.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = $(plugin_in_files) CLEANFILES = $(plugin_DATA) DISTCLEANFILES = $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000021400000000000010212 xustar00112 path=unity-settings-daemon-15.04.1+21.10.20220207/plugins/screensaver-proxy/gsd-screensaver-proxy-manager.c 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/screensaver-proxy/gsd-screensaver-proxy-manager0000664000175000017500000004532700000000000032036 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2012 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include "gnome-settings-bus.h" #include "gnome-settings-profile.h" #include "gsd-screensaver-proxy-manager.h" #include "gsd-idle-monitor.h" #define GSD_SCREENSAVER_PROXY_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_SCREENSAVER_PROXY_MANAGER, GsdScreensaverProxyManagerPrivate)) /* As available in: * https://projects.kde.org/projects/kde/kde-workspace/repository/revisions/master/entry/ksmserver/screenlocker/dbus/org.freedesktop.ScreenSaver.xml * and documented in: * https://projects.kde.org/projects/kde/kde-workspace/repository/revisions/master/entry/ksmserver/screenlocker/interface.h */ static const gchar introspection_xml[] = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; static const gchar introspection_xml2[] = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""; #define GSD_SCREENSAVER_PROXY_DBUS_SERVICE "org.freedesktop.ScreenSaver" #define GSD_SCREENSAVER_PROXY_DBUS_PATH "/org/freedesktop/ScreenSaver" #define GSD_SCREENSAVER_PROXY_DBUS_PATH2 "/ScreenSaver" #define GSD_SCREENSAVER_PROXY_DBUS_INTERFACE "org.freedesktop.ScreenSaver" #define GSM_INHIBITOR_FLAG_IDLE 1 << 3 struct GsdScreensaverProxyManagerPrivate { GsdSessionManager *session; GsdScreenSaver *screensaver; GDBusConnection *connection; GCancellable *bus_cancellable; GDBusNodeInfo *introspection_data; GDBusNodeInfo *introspection_data2; guint name_id; GHashTable *watch_ht; /* key = sender, value = name watch id */ GHashTable *cookie_ht; /* key = cookie, value = sender */ }; static void gsd_screensaver_proxy_manager_class_init (GsdScreensaverProxyManagerClass *klass); static void gsd_screensaver_proxy_manager_init (GsdScreensaverProxyManager *screensaver_proxy_manager); static void gsd_screensaver_proxy_manager_finalize (GObject *object); G_DEFINE_TYPE (GsdScreensaverProxyManager, gsd_screensaver_proxy_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static void name_vanished_cb (GDBusConnection *connection, const gchar *name, GsdScreensaverProxyManager *manager) { GHashTableIter iter; gpointer cookie_ptr; const char *sender; /* Look for all the cookies under that name, * and call uninhibit for them */ g_hash_table_iter_init (&iter, manager->priv->cookie_ht); while (g_hash_table_iter_next (&iter, &cookie_ptr, (gpointer *) &sender)) { if (g_strcmp0 (sender, name) == 0) { guint cookie = GPOINTER_TO_UINT (cookie_ptr); g_dbus_proxy_call_sync (G_DBUS_PROXY (manager->priv->session), "Uninhibit", g_variant_new ("(u)", cookie), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); g_debug ("Removing cookie %u for sender %s", cookie, sender); g_hash_table_iter_remove (&iter); } } g_hash_table_remove (manager->priv->watch_ht, name); } static void handle_method_call (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { GsdScreensaverProxyManager *manager = GSD_SCREENSAVER_PROXY_MANAGER (user_data); GError *error = NULL; GVariant *ret = NULL; /* Check session pointer as a proxy for whether the manager is in the start or stop state */ if (manager->priv->session == NULL || manager->priv->screensaver == NULL) { goto unimplemented; } g_debug ("Calling method '%s.%s' for ScreenSaver Proxy", interface_name, method_name); if (g_strcmp0 (method_name, "Inhibit") == 0) { const char *app_id; const char *reason; guint cookie; g_variant_get (parameters, "(ss)", &app_id, &reason); ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (manager->priv->session), "Inhibit", g_variant_new ("(susu)", app_id, 0, reason, GSM_INHIBITOR_FLAG_IDLE), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); g_variant_get (ret, "(u)", &cookie); g_hash_table_insert (manager->priv->cookie_ht, GUINT_TO_POINTER (cookie), g_strdup (sender)); if (g_hash_table_lookup (manager->priv->watch_ht, sender) == NULL) { guint watch_id; watch_id = g_bus_watch_name_on_connection (manager->priv->connection, sender, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, (GBusNameVanishedCallback) name_vanished_cb, manager, NULL); g_hash_table_insert (manager->priv->watch_ht, g_strdup (sender), GUINT_TO_POINTER (watch_id)); } } else if (g_strcmp0 (method_name, "UnInhibit") == 0) { guint cookie; g_variant_get (parameters, "(u)", &cookie); g_dbus_proxy_call_sync (G_DBUS_PROXY (manager->priv->session), "Uninhibit", parameters, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); g_debug ("Removing cookie %u from the list for %s", cookie, sender); g_hash_table_remove (manager->priv->cookie_ht, GUINT_TO_POINTER (cookie)); } else if (g_strcmp0 (method_name, "Lock") == 0 || g_strcmp0 (method_name, "SimulateUserActivity") == 0 || g_strcmp0 (method_name, "GetActive") == 0 || g_strcmp0 (method_name, "GetActiveTime") == 0 || g_strcmp0 (method_name, "SetActive") == 0) { ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (manager->priv->screensaver), method_name, parameters, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error == NULL && g_strcmp0 (method_name, "SetActive") == 0) { g_variant_unref (ret); /* Returning the actual Activate state here is not possible, * as calling GetActive at this point might return an invalid * value if the activation process is still ongoing. */ ret = g_variant_ref (parameters); } } else if (g_strcmp0 (method_name, "GetSessionIdleTime") == 0) { GsdIdleMonitor *idle_monitor = gsd_idle_monitor_get_core (); gint64 idle_time_ms = gsd_idle_monitor_get_idletime (idle_monitor); ret = g_variant_new ("(u)", idle_time_ms / 1000); } else { goto unimplemented; } if (error != NULL) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); return; } g_dbus_method_invocation_return_value (invocation, ret); return; unimplemented: g_dbus_method_invocation_return_dbus_error (invocation, "org.freedesktop.DBus.Error.NotSupported", "This method is not implemented"); } static const GDBusInterfaceVTable interface_vtable = { handle_method_call, NULL, /* GetProperty */ NULL, /* SetProperty */ }; static void on_bus_gotten (GObject *source_object, GAsyncResult *res, GsdScreensaverProxyManager *manager) { GDBusConnection *connection; GDBusInterfaceInfo **infos; GError *error = NULL; if (manager->priv->bus_cancellable == NULL || g_cancellable_is_cancelled (manager->priv->bus_cancellable)) { g_warning ("Operation has been cancelled, so not retrieving session bus"); return; } connection = g_bus_get_finish (res, &error); if (connection == NULL) { g_warning ("Could not get session bus: %s", error->message); g_error_free (error); return; } manager->priv->connection = connection; infos = manager->priv->introspection_data->interfaces; g_dbus_connection_register_object (connection, GSD_SCREENSAVER_PROXY_DBUS_PATH, infos[0], &interface_vtable, manager, NULL, NULL); infos = manager->priv->introspection_data2->interfaces; g_dbus_connection_register_object (connection, GSD_SCREENSAVER_PROXY_DBUS_PATH2, infos[0], &interface_vtable, manager, NULL, NULL); manager->priv->name_id = g_bus_own_name_on_connection (manager->priv->connection, GSD_SCREENSAVER_PROXY_DBUS_SERVICE, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL); } static void register_manager_dbus (GsdScreensaverProxyManager *manager) { manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); manager->priv->introspection_data2 = g_dbus_node_info_new_for_xml (introspection_xml2, NULL); manager->priv->bus_cancellable = g_cancellable_new (); g_assert (manager->priv->introspection_data != NULL); g_assert (manager->priv->introspection_data2 != NULL); g_bus_get (G_BUS_TYPE_SESSION, manager->priv->bus_cancellable, (GAsyncReadyCallback) on_bus_gotten, manager); } gboolean gsd_screensaver_proxy_manager_start (GsdScreensaverProxyManager *manager, GError **error) { g_debug ("Starting screensaver-proxy manager"); gnome_settings_profile_start (NULL); manager->priv->session = gnome_settings_bus_get_session_proxy (); manager->priv->screensaver = gnome_settings_bus_get_screen_saver_proxy (); manager->priv->watch_ht = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_bus_unwatch_name); manager->priv->cookie_ht = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) g_free); gnome_settings_profile_end (NULL); return TRUE; } void gsd_screensaver_proxy_manager_stop (GsdScreensaverProxyManager *manager) { g_debug ("Stopping screensaver_proxy manager"); g_clear_object (&manager->priv->session); g_clear_object (&manager->priv->screensaver); g_clear_pointer (&manager->priv->watch_ht, g_hash_table_destroy); g_clear_pointer (&manager->priv->cookie_ht, g_hash_table_destroy); } static void gsd_screensaver_proxy_manager_class_init (GsdScreensaverProxyManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_screensaver_proxy_manager_finalize; g_type_class_add_private (klass, sizeof (GsdScreensaverProxyManagerPrivate)); } static void gsd_screensaver_proxy_manager_init (GsdScreensaverProxyManager *manager) { manager->priv = GSD_SCREENSAVER_PROXY_MANAGER_GET_PRIVATE (manager); } static void gsd_screensaver_proxy_manager_finalize (GObject *object) { GsdScreensaverProxyManager *manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_SCREENSAVER_PROXY_MANAGER (object)); manager = GSD_SCREENSAVER_PROXY_MANAGER (object); g_return_if_fail (manager->priv != NULL); gsd_screensaver_proxy_manager_stop (manager); if (manager->priv->name_id != 0) { g_bus_unown_name (manager->priv->name_id); manager->priv->name_id = 0; } g_clear_object (&manager->priv->connection); g_clear_object (&manager->priv->bus_cancellable); g_clear_pointer (&manager->priv->introspection_data, g_dbus_node_info_unref); g_clear_pointer (&manager->priv->introspection_data2, g_dbus_node_info_unref); G_OBJECT_CLASS (gsd_screensaver_proxy_manager_parent_class)->finalize (object); } GsdScreensaverProxyManager * gsd_screensaver_proxy_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_SCREENSAVER_PROXY_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); register_manager_dbus (manager_object); } return GSD_SCREENSAVER_PROXY_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000021400000000000010212 xustar00112 path=unity-settings-daemon-15.04.1+21.10.20220207/plugins/screensaver-proxy/gsd-screensaver-proxy-manager.h 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/screensaver-proxy/gsd-screensaver-proxy-manager0000664000175000017500000000516700000000000032034 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2012 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_SCREENSAVER_PROXY_MANAGER_H #define __GSD_SCREENSAVER_PROXY_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_SCREENSAVER_PROXY_MANAGER (gsd_screensaver_proxy_manager_get_type ()) #define GSD_SCREENSAVER_PROXY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_SCREENSAVER_PROXY_MANAGER, GsdScreensaverProxyManager)) #define GSD_SCREENSAVER_PROXY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_SCREENSAVER_PROXY_MANAGER, GsdScreensaverProxyManagerClass)) #define GSD_IS_SCREENSAVER_PROXY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_SCREENSAVER_PROXY_MANAGER)) #define GSD_IS_SCREENSAVER_PROXY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_SCREENSAVER_PROXY_MANAGER)) #define GSD_SCREENSAVER_PROXY_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_SCREENSAVER_PROXY_MANAGER, GsdScreensaverProxyManagerClass)) typedef struct GsdScreensaverProxyManagerPrivate GsdScreensaverProxyManagerPrivate; typedef struct { GObject parent; GsdScreensaverProxyManagerPrivate *priv; } GsdScreensaverProxyManager; typedef struct { GObjectClass parent_class; } GsdScreensaverProxyManagerClass; GType gsd_screensaver_proxy_manager_get_type (void); GsdScreensaverProxyManager *gsd_screensaver_proxy_manager_new (void); gboolean gsd_screensaver_proxy_manager_start (GsdScreensaverProxyManager *manager, GError **error); void gsd_screensaver_proxy_manager_stop (GsdScreensaverProxyManager *manager); G_END_DECLS #endif /* __GSD_SCREENSAVER_PROXY_MANAGER_H */ ././@PaxHeader0000000000000000000000000000021300000000000010211 xustar00111 path=unity-settings-daemon-15.04.1+21.10.20220207/plugins/screensaver-proxy/gsd-screensaver-proxy-plugin.c 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/screensaver-proxy/gsd-screensaver-proxy-plugin.0000664000175000017500000000205700000000000031771 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2012 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-screensaver-proxy-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdScreensaverProxy, gsd_screensaver_proxy) ././@PaxHeader0000000000000000000000000000022700000000000010216 xustar00123 path=unity-settings-daemon-15.04.1+21.10.20220207/plugins/screensaver-proxy/screensaver-proxy.gnome-settings-plugin.in 28 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/screensaver-proxy/screensaver-proxy.gnome-setti0000664000175000017500000000035500000000000032075 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=screensaver-proxy IAge=0 Priority=8 _Name=Screensaver Proxy _Description=Proxy FreeDesktop screensaver inhibition to gnome-session Authors=Bastien Nocera Copyright=Copyright © 2012 Bastien Nocera Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/screensaver-proxy/test-screensaver-proxy.c0000664000175000017500000000040000000000000031030 0ustar00jeremyjeremy#define NEW gsd_screensaver_proxy_manager_new #define START gsd_screensaver_proxy_manager_start #define STOP gsd_screensaver_proxy_manager_stop #define MANAGER GsdScreensaverProxyManager #include "gsd-screensaver-proxy-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5917668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sharing/0000775000175000017500000000000000000000000022152 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sharing/Makefile.am0000664000175000017500000000246100000000000024211 0ustar00jeremyjeremyplugin_name = sharing plugin_LTLIBRARIES = libsharing.la libsharing_la_SOURCES = \ gsd-sharing-manager.c \ gsd-sharing-manager.h \ gsd-sharing-enums.h \ gsd-sharing-plugin.c libsharing_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_builddir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) libsharing_la_CFLAGS = \ -I$(top_srcdir)/plugins/common \ $(SHARING_CFLAGS) \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) libsharing_la_LDFLAGS = $(GSD_PLUGIN_LDFLAGS) libsharing_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(SETTINGS_PLUGIN_LIBS) \ $(SHARING_LIBS) \ $(NULL) noinst_PROGRAMS = gsd-test-sharing gsd_test_sharing_SOURCES = \ gsd-sharing-manager.c \ gsd-sharing-manager.h \ test-sharing.c gsd_test_sharing_CFLAGS = $(libsharing_la_CFLAGS) gsd_test_sharing_CPPFLAGS = $(libsharing_la_CPPFLAGS) gsd_test_sharing_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(SHARING_LIBS) \ $(SETTINGS_PLUGIN_LIBS) plugin_in_files = sharing.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = $(plugin_in_files) CLEANFILES = $(plugin_DATA) DISTCLEANFILES = $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sharing/gsd-sharing-enums.h0000664000175000017500000000214400000000000025657 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2014 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . * */ #ifndef __GSD_SHARING_ENUMS_H #define __GSD_SHARING_ENUMS_H G_BEGIN_DECLS typedef enum { GSD_SHARING_STATUS_OFFLINE, GSD_SHARING_STATUS_DISABLED_MOBILE_BROADBAND, GSD_SHARING_STATUS_DISABLED_LOW_SECURITY, GSD_SHARING_STATUS_AVAILABLE } GsdSharingStatus; G_END_DECLS #endif /* __GSD_SHARING_ENUMS_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sharing/gsd-sharing-manager.c0000664000175000017500000007154700000000000026152 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2014 Bastien Nocera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . * */ #include "config.h" #include #include #include #include #include #ifdef HAVE_NETWORK_MANAGER #include #endif /* HAVE_NETWORK_MANAGER */ #include "gnome-settings-plugin.h" #include "gnome-settings-profile.h" #include "gsd-sharing-manager.h" #include "gsd-sharing-enums.h" #define GSD_SHARING_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_SHARING_MANAGER, GsdSharingManagerPrivate)) typedef struct { const char *name; GSettings *settings; gboolean started; GSubprocess *process; } ServiceInfo; struct GsdSharingManagerPrivate { GDBusNodeInfo *introspection_data; guint name_id; GDBusConnection *connection; GCancellable *cancellable; #ifdef HAVE_NETWORK_MANAGER NMClient *client; #endif /* HAVE_NETWORK_MANAGER */ GHashTable *services; char *current_network; char *current_network_name; char *carrier_type; GsdSharingStatus sharing_status; }; #define GSD_SHARING_DBUS_NAME GSD_DBUS_NAME ".Sharing" #define GSD_SHARING_DBUS_PATH GSD_DBUS_PATH "/Sharing" static const gchar introspection_xml[] = "" " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " ""; static void gsd_sharing_manager_class_init (GsdSharingManagerClass *klass); static void gsd_sharing_manager_init (GsdSharingManager *manager); static void gsd_sharing_manager_finalize (GObject *object); G_DEFINE_TYPE (GsdSharingManager, gsd_sharing_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static const char * const services[] = { "rygel", "vino-server", "gnome-user-share-webdav" }; static void gsd_sharing_manager_start_service (GsdSharingManager *manager, ServiceInfo *service) { GDesktopAppInfo *app; const char *exec; char *desktop, **argvp; GError *error = NULL; if (service->started) return; g_debug ("About to start %s", service->name); desktop = g_strdup_printf ("%s.desktop", service->name); app = g_desktop_app_info_new (desktop); g_free (desktop); if (!app) { g_warning ("Could not find desktop file for service '%s'", service->name); return; } exec = g_app_info_get_commandline (G_APP_INFO (app)); if (!g_shell_parse_argv (exec, NULL, &argvp, &error)) { g_warning ("Could not parse command-line '%s': %s", exec, error->message); g_error_free (error); g_object_unref (app); return; } service->process = g_subprocess_newv ((const gchar * const*) argvp, G_SUBPROCESS_FLAGS_NONE, &error); if (!service->process) { g_warning ("Could not start command-line '%s': %s", exec, error->message); g_error_free (error); service->started = FALSE; } else { service->started = TRUE; } g_strfreev (argvp); g_object_unref (app); } #ifdef HAVE_NETWORK_MANAGER static gboolean service_is_enabled_on_current_connection (GsdSharingManager *manager, ServiceInfo *service) { char **connections; int j; gboolean ret; connections = g_settings_get_strv (service->settings, "enabled-connections"); ret = FALSE; for (j = 0; connections[j] != NULL; j++) { if (g_strcmp0 (connections[j], manager->priv->current_network) == 0) { ret = TRUE; break; } } g_strfreev (connections); return ret; } #else static gboolean service_is_enabled_on_current_connection (GsdSharingManager *manager, ServiceInfo *service) { return FALSE; } #endif /* HAVE_NETWORK_MANAGER */ static void gsd_sharing_manager_stop_service (GsdSharingManager *manager, ServiceInfo *service) { if (!service->started || service->process == NULL) { return; } g_debug ("About to stop %s", service->name); g_subprocess_send_signal (service->process, SIGTERM); g_clear_object (&service->process); service->started = FALSE; } static void gsd_sharing_manager_sync_services (GsdSharingManager *manager) { GList *services, *l; services = g_hash_table_get_values (manager->priv->services); for (l = services; l != NULL; l = l->next) { ServiceInfo *service = l->data; gboolean should_be_started = FALSE; if (manager->priv->sharing_status == GSD_SHARING_STATUS_AVAILABLE && service_is_enabled_on_current_connection (manager, service)) should_be_started = TRUE; if (service->started != should_be_started) { if (service->started) gsd_sharing_manager_stop_service (manager, service); else gsd_sharing_manager_start_service (manager, service); } } g_list_free (services); } #ifdef HAVE_NETWORK_MANAGER static void properties_changed (GsdSharingManager *manager) { GVariantBuilder props_builder; GVariant *props_changed = NULL; /* not yet connected to the session bus */ if (manager->priv->connection == NULL) return; g_variant_builder_init (&props_builder, G_VARIANT_TYPE ("a{sv}")); g_variant_builder_add (&props_builder, "{sv}", "CurrentNetwork", g_variant_new_string (manager->priv->current_network)); g_variant_builder_add (&props_builder, "{sv}", "CurrentNetworkName", g_variant_new_string (manager->priv->current_network_name)); g_variant_builder_add (&props_builder, "{sv}", "CarrierType", g_variant_new_string (manager->priv->carrier_type)); g_variant_builder_add (&props_builder, "{sv}", "SharingStatus", g_variant_new_uint32 (manager->priv->sharing_status)); props_changed = g_variant_new ("(s@a{sv}@as)", GSD_SHARING_DBUS_NAME, g_variant_builder_end (&props_builder), g_variant_new_strv (NULL, 0)); g_dbus_connection_emit_signal (manager->priv->connection, NULL, GSD_SHARING_DBUS_PATH, "org.freedesktop.DBus.Properties", "PropertiesChanged", props_changed, NULL); } static char ** get_connections_for_service (GsdSharingManager *manager, const char *service_name) { ServiceInfo *service; service = g_hash_table_lookup (manager->priv->services, service_name); return g_settings_get_strv (service->settings, "enabled-connections"); } #else static char ** get_connections_for_service (GsdSharingManager *manager, const char *service_name) { const char * const * connections [] = { NULL }; return g_strdupv ((char **) connections); } #endif /* HAVE_NETWORK_MANAGER */ static gboolean check_service (GsdSharingManager *manager, const char *service_name, GError **error) { if (g_hash_table_lookup (manager->priv->services, service_name)) return TRUE; g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid service name '%s'", service_name); return FALSE; } static gboolean gsd_sharing_manager_enable_service (GsdSharingManager *manager, const char *service_name, GError **error) { ServiceInfo *service; char **connections; GPtrArray *array; guint i; if (!check_service (manager, service_name, error)) return FALSE; if (manager->priv->sharing_status != GSD_SHARING_STATUS_AVAILABLE) { g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Sharing cannot be enabled on this network, status is '%d'", manager->priv->sharing_status); return FALSE; } service = g_hash_table_lookup (manager->priv->services, service_name); connections = g_settings_get_strv (service->settings, "enabled-connections"); array = g_ptr_array_new (); for (i = 0; connections[i] != NULL; i++) { if (g_strcmp0 (connections[i], manager->priv->current_network) == 0) goto bail; g_ptr_array_add (array, connections[i]); } g_ptr_array_add (array, manager->priv->current_network); g_ptr_array_add (array, NULL); g_settings_set_strv (service->settings, "enabled-connections", (const gchar *const *) array->pdata); bail: gsd_sharing_manager_start_service (manager, service); g_ptr_array_unref (array); g_strfreev (connections); return TRUE; } static gboolean gsd_sharing_manager_disable_service (GsdSharingManager *manager, const char *service_name, const char *network_name, GError **error) { ServiceInfo *service; char **connections; GPtrArray *array; guint i; if (!check_service (manager, service_name, error)) return FALSE; service = g_hash_table_lookup (manager->priv->services, service_name); connections = g_settings_get_strv (service->settings, "enabled-connections"); array = g_ptr_array_new (); for (i = 0; connections[i] != NULL; i++) { if (g_strcmp0 (connections[i], network_name) != 0) g_ptr_array_add (array, connections[i]); } g_ptr_array_add (array, NULL); g_settings_set_strv (service->settings, "enabled-connections", (const gchar *const *) array->pdata); g_ptr_array_unref (array); g_strfreev (connections); if (g_str_equal (network_name, manager->priv->current_network)) gsd_sharing_manager_stop_service (manager, service); return TRUE; } #ifdef HAVE_NETWORK_MANAGER static const char * get_type_and_name_for_connection_uuid (GsdSharingManager *manager, const char *uuid, const char **name) { NMRemoteConnection *conn; const char *type; if (!manager->priv->client) return NULL; conn = nm_client_get_connection_by_uuid (manager->priv->client, uuid); if (!conn) return NULL; type = nm_connection_get_connection_type (NM_CONNECTION (conn)); *name = nm_connection_get_id (NM_CONNECTION (conn)); return type; } #else static const char * get_type_and_name_for_connection_uuid (GsdSharingManager *manager, const char *id, const char **name) { return NULL; } #endif /* HAVE_NETWORK_MANAGER */ #ifdef HAVE_NETWORK_MANAGER static gboolean connection_is_low_security (GsdSharingManager *manager, const char *uuid) { NMRemoteConnection *conn; if (!manager->priv->client) return TRUE; conn = nm_client_get_connection_by_uuid (manager->priv->client, uuid); if (!conn) return TRUE; /* Disable sharing on open Wi-Fi * XXX: Also do this for WEP networks? */ return (nm_connection_get_setting_wireless_security (NM_CONNECTION (conn)) == NULL); } #endif /* HAVE_NETWORK_MANAGER */ static GVariant * gsd_sharing_manager_list_networks (GsdSharingManager *manager, const char *service_name, GError **error) { char **connections; GVariantBuilder builder; guint i; if (!check_service (manager, service_name, error)) return NULL; #ifdef HAVE_NETWORK_MANAGER if (!manager->priv->client) { g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Not ready yet"); return NULL; } #endif /* HAVE_NETWORK_MANAGER */ connections = get_connections_for_service (manager, service_name); g_variant_builder_init (&builder, G_VARIANT_TYPE ("(a(sss))")); g_variant_builder_open (&builder, G_VARIANT_TYPE ("a(sss)")); for (i = 0; connections[i] != NULL; i++) { const char *type, *name; type = get_type_and_name_for_connection_uuid (manager, connections[i], &name); if (!type) continue; g_variant_builder_add (&builder, "(sss)", connections[i], name, type); } g_strfreev (connections); g_variant_builder_close (&builder); return g_variant_builder_end (&builder); } static GVariant * handle_get_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data) { GsdSharingManager *manager = GSD_SHARING_MANAGER (user_data); /* Check session pointer as a proxy for whether the manager is in the start or stop state */ if (manager->priv->connection == NULL) return NULL; if (g_strcmp0 (property_name, "CurrentNetwork") == 0) { return g_variant_new_string (manager->priv->current_network); } if (g_strcmp0 (property_name, "CurrentNetworkName") == 0) { return g_variant_new_string (manager->priv->current_network_name); } if (g_strcmp0 (property_name, "CarrierType") == 0) { return g_variant_new_string (manager->priv->carrier_type); } if (g_strcmp0 (property_name, "SharingStatus") == 0) { return g_variant_new_uint32 (manager->priv->sharing_status); } return NULL; } static void handle_method_call (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) { GsdSharingManager *manager = (GsdSharingManager *) user_data; g_debug ("Calling method '%s' for sharing", method_name); /* Check session pointer as a proxy for whether the manager is in the start or stop state */ if (manager->priv->connection == NULL) return; if (g_strcmp0 (method_name, "EnableService") == 0) { const char *service; GError *error = NULL; g_variant_get (parameters, "(&s)", &service); if (!gsd_sharing_manager_enable_service (manager, service, &error)) g_dbus_method_invocation_take_error (invocation, error); else g_dbus_method_invocation_return_value (invocation, NULL); } else if (g_strcmp0 (method_name, "DisableService") == 0) { const char *service; const char *network_name; GError *error = NULL; g_variant_get (parameters, "(&s&s)", &service, &network_name); if (!gsd_sharing_manager_disable_service (manager, service, network_name, &error)) g_dbus_method_invocation_take_error (invocation, error); else g_dbus_method_invocation_return_value (invocation, NULL); } else if (g_strcmp0 (method_name, "ListNetworks") == 0) { const char *service; GError *error = NULL; GVariant *variant; g_variant_get (parameters, "(&s)", &service); variant = gsd_sharing_manager_list_networks (manager, service, &error); if (!variant) g_dbus_method_invocation_take_error (invocation, error); else g_dbus_method_invocation_return_value (invocation, variant); } } static const GDBusInterfaceVTable interface_vtable = { handle_method_call, handle_get_property, NULL }; static void on_bus_gotten (GObject *source_object, GAsyncResult *res, GsdSharingManager *manager) { GDBusConnection *connection; GError *error = NULL; connection = g_bus_get_finish (res, &error); if (connection == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Could not get session bus: %s", error->message); g_error_free (error); return; } manager->priv->connection = connection; g_dbus_connection_register_object (connection, GSD_SHARING_DBUS_PATH, manager->priv->introspection_data->interfaces[0], &interface_vtable, manager, NULL, NULL); manager->priv->name_id = g_bus_own_name_on_connection (connection, GSD_SHARING_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL); } #ifdef HAVE_NETWORK_MANAGER static void primary_connection_changed (GObject *gobject, GParamSpec *pspec, gpointer user_data) { GsdSharingManager *manager = user_data; NMActiveConnection *a_con; a_con = nm_client_get_primary_connection (manager->priv->client); g_clear_pointer (&manager->priv->current_network, g_free); g_clear_pointer (&manager->priv->current_network_name, g_free); g_clear_pointer (&manager->priv->carrier_type, g_free); if (a_con) { manager->priv->current_network = g_strdup (nm_active_connection_get_uuid (a_con)); manager->priv->current_network_name = g_strdup (nm_active_connection_get_id (a_con)); manager->priv->carrier_type = g_strdup (nm_active_connection_get_connection_type (a_con)); if (manager->priv->carrier_type == NULL) manager->priv->carrier_type = g_strdup (""); } else { manager->priv->current_network = g_strdup (""); manager->priv->current_network_name = g_strdup (""); manager->priv->carrier_type = g_strdup (""); } if (!a_con) { manager->priv->sharing_status = GSD_SHARING_STATUS_OFFLINE; } else if (*(manager->priv->carrier_type) == '\0') { /* Missing carrier type information? */ manager->priv->sharing_status = GSD_SHARING_STATUS_OFFLINE; } else if (g_str_equal (manager->priv->carrier_type, "bluetooth") || g_str_equal (manager->priv->carrier_type, "gsm") || g_str_equal (manager->priv->carrier_type, "cdma")) { manager->priv->sharing_status = GSD_SHARING_STATUS_DISABLED_MOBILE_BROADBAND; } else if (g_str_equal (manager->priv->carrier_type, "802-11-wireless")) { if (connection_is_low_security (manager, manager->priv->current_network)) manager->priv->sharing_status = GSD_SHARING_STATUS_DISABLED_LOW_SECURITY; else manager->priv->sharing_status = GSD_SHARING_STATUS_AVAILABLE; } else { manager->priv->sharing_status = GSD_SHARING_STATUS_AVAILABLE; } g_debug ("current network: %s", manager->priv->current_network); g_debug ("current network name: %s", manager->priv->current_network_name); g_debug ("conn type: %s", manager->priv->carrier_type); g_debug ("status: %d", manager->priv->sharing_status); properties_changed (manager); gsd_sharing_manager_sync_services (manager); } static void nm_client_ready (GObject *source_object, GAsyncResult *res, gpointer user_data) { GsdSharingManager *manager = user_data; GError *error = NULL; NMClient *client; client = nm_client_new_finish (res, &error); if (!client) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Couldn't get NMClient: %s", error->message); g_error_free (error); return; } manager->priv->client = client; g_signal_connect (G_OBJECT (client), "notify::primary-connection", G_CALLBACK (primary_connection_changed), manager); primary_connection_changed (NULL, NULL, manager); } #endif /* HAVE_NETWORK_MANAGER */ #define RYGEL_BUS_NAME "org.gnome.Rygel1" #define RYGEL_OBJECT_PATH "/org/gnome/Rygel1" #define RYGEL_INTERFACE_NAME "org.gnome.Rygel1" static void gsd_sharing_manager_disable_rygel (void) { GDBusConnection *connection; gchar *path; path = g_build_filename (g_get_user_config_dir (), "autostart", "rygel.desktop", NULL); if (!g_file_test (path, G_FILE_TEST_IS_SYMLINK | G_FILE_TEST_IS_REGULAR)) goto out; g_unlink (path); connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); if (connection) { g_dbus_connection_call (connection, RYGEL_BUS_NAME, RYGEL_OBJECT_PATH, RYGEL_INTERFACE_NAME, "Shutdown", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); } g_object_unref (connection); out: g_free (path); } gboolean gsd_sharing_manager_start (GsdSharingManager *manager, GError **error) { g_debug ("Starting sharing manager"); gnome_settings_profile_start (NULL); manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (manager->priv->introspection_data != NULL); gsd_sharing_manager_disable_rygel (); manager->priv->cancellable = g_cancellable_new (); #ifdef HAVE_NETWORK_MANAGER nm_client_new_async (manager->priv->cancellable, nm_client_ready, manager); #endif /* HAVE_NETWORK_MANAGER */ /* Start process of owning a D-Bus name */ g_bus_get (G_BUS_TYPE_SESSION, manager->priv->cancellable, (GAsyncReadyCallback) on_bus_gotten, manager); gnome_settings_profile_end (NULL); return TRUE; } void gsd_sharing_manager_stop (GsdSharingManager *manager) { g_debug ("Stopping sharing manager"); manager->priv->sharing_status = GSD_SHARING_STATUS_OFFLINE; gsd_sharing_manager_sync_services (manager); if (manager->priv->cancellable) { g_cancellable_cancel (manager->priv->cancellable); g_clear_object (&manager->priv->cancellable); } #ifdef HAVE_NETWORK_MANAGER g_clear_object (&manager->priv->client); #endif /* HAVE_NETWORK_MANAGER */ if (manager->priv->name_id != 0) { g_bus_unown_name (manager->priv->name_id); manager->priv->name_id = 0; } g_clear_pointer (&manager->priv->introspection_data, g_dbus_node_info_unref); g_clear_object (&manager->priv->connection); g_clear_pointer (&manager->priv->current_network, g_free); g_clear_pointer (&manager->priv->current_network_name, g_free); g_clear_pointer (&manager->priv->carrier_type, g_free); } static void gsd_sharing_manager_class_init (GsdSharingManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_sharing_manager_finalize; g_type_class_add_private (klass, sizeof (GsdSharingManagerPrivate)); } static void service_free (gpointer pointer) { ServiceInfo *service = pointer; g_clear_object (&service->settings); g_free (service); } static void gsd_sharing_manager_init (GsdSharingManager *manager) { guint i; manager->priv = GSD_SHARING_MANAGER_GET_PRIVATE (manager); manager->priv->services = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, service_free); /* Default state */ manager->priv->current_network = g_strdup (""); manager->priv->current_network_name = g_strdup (""); manager->priv->carrier_type = g_strdup (""); manager->priv->sharing_status = GSD_SHARING_STATUS_OFFLINE; for (i = 0; i < G_N_ELEMENTS (services); i++) { ServiceInfo *service; char *path; service = g_new0 (ServiceInfo, 1); service->name = services[i]; path = g_strdup_printf ("/com/canonical/unity/settings-daemon/plugins/sharing/%s/", services[i]); service->settings = g_settings_new_with_path ("com.canonical.unity.settings-daemon.plugins.sharing.service", path); g_free (path); g_hash_table_insert (manager->priv->services, (gpointer) services[i], service); } } static void gsd_sharing_manager_finalize (GObject *object) { GsdSharingManager *manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_SHARING_MANAGER (object)); manager = GSD_SHARING_MANAGER (object); g_return_if_fail (manager->priv != NULL); gsd_sharing_manager_stop (manager); g_hash_table_unref (manager->priv->services); G_OBJECT_CLASS (gsd_sharing_manager_parent_class)->finalize (object); } GsdSharingManager * gsd_sharing_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_SHARING_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_SHARING_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sharing/gsd-sharing-manager.h0000664000175000017500000000435700000000000026152 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . * */ #ifndef __GSD_SHARING_MANAGER_H #define __GSD_SHARING_MANAGER_H #include G_BEGIN_DECLS #define GSD_TYPE_SHARING_MANAGER (gsd_sharing_manager_get_type ()) #define GSD_SHARING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_SHARING_MANAGER, GsdSharingManager)) #define GSD_SHARING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_SHARING_MANAGER, GsdSharingManagerClass)) #define GSD_IS_SHARING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_SHARING_MANAGER)) #define GSD_IS_SHARING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_SHARING_MANAGER)) #define GSD_SHARING_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_SHARING_MANAGER, GsdSharingManagerClass)) typedef struct GsdSharingManagerPrivate GsdSharingManagerPrivate; typedef struct { GObject parent; GsdSharingManagerPrivate *priv; } GsdSharingManager; typedef struct { GObjectClass parent_class; } GsdSharingManagerClass; GType gsd_sharing_manager_get_type (void); GsdSharingManager * gsd_sharing_manager_new (void); gboolean gsd_sharing_manager_start (GsdSharingManager *manager, GError **error); void gsd_sharing_manager_stop (GsdSharingManager *manager); G_END_DECLS #endif /* __GSD_SHARING_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sharing/gsd-sharing-plugin.c0000664000175000017500000000171600000000000026025 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-sharing-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdSharing, gsd_sharing) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sharing/sharing.gnome-settings-plugin.in0000664000175000017500000000032400000000000030372 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=sharing IAge=0 # 100 is the default load Priority Priority=100 Name=Sharing Description=Sharing plugin Authors=Bastien Nocera Copyright=Copyright © 2014 AUTHOR ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sharing/test-sharing.c0000664000175000017500000000031700000000000024727 0ustar00jeremyjeremy#define NEW gsd_sharing_manager_new #define START gsd_sharing_manager_start #define STOP gsd_sharing_manager_stop #define MANAGER GsdSharingManager #include "gsd-sharing-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5917668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/smartcard/0000775000175000017500000000000000000000000022477 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/smartcard/Makefile.am0000664000175000017500000000326400000000000024540 0ustar00jeremyjeremyplugin_name = smartcard libexec_PROGRAMS = usd-test-smartcard usd_test_smartcard_SOURCES = \ gsd-smartcard-manager.h \ gsd-smartcard-manager.c \ gsd-smartcard.h \ gsd-smartcard.c \ test-smartcard.c usd_test_smartcard_CFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DSYSCONFDIR=\""$(sysconfdir)"\" \ -DLIBDIR=\""$(libdir)"\" \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(NSS_CFLAGS) \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) usd_test_smartcard_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(NSS_LIBS) \ $(SETTINGS_PLUGIN_LIBS) plugin_LTLIBRARIES = \ libsmartcard.la libsmartcard_la_SOURCES = \ gsd-smartcard-plugin.h \ gsd-smartcard-plugin.c \ gsd-smartcard.h \ gsd-smartcard.c \ gsd-smartcard-manager.h \ gsd-smartcard-manager.c libsmartcard_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DSYSCONFDIR=\""$(sysconfdir)"\" \ -DLIBDIR=\""$(libdir)"\" \ -DGSD_SMARTCARD_MANAGER_NSS_DB=\""$(NSS_DATABASE)"\" \ $(AM_CPPFLAGS) libsmartcard_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(NSS_CFLAGS) \ $(AM_CFLAGS) libsmartcard_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) libsmartcard_la_LIBADD = \ $(SETTINGS_PLUGIN_LIBS) \ $(NSS_LIBS) @GSD_INTLTOOL_PLUGIN_RULE@ plugin_in_files = \ smartcard.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = \ $(plugin_in_files) CLEANFILES = \ $(plugin_DATA) DISTCLEANFILES = \ $(plugin_DATA) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/smartcard/gsd-smartcard-manager.c0000664000175000017500000014362500000000000027021 0ustar00jeremyjeremy/* gsd-smartcard-manager.c - object for monitoring smartcard insertion and * removal events * * Copyright (C) 2006, 2009 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written By: Ray Strode */ #include "config.h" #include "gsd-smartcard-manager.h" #define SMARTCARD_ENABLE_INTERNAL_API #include "gsd-smartcard.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef GSD_SMARTCARD_MANAGER_DRIVER #define GSD_SMARTCARD_MANAGER_DRIVER LIBDIR"/pkcs11/libcoolkeypk11.so" #endif #ifndef GSD_SMARTCARD_MANAGER_NSS_DB #define GSD_SMARTCARD_MANAGER_NSS_DB SYSCONFDIR"/pki/nssdb" #endif #ifndef GSD_MAX_OPEN_FILE_DESCRIPTORS #define GSD_MAX_OPEN_FILE_DESCRIPTORS 1024 #endif #ifndef GSD_OPEN_FILE_DESCRIPTORS_DIR #define GSD_OPEN_FILE_DESCRIPTORS_DIR "/proc/self/fd" #endif typedef enum _GsdSmartcardManagerState GsdSmartcardManagerState; typedef struct _GsdSmartcardManagerWorker GsdSmartcardManagerWorker; enum _GsdSmartcardManagerState { GSD_SMARTCARD_MANAGER_STATE_STOPPED = 0, GSD_SMARTCARD_MANAGER_STATE_STARTING, GSD_SMARTCARD_MANAGER_STATE_STARTED, GSD_SMARTCARD_MANAGER_STATE_STOPPING, }; struct _GsdSmartcardManagerPrivate { GsdSmartcardManagerState state; GList *modules; char *module_path; GList *workers; GPid smartcard_event_watcher_pid; GHashTable *smartcards; guint poll_timeout_id; guint32 is_unstoppable : 1; guint32 nss_is_loaded : 1; }; struct _GsdSmartcardManagerWorker { GsdSmartcardManager *manager; int manager_fd; GThread *thread; SECMODModule *module; GHashTable *smartcards; int fd; GSource *event_source; guint32 nss_is_loaded : 1; }; static void gsd_smartcard_manager_finalize (GObject *object); static void gsd_smartcard_manager_class_install_signals (GsdSmartcardManagerClass *service_class); static void gsd_smartcard_manager_class_install_properties (GsdSmartcardManagerClass *service_class); static void gsd_smartcard_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); static void gsd_smartcard_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); static void gsd_smartcard_manager_set_module_path (GsdSmartcardManager *manager, const char *module_path); static void gsd_smartcard_manager_card_removed_handler (GsdSmartcardManager *manager, GsdSmartcard *card); static void gsd_smartcard_manager_card_inserted_handler (GsdSmartcardManager *manager_class, GsdSmartcard *card); static gboolean gsd_smartcard_manager_stop_now (GsdSmartcardManager *manager); static void gsd_smartcard_manager_queue_stop (GsdSmartcardManager *manager); static GsdSmartcardManagerWorker *gsd_smartcard_manager_create_worker (GsdSmartcardManager *manager, SECMODModule *module); static GsdSmartcardManagerWorker * gsd_smartcard_manager_worker_new (GsdSmartcardManager *manager, int worker_fd, int manager_fd, SECMODModule *module); static void gsd_smartcard_manager_worker_free (GsdSmartcardManagerWorker *worker); static gboolean open_pipe (int *write_fd, int *read_fd); static gboolean read_bytes (int fd, gpointer bytes, gsize num_bytes); static gboolean write_bytes (int fd, gconstpointer bytes, gsize num_bytes); static GsdSmartcard *read_smartcard (int fd, SECMODModule *module); static gboolean write_smartcard (int fd, GsdSmartcard *card); enum { PROP_0 = 0, PROP_MODULE_PATH, NUMBER_OF_PROPERTIES }; enum { SMARTCARD_INSERTED = 0, SMARTCARD_REMOVED, ERROR, NUMBER_OF_SIGNALS }; static guint gsd_smartcard_manager_signals[NUMBER_OF_SIGNALS]; G_DEFINE_TYPE (GsdSmartcardManager, gsd_smartcard_manager, G_TYPE_OBJECT); static void gsd_smartcard_manager_class_init (GsdSmartcardManagerClass *manager_class) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (manager_class); gobject_class->finalize = gsd_smartcard_manager_finalize; gsd_smartcard_manager_class_install_signals (manager_class); gsd_smartcard_manager_class_install_properties (manager_class); g_type_class_add_private (manager_class, sizeof (GsdSmartcardManagerPrivate)); } static void gsd_smartcard_manager_class_install_properties (GsdSmartcardManagerClass *card_class) { GObjectClass *object_class; GParamSpec *param_spec; object_class = G_OBJECT_CLASS (card_class); object_class->set_property = gsd_smartcard_manager_set_property; object_class->get_property = gsd_smartcard_manager_get_property; param_spec = g_param_spec_string ("module-path", "Module Path", "path to smartcard PKCS #11 driver", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_MODULE_PATH, param_spec); } static void gsd_smartcard_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GsdSmartcardManager *manager = GSD_SMARTCARD_MANAGER (object); switch (prop_id) { case PROP_MODULE_PATH: gsd_smartcard_manager_set_module_path (manager, g_value_get_string (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void gsd_smartcard_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GsdSmartcardManager *manager = GSD_SMARTCARD_MANAGER (object); char *module_path; switch (prop_id) { case PROP_MODULE_PATH: module_path = gsd_smartcard_manager_get_module_path (manager); g_value_set_string (value, module_path); g_free (module_path); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } char * gsd_smartcard_manager_get_module_path (GsdSmartcardManager *manager) { return manager->priv->module_path; } static void gsd_smartcard_manager_set_module_path (GsdSmartcardManager *manager, const char *module_path) { if ((manager->priv->module_path == NULL) && (module_path == NULL)) { return; } if (((manager->priv->module_path == NULL) || (module_path == NULL) || (strcmp (manager->priv->module_path, module_path) != 0))) { g_free (manager->priv->module_path); manager->priv->module_path = g_strdup (module_path); g_object_notify (G_OBJECT (manager), "module-path"); } } static void gsd_smartcard_manager_card_removed_handler (GsdSmartcardManager *manager, GsdSmartcard *card) { g_debug ("informing smartcard of its removal"); _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_REMOVED); g_debug ("done"); } static void gsd_smartcard_manager_card_inserted_handler (GsdSmartcardManager *manager, GsdSmartcard *card) { g_debug ("informing smartcard of its insertion"); _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_INSERTED); g_debug ("done"); } static void gsd_smartcard_manager_class_install_signals (GsdSmartcardManagerClass *manager_class) { GObjectClass *object_class; object_class = G_OBJECT_CLASS (manager_class); gsd_smartcard_manager_signals[SMARTCARD_INSERTED] = g_signal_new ("smartcard-inserted", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GsdSmartcardManagerClass, smartcard_inserted), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); manager_class->smartcard_inserted = gsd_smartcard_manager_card_inserted_handler; gsd_smartcard_manager_signals[SMARTCARD_REMOVED] = g_signal_new ("smartcard-removed", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GsdSmartcardManagerClass, smartcard_removed), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); manager_class->smartcard_removed = gsd_smartcard_manager_card_removed_handler; gsd_smartcard_manager_signals[ERROR] = g_signal_new ("error", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GsdSmartcardManagerClass, error), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); manager_class->error = NULL; } static gboolean slot_id_equal (CK_SLOT_ID *slot_id_1, CK_SLOT_ID *slot_id_2) { g_assert (slot_id_1 != NULL); g_assert (slot_id_2 != NULL); return *slot_id_1 == *slot_id_2; } static gboolean slot_id_hash (CK_SLOT_ID *slot_id) { guint32 upper_bits, lower_bits; int temp; if (sizeof (CK_SLOT_ID) == sizeof (int)) { return g_int_hash (slot_id); } upper_bits = ((*slot_id) >> 31) - 1; lower_bits = (*slot_id) & 0xffffffff; /* The upper bits are almost certainly always zero, * so let's degenerate to g_int_hash for the * (very) common case */ temp = lower_bits + upper_bits; return upper_bits + g_int_hash (&temp); } static void gsd_smartcard_manager_init (GsdSmartcardManager *manager) { g_debug ("initializing smartcard manager"); manager->priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, GSD_TYPE_SMARTCARD_MANAGER, GsdSmartcardManagerPrivate); manager->priv->poll_timeout_id = 0; manager->priv->is_unstoppable = FALSE; manager->priv->smartcards = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref); } static void gsd_smartcard_manager_finalize (GObject *object) { GsdSmartcardManager *manager; GObjectClass *gobject_class; manager = GSD_SMARTCARD_MANAGER (object); gobject_class = G_OBJECT_CLASS (gsd_smartcard_manager_parent_class); gsd_smartcard_manager_stop_now (manager); g_hash_table_destroy (manager->priv->smartcards); manager->priv->smartcards = NULL; gobject_class->finalize (object); } GQuark gsd_smartcard_manager_error_quark (void) { static GQuark error_quark = 0; if (error_quark == 0) { error_quark = g_quark_from_static_string ("gsd-smartcard-manager-error-quark"); } return error_quark; } GsdSmartcardManager * gsd_smartcard_manager_new_default (void) { return gsd_smartcard_manager_new (NULL); } GsdSmartcardManager * gsd_smartcard_manager_new (const char *module_path) { GsdSmartcardManager *instance; instance = GSD_SMARTCARD_MANAGER (g_object_new (GSD_TYPE_SMARTCARD_MANAGER, "module-path", module_path, NULL)); return instance; } static void gsd_smartcard_manager_emit_error (GsdSmartcardManager *manager, GError *error) { manager->priv->is_unstoppable = TRUE; g_signal_emit (manager, gsd_smartcard_manager_signals[ERROR], 0, error); manager->priv->is_unstoppable = FALSE; } static void gsd_smartcard_manager_emit_smartcard_inserted (GsdSmartcardManager *manager, GsdSmartcard *card) { manager->priv->is_unstoppable = TRUE; g_signal_emit (manager, gsd_smartcard_manager_signals[SMARTCARD_INSERTED], 0, card); manager->priv->is_unstoppable = FALSE; } static void gsd_smartcard_manager_emit_smartcard_removed (GsdSmartcardManager *manager, GsdSmartcard *card) { manager->priv->is_unstoppable = TRUE; g_signal_emit (manager, gsd_smartcard_manager_signals[SMARTCARD_REMOVED], 0, card); manager->priv->is_unstoppable = FALSE; } static gboolean gsd_smartcard_manager_check_for_and_process_events (GIOChannel *io_channel, GIOCondition condition, GsdSmartcardManagerWorker *worker) { GsdSmartcard *card; GsdSmartcardManager *manager; gboolean should_stop; guchar event_type; char *card_name; int fd; manager = worker->manager; g_debug ("event!"); card = NULL; should_stop = (condition & G_IO_HUP) || (condition & G_IO_ERR); if (should_stop) { g_debug ("received %s on event socket, stopping " "manager...", (condition & G_IO_HUP) && (condition & G_IO_ERR)? "error and hangup" : (condition & G_IO_HUP)? "hangup" : "error"); } if (!(condition & G_IO_IN)) { g_debug ("nevermind outta here!"); goto out; } fd = g_io_channel_unix_get_fd (io_channel); event_type = '\0'; if (!read_bytes (fd, &event_type, 1)) { g_debug ("could not read event type, stopping"); should_stop = TRUE; goto out; } card = read_smartcard (fd, worker->module); if (card == NULL) { g_debug ("could not read card, stopping"); should_stop = TRUE; goto out; } card_name = gsd_smartcard_get_name (card); g_debug ("card '%s' had event %c", card_name, event_type); switch (event_type) { case 'I': g_hash_table_replace (manager->priv->smartcards, card_name, card); card_name = NULL; gsd_smartcard_manager_emit_smartcard_inserted (manager, card); card = NULL; break; case 'R': gsd_smartcard_manager_emit_smartcard_removed (manager, card); if (!g_hash_table_remove (manager->priv->smartcards, card_name)) { g_debug ("got removal event of unknown card!"); } g_free (card_name); card_name = NULL; card = NULL; break; default: g_free (card_name); card_name = NULL; g_object_unref (card); should_stop = TRUE; break; } out: if (should_stop) { GError *error; error = g_error_new (GSD_SMARTCARD_MANAGER_ERROR, GSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, "%s", (condition & G_IO_IN) ? g_strerror (errno) : _("received error or hang up from event source")); gsd_smartcard_manager_emit_error (manager, error); g_error_free (error); gsd_smartcard_manager_stop_now (manager); return FALSE; } return TRUE; } static void stop_manager (GsdSmartcardManager *manager) { manager->priv->state = GSD_SMARTCARD_MANAGER_STATE_STOPPED; if (manager->priv->nss_is_loaded) { NSS_Shutdown (); manager->priv->nss_is_loaded = FALSE; } g_debug ("smartcard manager stopped"); } static void stop_worker (GsdSmartcardManagerWorker *worker) { GsdSmartcardManager *manager; manager = worker->manager; if (worker->event_source != NULL) { g_source_destroy (worker->event_source); worker->event_source = NULL; } if (worker->thread != NULL) { SECMOD_CancelWait (worker->module); worker->thread = NULL; } SECMOD_DestroyModule (worker->module); manager->priv->workers = g_list_remove (manager->priv->workers, worker); if (manager->priv->workers == NULL && manager->priv->state != GSD_SMARTCARD_MANAGER_STATE_STOPPED) { stop_manager (manager); } } static void gsd_smartcard_manager_event_processing_stopped_handler (GsdSmartcardManagerWorker *worker) { worker->event_source = NULL; stop_worker (worker); } static gboolean open_pipe (int *write_fd, int *read_fd) { int pipe_fds[2] = { -1, -1 }; g_assert (write_fd != NULL); g_assert (read_fd != NULL); if (pipe (pipe_fds) < 0) { return FALSE; } if (fcntl (pipe_fds[0], F_SETFD, FD_CLOEXEC) < 0) { close (pipe_fds[0]); close (pipe_fds[1]); return FALSE; } if (fcntl (pipe_fds[1], F_SETFD, FD_CLOEXEC) < 0) { close (pipe_fds[0]); close (pipe_fds[1]); return FALSE; } *read_fd = pipe_fds[0]; *write_fd = pipe_fds[1]; return TRUE; } static void gsd_smartcard_manager_stop_watching_for_events (GsdSmartcardManager *manager) { GList *node; node = manager->priv->workers; while (node != NULL) { GsdSmartcardManagerWorker *worker; GList *next_node; worker = (GsdSmartcardManagerWorker *) node->data; next_node = node->next; stop_worker (worker); node = next_node; } } static gboolean load_nss (GError **error) { SECStatus status = SECSuccess; static const guint32 flags = NSS_INIT_READONLY | NSS_INIT_FORCEOPEN | NSS_INIT_NOROOTINIT | NSS_INIT_OPTIMIZESPACE | NSS_INIT_PK11RELOAD; g_debug ("attempting to load NSS database '%s'", GSD_SMARTCARD_MANAGER_NSS_DB); PR_Init (PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); status = NSS_Initialize (GSD_SMARTCARD_MANAGER_NSS_DB, "", "", SECMOD_DB, flags); if (status != SECSuccess) { gsize error_message_size; char *error_message; error_message_size = PR_GetErrorTextLength (); if (error_message_size == 0) { g_debug ("NSS security system could not be initialized"); g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, GSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, _("NSS security system could not be initialized")); goto out; } error_message = g_slice_alloc0 (error_message_size); PR_GetErrorText (error_message); g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, GSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, "%s", error_message); g_debug ("NSS security system could not be initialized - %s", error_message); g_slice_free1 (error_message_size, error_message); goto out; } g_debug ("NSS database sucessfully loaded"); return TRUE; out: g_debug ("NSS database couldn't be sucessfully loaded"); return FALSE; } static GList * get_available_modules (GsdSmartcardManager *manager) { SECMODModuleList *module_list, *tmp; GList *modules; g_debug ("Getting list of suitable modules"); module_list = SECMOD_GetDefaultModuleList (); modules = NULL; for (tmp = module_list; tmp != NULL; tmp = tmp->next) { if (!SECMOD_HasRemovableSlots (tmp->module) || !tmp->module->loaded) continue; g_debug ("Using module '%s'", tmp->module->commonName); modules = g_list_prepend (modules, SECMOD_ReferenceModule (tmp->module)); } return modules; } static gboolean load_driver (GsdSmartcardManager *manager, char *module_path, GError **error) { GList *modules; char *module_spec; gboolean module_explicitly_specified; g_debug ("attempting to load driver..."); modules = NULL; module_explicitly_specified = module_path != NULL; if (module_explicitly_specified) { SECMODModule *module; module_spec = g_strdup_printf ("library=\"%s\"", module_path); g_debug ("loading smartcard driver using spec '%s'", module_spec); module = SECMOD_LoadUserModule (module_spec, NULL /* parent */, FALSE /* recurse */); g_free (module_spec); module_spec = NULL; if (SECMOD_HasRemovableSlots (module) && module->loaded) { modules = g_list_prepend (modules, module); } else { g_debug ("fallback module found but not %s", SECMOD_HasRemovableSlots (module)? "removable" : "loaded"); SECMOD_DestroyModule (module); } } else { SECMODListLock *lock; lock = SECMOD_GetDefaultModuleListLock (); if (lock != NULL) { SECMOD_GetReadLock (lock); modules = get_available_modules (manager); SECMOD_ReleaseReadLock (lock); } /* fallback to compiled in driver path */ if (modules == NULL) { SECMODModule *module; module_path = GSD_SMARTCARD_MANAGER_DRIVER; module_spec = g_strdup_printf ("library=\"%s\"", module_path); g_debug ("loading smartcard driver using spec '%s'", module_spec); module = SECMOD_LoadUserModule (module_spec, NULL /* parent */, FALSE /* recurse */); g_free (module_spec); module_spec = NULL; if (SECMOD_HasRemovableSlots (module) && module->loaded) { modules = g_list_prepend (modules, module); } else { g_debug ("fallback module found but not loaded"); SECMOD_DestroyModule (module); } } } if (!module_explicitly_specified && modules == NULL) { g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, GSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, _("no suitable smartcard driver could be found")); } else if (modules == NULL) { gsize error_message_size; char *error_message; error_message_size = PR_GetErrorTextLength (); if (error_message_size == 0) { g_debug ("smartcard driver '%s' could not be loaded", module_path); g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, GSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, _("smartcard driver '%s' could not be " "loaded"), module_path); goto out; } error_message = g_slice_alloc0 (error_message_size); PR_GetErrorText (error_message); g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, GSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, "%s", error_message); g_debug ("smartcard driver '%s' could not be loaded - %s", module_path, error_message); g_slice_free1 (error_message_size, error_message); } manager->priv->modules = modules; out: return manager->priv->modules != NULL; } static void gsd_smartcard_manager_get_all_cards (GsdSmartcardManager *manager) { GList *node; int i; node = manager->priv->workers; while (node != NULL) { GsdSmartcardManagerWorker *worker; worker = (GsdSmartcardManagerWorker *) node->data; for (i = 0; i < worker->module->slotCount; i++) { GsdSmartcard *card; CK_SLOT_ID slot_id; int slot_series; char *card_name; slot_id = PK11_GetSlotID (worker->module->slots[i]); slot_series = PK11_GetSlotSeries (worker->module->slots[i]); card = _gsd_smartcard_new (worker->module, slot_id, slot_series); card_name = gsd_smartcard_get_name (card); g_hash_table_replace (manager->priv->smartcards, card_name, card); } node = node->next; } } static GsdSmartcardManagerWorker * start_worker (GsdSmartcardManager *manager, SECMODModule *module, GError **error) { GIOChannel *io_channel; GSource *source; GsdSmartcardManagerWorker *worker; worker = gsd_smartcard_manager_create_worker (manager, module); if (worker == NULL) { g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, GSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, _("could not watch for incoming card events - %s"), g_strerror (errno)); goto out; } io_channel = g_io_channel_unix_new (worker->manager_fd); source = g_io_create_watch (io_channel, G_IO_IN | G_IO_HUP); g_io_channel_unref (io_channel); io_channel = NULL; worker->event_source = source; g_source_set_callback (worker->event_source, (GSourceFunc) (GIOFunc) gsd_smartcard_manager_check_for_and_process_events, worker, (GDestroyNotify) gsd_smartcard_manager_event_processing_stopped_handler); g_source_attach (worker->event_source, NULL); g_source_unref (worker->event_source); out: return worker; } static void start_workers (GsdSmartcardManager *manager) { GList *node; node = manager->priv->modules; while (node != NULL) { SECMODModule *module; GsdSmartcardManagerWorker *worker; GError *error; module = (SECMODModule *) node->data; error = NULL; worker = start_worker (manager, module, &error); if (worker == NULL) { g_warning ("%s", error->message); g_error_free (error); } else { manager->priv->workers = g_list_prepend (manager->priv->workers, worker); } node = node->next; } } gboolean gsd_smartcard_manager_start (GsdSmartcardManager *manager, GError **error) { GError *nss_error; if (manager->priv->state == GSD_SMARTCARD_MANAGER_STATE_STARTED) { g_debug ("smartcard manager already started"); return TRUE; } manager->priv->state = GSD_SMARTCARD_MANAGER_STATE_STARTING; nss_error = NULL; if (!manager->priv->nss_is_loaded && !load_nss (&nss_error)) { g_propagate_error (error, nss_error); goto out; } manager->priv->nss_is_loaded = TRUE; if (manager->priv->modules == NULL) { if (!load_driver (manager, manager->priv->module_path, &nss_error)) { g_propagate_error (error, nss_error); goto out; } } start_workers (manager); /* populate the hash with cards that are already inserted */ gsd_smartcard_manager_get_all_cards (manager); manager->priv->state = GSD_SMARTCARD_MANAGER_STATE_STARTED; out: /* don't leave it in a half started state */ if (manager->priv->state != GSD_SMARTCARD_MANAGER_STATE_STARTED) { g_debug ("smartcard manager could not be completely started"); gsd_smartcard_manager_stop (manager); } else { g_debug ("smartcard manager started"); } return manager->priv->state == GSD_SMARTCARD_MANAGER_STATE_STARTED; } static gboolean gsd_smartcard_manager_stop_now (GsdSmartcardManager *manager) { if (manager->priv->state == GSD_SMARTCARD_MANAGER_STATE_STOPPED) { return FALSE; } gsd_smartcard_manager_stop_watching_for_events (manager); return FALSE; } static void gsd_smartcard_manager_queue_stop (GsdSmartcardManager *manager) { manager->priv->state = GSD_SMARTCARD_MANAGER_STATE_STOPPING; g_idle_add ((GSourceFunc) gsd_smartcard_manager_stop_now, manager); } void gsd_smartcard_manager_stop (GsdSmartcardManager *manager) { if (manager->priv->state == GSD_SMARTCARD_MANAGER_STATE_STOPPED) { return; } if (manager->priv->is_unstoppable) { gsd_smartcard_manager_queue_stop (manager); return; } gsd_smartcard_manager_stop_now (manager); } static void gsd_smartcard_manager_check_for_login_card (CK_SLOT_ID slot_id, GsdSmartcard *card, gboolean *is_inserted) { g_assert (is_inserted != NULL); if (gsd_smartcard_is_login_card (card)) { *is_inserted = TRUE; } } gboolean gsd_smartcard_manager_login_card_is_inserted (GsdSmartcardManager *manager) { gboolean is_inserted; is_inserted = FALSE; g_hash_table_foreach (manager->priv->smartcards, (GHFunc) gsd_smartcard_manager_check_for_login_card, &is_inserted); return is_inserted; } static GsdSmartcardManagerWorker * gsd_smartcard_manager_worker_new (GsdSmartcardManager *manager, int worker_fd, int manager_fd, SECMODModule *module) { GsdSmartcardManagerWorker *worker; worker = g_slice_new0 (GsdSmartcardManagerWorker); worker->manager = manager; worker->fd = worker_fd; worker->manager_fd = manager_fd; worker->module = module; worker->smartcards = g_hash_table_new_full ((GHashFunc) slot_id_hash, (GEqualFunc) slot_id_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref); return worker; } static void gsd_smartcard_manager_worker_free (GsdSmartcardManagerWorker *worker) { if (worker->smartcards != NULL) { g_hash_table_destroy (worker->smartcards); worker->smartcards = NULL; } g_slice_free (GsdSmartcardManagerWorker, worker); } static gboolean read_bytes (int fd, gpointer bytes, gsize num_bytes) { size_t bytes_left; size_t total_bytes_read; ssize_t bytes_read; bytes_left = (size_t) num_bytes; total_bytes_read = 0; do { bytes_read = read (fd, (char *) bytes + total_bytes_read, bytes_left); g_assert (bytes_read <= (ssize_t) bytes_left); if (bytes_read <= 0) { if ((bytes_read < 0) && (errno == EINTR || errno == EAGAIN)) { continue; } bytes_left = 0; } else { bytes_left -= bytes_read; total_bytes_read += bytes_read; } } while (bytes_left > 0); if (total_bytes_read < (size_t) num_bytes) { return FALSE; } return TRUE; } static gboolean write_bytes (int fd, gconstpointer bytes, gsize num_bytes) { size_t bytes_left; size_t total_bytes_written; ssize_t bytes_written; bytes_left = (size_t) num_bytes; total_bytes_written = 0; do { bytes_written = write (fd, (char *) bytes + total_bytes_written, bytes_left); g_assert (bytes_written <= (ssize_t) bytes_left); if (bytes_written <= 0) { if ((bytes_written < 0) && (errno == EINTR || errno == EAGAIN)) { continue; } bytes_left = 0; } else { bytes_left -= bytes_written; total_bytes_written += bytes_written; } } while (bytes_left > 0); if (total_bytes_written < (size_t) num_bytes) { return FALSE; } return TRUE; } static GsdSmartcard * read_smartcard (int fd, SECMODModule *module) { GsdSmartcard *card; char *card_name; gsize card_name_size; card_name_size = 0; if (!read_bytes (fd, &card_name_size, sizeof (card_name_size))) { return NULL; } card_name = g_slice_alloc0 (card_name_size); if (!read_bytes (fd, card_name, card_name_size)) { g_slice_free1 (card_name_size, card_name); return NULL; } card = _gsd_smartcard_new_from_name (module, card_name); g_slice_free1 (card_name_size, card_name); return card; } static gboolean write_smartcard (int fd, GsdSmartcard *card) { gsize card_name_size; char *card_name; card_name = gsd_smartcard_get_name (card); card_name_size = strlen (card_name) + 1; if (!write_bytes (fd, &card_name_size, sizeof (card_name_size))) { g_free (card_name); return FALSE; } if (!write_bytes (fd, card_name, card_name_size)) { g_free (card_name); return FALSE; } g_free (card_name); return TRUE; } static gboolean gsd_smartcard_manager_worker_emit_smartcard_removed (GsdSmartcardManagerWorker *worker, GsdSmartcard *card, GError **error) { g_debug ("card '%s' removed!", gsd_smartcard_get_name (card)); if (!write_bytes (worker->fd, "R", 1)) { goto error_out; } if (!write_smartcard (worker->fd, card)) { goto error_out; } return TRUE; error_out: g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, GSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS, "%s", g_strerror (errno)); return FALSE; } static gboolean gsd_smartcard_manager_worker_emit_smartcard_inserted (GsdSmartcardManagerWorker *worker, GsdSmartcard *card, GError **error) { g_debug ("card '%s' inserted!", gsd_smartcard_get_name (card)); if (!write_bytes (worker->fd, "I", 1)) { goto error_out; } if (!write_smartcard (worker->fd, card)) { goto error_out; } return TRUE; error_out: g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, GSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS, "%s", g_strerror (errno)); return FALSE; } static gboolean gsd_smartcard_manager_worker_watch_for_and_process_event (GsdSmartcardManagerWorker *worker, GError **error) { PK11SlotInfo *slot; CK_SLOT_ID slot_id, *key = NULL; int slot_series, card_slot_series; GsdSmartcard *card; GError *processing_error; gboolean ret; g_debug ("waiting for card event"); ret = FALSE; slot = SECMOD_WaitForAnyTokenEvent (worker->module, 0, PR_SecondsToInterval (1)); processing_error = NULL; if (slot == NULL) { int error_code; error_code = PORT_GetError (); if ((error_code == 0) || (error_code == SEC_ERROR_NO_EVENT)) { g_debug ("spurrious event occurred"); return TRUE; } /* FIXME: is there a function to convert from a PORT error * code to a translated string? */ g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, GSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, _("encountered unexpected error while " "waiting for smartcard events")); goto out; } /* the slot id and series together uniquely identify a card. * You can never have two cards with the same slot id at the * same time, however (I think), so we can key off of it. */ slot_id = PK11_GetSlotID (slot); slot_series = PK11_GetSlotSeries (slot); /* First check to see if there is a card that we're currently * tracking in the slot. */ key = g_new (CK_SLOT_ID, 1); *key = slot_id; card = g_hash_table_lookup (worker->smartcards, key); if (card != NULL) { card_slot_series = gsd_smartcard_get_slot_series (card); } else { card_slot_series = -1; } if (PK11_IsPresent (slot)) { /* Now, check to see if their is a new card in the slot. * If there was a different card in the slot now than * there was before, then we need to emit a removed signal * for the old card (we don't want unpaired insertion events). */ if ((card != NULL) && card_slot_series != slot_series) { if (!gsd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { g_propagate_error (error, processing_error); goto out; } } card = _gsd_smartcard_new (worker->module, slot_id, slot_series); g_hash_table_replace (worker->smartcards, key, card); key = NULL; if (!gsd_smartcard_manager_worker_emit_smartcard_inserted (worker, card, &processing_error)) { g_propagate_error (error, processing_error); goto out; } } else { /* if we aren't tracking the card, just discard the event. * We don't want unpaired remove events. Note on startup * NSS will generate an "insertion" event if a card is * already inserted in the slot. */ if ((card != NULL)) { /* FIXME: i'm not sure about this code. Maybe we * shouldn't do this at all, or maybe we should do it * n times (where n = slot_series - card_slot_series + 1) * * Right now, i'm just doing it once. */ if ((slot_series - card_slot_series) > 1) { if (!gsd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { g_propagate_error (error, processing_error); goto out; } g_hash_table_remove (worker->smartcards, key); card = _gsd_smartcard_new (worker->module, slot_id, slot_series); g_hash_table_replace (worker->smartcards, key, card); key = NULL; if (!gsd_smartcard_manager_worker_emit_smartcard_inserted (worker, card, &processing_error)) { g_propagate_error (error, processing_error); goto out; } } if (!gsd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { g_propagate_error (error, processing_error); goto out; } g_hash_table_remove (worker->smartcards, key); card = NULL; } else { g_debug ("got spurious remove event"); } } ret = TRUE; out: g_free (key); PK11_FreeSlot (slot); return ret; } static void gsd_smartcard_manager_worker_run (GsdSmartcardManagerWorker *worker) { GError *error; gboolean should_continue; do { error = NULL; should_continue = gsd_smartcard_manager_worker_watch_for_and_process_event (worker, &error); } while (should_continue); if (error != NULL) { g_debug ("could not process card event - %s", error->message); g_error_free (error); } gsd_smartcard_manager_worker_free (worker); } static GsdSmartcardManagerWorker * gsd_smartcard_manager_create_worker (GsdSmartcardManager *manager, SECMODModule *module) { GsdSmartcardManagerWorker *worker; int write_fd, read_fd; write_fd = -1; read_fd = -1; if (!open_pipe (&write_fd, &read_fd)) { return NULL; } worker = gsd_smartcard_manager_worker_new (manager, write_fd, read_fd, module); worker->thread = g_thread_create ((GThreadFunc) gsd_smartcard_manager_worker_run, worker, FALSE, NULL); if (worker->thread == NULL) { gsd_smartcard_manager_worker_free (worker); return NULL; } return worker; } #ifdef GSD_SMARTCARD_MANAGER_ENABLE_TEST #include static GMainLoop *event_loop; static gboolean should_exit_on_next_remove = FALSE; static gboolean on_timeout (GsdSmartcardManager *manager) { GError *error; g_print ("Re-enabling manager.\n"); if (!gsd_smartcard_manager_start (manager, &error)) { g_warning ("could not start smartcard manager - %s", error->message); g_error_free (error); return TRUE; } g_print ("Please re-insert smartcard\n"); should_exit_on_next_remove = TRUE; return FALSE; } static void on_device_inserted (GsdSmartcardManager *manager, GsdSmartcard *card) { g_print ("smartcard inserted!\n"); g_print ("Please remove it.\n"); } static void on_device_removed (GsdSmartcardManager *manager, GsdSmartcard *card) { g_print ("smartcard removed!\n"); if (should_exit_on_next_remove) { g_main_loop_quit (event_loop); } else { g_print ("disabling manager for 2 seconds\n"); gsd_smartcard_manager_stop (manager); g_timeout_add_seconds (2, (GSourceFunc) on_timeout, manager); } } int main (int argc, char *argv[]) { GsdSmartcardManager *manager; GError *error; g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); g_message ("creating instance of 'smartcard manager' object..."); manager = gsd_smartcard_manager_new (NULL); g_message ("'smartcard manager' object created successfully"); g_signal_connect (manager, "smartcard-inserted", G_CALLBACK (on_device_inserted), NULL); g_signal_connect (manager, "smartcard-removed", G_CALLBACK (on_device_removed), NULL); g_message ("starting listener..."); error = NULL; if (!gsd_smartcard_manager_start (manager, &error)) { g_warning ("could not start smartcard manager - %s", error->message); g_error_free (error); return 1; } event_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (event_loop); g_main_loop_unref (event_loop); event_loop = NULL; g_message ("destroying previously created 'smartcard manager' object..."); g_object_unref (manager); manager = NULL; g_message ("'smartcard manager' object destroyed successfully"); return 0; } #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/smartcard/gsd-smartcard-manager.h0000664000175000017500000000716000000000000027017 0ustar00jeremyjeremy/* gsd-smartcard-manager.h - object for monitoring smartcard insertion and * removal events * * Copyright (C) 2006, 2009 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: Ray Strode */ #ifndef GSD_SMARTCARD_MANAGER_H #define GSD_SMARTCARD_MANAGER_H #define GSD_SMARTCARD_ENABLE_INTERNAL_API #include "gsd-smartcard.h" #include #include G_BEGIN_DECLS #define GSD_TYPE_SMARTCARD_MANAGER (gsd_smartcard_manager_get_type ()) #define GSD_SMARTCARD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_SMARTCARD_MANAGER, GsdSmartcardManager)) #define GSD_SMARTCARD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_SMARTCARD_MANAGER, GsdSmartcardManagerClass)) #define GSD_IS_SMARTCARD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SC_TYPE_SMARTCARD_MANAGER)) #define GSD_IS_SMARTCARD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SC_TYPE_SMARTCARD_MANAGER)) #define GSD_SMARTCARD_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GSD_TYPE_SMARTCARD_MANAGER, GsdSmartcardManagerClass)) #define GSD_SMARTCARD_MANAGER_ERROR (gsd_smartcard_manager_error_quark ()) typedef struct _GsdSmartcardManager GsdSmartcardManager; typedef struct _GsdSmartcardManagerClass GsdSmartcardManagerClass; typedef struct _GsdSmartcardManagerPrivate GsdSmartcardManagerPrivate; typedef enum _GsdSmartcardManagerError GsdSmartcardManagerError; struct _GsdSmartcardManager { GObject parent; /*< private > */ GsdSmartcardManagerPrivate *priv; }; struct _GsdSmartcardManagerClass { GObjectClass parent_class; /* Signals */ void (*smartcard_inserted) (GsdSmartcardManager *manager, GsdSmartcard *token); void (*smartcard_removed) (GsdSmartcardManager *manager, GsdSmartcard *token); void (*error) (GsdSmartcardManager *manager, GError *error); }; enum _GsdSmartcardManagerError { GSD_SMARTCARD_MANAGER_ERROR_GENERIC = 0, GSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, GSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, GSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, GSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS }; GType gsd_smartcard_manager_get_type (void) G_GNUC_CONST; GQuark gsd_smartcard_manager_error_quark (void) G_GNUC_CONST; GsdSmartcardManager *gsd_smartcard_manager_new_default (void); GsdSmartcardManager *gsd_smartcard_manager_new (const char *module); gboolean gsd_smartcard_manager_start (GsdSmartcardManager *manager, GError **error); void gsd_smartcard_manager_stop (GsdSmartcardManager *manager); char *gsd_smartcard_manager_get_module_path (GsdSmartcardManager *manager); gboolean gsd_smartcard_manager_login_card_is_inserted (GsdSmartcardManager *manager); G_END_DECLS #endif /* GSD_SMARTCARD_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/smartcard/gsd-smartcard-plugin.c0000664000175000017500000002405200000000000026675 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2010 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include "gnome-settings-plugin.h" #include "gnome-settings-bus.h" #include "gsd-smartcard-plugin.h" #include "gsd-smartcard-manager.h" struct GsdSmartcardPluginPrivate { GsdSmartcardManager *manager; guint32 is_active : 1; }; typedef enum { GSD_SMARTCARD_REMOVE_ACTION_NONE, GSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN, GSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT, } GsdSmartcardRemoveAction; #define SM_LOGOUT_MODE_FORCE 2 #define KEY_REMOVE_ACTION "removal-action" #define GSD_SMARTCARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_SMARTCARD_PLUGIN, GsdSmartcardPluginPrivate)) GNOME_SETTINGS_PLUGIN_REGISTER (GsdSmartcardPlugin, gsd_smartcard_plugin); static void simulate_user_activity (GsdSmartcardPlugin *plugin) { GsdScreenSaver *screensaver_proxy; GDBusProxy *screensaver_proxy; g_debug ("GsdSmartcardPlugin telling screensaver about smart card insertion"); screensaver_proxy = gnome_settings_bus_get_screen_saver_proxy (); gsd_screen_saver_call_simulate_user_activity_sync (screensaver_proxy, NULL, NULL); g_object_unref (screensaver_proxy); } static void lock_screen (GsdSmartcardPlugin *plugin) { GDBusProxy *screensaver_proxy; g_debug ("GsdSmartcardPlugin telling screensaver to lock screen"); screensaver_proxy = gnome_settings_bus_get_screen_saver_proxy (); gsd_screen_saver_call_lock_sync (screensaver_proxy, NULL, NULL); g_object_unref (screensaver_proxy); } static void force_logout (GsdSmartcardPlugin *plugin) { GDBusProxy *sm_proxy; GError *error; GVariant *res; g_debug ("GsdSmartcardPlugin telling session manager to force logout"); sm_proxy = gnome_settings_bus_get_session_proxy (); error = NULL; res = g_dbus_proxy_call_sync (sm_proxy, "Logout", g_variant_new ("(i)", SM_LOGOUT_MODE_FORCE), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (! res) { g_warning ("GsdSmartcardPlugin Unable to force logout: %s", error->message); g_error_free (error); } else g_variant_unref (res); g_object_unref (sm_proxy); } static void gsd_smartcard_plugin_init (GsdSmartcardPlugin *plugin) { plugin->priv = GSD_SMARTCARD_PLUGIN_GET_PRIVATE (plugin); g_debug ("GsdSmartcardPlugin initializing"); plugin->priv->manager = gsd_smartcard_manager_new (NULL); } static void gsd_smartcard_plugin_finalize (GObject *object) { GsdSmartcardPlugin *plugin; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_SMARTCARD_PLUGIN (object)); g_debug ("GsdSmartcardPlugin finalizing"); plugin = GSD_SMARTCARD_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); if (plugin->priv->manager != NULL) { g_object_unref (plugin->priv->manager); } G_OBJECT_CLASS (gsd_smartcard_plugin_parent_class)->finalize (object); } static void smartcard_inserted_cb (GsdSmartcardManager *card_monitor, GsdSmartcard *card, GsdSmartcardPlugin *plugin) { char *name; name = gsd_smartcard_get_name (card); g_debug ("GsdSmartcardPlugin smart card '%s' inserted", name); g_free (name); simulate_user_activity (plugin); } static gboolean user_logged_in_with_smartcard (void) { return g_getenv ("PKCS11_LOGIN_TOKEN_NAME") != NULL; } static GsdSmartcardRemoveAction get_configured_remove_action (GsdSmartcardPlugin *plugin) { GSettings *settings; char *remove_action_string; GsdSmartcardRemoveAction remove_action; settings = g_settings_new ("com.canonical.unity.settings-daemon.peripherals.smartcard"); remove_action_string = g_settings_get_string (settings, KEY_REMOVE_ACTION); if (remove_action_string == NULL) { g_warning ("GsdSmartcardPlugin unable to get smartcard remove action"); remove_action = GSD_SMARTCARD_REMOVE_ACTION_NONE; } else if (strcmp (remove_action_string, "none") == 0) { remove_action = GSD_SMARTCARD_REMOVE_ACTION_NONE; } else if (strcmp (remove_action_string, "lock_screen") == 0) { remove_action = GSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN; } else if (strcmp (remove_action_string, "force_logout") == 0) { remove_action = GSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT; } else { g_warning ("GsdSmartcardPlugin unknown smartcard remove action"); remove_action = GSD_SMARTCARD_REMOVE_ACTION_NONE; } g_object_unref (settings); return remove_action; } static void process_smartcard_removal (GsdSmartcardPlugin *plugin) { GsdSmartcardRemoveAction remove_action; g_debug ("GsdSmartcardPlugin processing smartcard removal"); remove_action = get_configured_remove_action (plugin); switch (remove_action) { case GSD_SMARTCARD_REMOVE_ACTION_NONE: return; case GSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN: lock_screen (plugin); break; case GSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT: force_logout (plugin); break; } } static void smartcard_removed_cb (GsdSmartcardManager *card_monitor, GsdSmartcard *card, GsdSmartcardPlugin *plugin) { char *name; name = gsd_smartcard_get_name (card); g_debug ("GsdSmartcardPlugin smart card '%s' removed", name); g_free (name); if (!gsd_smartcard_is_login_card (card)) { g_debug ("GsdSmartcardPlugin removed smart card was not used to login"); return; } process_smartcard_removal (plugin); } static void impl_activate (GnomeSettingsPlugin *plugin) { GError *error; GsdSmartcardPlugin *smartcard_plugin = GSD_SMARTCARD_PLUGIN (plugin); if (smartcard_plugin->priv->is_active) { g_debug ("GsdSmartcardPlugin Not activating smartcard plugin, because it's " "already active"); return; } if (!user_logged_in_with_smartcard ()) { g_debug ("GsdSmartcardPlugin Not activating smartcard plugin, because user didn't use " " smartcard to log in"); smartcard_plugin->priv->is_active = FALSE; return; } g_debug ("GsdSmartcardPlugin Activating smartcard plugin"); error = NULL; if (!gsd_smartcard_manager_start (smartcard_plugin->priv->manager, &error)) { g_warning ("GsdSmartcardPlugin Unable to start smartcard manager: %s", error->message); g_error_free (error); } g_signal_connect (smartcard_plugin->priv->manager, "smartcard-removed", G_CALLBACK (smartcard_removed_cb), smartcard_plugin); g_signal_connect (smartcard_plugin->priv->manager, "smartcard-inserted", G_CALLBACK (smartcard_inserted_cb), smartcard_plugin); if (!gsd_smartcard_manager_login_card_is_inserted (smartcard_plugin->priv->manager)) { g_debug ("GsdSmartcardPlugin processing smartcard removal immediately user logged in with smartcard " "and it's not inserted"); process_smartcard_removal (smartcard_plugin); } smartcard_plugin->priv->is_active = TRUE; } static void impl_deactivate (GnomeSettingsPlugin *plugin) { GsdSmartcardPlugin *smartcard_plugin = GSD_SMARTCARD_PLUGIN (plugin); if (!smartcard_plugin->priv->is_active) { g_debug ("GsdSmartcardPlugin Not deactivating smartcard plugin, " "because it's already inactive"); return; } g_debug ("GsdSmartcardPlugin Deactivating smartcard plugin"); gsd_smartcard_manager_stop (smartcard_plugin->priv->manager); g_signal_handlers_disconnect_by_func (smartcard_plugin->priv->manager, smartcard_removed_cb, smartcard_plugin); g_signal_handlers_disconnect_by_func (smartcard_plugin->priv->manager, smartcard_inserted_cb, smartcard_plugin); smartcard_plugin->priv->is_active = FALSE; } static void gsd_smartcard_plugin_class_init (GsdSmartcardPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GnomeSettingsPluginClass *plugin_class = GNOME_SETTINGS_PLUGIN_CLASS (klass); object_class->finalize = gsd_smartcard_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; g_type_class_add_private (klass, sizeof (GsdSmartcardPluginPrivate)); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/smartcard/gsd-smartcard-plugin.h0000664000175000017500000000426700000000000026710 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2010 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_SMARTCARD_PLUGIN_H__ #define __GSD_SMARTCARD_PLUGIN_H__ #include #include #include #include "gnome-settings-plugin.h" G_BEGIN_DECLS #define GSD_TYPE_SMARTCARD_PLUGIN (gsd_smartcard_plugin_get_type ()) #define GSD_SMARTCARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_SMARTCARD_PLUGIN, GsdSmartcardPlugin)) #define GSD_SMARTCARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GSD_TYPE_SMARTCARD_PLUGIN, GsdSmartcardPluginClass)) #define GSD_IS_SMARTCARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_SMARTCARD_PLUGIN)) #define GSD_IS_SMARTCARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_SMARTCARD_PLUGIN)) #define GSD_SMARTCARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_SMARTCARD_PLUGIN, GsdSmartcardPluginClass)) typedef struct GsdSmartcardPluginPrivate GsdSmartcardPluginPrivate; typedef struct { GnomeSettingsPlugin parent; GsdSmartcardPluginPrivate *priv; } GsdSmartcardPlugin; typedef struct { GnomeSettingsPluginClass parent_class; } GsdSmartcardPluginClass; GType gsd_smartcard_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_gnome_settings_plugin (GTypeModule *module); G_END_DECLS #endif /* __GSD_SMARTCARD_PLUGIN_H__ */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/smartcard/gsd-smartcard.c0000664000175000017500000004424100000000000025403 0ustar00jeremyjeremy/* gsd-smartcard.c - smartcard object * * Copyright (C) 2006 Ray Strode * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #include "config.h" #define GSD_SMARTCARD_ENABLE_INTERNAL_API #include "gsd-smartcard.h" #include #include #include #include #include #include #include #include #include #include #include struct _GsdSmartcardPrivate { SECMODModule *module; GsdSmartcardState state; CK_SLOT_ID slot_id; int slot_series; PK11SlotInfo *slot; char *name; CERTCertificate *signing_certificate; CERTCertificate *encryption_certificate; }; static void gsd_smartcard_finalize (GObject *object); static void gsd_smartcard_class_install_signals (GsdSmartcardClass *card_class); static void gsd_smartcard_class_install_properties (GsdSmartcardClass *card_class); static void gsd_smartcard_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); static void gsd_smartcard_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); static void gsd_smartcard_set_name (GsdSmartcard *card, const char *name); static void gsd_smartcard_set_slot_id (GsdSmartcard *card, int slot_id); static void gsd_smartcard_set_slot_series (GsdSmartcard *card, int slot_series); static void gsd_smartcard_set_module (GsdSmartcard *card, SECMODModule *module); static PK11SlotInfo *gsd_smartcard_find_slot_from_id (GsdSmartcard *card, int slot_id); static PK11SlotInfo *gsd_smartcard_find_slot_from_card_name (GsdSmartcard *card, const char *card_name); #ifndef GSD_SMARTCARD_DEFAULT_SLOT_ID #define GSD_SMARTCARD_DEFAULT_SLOT_ID ((gulong) -1) #endif #ifndef GSD_SMARTCARD_DEFAULT_SLOT_SERIES #define GSD_SMARTCARD_DEFAULT_SLOT_SERIES -1 #endif enum { PROP_0 = 0, PROP_NAME, PROP_SLOT_ID, PROP_SLOT_SERIES, PROP_MODULE, NUMBER_OF_PROPERTIES }; enum { INSERTED, REMOVED, NUMBER_OF_SIGNALS }; static guint gsd_smartcard_signals[NUMBER_OF_SIGNALS]; G_DEFINE_TYPE (GsdSmartcard, gsd_smartcard, G_TYPE_OBJECT); static void gsd_smartcard_class_init (GsdSmartcardClass *card_class) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (card_class); gobject_class->finalize = gsd_smartcard_finalize; gsd_smartcard_class_install_signals (card_class); gsd_smartcard_class_install_properties (card_class); g_type_class_add_private (card_class, sizeof (GsdSmartcardPrivate)); } static void gsd_smartcard_class_install_signals (GsdSmartcardClass *card_class) { GObjectClass *object_class; object_class = G_OBJECT_CLASS (card_class); gsd_smartcard_signals[INSERTED] = g_signal_new ("inserted", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GsdSmartcardClass, inserted), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); gsd_smartcard_signals[REMOVED] = g_signal_new ("removed", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GsdSmartcardClass, removed), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } static void gsd_smartcard_class_install_properties (GsdSmartcardClass *card_class) { GObjectClass *object_class; GParamSpec *param_spec; object_class = G_OBJECT_CLASS (card_class); object_class->set_property = gsd_smartcard_set_property; object_class->get_property = gsd_smartcard_get_property; param_spec = g_param_spec_ulong ("slot-id", "Slot ID", "The slot the card is in", 1, G_MAXULONG, GSD_SMARTCARD_DEFAULT_SLOT_ID, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_SLOT_ID, param_spec); param_spec = g_param_spec_int ("slot-series", "Slot Series", "per-slot card identifier", -1, G_MAXINT, GSD_SMARTCARD_DEFAULT_SLOT_SERIES, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_SLOT_SERIES, param_spec); param_spec = g_param_spec_string ("name", "name", "name", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_NAME, param_spec); param_spec = g_param_spec_pointer ("module", "Module", "smartcard driver", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_MODULE, param_spec); } static void gsd_smartcard_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GsdSmartcard *card = GSD_SMARTCARD (object); switch (prop_id) { case PROP_NAME: gsd_smartcard_set_name (card, g_value_get_string (value)); break; case PROP_SLOT_ID: gsd_smartcard_set_slot_id (card, g_value_get_ulong (value)); break; case PROP_SLOT_SERIES: gsd_smartcard_set_slot_series (card, g_value_get_int (value)); break; case PROP_MODULE: gsd_smartcard_set_module (card, (SECMODModule *) g_value_get_pointer (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } CK_SLOT_ID gsd_smartcard_get_slot_id (GsdSmartcard *card) { return card->priv->slot_id; } GsdSmartcardState gsd_smartcard_get_state (GsdSmartcard *card) { return card->priv->state; } char * gsd_smartcard_get_name (GsdSmartcard *card) { return g_strdup (card->priv->name); } gboolean gsd_smartcard_is_login_card (GsdSmartcard *card) { const char *login_card_name; login_card_name = g_getenv ("PKCS11_LOGIN_TOKEN_NAME"); if ((login_card_name == NULL) || (card->priv->name == NULL)) { return FALSE; } if (strcmp (card->priv->name, login_card_name) == 0) { return TRUE; } return FALSE; } static void gsd_smartcard_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GsdSmartcard *card = GSD_SMARTCARD (object); switch (prop_id) { case PROP_NAME: g_value_take_string (value, gsd_smartcard_get_name (card)); break; case PROP_SLOT_ID: g_value_set_ulong (value, (gulong) gsd_smartcard_get_slot_id (card)); break; case PROP_SLOT_SERIES: g_value_set_int (value, gsd_smartcard_get_slot_series (card)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void gsd_smartcard_set_name (GsdSmartcard *card, const char *name) { if (name == NULL) { return; } if ((card->priv->name == NULL) || (strcmp (card->priv->name, name) != 0)) { g_free (card->priv->name); card->priv->name = g_strdup (name); if (card->priv->slot == NULL) { card->priv->slot = gsd_smartcard_find_slot_from_card_name (card, card->priv->name); if (card->priv->slot != NULL) { int slot_id, slot_series; slot_id = PK11_GetSlotID (card->priv->slot); if (slot_id != card->priv->slot_id) { gsd_smartcard_set_slot_id (card, slot_id); } slot_series = PK11_GetSlotSeries (card->priv->slot); if (slot_series != card->priv->slot_series) { gsd_smartcard_set_slot_series (card, slot_series); } _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_INSERTED); } else { _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_REMOVED); } } g_object_notify (G_OBJECT (card), "name"); } } static void gsd_smartcard_set_slot_id (GsdSmartcard *card, int slot_id) { if (card->priv->slot_id != slot_id) { card->priv->slot_id = slot_id; if (card->priv->slot == NULL) { card->priv->slot = gsd_smartcard_find_slot_from_id (card, card->priv->slot_id); if (card->priv->slot != NULL) { const char *card_name; card_name = PK11_GetTokenName (card->priv->slot); if ((card->priv->name == NULL) || ((card_name != NULL) && (strcmp (card_name, card->priv->name) != 0))) { gsd_smartcard_set_name (card, card_name); } _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_INSERTED); } else { _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_REMOVED); } } g_object_notify (G_OBJECT (card), "slot-id"); } } static void gsd_smartcard_set_slot_series (GsdSmartcard *card, int slot_series) { if (card->priv->slot_series != slot_series) { card->priv->slot_series = slot_series; g_object_notify (G_OBJECT (card), "slot-series"); } } static void gsd_smartcard_set_module (GsdSmartcard *card, SECMODModule *module) { gboolean should_notify; if (card->priv->module != module) { should_notify = TRUE; } else { should_notify = FALSE; } if (card->priv->module != NULL) { SECMOD_DestroyModule (card->priv->module); card->priv->module = NULL; } if (module != NULL) { card->priv->module = SECMOD_ReferenceModule (module); } if (should_notify) { g_object_notify (G_OBJECT (card), "module"); } } int gsd_smartcard_get_slot_series (GsdSmartcard *card) { return card->priv->slot_series; } static void gsd_smartcard_init (GsdSmartcard *card) { g_debug ("initializing smartcard "); card->priv = G_TYPE_INSTANCE_GET_PRIVATE (card, GSD_TYPE_SMARTCARD, GsdSmartcardPrivate); } static void gsd_smartcard_finalize (GObject *object) { GsdSmartcard *card; GObjectClass *gobject_class; card = GSD_SMARTCARD (object); g_free (card->priv->name); gsd_smartcard_set_module (card, NULL); gobject_class = G_OBJECT_CLASS (gsd_smartcard_parent_class); gobject_class->finalize (object); } GQuark gsd_smartcard_error_quark (void) { static GQuark error_quark = 0; if (error_quark == 0) { error_quark = g_quark_from_static_string ("gsd-smartcard-error-quark"); } return error_quark; } GsdSmartcard * _gsd_smartcard_new (SECMODModule *module, CK_SLOT_ID slot_id, int slot_series) { GsdSmartcard *card; g_return_val_if_fail (module != NULL, NULL); g_return_val_if_fail (slot_id >= 1, NULL); g_return_val_if_fail (slot_series > 0, NULL); g_return_val_if_fail (sizeof (gulong) == sizeof (slot_id), NULL); card = GSD_SMARTCARD (g_object_new (GSD_TYPE_SMARTCARD, "module", module, "slot-id", (gulong) slot_id, "slot-series", slot_series, NULL)); return card; } GsdSmartcard * _gsd_smartcard_new_from_name (SECMODModule *module, const char *name) { GsdSmartcard *card; g_return_val_if_fail (module != NULL, NULL); g_return_val_if_fail (name != NULL, NULL); card = GSD_SMARTCARD (g_object_new (GSD_TYPE_SMARTCARD, "module", module, "name", name, NULL)); return card; } void _gsd_smartcard_set_state (GsdSmartcard *card, GsdSmartcardState state) { /* gsd_smartcard_fetch_certificates (card); */ if (card->priv->state != state) { card->priv->state = state; if (state == GSD_SMARTCARD_STATE_INSERTED) { g_signal_emit (card, gsd_smartcard_signals[INSERTED], 0); } else if (state == GSD_SMARTCARD_STATE_REMOVED) { g_signal_emit (card, gsd_smartcard_signals[REMOVED], 0); } else { g_assert_not_reached (); } } } /* So we could conceivably make the closure data a pointer to the card * or something similiar and then emit signals when we want passwords, * but it's probably easier to just get the password up front and use * it. So we just take the passed in g_malloc'd (well probably, who knows) * and strdup it using NSPR's memory allocation routines. */ static char * gsd_smartcard_password_handler (PK11SlotInfo *slot, PRBool is_retrying, const char *password) { if (is_retrying) { return NULL; } return password != NULL? PL_strdup (password): NULL; } gboolean gsd_smartcard_unlock (GsdSmartcard *card, const char *password) { SECStatus status; PK11_SetPasswordFunc ((PK11PasswordFunc) gsd_smartcard_password_handler); /* we pass PR_TRUE to load certificates */ status = PK11_Authenticate (card->priv->slot, PR_TRUE, (gpointer) password); if (status != SECSuccess) { g_debug ("could not unlock card - %d", status); return FALSE; } return TRUE; } static PK11SlotInfo * gsd_smartcard_find_slot_from_card_name (GsdSmartcard *card, const char *card_name) { int i; for (i = 0; i < card->priv->module->slotCount; i++) { const char *slot_card_name; slot_card_name = PK11_GetTokenName (card->priv->module->slots[i]); if ((slot_card_name != NULL) && (strcmp (slot_card_name, card_name) == 0)) { return card->priv->module->slots[i]; } } return NULL; } static PK11SlotInfo * gsd_smartcard_find_slot_from_id (GsdSmartcard *card, int slot_id) { int i; for (i = 0; i < card->priv->module->slotCount; i++) { if (PK11_GetSlotID (card->priv->module->slots[i]) == slot_id) { return card->priv->module->slots[i]; } } return NULL; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/smartcard/gsd-smartcard.h0000664000175000017500000000656200000000000025414 0ustar00jeremyjeremy/* securitycard.h - api for reading and writing data to a security card * * Copyright (C) 2006 Ray Strode * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #ifndef GSD_SMARTCARD_H #define GSD_SMARTCARD_H #include #include #include G_BEGIN_DECLS #define GSD_TYPE_SMARTCARD (gsd_smartcard_get_type ()) #define GSD_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_SMARTCARD, GsdSmartcard)) #define GSD_SMARTCARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_SMARTCARD, GsdSmartcardClass)) #define GSD_IS_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_SMARTCARD)) #define GSD_IS_SMARTCARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_SMARTCARD)) #define GSD_SMARTCARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GSD_TYPE_SMARTCARD, GsdSmartcardClass)) #define GSD_SMARTCARD_ERROR (gsd_smartcard_error_quark ()) typedef struct _GsdSmartcardClass GsdSmartcardClass; typedef struct _GsdSmartcard GsdSmartcard; typedef struct _GsdSmartcardPrivate GsdSmartcardPrivate; typedef enum _GsdSmartcardError GsdSmartcardError; typedef enum _GsdSmartcardState GsdSmartcardState; typedef struct _GsdSmartcardRequest GsdSmartcardRequest; struct _GsdSmartcard { GObject parent; /*< private > */ GsdSmartcardPrivate *priv; }; struct _GsdSmartcardClass { GObjectClass parent_class; void (* inserted) (GsdSmartcard *card); void (* removed) (GsdSmartcard *card); }; enum _GsdSmartcardError { GSD_SMARTCARD_ERROR_GENERIC = 0, }; enum _GsdSmartcardState { GSD_SMARTCARD_STATE_INSERTED = 0, GSD_SMARTCARD_STATE_REMOVED, }; GType gsd_smartcard_get_type (void) G_GNUC_CONST; GQuark gsd_smartcard_error_quark (void) G_GNUC_CONST; CK_SLOT_ID gsd_smartcard_get_slot_id (GsdSmartcard *card); gint gsd_smartcard_get_slot_series (GsdSmartcard *card); GsdSmartcardState gsd_smartcard_get_state (GsdSmartcard *card); char *gsd_smartcard_get_name (GsdSmartcard *card); gboolean gsd_smartcard_is_login_card (GsdSmartcard *card); gboolean gsd_smartcard_unlock (GsdSmartcard *card, const char *password); /* don't under any circumstances call these functions */ #ifdef GSD_SMARTCARD_ENABLE_INTERNAL_API GsdSmartcard *_gsd_smartcard_new (SECMODModule *module, CK_SLOT_ID slot_id, gint slot_series); GsdSmartcard *_gsd_smartcard_new_from_name (SECMODModule *module, const char *name); void _gsd_smartcard_set_state (GsdSmartcard *card, GsdSmartcardState state); #endif G_END_DECLS #endif /* GSD_SMARTCARD_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/smartcard/smartcard.gnome-settings-plugin.in0000664000175000017500000000025700000000000031251 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=smartcard IAge=0 Priority=8 _Name=Smartcard _Description=Smartcard plugin Authors=Ray Strode Copyright=Copyright © 2010 Red Hat, Inc. Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/smartcard/test-smartcard.c0000664000175000017500000000034100000000000025576 0ustar00jeremyjeremy#define NEW gsd_smartcard_manager_new_default #define START gsd_smartcard_manager_start #define STOP gsd_smartcard_manager_stop #define MANAGER GsdSmartcardManager #include "gsd-smartcard-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5957668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sound/0000775000175000017500000000000000000000000021647 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sound/Makefile.am0000664000175000017500000000255200000000000023707 0ustar00jeremyjeremyplugin_name = sound libexec_PROGRAMS = usd-test-sound usd_test_sound_SOURCES = \ gsd-sound-manager.h \ gsd-sound-manager.c \ test-sound.c usd_test_sound_CFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(SOUND_CFLAGS) \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) usd_test_sound_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(SOUND_LIBS) \ $(SETTINGS_PLUGIN_LIBS) plugin_LTLIBRARIES = \ libsound.la libsound_la_SOURCES = \ gsd-sound-plugin.c \ gsd-sound-manager.h \ gsd-sound-manager.c libsound_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) libsound_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(SOUND_CFLAGS) \ $(AM_CFLAGS) libsound_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) libsound_la_LIBADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(SETTINGS_PLUGIN_LIBS) \ $(SOUND_LIBS) plugin_in_files = \ sound.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = \ $(plugin_in_files) CLEANFILES = \ $(plugin_DATA) DISTCLEANFILES = \ $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sound/gsd-sound-manager.c0000664000175000017500000002725600000000000025342 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Lennart Poettering * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "gsd-sound-manager.h" #include "gnome-settings-profile.h" #define GSD_SOUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_SOUND_MANAGER, GsdSoundManagerPrivate)) struct GsdSoundManagerPrivate { GSettings *settings; GList *monitors; guint timeout; }; static void gsd_sound_manager_class_init (GsdSoundManagerClass *klass); static void gsd_sound_manager_init (GsdSoundManager *sound_manager); static void gsd_sound_manager_finalize (GObject *object); G_DEFINE_TYPE (GsdSoundManager, gsd_sound_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static void sample_info_cb (pa_context *c, const pa_sample_info *i, int eol, void *userdata) { pa_operation *o; if (!i) return; g_debug ("Found sample %s", i->name); /* We only flush those samples which have an XDG sound name * attached, because only those originate from themeing */ if (!(pa_proplist_gets (i->proplist, PA_PROP_EVENT_ID))) return; g_debug ("Dropping sample %s from cache", i->name); if (!(o = pa_context_remove_sample (c, i->name, NULL, NULL))) { g_debug ("pa_context_remove_sample (): %s", pa_strerror (pa_context_errno (c))); return; } pa_operation_unref (o); /* We won't wait until the operation is actually executed to * speed things up a bit.*/ } static void flush_cache (void) { pa_mainloop *ml = NULL; pa_context *c = NULL; pa_proplist *pl = NULL; pa_operation *o = NULL; g_debug ("Flushing sample cache"); if (!(ml = pa_mainloop_new ())) { g_debug ("Failed to allocate pa_mainloop"); goto fail; } if (!(pl = pa_proplist_new ())) { g_debug ("Failed to allocate pa_proplist"); goto fail; } pa_proplist_sets (pl, PA_PROP_APPLICATION_NAME, PACKAGE_NAME); pa_proplist_sets (pl, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION); pa_proplist_sets (pl, PA_PROP_APPLICATION_ID, "org.gnome.SettingsDaemon"); if (!(c = pa_context_new_with_proplist (pa_mainloop_get_api (ml), PACKAGE_NAME, pl))) { g_debug ("Failed to allocate pa_context"); goto fail; } pa_proplist_free (pl); pl = NULL; if (pa_context_connect (c, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) < 0) { g_debug ("pa_context_connect(): %s", pa_strerror (pa_context_errno (c))); goto fail; } /* Wait until the connection is established */ while (pa_context_get_state (c) != PA_CONTEXT_READY) { if (!PA_CONTEXT_IS_GOOD (pa_context_get_state (c))) { g_debug ("Connection failed: %s", pa_strerror (pa_context_errno (c))); goto fail; } if (pa_mainloop_iterate (ml, TRUE, NULL) < 0) { g_debug ("pa_mainloop_iterate() failed"); goto fail; } } /* Enumerate all cached samples */ if (!(o = pa_context_get_sample_info_list (c, sample_info_cb, NULL))) { g_debug ("pa_context_get_sample_info_list(): %s", pa_strerror (pa_context_errno (c))); goto fail; } /* Wait until our operation is finished and there's nothing * more queued to send to the server */ while (pa_operation_get_state (o) == PA_OPERATION_RUNNING || pa_context_is_pending (c)) { if (!PA_CONTEXT_IS_GOOD (pa_context_get_state (c))) { g_debug ("Connection failed: %s", pa_strerror (pa_context_errno (c))); goto fail; } if (pa_mainloop_iterate (ml, TRUE, NULL) < 0) { g_debug ("pa_mainloop_iterate() failed"); goto fail; } } g_debug ("Sample cache flushed"); fail: if (o) { pa_operation_cancel (o); pa_operation_unref (o); } if (c) { pa_context_disconnect (c); pa_context_unref (c); } if (pl) pa_proplist_free (pl); if (ml) pa_mainloop_free (ml); } static gboolean flush_cb (GsdSoundManager *manager) { flush_cache (); manager->priv->timeout = 0; return FALSE; } static void trigger_flush (GsdSoundManager *manager) { if (manager->priv->timeout) g_source_remove (manager->priv->timeout); /* We delay the flushing a bit so that we can coalesce * multiple changes into a single cache flush */ manager->priv->timeout = g_timeout_add (500, (GSourceFunc) flush_cb, manager); } static void settings_changed_cb (GSettings *settings, const char *key, GsdSoundManager *manager) { trigger_flush (manager); } static void register_config_callback (GsdSoundManager *manager) { manager->priv->settings = g_settings_new ("org.gnome.desktop.sound"); g_signal_connect (G_OBJECT (manager->priv->settings), "changed", G_CALLBACK (settings_changed_cb), manager); } static void file_monitor_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event, GsdSoundManager *manager) { g_debug ("Theme dir changed"); trigger_flush (manager); } static gboolean register_directory_callback (GsdSoundManager *manager, const char *path, GError **error) { GFile *f; GFileMonitor *m; gboolean succ = FALSE; g_debug ("Registering directory monitor for %s", path); f = g_file_new_for_path (path); m = g_file_monitor_directory (f, 0, NULL, error); if (m != NULL) { g_signal_connect (m, "changed", G_CALLBACK (file_monitor_changed_cb), manager); manager->priv->monitors = g_list_prepend (manager->priv->monitors, m); succ = TRUE; } g_object_unref (f); return succ; } gboolean gsd_sound_manager_start (GsdSoundManager *manager, GError **error) { guint i; const gchar * const * dirs; char *p; g_debug ("Starting sound manager"); gnome_settings_profile_start (NULL); /* We listen for change of the selected theme ... */ register_config_callback (manager); /* ... and we listen to changes of the theme base directories * in $HOME ...*/ p = g_build_filename (g_get_user_data_dir (), "sounds", NULL); /* See bug #694134 - the initial commit had the permissions below wrong * so users may have the directory without the right permissions. Fix * them up if so. */ if (!g_access (p, F_OK) && g_access (p, R_OK | W_OK | X_OK) != 0) { g_debug ("Permissions on %s wrong; resetting", p); g_chmod (p, S_IRUSR | S_IWUSR | S_IXUSR); } if (g_mkdir_with_parents(p, 0700) == 0) register_directory_callback (manager, p, NULL); g_free (p); /* ... and globally. */ dirs = g_get_system_data_dirs (); for (i = 0; dirs[i] != NULL; i++) { p = g_build_filename (dirs[i], "sounds", NULL); if (g_file_test (p, G_FILE_TEST_IS_DIR)) register_directory_callback (manager, p, NULL); g_free (p); } gnome_settings_profile_end (NULL); return TRUE; } void gsd_sound_manager_stop (GsdSoundManager *manager) { g_debug ("Stopping sound manager"); if (manager->priv->settings != NULL) { g_object_unref (manager->priv->settings); manager->priv->settings = NULL; } if (manager->priv->timeout) { g_source_remove (manager->priv->timeout); manager->priv->timeout = 0; } while (manager->priv->monitors) { g_file_monitor_cancel (G_FILE_MONITOR (manager->priv->monitors->data)); g_object_unref (manager->priv->monitors->data); manager->priv->monitors = g_list_delete_link (manager->priv->monitors, manager->priv->monitors); } } static GObject * gsd_sound_manager_constructor ( GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { GsdSoundManager *m; m = GSD_SOUND_MANAGER (G_OBJECT_CLASS (gsd_sound_manager_parent_class)->constructor ( type, n_construct_properties, construct_properties)); return G_OBJECT (m); } static void gsd_sound_manager_dispose (GObject *object) { GsdSoundManager *manager; manager = GSD_SOUND_MANAGER (object); gsd_sound_manager_stop (manager); G_OBJECT_CLASS (gsd_sound_manager_parent_class)->dispose (object); } static void gsd_sound_manager_class_init (GsdSoundManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructor = gsd_sound_manager_constructor; object_class->dispose = gsd_sound_manager_dispose; object_class->finalize = gsd_sound_manager_finalize; g_type_class_add_private (klass, sizeof (GsdSoundManagerPrivate)); } static void gsd_sound_manager_init (GsdSoundManager *manager) { manager->priv = GSD_SOUND_MANAGER_GET_PRIVATE (manager); } static void gsd_sound_manager_finalize (GObject *object) { GsdSoundManager *sound_manager; g_return_if_fail (object != NULL); g_return_if_fail (GSD_IS_SOUND_MANAGER (object)); sound_manager = GSD_SOUND_MANAGER (object); g_return_if_fail (sound_manager->priv); G_OBJECT_CLASS (gsd_sound_manager_parent_class)->finalize (object); } GsdSoundManager * gsd_sound_manager_new (void) { if (manager_object) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_SOUND_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_SOUND_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sound/gsd-sound-manager.h0000664000175000017500000000412000000000000025330 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Lennart Poettering * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_SOUND_MANAGER_H #define __GSD_SOUND_MANAGER_H #include #include G_BEGIN_DECLS #define GSD_TYPE_SOUND_MANAGER (gsd_sound_manager_get_type ()) #define GSD_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_SOUND_MANAGER, GsdSoundManager)) #define GSD_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GSD_TYPE_SOUND_MANAGER, GsdSoundManagerClass)) #define GSD_IS_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_SOUND_MANAGER)) #define GSD_IS_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_SOUND_MANAGER)) #define GSD_SOUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_SOUND_MANAGER, GsdSoundManagerClass)) typedef struct GsdSoundManagerPrivate GsdSoundManagerPrivate; typedef struct { GObject parent; GsdSoundManagerPrivate *priv; } GsdSoundManager; typedef struct { GObjectClass parent_class; } GsdSoundManagerClass; GType gsd_sound_manager_get_type (void) G_GNUC_CONST; GsdSoundManager *gsd_sound_manager_new (void); gboolean gsd_sound_manager_start (GsdSoundManager *manager, GError **error); void gsd_sound_manager_stop (GsdSoundManager *manager); G_END_DECLS #endif /* __GSD_SOUND_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sound/gsd-sound-plugin.c0000664000175000017500000000202500000000000025211 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2008 Lennart Poettering * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-sound-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdSound, gsd_sound) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sound/sound.gnome-settings-plugin.in0000664000175000017500000000025200000000000027564 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=sound IAge=0 Priority=5 _Name=Sound _Description=Sound Sample Cache plugin Authors=Lennart Poettering Copyright=Copyright © 2008 Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/sound/test-sound.c0000664000175000017500000000030500000000000024116 0ustar00jeremyjeremy#define NEW gsd_sound_manager_new #define START gsd_sound_manager_start #define STOP gsd_sound_manager_stop #define MANAGER GsdSoundManager #include "gsd-sound-manager.h" #include "test-plugin.h" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5957668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/0000775000175000017500000000000000000000000022164 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/Makefile.am0000664000175000017500000000220500000000000024217 0ustar00jeremyjeremyplugin_name = updates plugin_LTLIBRARIES = \ libupdates.la libupdates_la_SOURCES = \ gsd-updates-common.h \ gsd-updates-plugin.c \ gsd-updates-refresh.h \ gsd-updates-refresh.c \ gsd-updates-firmware.h \ gsd-updates-firmware.c \ gsd-updates-manager.h \ gsd-updates-manager.c libupdates_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) libupdates_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(GUDEV_CFLAGS) \ -DG_UDEV_API_IS_SUBJECT_TO_CHANGE \ $(PACKAGEKIT_CFLAGS) \ -DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE \ -DDATADIR=\"$(datadir)\" \ -DBINDIR=\"$(bindir)\" \ -DLIBEXECDIR=\"$(libexecdir)\" \ -I$(top_srcdir)/data \ $(AM_CFLAGS) libupdates_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) libupdates_la_LIBADD = \ $(SETTINGS_PLUGIN_LIBS) \ $(PACKAGEKIT_LIBS) plugin_in_files = \ updates.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST = \ $(plugin_in_files) CLEANFILES = \ $(plugin_DATA) DISTCLEANFILES = \ $(plugin_DATA) @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/gsd-updates-common.h0000664000175000017500000000422700000000000026050 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __GSD_UPDATES_COMMON_H #define __GSD_UPDATES_COMMON_H G_BEGIN_DECLS #define GSD_SETTINGS_BANNED_FIRMWARE "banned-firmware" #define GSD_SETTINGS_CONNECTION_USE_MOBILE "connection-use-mobile" #define GSD_SETTINGS_ENABLE_CHECK_FIRMWARE "enable-check-firmware" #define GSD_SETTINGS_FREQUENCY_GET_UPDATES "frequency-get-updates" #define GSD_SETTINGS_FREQUENCY_GET_UPGRADES "frequency-get-upgrades" #define GSD_SETTINGS_FREQUENCY_REFRESH_CACHE "frequency-refresh-cache" #define GSD_SETTINGS_FREQUENCY_UPDATES_NOTIFICATION "frequency-updates-notification" #define GSD_SETTINGS_IGNORED_DEVICES "ignored-devices" #define GSD_SETTINGS_LAST_UPDATES_NOTIFICATION "last-updates-notification" #define GSD_SETTINGS_MEDIA_REPO_FILENAMES "media-repo-filenames" #define GSD_SETTINGS_NOTIFY_DISTRO_UPGRADES "notify-distro-upgrades" #define GSD_SETTINGS_SCHEMA "com.canonical.unity.settings-daemon.plugins.updates" #define GSD_SETTINGS_UPDATE_BATTERY "update-battery" #define GSD_SETTINGS_AUTO_DOWNLOAD_UPDATES "auto-download-updates" G_END_DECLS #endif /* __GSD_UPDATES_COMMON_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/gsd-updates-firmware.c0000664000175000017500000010750400000000000026371 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007-2012 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #include #include #include #include #include #include #ifdef HAVE_UNISTD_H #include #endif /* HAVE_UNISTD_H */ #include #include #include #include #ifdef HAVE_GUDEV #include #endif #include "gsd-updates-common.h" #include "gsd-updates-firmware.h" static void gsd_updates_firmware_finalize (GObject *object); #define GSD_UPDATES_FIRMWARE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_UPDATES_TYPE_FIRMWARE, GsdUpdatesFirmwarePrivate)) #define GSD_UPDATES_FIRMWARE_MISSING_DIR "/run/udev/firmware-missing" #define GSD_UPDATES_FIRMWARE_LOADING_DIR "/lib/firmware" #define GSD_UPDATES_FIRMWARE_LOGIN_DELAY 10 /* seconds */ #define GSD_UPDATES_FIRMWARE_PROCESS_DELAY 2 /* seconds */ #define GSD_UPDATES_FIRMWARE_INSERT_DELAY 2 /* seconds */ #define GSD_UPDATES_FIRMWARE_DEVICE_REBIND_PROGRAM "/usr/sbin/pk-device-rebind" struct GsdUpdatesFirmwarePrivate { GSettings *settings; GFileMonitor *monitor; GPtrArray *array_requested; PkTask *task; GPtrArray *packages_found; guint timeout_id; }; typedef enum { FIRMWARE_SUBSYSTEM_USB, FIRMWARE_SUBSYSTEM_PCI, FIRMWARE_SUBSYSTEM_UNKNOWN } FirmwareSubsystem; typedef struct { gchar *filename; gchar *sysfs_path; gchar *model; gchar *id; FirmwareSubsystem subsystem; } GsdUpdatesFirmwareRequest; G_DEFINE_TYPE (GsdUpdatesFirmware, gsd_updates_firmware, G_TYPE_OBJECT) static void install_package_ids (GsdUpdatesFirmware *firmware); static void ignore_devices (GsdUpdatesFirmware *firmware); static gboolean subsystem_can_replug (FirmwareSubsystem subsystem) { if (subsystem == FIRMWARE_SUBSYSTEM_USB) return TRUE; return FALSE; } static GsdUpdatesFirmwareRequest * request_new (const gchar *filename, const gchar *sysfs_path) { GsdUpdatesFirmwareRequest *req; #ifdef HAVE_GUDEV GUdevDevice *device; GUdevClient *client; const gchar *subsystem; const gchar *model; const gchar *id_vendor; const gchar *id_product; #endif req = g_new0 (GsdUpdatesFirmwareRequest, 1); req->filename = g_strdup (filename); req->sysfs_path = g_strdup (sysfs_path); req->subsystem = FIRMWARE_SUBSYSTEM_UNKNOWN; #ifdef HAVE_GUDEV /* get all subsystems */ client = g_udev_client_new (NULL); device = g_udev_client_query_by_sysfs_path (client, sysfs_path); if (device == NULL) goto out; /* find subsystem, which will affect if we have to replug, or reboot */ subsystem = g_udev_device_get_subsystem (device); if (g_strcmp0 (subsystem, "usb") == 0) { req->subsystem = FIRMWARE_SUBSYSTEM_USB; } else if (g_strcmp0 (subsystem, "pci") == 0) { req->subsystem = FIRMWARE_SUBSYSTEM_PCI; } else { g_warning ("subsystem unrecognised: %s", subsystem); } /* get model, so we can show something sensible */ model = g_udev_device_get_property (device, "ID_MODEL"); if (model != NULL && model[0] != '\0') { req->model = g_strdup (model); /* replace invalid chars */ g_strdelimit (req->model, "_", ' '); } /* create ID so we can ignore the specific device */ id_vendor = g_udev_device_get_property (device, "ID_VENDOR"); id_product = g_udev_device_get_property (device, "ID_MODEL_ID"); req->id = g_strdup_printf ("%s_%s", id_vendor, id_product); out: if (device != NULL) g_object_unref (device); g_object_unref (client); #endif return req; } static void request_free (GsdUpdatesFirmwareRequest *req) { g_free (req->filename); g_free (req->model); g_free (req->sysfs_path); g_free (req->id); g_free (req); } static gboolean device_rebind (GsdUpdatesFirmware *firmware) { gboolean ret; gchar *argv[4]; gchar *rebind_stderr = NULL; gchar *rebind_stdout = NULL; GError *error = NULL; gint exit_status = 0; guint i; GPtrArray *array; const GsdUpdatesFirmwareRequest *req; GString *string; string = g_string_new (""); /* make a string array of all the devices to replug */ array = firmware->priv->array_requested; for (i=0; ilen; i++) { req = g_ptr_array_index (array, i); g_string_append_printf (string, "%s ", req->sysfs_path); } /* remove trailing space */ if (string->len > 0) g_string_set_size (string, string->len-1); /* use PolicyKit to do this as root */ argv[0] = "pkexec"; argv[1] = GSD_UPDATES_FIRMWARE_DEVICE_REBIND_PROGRAM; argv[2] = string->str; argv[3] = NULL; ret = g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &rebind_stdout, &rebind_stderr, &exit_status, &error); if (!ret) { g_warning ("failed to spawn '%s': %s", argv[1], error->message); g_error_free (error); goto out; } /* if we failed to rebind the device */ if (exit_status != 0) { g_warning ("failed to rebind: %s, %s", rebind_stdout, rebind_stderr); ret = FALSE; goto out; } out: g_free (rebind_stdout); g_free (rebind_stderr); g_string_free (string, TRUE); return ret; } static void libnotify_cb (NotifyNotification *notification, gchar *action, gpointer data) { GsdUpdatesFirmware *firmware = GSD_UPDATES_FIRMWARE (data); if (g_strcmp0 (action, "install-firmware") == 0) { install_package_ids (firmware); } else if (g_strcmp0 (action, "ignore-devices") == 0) { ignore_devices (firmware); } else { g_warning ("unknown action id: %s", action); } notify_notification_close (notification, NULL); } static void on_notification_closed (NotifyNotification *notification, gpointer data) { g_object_unref (notification); } static void require_restart (GsdUpdatesFirmware *firmware) { const gchar *message; gboolean ret; GError *error = NULL; NotifyNotification *notification; /* TRANSLATORS: we need to restart so the new hardware can re-request the firmware */ message = _("You will need to restart this computer before the hardware will work correctly."); /* TRANSLATORS: title of libnotify bubble */ notification = notify_notification_new (_("Additional software was installed"), message, NULL); notify_notification_set_hint_string (notification, "desktop-entry", "gpk-update-viewer"); notify_notification_set_app_name (notification, _("Software Updates")); notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER); notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), NULL); /* show the bubble */ ret = notify_notification_show (notification, &error); if (!ret) { g_warning ("error: %s", error->message); g_error_free (error); } } static void require_replug (GsdUpdatesFirmware *firmware) { const gchar *message; gboolean ret; GError *error = NULL; NotifyNotification *notification; /* TRANSLATORS: we need to remove an replug so the new hardware can re-request the firmware */ message = _("You will need to remove and then reinsert the hardware before it will work correctly."); /* TRANSLATORS: title of libnotify bubble */ notification = notify_notification_new (_("Additional software was installed"), message, NULL); notify_notification_set_hint_string (notification, "desktop-entry", "gpk-update-viewer"); notify_notification_set_app_name (notification, _("Software Updates")); notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER); notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), NULL); /* show the bubble */ ret = notify_notification_show (notification, &error); if (!ret) { g_warning ("error: %s", error->message); g_error_free (error); } } static void require_nothing (GsdUpdatesFirmware *firmware) { const gchar *message; gboolean ret; GError *error = NULL; NotifyNotification *notification; /* TRANSLATORS: we need to remove an replug so the new hardware can re-request the firmware */ message = _("Your hardware has been set up and is now ready to use."); /* TRANSLATORS: title of libnotify bubble */ notification = notify_notification_new (_("Additional software was installed"), message, NULL); notify_notification_set_hint_string (notification, "desktop-entry", "gpk-update-viewer"); notify_notification_set_app_name (notification, _("Software Updates")); notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER); notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), NULL); /* show the bubble */ ret = notify_notification_show (notification, &error); if (!ret) { g_warning ("error: %s", error->message); g_error_free (error); } } static void install_packages_cb (GObject *object, GAsyncResult *res, GsdUpdatesFirmware *firmware) { PkClient *client = PK_CLIENT (object); GError *error = NULL; PkResults *results = NULL; GPtrArray *array = NULL; gboolean restart = FALSE; const GsdUpdatesFirmwareRequest *req; gboolean ret; guint i; PkError *error_code = NULL; /* get the results */ results = pk_client_generic_finish (client, res, &error); if (results == NULL) { g_warning ("failed to install file: %s", error->message); g_error_free (error); goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { g_warning ("failed to install file: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); goto out; } /* go through all the requests, and find the worst type */ array = firmware->priv->array_requested; for (i=0; ilen; i++) { req = g_ptr_array_index (array, i); ret = subsystem_can_replug (req->subsystem); if (!ret) { restart = TRUE; break; } } /* can we just rebind the device */ ret = g_file_test (GSD_UPDATES_FIRMWARE_DEVICE_REBIND_PROGRAM, G_FILE_TEST_EXISTS); if (ret) { ret = device_rebind (firmware); if (ret) { require_nothing (firmware); goto out; } } else { /* give the user the correct message */ if (restart) require_restart (firmware); else require_replug (firmware); } /* clear array */ g_ptr_array_set_size (firmware->priv->array_requested, 0); out: if (error_code != NULL) g_object_unref (error_code); if (array != NULL) g_ptr_array_unref (array); if (results != NULL) g_object_unref (results); } static gchar ** package_array_to_strv (GPtrArray *array) { PkPackage *item; gchar **results; guint i; results = g_new0 (gchar *, array->len+1); for (i=0; ilen; i++) { item = g_ptr_array_index (array, i); results[i] = g_strdup (pk_package_get_id (item)); } return results; } static void install_package_ids (GsdUpdatesFirmware *firmware) { gchar **package_ids; /* install all of the firmware files */ package_ids = package_array_to_strv (firmware->priv->packages_found); pk_client_install_packages_async (PK_CLIENT(firmware->priv->task), TRUE, package_ids, NULL, NULL, NULL, (GAsyncReadyCallback) install_packages_cb, firmware); g_strfreev (package_ids); } static void ignore_devices (GsdUpdatesFirmware *firmware) { gchar *existing = NULL; GsdUpdatesFirmwareRequest *req; GPtrArray *array; GString *string; guint i; /* get from settings */ existing = g_settings_get_string (firmware->priv->settings, GSD_SETTINGS_IGNORED_DEVICES); /* get existing string */ string = g_string_new (existing); if (string->len > 0) g_string_append (string, ","); /* add all listed devices */ array = firmware->priv->array_requested; for (i=0; ilen; i++) { req = g_ptr_array_index (array, i); g_string_append_printf (string, "%s,", req->id); } /* remove final ',' */ if (string->len > 2) g_string_set_size (string, string->len - 1); /* set new string */ g_settings_set_string (firmware->priv->settings, GSD_SETTINGS_IGNORED_DEVICES, string->str); g_free (existing); g_string_free (string, TRUE); } static PkPackage * check_available (GsdUpdatesFirmware *firmware, const gchar *filename) { guint length = 0; GPtrArray *array = NULL; GError *error = NULL; PkPackage *item = NULL; PkBitfield filter; PkResults *results; gchar **values = NULL; PkError *error_code = NULL; /* search for newest not installed package */ filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NOT_INSTALLED, PK_FILTER_ENUM_NEWEST, -1); values = g_strsplit (filename, "&", -1); results = pk_client_search_files (PK_CLIENT(firmware->priv->task), filter, values, NULL, NULL, NULL, &error); if (results == NULL) { g_warning ("failed to search file %s: %s", filename, error->message); g_error_free (error); goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { g_warning ("failed to search file: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); goto out; } /* make sure we have one package */ array = pk_results_get_package_array (results); if (array->len == 0) g_debug ("no package providing %s found", filename); else if (array->len != 1) g_warning ("not one package providing %s found (%i)", filename, length); else item = g_object_ref (g_ptr_array_index (array, 0)); out: g_strfreev (values); if (error_code != NULL) g_object_unref (error_code); if (array != NULL) g_ptr_array_unref (array); if (results != NULL) g_object_unref (results); return item; } static void remove_duplicate (GPtrArray *array) { guint i, j; const gchar *val; const gchar *val_tmp; /* remove each duplicate entry */ for (i=0; ilen; i++) { val = g_ptr_array_index (array, i); for (j=i+1; jlen; j++) { val_tmp = g_ptr_array_index (array, j); if (g_strcmp0 (val_tmp, val) == 0) g_ptr_array_remove_index_fast (array, j); } } } static gboolean delay_timeout_cb (gpointer data) { guint i; gboolean ret; GString *string; GsdUpdatesFirmware *firmware = GSD_UPDATES_FIRMWARE (data); NotifyNotification *notification; GPtrArray *array; GError *error = NULL; PkPackage *item = NULL; const GsdUpdatesFirmwareRequest *req; gboolean has_data = FALSE; /* message string */ string = g_string_new (""); /* try to find each firmware file in an available package */ array = firmware->priv->array_requested; for (i=0; ilen; i++) { req = g_ptr_array_index (array, i); /* save to new array if we found one package for this file */ item = check_available (firmware, req->filename); if (item != NULL) { g_ptr_array_add (firmware->priv->packages_found, item); g_object_unref (item); } } /* nothing to do */ if (firmware->priv->packages_found->len == 0) { g_debug ("no packages providing any of the missing firmware"); goto out; } /* check we don't want the same package more than once */ remove_duplicate (firmware->priv->packages_found); /* have we got any models to array */ for (i=0; ilen; i++) { req = g_ptr_array_index (array, i); if (req->model != NULL) { has_data = TRUE; break; } } /* TRANSLATORS: we need another package to keep udev quiet */ g_string_append (string, _("Additional firmware is required to make hardware in this computer function correctly.")); /* sdd what information we have */ if (has_data) { g_string_append (string, "\n"); for (i=0; ilen; i++) { req = g_ptr_array_index (array, i); if (req->model != NULL) g_string_append_printf (string, "\n• %s", req->model); } g_string_append (string, "\n"); } /* TRANSLATORS: title of libnotify bubble */ notification = notify_notification_new (_("Additional firmware required"), string->str, NULL); notify_notification_set_hint_string (notification, "desktop-entry", "gpk-update-viewer"); notify_notification_set_app_name (notification, _("Software Updates")); notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER); notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW); notify_notification_add_action (notification, "install-firmware", /* TRANSLATORS: button label */ _("Install firmware"), libnotify_cb, firmware, NULL); notify_notification_add_action (notification, "ignore-devices", /* TRANSLATORS: we should ignore this device and not ask anymore */ _("Ignore devices"), libnotify_cb, firmware, NULL); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), NULL); ret = notify_notification_show (notification, &error); if (!ret) { g_warning ("error: %s", error->message); g_error_free (error); } out: g_string_free (string, TRUE); /* never repeat */ return FALSE; } static void remove_banned (GsdUpdatesFirmware *firmware, GPtrArray *array) { gboolean ret; gchar **banned = NULL; gchar *banned_str; GsdUpdatesFirmwareRequest *req; guint i, j; /* get from settings */ banned_str = g_settings_get_string (firmware->priv->settings, GSD_SETTINGS_BANNED_FIRMWARE); if (banned_str == NULL) { g_warning ("could not read banned list"); goto out; } /* nothing in list, common case */ if (banned_str[0] == '\0') { g_debug ("nothing in banned list"); goto out; } /* split using "," */ banned = g_strsplit (banned_str, ",", 0); /* remove any banned pattern matches */ i = 0; while (i < array->len) { ret = FALSE; req = g_ptr_array_index (array, i); for (j=0; banned[j] != NULL; j++) { ret = g_pattern_match_simple (banned[j], req->filename); if (ret) { g_debug ("match %s for %s, removing", banned[j], req->filename); g_ptr_array_remove_index_fast (array, i); break; } } if (!ret) i++; } out: g_free (banned_str); g_strfreev (banned); } static void remove_ignored (GsdUpdatesFirmware *firmware, GPtrArray *array) { gboolean ret; gchar **ignored = NULL; gchar *ignored_str; GsdUpdatesFirmwareRequest *req; guint i, j; /* get from settings */ ignored_str = g_settings_get_string (firmware->priv->settings, GSD_SETTINGS_IGNORED_DEVICES); if (ignored_str == NULL) { g_warning ("could not read ignored list"); goto out; } /* nothing in list, common case */ if (ignored_str[0] == '\0') { g_debug ("nothing in ignored list"); goto out; } /* split using "," */ ignored = g_strsplit (ignored_str, ",", 0); /* remove any ignored pattern matches */ i = 0; while (i < array->len) { ret = FALSE; req = g_ptr_array_index (array, i); if (req->id == NULL) continue; for (j=0; ignored[j] != NULL; j++) { ret = g_pattern_match_simple (ignored[j], req->id); if (ret) { g_debug ("match %s for %s, removing", ignored[j], req->id); g_ptr_array_remove_index_fast (array, i); break; } } if (!ret) i++; } out: g_free (ignored_str); g_strfreev (ignored); } static gchar * udev_text_decode (const gchar *data) { guint i; guint j; gchar *decode; decode = g_strdup (data); for (i = 0, j = 0; data[i] != '\0'; j++) { if (memcmp (&data[i], "\\x2f", 4) == 0) { decode[j] = '/'; i += 4; } else if (memcmp (&data[i], "\\x5c", 4) == 0) { decode[j] = '\\'; i += 4; } else { decode[j] = data[i]; i++; } } decode[j] = '\0'; return decode; } static gchar * get_device (GsdUpdatesFirmware *firmware, const gchar *filename) { GFile *file; GFileInfo *info; const gchar *symlink_path; gchar *syspath = NULL; GError *error = NULL; gchar *target = NULL; gchar *tmp; /* get the file data */ file = g_file_new_for_path (filename); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET, G_FILE_QUERY_INFO_NONE, NULL, &error); if (info == NULL) { g_warning ("Failed to get symlink: %s", error->message); g_error_free (error); goto out; } /* /devices/pci0000:00/0000:00:1d.0/usb5/5-2/firmware/5-2 */ symlink_path = g_file_info_get_symlink_target (info); if (symlink_path == NULL) { g_warning ("failed to get symlink target"); goto out; } /* prepend sys to make '/sys/devices/pci0000:00/0000:00:1d.0/usb5/5-2/firmware/5-2' */ syspath = g_strconcat ("/sys", symlink_path, NULL); /* start with the longest, and try to find a sub-path that exists */ tmp = &syspath[strlen (syspath)]; while (tmp != NULL) { *tmp = '\0'; g_debug ("testing %s", target); if (g_file_test (syspath, G_FILE_TEST_EXISTS)) { target = g_strdup (syspath); goto out; } tmp = g_strrstr (syspath, "/"); } out: if (info != NULL) g_object_unref (info); g_object_unref (file); g_free (syspath); return target; } static void add_filename (GsdUpdatesFirmware *firmware, const gchar *filename_no_path) { gboolean ret; gchar *filename_path = NULL; gchar *missing_path = NULL; gchar *sysfs_path = NULL; GsdUpdatesFirmwareRequest *req; GPtrArray *array; guint i; /* this is the file we want to load */ filename_path = g_build_filename (GSD_UPDATES_FIRMWARE_LOADING_DIR, filename_no_path, NULL); /* file already exists */ ret = g_file_test (filename_path, G_FILE_TEST_EXISTS); if (ret) goto out; /* this is the file that udev created for us */ missing_path = g_build_filename (GSD_UPDATES_FIRMWARE_MISSING_DIR, filename_no_path, NULL); g_debug ("filename=%s -> %s", missing_path, filename_path); /* get symlink target */ sysfs_path = get_device (firmware, missing_path); if (sysfs_path == NULL) goto out; /* find any previous requests with this path or firmware */ array = firmware->priv->array_requested; for (i=0; ilen; i++) { req = g_ptr_array_index (array, i); if (g_strcmp0 (sysfs_path, req->sysfs_path) == 0) { g_debug ("ignoring previous sysfs request for %s", sysfs_path); goto out; } if (g_strcmp0 (filename_path, req->filename) == 0) { g_debug ("ignoring previous filename request for %s", filename_path); goto out; } } /* create new request object */ req = request_new (filename_path, sysfs_path); g_ptr_array_add (firmware->priv->array_requested, req); out: g_free (missing_path); g_free (filename_path); g_free (sysfs_path); } static void scan_directory (GsdUpdatesFirmware *firmware) { gboolean ret; GError *error = NULL; GDir *dir; const gchar *filename; gchar *filename_decoded; guint i; GPtrArray *array; const GsdUpdatesFirmwareRequest *req; guint scan_id = 0; /* should we check and show the user */ ret = g_settings_get_boolean (firmware->priv->settings, GSD_SETTINGS_ENABLE_CHECK_FIRMWARE); if (!ret) { g_debug ("not showing thanks to GSettings"); return; } /* open the directory of requests */ dir = g_dir_open (GSD_UPDATES_FIRMWARE_MISSING_DIR, 0, &error); if (dir == NULL) { if (error->code != G_FILE_ERROR_NOENT) { g_warning ("failed to open directory: %s", error->message); } g_error_free (error); return; } /* find all the firmware requests */ filename = g_dir_read_name (dir); while (filename != NULL) { filename_decoded = udev_text_decode (filename); add_filename (firmware, filename_decoded); g_free (filename_decoded); /* next file */ filename = g_dir_read_name (dir); } g_dir_close (dir); /* debugging */ array = firmware->priv->array_requested; for (i=0; ilen; i++) { req = g_ptr_array_index (array, i); g_debug ("requested: %s", req->filename); } /* remove banned files */ remove_banned (firmware, array); /* remove ignored devices */ remove_ignored (firmware, array); /* debugging */ array = firmware->priv->array_requested; for (i=0; ilen; i++) { req = g_ptr_array_index (array, i); g_debug ("searching for: %s", req->filename); } /* don't spam the user at startup, so wait a little delay */ if (array->len > 0) { scan_id = g_timeout_add_seconds (GSD_UPDATES_FIRMWARE_PROCESS_DELAY, delay_timeout_cb, firmware); g_source_set_name_by_id (scan_id, "[GsdUpdatesFirmware] process"); } } static gboolean scan_directory_cb (GsdUpdatesFirmware *firmware) { scan_directory (firmware); firmware->priv->timeout_id = 0; return FALSE; } static void monitor_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, GsdUpdatesFirmware *firmware) { if (firmware->priv->timeout_id > 0) { g_debug ("clearing timeout as device changed"); g_source_remove (firmware->priv->timeout_id); } /* wait for the device to settle */ firmware->priv->timeout_id = g_timeout_add_seconds (GSD_UPDATES_FIRMWARE_INSERT_DELAY, (GSourceFunc) scan_directory_cb, firmware); g_source_set_name_by_id (firmware->priv->timeout_id, "[GsdUpdatesFirmware] changed"); } static void gsd_updates_firmware_class_init (GsdUpdatesFirmwareClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_updates_firmware_finalize; g_type_class_add_private (klass, sizeof (GsdUpdatesFirmwarePrivate)); } static void gsd_updates_firmware_init (GsdUpdatesFirmware *firmware) { GFile *file; GError *error = NULL; firmware->priv = GSD_UPDATES_FIRMWARE_GET_PRIVATE (firmware); firmware->priv->timeout_id = 0; firmware->priv->packages_found = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); firmware->priv->array_requested = g_ptr_array_new_with_free_func ((GDestroyNotify) request_free); firmware->priv->settings = g_settings_new (GSD_SETTINGS_SCHEMA); firmware->priv->task = pk_task_new (); g_object_set (firmware->priv->task, "background", TRUE, NULL); /* setup watch for new hardware */ file = g_file_new_for_path (GSD_UPDATES_FIRMWARE_MISSING_DIR); firmware->priv->monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, &error); if (firmware->priv->monitor == NULL) { g_warning ("failed to setup monitor: %s", error->message); g_error_free (error); goto out; } /* limit to one per second */ g_file_monitor_set_rate_limit (firmware->priv->monitor, 1000); /* get notified of changes */ g_signal_connect (firmware->priv->monitor, "changed", G_CALLBACK (monitor_changed_cb), firmware); out: g_object_unref (file); firmware->priv->timeout_id = g_timeout_add_seconds (GSD_UPDATES_FIRMWARE_LOGIN_DELAY, (GSourceFunc) scan_directory_cb, firmware); g_source_set_name_by_id (firmware->priv->timeout_id, "[GsdUpdatesFirmware] login coldplug"); } static void gsd_updates_firmware_finalize (GObject *object) { GsdUpdatesFirmware *firmware; g_return_if_fail (GSD_UPDATES_IS_FIRMWARE (object)); firmware = GSD_UPDATES_FIRMWARE (object); g_return_if_fail (firmware->priv != NULL); g_ptr_array_unref (firmware->priv->array_requested); g_ptr_array_unref (firmware->priv->packages_found); g_object_unref (PK_CLIENT(firmware->priv->task)); g_object_unref (firmware->priv->settings); if (firmware->priv->monitor != NULL) g_object_unref (firmware->priv->monitor); if (firmware->priv->timeout_id > 0) g_source_remove (firmware->priv->timeout_id); G_OBJECT_CLASS (gsd_updates_firmware_parent_class)->finalize (object); } GsdUpdatesFirmware * gsd_updates_firmware_new (void) { GsdUpdatesFirmware *firmware; firmware = g_object_new (GSD_UPDATES_TYPE_FIRMWARE, NULL); return GSD_UPDATES_FIRMWARE (firmware); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/gsd-updates-firmware.h0000664000175000017500000000367000000000000026375 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __GSD_UPDATES_FIRMWARE_H #define __GSD_UPDATES_FIRMWARE_H #include G_BEGIN_DECLS #define GSD_UPDATES_TYPE_FIRMWARE (gsd_updates_firmware_get_type ()) #define GSD_UPDATES_FIRMWARE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_UPDATES_TYPE_FIRMWARE, GsdUpdatesFirmware)) #define GSD_UPDATES_FIRMWARE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_UPDATES_TYPE_FIRMWARE, GsdUpdatesFirmwareClass)) #define GSD_UPDATES_IS_FIRMWARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_UPDATES_TYPE_FIRMWARE)) typedef struct GsdUpdatesFirmwarePrivate GsdUpdatesFirmwarePrivate; typedef struct { GObject parent; GsdUpdatesFirmwarePrivate *priv; } GsdUpdatesFirmware; typedef struct { GObjectClass parent_class; } GsdUpdatesFirmwareClass; GType gsd_updates_firmware_get_type (void); GsdUpdatesFirmware *gsd_updates_firmware_new (void); G_END_DECLS #endif /* __GSD_UPDATES_FIRMWARE_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/gsd-updates-manager.c0000664000175000017500000016152700000000000026174 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2011 Richard Hughes * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include #include #include #include #include #include "gsd-enums.h" #include "gsd-updates-manager.h" #include "gsd-updates-firmware.h" #include "gsd-updates-refresh.h" #include "gsd-updates-common.h" #include "gnome-settings-profile.h" #include "gnome-settings-bus.h" #define GSD_UPDATES_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_UPDATES_MANAGER, GsdUpdatesManagerPrivate)) #define MAX_FAILED_GET_UPDATES 10 /* the maximum number of tries */ #define GSD_UPDATES_ICON_NORMAL "software-update-available-symbolic" #define GSD_UPDATES_ICON_URGENT "software-update-urgent-symbolic" #define GSD_UPDATES_CHECK_OFFLINE_TIMEOUT 30 /* time in seconds */ struct GsdUpdatesManagerPrivate { GCancellable *cancellable; GsdUpdatesRefresh *refresh; GsdUpdatesFirmware *firmware; GSettings *settings_proxy; GSettings *settings_ftp; GSettings *settings_gsd; GSettings *settings_http; guint number_updates_critical_last_shown; guint offline_update_id; PkError *offline_update_error; NotifyNotification *notification_updates; PkControl *control; PkTask *task; guint inhibit_cookie; GsdSessionManager *proxy_session; guint update_viewer_watcher_id; GVolumeMonitor *volume_monitor; guint failed_get_updates_count; GPtrArray *update_packages; }; static void gsd_updates_manager_class_init (GsdUpdatesManagerClass *klass); static void gsd_updates_manager_init (GsdUpdatesManager *updates_manager); G_DEFINE_TYPE (GsdUpdatesManager, gsd_updates_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static void child_exit_cb (GPid pid, gint status, gpointer user_data) { g_spawn_close_pid (pid); } static void clear_offline_updates_message (void) { gboolean ret; GError *error = NULL; gchar *argv[3]; GPid pid; argv[0] = "pkexec"; argv[1] = LIBEXECDIR "/pk-clear-offline-update"; argv[2] = NULL; ret = g_spawn_async (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &error); if (!ret) { g_warning ("Failure clearing offline update message: %s", error->message); g_error_free (error); return; } g_child_watch_add (pid, child_exit_cb, NULL); } static void show_offline_updates_error (GsdUpdatesManager *manager) { const gchar *title; gboolean show_geeky = FALSE; GString *msg; GtkWidget *dialog; /* TRANSLATORS: this is when the offline update failed */ title = _("Failed To Update"); msg = g_string_new (""); switch (pk_error_get_code (manager->priv->offline_update_error)) { case PK_ERROR_ENUM_UNFINISHED_TRANSACTION: /* TRANSLATORS: the transaction could not be completed * as a previous transaction was unfinished */ g_string_append (msg, _("A previous update was unfinished.")); show_geeky = TRUE; break; case PK_ERROR_ENUM_PACKAGE_DOWNLOAD_FAILED: case PK_ERROR_ENUM_NO_CACHE: case PK_ERROR_ENUM_NO_NETWORK: case PK_ERROR_ENUM_NO_MORE_MIRRORS_TO_TRY: case PK_ERROR_ENUM_CANNOT_FETCH_SOURCES: /* TRANSLATORS: the package manager needed to download * something with no network available */ g_string_append (msg, _("Network access was required but not available.")); break; case PK_ERROR_ENUM_BAD_GPG_SIGNATURE: case PK_ERROR_ENUM_CANNOT_UPDATE_REPO_UNSIGNED: case PK_ERROR_ENUM_GPG_FAILURE: case PK_ERROR_ENUM_MISSING_GPG_SIGNATURE: case PK_ERROR_ENUM_PACKAGE_CORRUPT: /* TRANSLATORS: if the package is not signed correctly * */ g_string_append (msg, _("An update was not signed in the correct way.")); show_geeky = TRUE; break; case PK_ERROR_ENUM_DEP_RESOLUTION_FAILED: case PK_ERROR_ENUM_FILE_CONFLICTS: case PK_ERROR_ENUM_INCOMPATIBLE_ARCHITECTURE: case PK_ERROR_ENUM_PACKAGE_CONFLICTS: /* TRANSLATORS: the transaction failed in a way the user * probably cannot comprehend. Package management systems * really are teh suck.*/ g_string_append (msg, _("The update could not be completed.")); show_geeky = TRUE; break; case PK_ERROR_ENUM_TRANSACTION_CANCELLED: /* TRANSLATORS: the user aborted the update manually */ g_string_append (msg, _("The update was cancelled.")); break; case PK_ERROR_ENUM_NO_PACKAGES_TO_UPDATE: case PK_ERROR_ENUM_UPDATE_NOT_FOUND: /* TRANSLATORS: the user must have updated manually after * the updates were prepared */ g_string_append (msg, _("An offline update was requested but no packages required updating.")); break; case PK_ERROR_ENUM_NO_SPACE_ON_DEVICE: /* TRANSLATORS: we ran out of disk space */ g_string_append (msg, _("No space was left on the drive.")); break; case PK_ERROR_ENUM_PACKAGE_FAILED_TO_BUILD: case PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL: case PK_ERROR_ENUM_PACKAGE_FAILED_TO_REMOVE: /* TRANSLATORS: the update process failed in a general * way, usually this message will come from source distros * like gentoo */ g_string_append (msg, _("An update failed to install correctly.")); show_geeky = TRUE; break; default: /* TRANSLATORS: We didn't handle the error type */ g_string_append (msg, _("The offline update failed in an unexpected way.")); show_geeky = TRUE; break; } if (show_geeky) { g_string_append_printf (msg, "\n%s\n\n%s", /* TRANSLATORS: these are geeky messages from the * package manager no mortal is supposed to understand, * but google might know what they mean */ _("Detailed errors from the package manager follow:"), pk_error_get_details (manager->priv->offline_update_error)); } dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "%s", title); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", msg->str); g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); gtk_widget_show (dialog); clear_offline_updates_message (); g_string_free (msg, TRUE); } static void libnotify_action_cb (NotifyNotification *notification, gchar *action, gpointer user_data) { gboolean ret; GError *error = NULL; GsdUpdatesManager *manager = GSD_UPDATES_MANAGER (user_data); notify_notification_close (notification, NULL); if (g_strcmp0 (action, "distro-upgrade-info") == 0) { ret = g_spawn_command_line_async (DATADIR "/PackageKit/pk-upgrade-distro.sh", &error); if (!ret) { g_warning ("Failure launching pk-upgrade-distro.sh: %s", error->message); g_error_free (error); } goto out; } if (g_strcmp0 (action, "show-update-viewer") == 0) { ret = g_spawn_command_line_async (BINDIR "/gpk-update-viewer", &error); if (!ret) { g_warning ("Failure launching update viewer: %s", error->message); g_error_free (error); } goto out; } if (g_strcmp0 (action, "clear-offline-updates") == 0) { clear_offline_updates_message (); goto out; } if (g_strcmp0 (action, "error-offline-updates") == 0) { show_offline_updates_error (manager); goto out; } if (g_strcmp0 (action, "cancel") == 0) { /* try to cancel */ g_cancellable_cancel (manager->priv->cancellable); goto out; } g_warning ("unknown action id: %s", action); out: return; } static void on_notification_closed (NotifyNotification *notification, gpointer data) { g_object_unref (notification); } static void get_distro_upgrades_finished_cb (GObject *object, GAsyncResult *res, GsdUpdatesManager *manager) { const gchar *title; gboolean ret; gchar *name = NULL; GError *error = NULL; GPtrArray *array = NULL; GString *string = NULL; guint i; NotifyNotification *notification; PkClient *client = PK_CLIENT(object); PkDistroUpgrade *item; PkError *error_code = NULL; PkResults *results; PkUpdateStateEnum state; /* get the results */ results = pk_client_generic_finish (PK_CLIENT(client), res, &error); if (results == NULL) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_error_free (error); return; } if (error->domain != PK_CLIENT_ERROR || error->code != PK_CLIENT_ERROR_NOT_SUPPORTED) { g_warning ("failed to get upgrades: %s", error->message); } g_error_free (error); goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { g_warning ("failed to get upgrades: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); goto out; } /* process results */ array = pk_results_get_distro_upgrade_array (results); /* any updates? */ if (array->len == 0) { g_debug ("no upgrades"); goto out; } /* do we do the notification? */ ret = g_settings_get_boolean (manager->priv->settings_gsd, GSD_SETTINGS_NOTIFY_DISTRO_UPGRADES); if (!ret) { g_debug ("ignoring due to GSettings"); goto out; } /* find the upgrade string */ string = g_string_new (""); for (i=0; i < array->len; i++) { item = (PkDistroUpgrade *) g_ptr_array_index (array, i); g_object_get (item, "name", &name, "state", &state, NULL); g_string_append_printf (string, "%s (%s)\n", name, pk_distro_upgrade_enum_to_string (state)); g_free (name); } if (string->len != 0) g_string_set_size (string, string->len-1); /* TRANSLATORS: a distro update is available, e.g. Fedora 8 to Fedora 9 */ title = _("Distribution upgrades available"); notification = notify_notification_new (title, string->str, GSD_UPDATES_ICON_NORMAL); notify_notification_set_hint_string (notification, "desktop-entry", "gpk-update-viewer"); notify_notification_set_app_name (notification, _("Software Updates")); notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER); notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL); notify_notification_add_action (notification, "distro-upgrade-info", /* TRANSLATORS: provides more information about the upgrade */ _("More information"), libnotify_action_cb, manager, NULL); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), NULL); ret = notify_notification_show (notification, &error); if (!ret) { g_warning ("error: %s", error->message); g_error_free (error); } out: if (error_code != NULL) g_object_unref (error_code); if (array != NULL) g_ptr_array_unref (array); if (string != NULL) g_string_free (string, TRUE); if (results != NULL) g_object_unref (results); } static void due_get_upgrades_cb (GsdUpdatesRefresh *refresh, GsdUpdatesManager *manager) { /* optimize the amount of downloaded data by setting the cache age */ pk_client_set_cache_age (PK_CLIENT(manager->priv->task), g_settings_get_int (manager->priv->settings_gsd, GSD_SETTINGS_FREQUENCY_GET_UPGRADES)); /* get new distro upgrades list */ pk_client_get_distro_upgrades_async (PK_CLIENT(manager->priv->task), NULL, NULL, NULL, (GAsyncReadyCallback) get_distro_upgrades_finished_cb, manager); } static void refresh_cache_finished_cb (GObject *object, GAsyncResult *res, GsdUpdatesManager *manager) { PkClient *client = PK_CLIENT(object); PkResults *results; GError *error = NULL; PkError *error_code = NULL; /* get the results */ results = pk_client_generic_finish (PK_CLIENT(client), res, &error); if (results == NULL) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_error_free (error); return; } g_warning ("failed to refresh the cache: %s", error->message); g_error_free (error); return; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { g_warning ("failed to refresh the cache: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); } if (error_code != NULL) g_object_unref (error_code); if (results != NULL) g_object_unref (results); } static void due_refresh_cache_cb (GsdUpdatesRefresh *refresh, GsdUpdatesManager *manager) { /* optimize the amount of downloaded data by setting the cache age */ pk_client_set_cache_age (PK_CLIENT(manager->priv->task), g_settings_get_int (manager->priv->settings_gsd, GSD_SETTINGS_FREQUENCY_REFRESH_CACHE)); pk_client_refresh_cache_async (PK_CLIENT(manager->priv->task), TRUE, NULL, NULL, NULL, (GAsyncReadyCallback) refresh_cache_finished_cb, manager); } static void notify_critical_updates (GsdUpdatesManager *manager, GPtrArray *array) { const gchar *message; const gchar *title; gboolean ret; GError *error = NULL; NotifyNotification *notification; /* if the number of critical updates is the same as the last notification, * then skip the notifcation as we don't want to bombard the user every hour */ if (array->len == manager->priv->number_updates_critical_last_shown) { g_debug ("ignoring as user ignored last warning"); return; } /* save for comparison later */ manager->priv->number_updates_critical_last_shown = array->len; /* TRANSLATORS: title in the libnotify popup */ title = ngettext ("Update", "Updates", array->len); /* TRANSLATORS: message when there are security updates */ message = ngettext ("An important software update is available", "Important software updates are available", array->len); /* close any existing notification */ if (manager->priv->notification_updates != NULL) { notify_notification_close (manager->priv->notification_updates, NULL); manager->priv->notification_updates = NULL; } /* do the bubble */ g_debug ("title=%s, message=%s", title, message); notification = notify_notification_new (title, message, GSD_UPDATES_ICON_URGENT); notify_notification_set_hint_string (notification, "desktop-entry", "gpk-update-viewer"); notify_notification_set_app_name (notification, _("Software Updates")); notify_notification_set_timeout (notification, 15000); notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL); notify_notification_add_action (notification, "show-update-viewer", /* TRANSLATORS: button: open the update viewer to install updates*/ _("Install updates"), libnotify_action_cb, manager, NULL); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), NULL); ret = notify_notification_show (notification, &error); if (!ret) { g_warning ("error: %s", error->message); g_error_free (error); } /* track so we can prevent doubled notifications */ manager->priv->notification_updates = notification; g_object_add_weak_pointer (G_OBJECT (manager->priv->notification_updates), (void **) &manager->priv->notification_updates); } static void notify_normal_updates_maybe (GsdUpdatesManager *manager, GPtrArray *array) { const gchar *message; const gchar *title; gboolean ret; GError *error = NULL; guint64 time_last_notify; guint64 time_now; guint freq_updates_notify; NotifyNotification *notification; /* find out if enough time has passed since the last notification */ time_now = g_get_real_time () / 1000000; freq_updates_notify = g_settings_get_int (manager->priv->settings_gsd, GSD_SETTINGS_FREQUENCY_UPDATES_NOTIFICATION); g_settings_get (manager->priv->settings_gsd, GSD_SETTINGS_LAST_UPDATES_NOTIFICATION, "t", &time_last_notify); if (time_last_notify > 0 && (guint64) freq_updates_notify > time_now - time_last_notify) { g_debug ("not showing non-critical notification as already shown %i hours ago", (guint) (time_now - time_last_notify) / (60 * 60)); return; } /* TRANSLATORS: title in the libnotify popup */ title = ngettext ("Update", "Updates", array->len); /* TRANSLATORS: message when there are non-security updates */ message = ngettext ("A software update is available.", "Software updates are available.", array->len); /* close any existing notification */ if (manager->priv->notification_updates != NULL) { notify_notification_close (manager->priv->notification_updates, NULL); manager->priv->notification_updates = NULL; } /* do the bubble */ g_debug ("title=%s, message=%s", title, message); notification = notify_notification_new (title, message, GSD_UPDATES_ICON_NORMAL); notify_notification_set_hint_string (notification, "desktop-entry", "gpk-update-viewer"); notify_notification_set_app_name (notification, _("Software Updates")); notify_notification_set_timeout (notification, 15000); notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL); notify_notification_add_action (notification, "show-update-viewer", /* TRANSLATORS: button: open the update viewer to install updates*/ _("Install updates"), libnotify_action_cb, manager, NULL); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), NULL); ret = notify_notification_show (notification, &error); if (!ret) { g_warning ("error: %s", error->message); g_error_free (error); } /* reset notification time */ g_settings_set (manager->priv->settings_gsd, GSD_SETTINGS_LAST_UPDATES_NOTIFICATION, "t", time_now); /* track so we can prevent doubled notifications */ manager->priv->notification_updates = notification; g_object_add_weak_pointer (G_OBJECT (manager->priv->notification_updates), (void **) &manager->priv->notification_updates); } static void notify_failed_get_updates_maybe (GsdUpdatesManager *manager) { const gchar *button; const gchar *message; const gchar *title; gboolean ret; GError *error = NULL; NotifyNotification *notification; /* give the user a break */ if (manager->priv->failed_get_updates_count++ < MAX_FAILED_GET_UPDATES) { g_debug ("failed GetUpdates, but will retry %i more times before notification", MAX_FAILED_GET_UPDATES - manager->priv->failed_get_updates_count); goto out; } /* TRANSLATORS: the updates mechanism */ title = _("Updates"); /* TRANSLATORS: we failed to get the updates multiple times, * and now we need to inform the user that something might be wrong */ message = _("Unable to access software updates"); /* TRANSLATORS: try again, this time launching the update viewer */ button = _("Try again"); notification = notify_notification_new (title, message, GSD_UPDATES_ICON_NORMAL); notify_notification_set_hint_string (notification, "desktop-entry", "gpk-update-viewer"); notify_notification_set_app_name (notification, _("Software Updates")); notify_notification_set_timeout (notification, 120*1000); notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL); notify_notification_add_action (notification, "show-update-viewer", button, libnotify_action_cb, manager, NULL); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), NULL); ret = notify_notification_show (notification, &error); if (!ret) { g_warning ("failed to show notification: %s", error->message); g_error_free (error); } out: /* reset, even if the message failed */ manager->priv->failed_get_updates_count = 0; } static void check_updates_for_importance (GsdUpdatesManager *manager) { guint i; PkPackage *pkg; GPtrArray *important_array; /* check each package */ important_array = g_ptr_array_new (); for (i = 0; i < manager->priv->update_packages->len; i++) { pkg = g_ptr_array_index (manager->priv->update_packages, i); if (pk_package_get_info (pkg) == PK_INFO_ENUM_SECURITY || pk_package_get_info (pkg) == PK_INFO_ENUM_IMPORTANT) g_ptr_array_add (important_array, pkg); } if (important_array->len > 0) { notify_critical_updates (manager, important_array); } else { notify_normal_updates_maybe (manager, manager->priv->update_packages); } g_ptr_array_unref (important_array); } static void package_download_finished_cb (GObject *object, GAsyncResult *res, GsdUpdatesManager *manager) { PkClient *client = PK_CLIENT(object); PkResults *results; GError *error = NULL; PkError *error_code = NULL; /* get the results */ results = pk_client_generic_finish (PK_CLIENT(client), res, &error); if (results == NULL) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_error_free (error); return; } g_warning ("failed to download: %s", error->message); g_error_free (error); notify_failed_get_updates_maybe (manager); return; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { g_warning ("failed to download: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); switch (pk_error_get_code (error_code)) { case PK_ERROR_ENUM_CANCELLED_PRIORITY: case PK_ERROR_ENUM_TRANSACTION_CANCELLED: g_debug ("ignoring error"); break; default: notify_failed_get_updates_maybe (manager); break; } goto out; } /* check to see if should notify */ check_updates_for_importance (manager); out: if (error_code != NULL) g_object_unref (error_code); if (results != NULL) g_object_unref (results); } static void auto_download_updates (GsdUpdatesManager *manager) { gchar **package_ids; guint i; PkPackage *pkg; /* download each package */ package_ids = g_new0 (gchar *, manager->priv->update_packages->len + 1); for (i = 0; i < manager->priv->update_packages->len; i++) { pkg = g_ptr_array_index (manager->priv->update_packages, i); package_ids[i] = g_strdup (pk_package_get_id (pkg)); } #if PK_CHECK_VERSION(0,8,1) /* we've set only-download in PkTask */ pk_task_update_packages_async (manager->priv->task, package_ids, manager->priv->cancellable, NULL, NULL, (GAsyncReadyCallback) package_download_finished_cb, manager); #else /* download them all */ pk_client_download_packages_async (PK_CLIENT(manager->priv->task), package_ids, NULL, /* this means system cache */ manager->priv->cancellable, NULL, NULL, (GAsyncReadyCallback) package_download_finished_cb, manager); #endif g_strfreev (package_ids); } static void get_updates_finished_cb (GObject *object, GAsyncResult *res, GsdUpdatesManager *manager) { PkClient *client = PK_CLIENT(object); PkResults *results; GError *error = NULL; gboolean ret; PkError *error_code = NULL; /* get the results */ results = pk_client_generic_finish (PK_CLIENT(client), res, &error); if (results == NULL) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_error_free (error); return; } g_warning ("failed to get updates: %s", error->message); g_error_free (error); notify_failed_get_updates_maybe (manager); goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { g_warning ("failed to get updates: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); switch (pk_error_get_code (error_code)) { case PK_ERROR_ENUM_CANCELLED_PRIORITY: case PK_ERROR_ENUM_TRANSACTION_CANCELLED: g_debug ("ignoring error"); break; default: notify_failed_get_updates_maybe (manager); break; } goto out; } /* we succeeded, so clear the count */ manager->priv->failed_get_updates_count = 0; /* so we can download or check for important & security updates */ if (manager->priv->update_packages != NULL) g_ptr_array_unref (manager->priv->update_packages); manager->priv->update_packages = pk_results_get_package_array (results); /* we have no updates */ if (manager->priv->update_packages->len == 0) { g_debug ("no updates"); goto out; } /* should we auto-download the updates? */ ret = g_settings_get_boolean (manager->priv->settings_gsd, GSD_SETTINGS_AUTO_DOWNLOAD_UPDATES); if (ret) { auto_download_updates (manager); goto out; } /* just check to see if should notify */ check_updates_for_importance (manager); out: if (error_code != NULL) g_object_unref (error_code); if (results != NULL) g_object_unref (results); } static void query_updates (GsdUpdatesManager *manager) { /* optimize the amount of downloaded data by setting the cache age */ pk_client_set_cache_age (PK_CLIENT(manager->priv->task), g_settings_get_int (manager->priv->settings_gsd, GSD_SETTINGS_FREQUENCY_GET_UPDATES)); /* get new update list */ pk_client_get_updates_async (PK_CLIENT(manager->priv->task), pk_bitfield_value (PK_FILTER_ENUM_NONE), manager->priv->cancellable, NULL, NULL, (GAsyncReadyCallback) get_updates_finished_cb, manager); } static void due_get_updates_cb (GsdUpdatesRefresh *refresh, GsdUpdatesManager *manager) { query_updates (manager); } static gchar * get_proxy_http (GsdUpdatesManager *manager) { gboolean ret; gchar *host = NULL; gchar *password = NULL; gchar *proxy = NULL; gchar *username = NULL; GString *string = NULL; guint port; GDesktopProxyMode proxy_mode; proxy_mode = g_settings_get_enum (manager->priv->settings_proxy, "mode"); if (proxy_mode != G_DESKTOP_PROXY_MODE_MANUAL) goto out; host = g_settings_get_string (manager->priv->settings_http, "host"); if (host == NULL) goto out; port = g_settings_get_int (manager->priv->settings_http, "port"); /* use an HTTP auth string? */ ret = g_settings_get_boolean (manager->priv->settings_http, "use-authentication"); if (ret) { username = g_settings_get_string (manager->priv->settings_http, "authentication-user"); password = g_settings_get_string (manager->priv->settings_http, "authentication-password"); } /* make PackageKit proxy string */ string = g_string_new (host); if (port > 0) g_string_append_printf (string, ":%i", port); if (username != NULL && password != NULL) g_string_append_printf (string, "@%s:%s", username, password); else if (username != NULL) g_string_append_printf (string, "@%s", username); else if (password != NULL) g_string_append_printf (string, "@:%s", password); proxy = g_string_free (string, FALSE); out: g_free (host); g_free (username); g_free (password); return proxy; } static gchar * get_proxy_ftp (GsdUpdatesManager *manager) { gchar *host = NULL; gchar *proxy = NULL; GString *string = NULL; guint port; GDesktopProxyMode proxy_mode; proxy_mode = g_settings_get_enum (manager->priv->settings_proxy, "mode"); if (proxy_mode != G_DESKTOP_PROXY_MODE_MANUAL) goto out; host = g_settings_get_string (manager->priv->settings_ftp, "host"); if (host == NULL) goto out; port = g_settings_get_int (manager->priv->settings_ftp, "port"); if (port == 0) goto out; /* make PackageKit proxy string */ string = g_string_new (host); if (port > 0) g_string_append_printf (string, ":%i", port); proxy = g_string_free (string, FALSE); out: g_free (host); return proxy; } static void set_proxy_cb (GObject *object, GAsyncResult *res, gpointer user_data) { gboolean ret; GError *error = NULL; PkControl *control = PK_CONTROL (object); /* get the result */ ret = pk_control_set_proxy_finish (control, res, &error); if (!ret) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("failed to set proxies: %s", error->message); g_error_free (error); } } static void reload_proxy_settings (GsdUpdatesManager *manager) { gchar *proxy_http; gchar *proxy_ftp; proxy_http = get_proxy_http (manager); proxy_ftp = get_proxy_ftp (manager); /* send to daemon */ pk_control_set_proxy_async (manager->priv->control, proxy_http, proxy_ftp, NULL, set_proxy_cb, manager); g_free (proxy_http); g_free (proxy_ftp); } static void settings_changed_cb (GSettings *settings, const char *key, GsdUpdatesManager *manager) { reload_proxy_settings (manager); } static void settings_gsd_changed_cb (GSettings *settings, const char *key, GsdUpdatesManager *manager) { } static void session_inhibit (GsdUpdatesManager *manager) { const gchar *reason; GError *error = NULL; GVariant *retval = NULL; /* state invalid somehow */ if (manager->priv->inhibit_cookie != 0) { g_warning ("already locked"); goto out; } /* TRANSLATORS: the reason why we've inhibited it */ reason = _("A transaction that cannot be interrupted is running"); retval = g_dbus_proxy_call_sync (G_DBUS_PROXY (manager->priv->proxy_session), "Inhibit", g_variant_new ("(susu)", "gnome-settings-daemon", /* app-id */ 0, /* xid */ reason, /* reason */ 4 /* flags */), G_DBUS_CALL_FLAGS_NONE, -1, manager->priv->cancellable, &error); if (retval == NULL) { g_warning ("failed to inhibit gnome-session: %s", error->message); g_error_free (error); goto out; } /* get cookie */ g_variant_get (retval, "(u)", &manager->priv->inhibit_cookie); out: if (retval != NULL) g_variant_unref (retval); } static void session_uninhibit (GsdUpdatesManager *manager) { GError *error = NULL; GVariant *retval = NULL; /* state invalid somehow */ if (manager->priv->inhibit_cookie == 0) { g_warning ("not locked"); goto out; } retval = g_dbus_proxy_call_sync (G_DBUS_PROXY (manager->priv->proxy_session), "Uninhibit", g_variant_new ("(u)", manager->priv->inhibit_cookie), G_DBUS_CALL_FLAGS_NONE, -1, manager->priv->cancellable, &error); if (retval == NULL) { g_warning ("failed to uninhibit gnome-session: %s", error->message); g_error_free (error); goto out; } out: manager->priv->inhibit_cookie = 0; if (retval != NULL) g_variant_unref (retval); } static void notify_locked_cb (PkControl *control, GParamSpec *pspec, GsdUpdatesManager *manager) { gboolean locked; g_object_get (control, "locked", &locked, NULL); /* TODO: locked is a bit harsh, we can probably still allow * reboot when packages are downloading or the transaction is * depsolving */ if (locked) { session_inhibit (manager); } else { session_uninhibit (manager); } } static void update_viewer_appeared_cb (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data) { GsdUpdatesManager *manager = GSD_UPDATES_MANAGER (user_data); /* close any existing notification */ if (manager->priv->notification_updates != NULL) { g_debug ("update viewer on the bus, clearing bubble"); notify_notification_close (manager->priv->notification_updates, NULL); manager->priv->notification_updates = NULL; } } static gboolean file_exists_in_root (const gchar *root, const gchar *filename) { gboolean ret = FALSE; GFile *source; gchar *source_path; source_path = g_build_filename (root, filename, NULL); source = g_file_new_for_path (source_path); /* ignore virtual mountpoints */ if (!g_file_is_native (source)) goto out; /* an interesting file exists */ ret = g_file_query_exists (source, NULL); g_debug ("checking for %s: %s", source_path, ret ? "yes" : "no"); if (!ret) goto out; out: g_free (source_path); g_object_unref (source); return ret; } static void mount_added_cb (GVolumeMonitor *volume_monitor, GMount *mount, GsdUpdatesManager *manager) { gboolean ret = FALSE; gchar **filenames = NULL; gchar *media_repo_filenames; gchar *root_path; GFile *root; guint i; /* check if any installed media is an install disk */ root = g_mount_get_root (mount); root_path = g_file_get_path (root); /* use settings */ media_repo_filenames = g_settings_get_string (manager->priv->settings_gsd, GSD_SETTINGS_MEDIA_REPO_FILENAMES); if (media_repo_filenames == NULL) { g_warning ("failed to get media repo filenames"); goto out; } /* search each possible filename */ filenames = g_strsplit (media_repo_filenames, ",", -1); for (i=0; filenames[i] != NULL; i++) { ret = file_exists_in_root (root_path, filenames[i]); if (ret) break; } /* do an updates check with the new media */ if (ret) query_updates (manager); out: g_strfreev (filenames); g_free (media_repo_filenames); g_free (root_path); g_object_unref (root); } #define PK_OFFLINE_UPDATE_RESULTS_GROUP "PackageKit Offline Update Results" #define PK_OFFLINE_UPDATE_RESULTS_FILENAME "/var/lib/PackageKit/offline-update-competed" static gboolean check_offline_update_cb (gpointer user_data) { const gchar *message; const gchar *title; gboolean ret; gboolean success; gchar *error_code = NULL; gchar *error_details = NULL; gchar *packages = NULL; GError *error = NULL; GKeyFile *key_file = NULL; GsdUpdatesManager *manager = (GsdUpdatesManager *) user_data; guint i; guint num_packages = 1; NotifyNotification *notification; PkErrorEnum error_enum = PK_ERROR_ENUM_UNKNOWN; /* was any offline update attempted */ if (!g_file_test (PK_OFFLINE_UPDATE_RESULTS_FILENAME, G_FILE_TEST_EXISTS)) goto out; /* open the file and see what happened */ key_file = g_key_file_new (); ret = g_key_file_load_from_file (key_file, PK_OFFLINE_UPDATE_RESULTS_FILENAME, G_KEY_FILE_NONE, &error); if (!ret) { g_warning ("failed to open %s: %s", PK_OFFLINE_UPDATE_RESULTS_FILENAME, error->message); g_error_free (error); goto out; } success = g_key_file_get_boolean (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Success", NULL); if (success) { packages = g_key_file_get_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "Packages", NULL); if (packages == NULL) { g_warning ("No 'Packages' in %s", PK_OFFLINE_UPDATE_RESULTS_FILENAME); goto out; } /* count the packages for translators */ for (i = 0; packages[i] != '\0'; i++) { if (packages[i] == ',') num_packages++; } /* TRANSLATORS: title in the libnotify popup */ title = ngettext ("Software Update Installed", "Software Updates Installed", num_packages); /* TRANSLATORS: message when we've done offline updates */ message = ngettext ("An important OS update has been installed.", "Important OS updates have been installed.", num_packages); /* no need to keep the file around anymore */ clear_offline_updates_message (); } else { /* get error details */ manager->priv->offline_update_error = pk_error_new (); error_code = g_key_file_get_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "ErrorCode", NULL); if (error_code != NULL) error_enum = pk_error_enum_from_string (error_code); error_details = g_key_file_get_string (key_file, PK_OFFLINE_UPDATE_RESULTS_GROUP, "ErrorDetails", NULL); g_object_set (manager->priv->offline_update_error, "code", error_enum, "details", error_details, NULL); /* TRANSLATORS: title in the libnotify popup */ title = _("Software Updates Failed"); /* TRANSLATORS: message when we've not done offline updates */ message = _("An important OS update failed to be installed."); } /* do the bubble */ g_debug ("title=%s, message=%s", title, message); notification = notify_notification_new (title, message, GSD_UPDATES_ICON_URGENT); notify_notification_set_hint_string (notification, "desktop-entry", "gpk-update-viewer"); notify_notification_set_app_name (notification, _("Software Updates")); notify_notification_set_timeout (notification, -1); notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL); if (success) { #if 0 notify_notification_add_action (notification, "review-offline-updates", /* TRANSLATORS: button: review the offline update changes */ _("Review"), libnotify_action_cb, manager, NULL); #endif } else { notify_notification_add_action (notification, "error-offline-updates", /* TRANSLATORS: button: review the offline update changes */ _("Show details"), libnotify_action_cb, manager, NULL); } notify_notification_add_action (notification, "clear-offline-updates", /* TRANSLATORS: button: clear notification */ _("OK"), libnotify_action_cb, manager, NULL); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), NULL); ret = notify_notification_show (notification, &error); if (!ret) { g_warning ("error: %s", error->message); g_error_free (error); } out: g_free (packages); g_free (error_code); g_free (error_details); if (key_file != NULL) g_key_file_free (key_file); manager->priv->offline_update_id = 0; return FALSE; } gboolean gsd_updates_manager_start (GsdUpdatesManager *manager, GError **error) { gboolean ret = FALSE; g_debug ("Starting updates manager"); /* use PackageKit */ manager->priv->cancellable = g_cancellable_new (); manager->priv->control = pk_control_new (); g_signal_connect (manager->priv->control, "notify::locked", G_CALLBACK (notify_locked_cb), manager); manager->priv->task = pk_task_new (); g_object_set (manager->priv->task, "background", TRUE, "interactive", FALSE, #if PK_CHECK_VERSION(0,8,1) "only-download", TRUE, #endif NULL); /* watch UDev for missing firmware */ manager->priv->firmware = gsd_updates_firmware_new (); /* get automatic callbacks about when we should check for * updates, refresh-caches and upgrades */ manager->priv->refresh = gsd_updates_refresh_new (); g_signal_connect (manager->priv->refresh, "get-upgrades", G_CALLBACK (due_get_upgrades_cb), manager); g_signal_connect (manager->priv->refresh, "refresh-cache", G_CALLBACK (due_refresh_cache_cb), manager); g_signal_connect (manager->priv->refresh, "get-updates", G_CALLBACK (due_get_updates_cb), manager); /* get proxy settings */ manager->priv->settings_proxy = g_settings_new ("org.gnome.system.proxy"); g_signal_connect (manager->priv->settings_proxy, "changed", G_CALLBACK (settings_changed_cb), manager); /* get http settings */ manager->priv->settings_http = g_settings_new ("org.gnome.system.proxy.http"); g_signal_connect (manager->priv->settings_http, "changed", G_CALLBACK (settings_changed_cb), manager); /* get ftp settings */ manager->priv->settings_ftp = g_settings_new ("org.gnome.system.proxy.ftp"); g_signal_connect (manager->priv->settings_ftp, "changed", G_CALLBACK (settings_changed_cb), manager); /* get ftp settings */ manager->priv->settings_gsd = g_settings_new ("com.canonical.unity.settings-daemon.plugins.updates"); g_signal_connect (manager->priv->settings_gsd, "changed", G_CALLBACK (settings_gsd_changed_cb), manager); /* use gnome-session for the idle detection */ manager->priv->proxy_session = gnome_settings_bus_get_session_proxy (); if (manager->priv->proxy_session == NULL) goto out; /* if the update viewer is started, then hide the notification */ manager->priv->update_viewer_watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, "org.freedesktop.PackageKit.UpdateViewer", G_BUS_NAME_WATCHER_FLAGS_NONE, update_viewer_appeared_cb, NULL, manager, NULL); /* get a volume monitor so we can watch media */ manager->priv->volume_monitor = g_volume_monitor_get (); g_signal_connect (manager->priv->volume_monitor, "mount-added", G_CALLBACK (mount_added_cb), manager); /* coldplug */ reload_proxy_settings (manager); /* check for offline update */ manager->priv->offline_update_id = g_timeout_add_seconds (GSD_UPDATES_CHECK_OFFLINE_TIMEOUT, check_offline_update_cb, manager); /* success */ ret = TRUE; g_debug ("Started updates manager"); out: return ret; } void gsd_updates_manager_stop (GsdUpdatesManager *manager) { g_debug ("Stopping updates manager"); g_clear_object (&manager->priv->settings_proxy); g_clear_object (&manager->priv->settings_http); g_clear_object (&manager->priv->settings_ftp); g_clear_object (&manager->priv->settings_gsd); g_clear_object (&manager->priv->control); g_clear_object (&manager->priv->task); g_clear_object (&manager->priv->refresh); g_clear_object (&manager->priv->firmware); g_clear_object (&manager->priv->proxy_session); g_clear_object (&manager->priv->volume_monitor); if (manager->priv->cancellable) { g_cancellable_cancel (manager->priv->cancellable); g_clear_object (&manager->priv->cancellable); } if (manager->priv->update_viewer_watcher_id != 0) { g_bus_unwatch_name (manager->priv->update_viewer_watcher_id); manager->priv->update_viewer_watcher_id = 0; } if (manager->priv->offline_update_id) { g_source_remove (manager->priv->offline_update_id); manager->priv->offline_update_id = 0; } if (manager->priv->update_packages != NULL) { g_ptr_array_unref (manager->priv->update_packages); manager->priv->update_packages = NULL; } g_clear_object (&manager->priv->offline_update_error); } static GObject * gsd_updates_manager_constructor ( GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { GsdUpdatesManager *m; m = GSD_UPDATES_MANAGER (G_OBJECT_CLASS (gsd_updates_manager_parent_class)->constructor ( type, n_construct_properties, construct_properties)); return G_OBJECT (m); } static void gsd_updates_manager_dispose (GObject *object) { GsdUpdatesManager *manager; manager = GSD_UPDATES_MANAGER (object); gsd_updates_manager_stop (manager); G_OBJECT_CLASS (gsd_updates_manager_parent_class)->dispose (object); } static void gsd_updates_manager_class_init (GsdUpdatesManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructor = gsd_updates_manager_constructor; object_class->dispose = gsd_updates_manager_dispose; g_type_class_add_private (klass, sizeof (GsdUpdatesManagerPrivate)); } static void gsd_updates_manager_init (GsdUpdatesManager *manager) { manager->priv = GSD_UPDATES_MANAGER_GET_PRIVATE (manager); } GsdUpdatesManager * gsd_updates_manager_new (void) { if (manager_object) { g_object_ref (manager_object); } else { manager_object = g_object_new (GSD_TYPE_UPDATES_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } return GSD_UPDATES_MANAGER (manager_object); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/gsd-updates-manager.h0000664000175000017500000000420500000000000026166 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2011 Richard Hughes * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __GSD_UPDATES_MANAGER_H #define __GSD_UPDATES_MANAGER_H #include #include G_BEGIN_DECLS #define GSD_TYPE_UPDATES_MANAGER (gsd_updates_manager_get_type ()) #define GSD_UPDATES_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_UPDATES_MANAGER, GsdUpdatesManager)) #define GSD_UPDATES_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GSD_TYPE_UPDATES_MANAGER, GsdUpdatesManagerClass)) #define GSD_IS_UPDATES_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_UPDATES_MANAGER)) #define GSD_IS_UPDATES_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_UPDATES_MANAGER)) #define GSD_UPDATES_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_UPDATES_MANAGER, GsdUpdatesManagerClass)) typedef struct GsdUpdatesManagerPrivate GsdUpdatesManagerPrivate; typedef struct { GObject parent; GsdUpdatesManagerPrivate *priv; } GsdUpdatesManager; typedef struct { GObjectClass parent_class; } GsdUpdatesManagerClass; GType gsd_updates_manager_get_type (void) G_GNUC_CONST; GsdUpdatesManager *gsd_updates_manager_new (void); gboolean gsd_updates_manager_start (GsdUpdatesManager *manager, GError **error); void gsd_updates_manager_stop (GsdUpdatesManager *manager); G_END_DECLS #endif /* __GSD_UPDATES_MANAGER_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/gsd-updates-plugin.c0000664000175000017500000000202400000000000026042 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2011 Richard Hughes * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "config.h" #include #include #include "gnome-settings-plugin.h" #include "gsd-updates-manager.h" GNOME_SETTINGS_PLUGIN_REGISTER (GsdUpdates, gsd_updates) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/gsd-updates-refresh.c0000664000175000017500000004757700000000000026230 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2007-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include #include #include #include "gnome-settings-bus.h" #include "gsd-updates-common.h" #include "gsd-updates-refresh.h" static void gsd_updates_refresh_finalize (GObject *object); #define GSD_UPDATES_REFRESH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_UPDATES_REFRESH, GsdUpdatesRefreshPrivate)) #define PERIODIC_CHECK_TIME 60*60 /* poke PackageKit every hour */ #define LOGIN_TIMEOUT 3 /* seconds */ #define SESSION_STARTUP_TIMEOUT 10 /* seconds */ enum { PRESENCE_STATUS_AVAILABLE = 0, PRESENCE_STATUS_INVISIBLE, PRESENCE_STATUS_BUSY, PRESENCE_STATUS_IDLE, PRESENCE_STATUS_UNKNOWN }; /* * at startup, after a small delay, force a GetUpdates call * every hour (or any event) check: - if we are online, idle and on AC power, it's been more than a day since we refreshed then RefreshCache - if we are online and it's been longer than the timeout since getting the updates period then GetUpdates */ struct GsdUpdatesRefreshPrivate { gboolean session_idle; gboolean on_battery; gboolean network_active; guint timeout_id; guint periodic_id; UpClient *client; GSettings *settings; GsdSessionManager *proxy_session; PkControl *control; }; enum { REFRESH_CACHE, GET_UPDATES, GET_UPGRADES, LAST_SIGNAL }; static guint signals [LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE (GsdUpdatesRefresh, gsd_updates_refresh, G_TYPE_OBJECT) static void gsd_updates_refresh_class_init (GsdUpdatesRefreshClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gsd_updates_refresh_finalize; g_type_class_add_private (klass, sizeof (GsdUpdatesRefreshPrivate)); signals [REFRESH_CACHE] = g_signal_new ("refresh-cache", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); signals [GET_UPDATES] = g_signal_new ("get-updates", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); signals [GET_UPGRADES] = g_signal_new ("get-upgrades", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } static void get_time_refresh_cache_cb (GObject *object, GAsyncResult *res, GsdUpdatesRefresh *refresh) { PkControl *control = PK_CONTROL (object); GError *error = NULL; guint seconds; guint thresh; /* get the result */ seconds = pk_control_get_time_since_action_finish (control, res, &error); if (seconds == 0) { g_warning ("failed to get time: %s", error->message); g_error_free (error); return; } /* have we passed the timout? */ thresh = g_settings_get_int (refresh->priv->settings, GSD_SETTINGS_FREQUENCY_GET_UPDATES); if (seconds < thresh) { g_debug ("not before timeout, thresh=%u, now=%u", thresh, seconds); return; } /* send signal */ g_debug ("emitting refresh-cache"); g_signal_emit (refresh, signals [REFRESH_CACHE], 0); } static void maybe_refresh_cache (GsdUpdatesRefresh *refresh) { guint thresh; g_return_if_fail (GSD_IS_UPDATES_REFRESH (refresh)); /* if we don't want to auto check for updates, don't do this either */ thresh = g_settings_get_int (refresh->priv->settings, GSD_SETTINGS_FREQUENCY_GET_UPDATES); if (thresh == 0) { g_debug ("not when policy is set to never"); return; } /* only do the refresh cache when the user is idle */ if (!refresh->priv->session_idle) { g_debug ("not when session active"); return; } /* get this each time, as it may have changed behind out back */ thresh = g_settings_get_int (refresh->priv->settings, GSD_SETTINGS_FREQUENCY_REFRESH_CACHE); if (thresh == 0) { g_debug ("not when policy is set to never"); return; } /* get the time since the last refresh */ pk_control_get_time_since_action_async (refresh->priv->control, PK_ROLE_ENUM_REFRESH_CACHE, NULL, (GAsyncReadyCallback) get_time_refresh_cache_cb, refresh); } static void get_time_get_updates_cb (GObject *object, GAsyncResult *res, GsdUpdatesRefresh *refresh) { PkControl *control = PK_CONTROL (object); GError *error = NULL; guint seconds; guint thresh; /* get the result */ seconds = pk_control_get_time_since_action_finish (control, res, &error); if (seconds == 0) { g_warning ("failed to get time: %s", error->message); g_error_free (error); return; } /* have we passed the timout? */ thresh = g_settings_get_int (refresh->priv->settings, GSD_SETTINGS_FREQUENCY_GET_UPDATES); if (seconds < thresh) { g_debug ("not before timeout, thresh=%u, now=%u", thresh, seconds); return; } /* send signal */ g_debug ("emitting get-updates"); g_signal_emit (refresh, signals [GET_UPDATES], 0); } static void maybe_get_updates (GsdUpdatesRefresh *refresh) { guint thresh; g_return_if_fail (GSD_IS_UPDATES_REFRESH (refresh)); /* if we don't want to auto check for updates, don't do this either */ thresh = g_settings_get_int (refresh->priv->settings, GSD_SETTINGS_FREQUENCY_GET_UPDATES); if (thresh == 0) { g_debug ("not when policy is set to never"); return; } /* get the time since the last refresh */ pk_control_get_time_since_action_async (refresh->priv->control, PK_ROLE_ENUM_GET_UPDATES, NULL, (GAsyncReadyCallback) get_time_get_updates_cb, refresh); } static void get_time_get_upgrades_cb (GObject *object, GAsyncResult *res, GsdUpdatesRefresh *refresh) { PkControl *control = PK_CONTROL (object); GError *error = NULL; guint seconds; guint thresh; /* get the result */ seconds = pk_control_get_time_since_action_finish (control, res, &error); if (seconds == 0) { g_warning ("failed to get time: %s", error->message); g_error_free (error); return; } /* have we passed the timout? */ thresh = g_settings_get_int (refresh->priv->settings, GSD_SETTINGS_FREQUENCY_GET_UPDATES); if (seconds < thresh) { g_debug ("not before timeout, thresh=%u, now=%u", thresh, seconds); return; } /* send signal */ g_debug ("emitting get-upgrades"); g_signal_emit (refresh, signals [GET_UPGRADES], 0); } static void maybe_get_upgrades (GsdUpdatesRefresh *refresh) { guint thresh; g_return_if_fail (GSD_IS_UPDATES_REFRESH (refresh)); /* get this each time, as it may have changed behind out back */ thresh = g_settings_get_int (refresh->priv->settings, GSD_SETTINGS_FREQUENCY_GET_UPGRADES); if (thresh == 0) { g_debug ("not when policy is set to never"); return; } /* get the time since the last refresh */ pk_control_get_time_since_action_async (refresh->priv->control, PK_ROLE_ENUM_GET_DISTRO_UPGRADES, NULL, (GAsyncReadyCallback) get_time_get_upgrades_cb, refresh); } static gboolean change_state_cb (GsdUpdatesRefresh *refresh) { /* check all actions */ maybe_refresh_cache (refresh); maybe_get_updates (refresh); maybe_get_upgrades (refresh); return FALSE; } static gboolean change_state (GsdUpdatesRefresh *refresh) { gboolean ret; g_return_val_if_fail (GSD_IS_UPDATES_REFRESH (refresh), FALSE); /* no point continuing if we have no network */ if (!refresh->priv->network_active) { g_debug ("not when no network"); return FALSE; } /* not on battery unless overridden */ ret = g_settings_get_boolean (refresh->priv->settings, GSD_SETTINGS_UPDATE_BATTERY); if (!ret && refresh->priv->on_battery) { g_debug ("not when on battery"); return FALSE; } /* wait a little time for things to settle down */ if (refresh->priv->timeout_id != 0) g_source_remove (refresh->priv->timeout_id); g_debug ("defering action for %i seconds", SESSION_STARTUP_TIMEOUT); refresh->priv->timeout_id = g_timeout_add_seconds (SESSION_STARTUP_TIMEOUT, (GSourceFunc) change_state_cb, refresh); g_source_set_name_by_id (refresh->priv->timeout_id, "[GsdUpdatesRefresh] change-state"); return TRUE; } static void settings_key_changed_cb (GSettings *client, const gchar *key, GsdUpdatesRefresh *refresh) { g_return_if_fail (GSD_IS_UPDATES_REFRESH (refresh)); if (g_strcmp0 (key, GSD_SETTINGS_FREQUENCY_GET_UPDATES) == 0 || g_strcmp0 (key, GSD_SETTINGS_FREQUENCY_GET_UPGRADES) == 0 || g_strcmp0 (key, GSD_SETTINGS_FREQUENCY_REFRESH_CACHE) == 0 || g_strcmp0 (key, GSD_SETTINGS_UPDATE_BATTERY) == 0) change_state (refresh); } static gboolean convert_network_state (GsdUpdatesRefresh *refresh, PkNetworkEnum state) { /* offline */ if (state == PK_NETWORK_ENUM_OFFLINE) return FALSE; /* online */ if (state == PK_NETWORK_ENUM_ONLINE || state == PK_NETWORK_ENUM_WIFI || state == PK_NETWORK_ENUM_WIRED) return TRUE; /* check policy */ if (state == PK_NETWORK_ENUM_MOBILE) return g_settings_get_boolean (refresh->priv->settings, GSD_SETTINGS_CONNECTION_USE_MOBILE); /* not recognised */ g_warning ("state unknown: %i", state); return TRUE; } static void notify_network_state_cb (PkControl *control, GParamSpec *pspec, GsdUpdatesRefresh *refresh) { PkNetworkEnum state; g_return_if_fail (GSD_IS_UPDATES_REFRESH (refresh)); g_object_get (control, "network-state", &state, NULL); refresh->priv->network_active = convert_network_state (refresh, state); g_debug ("setting online %i", refresh->priv->network_active); if (refresh->priv->network_active) change_state (refresh); } static gboolean periodic_timeout_cb (gpointer user_data) { GsdUpdatesRefresh *refresh = GSD_UPDATES_REFRESH (user_data); g_return_val_if_fail (GSD_IS_UPDATES_REFRESH (refresh), FALSE); /* debug so we can catch polling */ g_debug ("polling check"); /* triggered once an hour */ change_state (refresh); /* always return */ return TRUE; } static void gsd_updates_refresh_client_changed_cb (UpClient *client, GsdUpdatesRefresh *refresh) { gboolean on_battery; g_return_if_fail (GSD_IS_UPDATES_REFRESH (refresh)); /* get the on-battery state */ on_battery = up_client_get_on_battery (refresh->priv->client); if (on_battery == refresh->priv->on_battery) { g_debug ("same state as before, ignoring"); return; } /* save in local cache */ g_debug ("setting on_battery %i", on_battery); refresh->priv->on_battery = on_battery; if (!on_battery) change_state (refresh); } static void get_properties_cb (GObject *object, GAsyncResult *res, GsdUpdatesRefresh *refresh) { PkNetworkEnum state; GError *error = NULL; PkControl *control = PK_CONTROL(object); gboolean ret; /* get the result */ ret = pk_control_get_properties_finish (control, res, &error); if (!ret) { /* TRANSLATORS: backend is broken, and won't tell us what it supports */ g_warning ("could not get properties"); g_error_free (error); goto out; } /* get values */ g_object_get (control, "network-state", &state, NULL); refresh->priv->network_active = convert_network_state (refresh, state); out: return; } static void session_presence_signal_cb (GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, GsdUpdatesRefresh *refresh) { guint status; g_return_if_fail (GSD_IS_UPDATES_REFRESH (refresh)); if (g_strcmp0 (signal_name, "StatusChanged") != 0) return; /* map status code into boolean */ g_variant_get (parameters, "(u)", &status); refresh->priv->session_idle = (status == PRESENCE_STATUS_IDLE); g_debug ("setting is_idle %i", refresh->priv->session_idle); if (refresh->priv->session_idle) change_state (refresh); } static void gsd_updates_refresh_init (GsdUpdatesRefresh *refresh) { GVariant *status; guint status_code; refresh->priv = GSD_UPDATES_REFRESH_GET_PRIVATE (refresh); refresh->priv->on_battery = FALSE; refresh->priv->network_active = FALSE; refresh->priv->timeout_id = 0; refresh->priv->periodic_id = 0; /* we need to know the updates frequency */ refresh->priv->settings = g_settings_new (GSD_SETTINGS_SCHEMA); g_signal_connect (refresh->priv->settings, "changed", G_CALLBACK (settings_key_changed_cb), refresh); /* we need to query the last cache refresh time */ refresh->priv->control = pk_control_new (); g_signal_connect (refresh->priv->control, "notify::network-state", G_CALLBACK (notify_network_state_cb), refresh); /* get network state */ pk_control_get_properties_async (refresh->priv->control, NULL, (GAsyncReadyCallback) get_properties_cb, refresh); /* use a UpClient */ refresh->priv->client = up_client_new (); g_signal_connect (refresh->priv->client, "changed", G_CALLBACK (gsd_updates_refresh_client_changed_cb), refresh); /* get the battery state */ refresh->priv->on_battery = up_client_get_on_battery (refresh->priv->client); g_debug ("setting on battery %i", refresh->priv->on_battery); /* use gnome-session for the idle detection */ refresh->priv->proxy_session = gnome_settings_bus_get_session_proxy (); if (refresh->priv->proxy_session != NULL) { g_signal_connect (G_DBUS_PROXY (refresh->priv->proxy_session), "g-signal", G_CALLBACK (session_presence_signal_cb), refresh); status = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (refresh->priv->proxy_session), "status"); if (status) { g_variant_get (status, "u", &status_code); refresh->priv->session_idle = (status_code == PRESENCE_STATUS_IDLE); g_variant_unref (status); } else { refresh->priv->session_idle = FALSE; } } /* we check this in case we miss one of the async signals */ refresh->priv->periodic_id = g_timeout_add_seconds (PERIODIC_CHECK_TIME, periodic_timeout_cb, refresh); g_source_set_name_by_id (refresh->priv->periodic_id, "[GsdUpdatesRefresh] periodic check"); /* check system state */ change_state (refresh); } static void gsd_updates_refresh_finalize (GObject *object) { GsdUpdatesRefresh *refresh; g_return_if_fail (GSD_IS_UPDATES_REFRESH (object)); refresh = GSD_UPDATES_REFRESH (object); g_return_if_fail (refresh->priv != NULL); if (refresh->priv->timeout_id != 0) g_source_remove (refresh->priv->timeout_id); if (refresh->priv->periodic_id != 0) g_source_remove (refresh->priv->periodic_id); g_signal_handlers_disconnect_by_data (refresh->priv->client, refresh); g_signal_handlers_disconnect_by_data (refresh->priv->proxy_session, refresh); g_object_unref (refresh->priv->control); g_object_unref (refresh->priv->settings); g_object_unref (refresh->priv->client); if (refresh->priv->proxy_session != NULL) g_object_unref (refresh->priv->proxy_session); G_OBJECT_CLASS (gsd_updates_refresh_parent_class)->finalize (object); } GsdUpdatesRefresh * gsd_updates_refresh_new (void) { GsdUpdatesRefresh *refresh; refresh = g_object_new (GSD_TYPE_UPDATES_REFRESH, NULL); return GSD_UPDATES_REFRESH (refresh); } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/gsd-updates-refresh.h0000664000175000017500000000361200000000000026213 0ustar00jeremyjeremy/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2007-2011 Richard Hughes * * Licensed under the GNU General Public License Version 2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __GSD_UPDATES_REFRESH_H #define __GSD_UPDATES_REFRESH_H #include G_BEGIN_DECLS #define GSD_TYPE_UPDATES_REFRESH (gsd_updates_refresh_get_type ()) #define GSD_UPDATES_REFRESH(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_UPDATES_REFRESH, GsdUpdatesRefresh)) #define GSD_UPDATES_REFRESH_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_UPDATES_REFRESH, GsdUpdatesRefreshClass)) #define GSD_IS_UPDATES_REFRESH(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_UPDATES_REFRESH)) typedef struct GsdUpdatesRefreshPrivate GsdUpdatesRefreshPrivate; typedef struct { GObject parent; GsdUpdatesRefreshPrivate *priv; } GsdUpdatesRefresh; typedef struct { GObjectClass parent_class; } GsdUpdatesRefreshClass; GType gsd_updates_refresh_get_type (void); GsdUpdatesRefresh *gsd_updates_refresh_new (void); G_END_DECLS #endif /* __GSD_UPDATES_REFRESH_H */ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/updates-design.svg0000664000175000017500000010124000000000000025617 0ustar00jeremyjeremy image/svg+xml Wait for refresh dueGetUpdates (typ. 1 day) GetUpdates() 'Auto download'checkbox set? Y N UpdatePackages(only-download) Any security orcritical updates? Y N Y N > notify threshold?typ. 1 week Y N 'Use Mobile'checkbox set? Y N On GPRS orCDMA? Notify the user aboutimportant updates Notify the user aboutregular updates ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/updates/updates.gnome-settings-plugin.in0000664000175000017500000000024100000000000030414 0ustar00jeremyjeremy[GNOME Settings Plugin] Module=updates IAge=0 Priority=300 _Name=Updates _Description=Updates plugin Authors=Richard Hughes Copyright=Copyright © 2011 Website= ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5957668 unity-settings-daemon-15.04.1+21.10.20220207/plugins/wacom/0000775000175000017500000000000000000000000021625 5ustar00jeremyjeremy././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/wacom/Makefile.am0000664000175000017500000001221300000000000023660 0ustar00jeremyjeremyplugin_name = wacom plugin_LTLIBRARIES = libgsdwacom.la libgsdwacom_la_SOURCES = \ gsd-wacom-plugin.c \ gsd-wacom-manager.h \ gsd-wacom-manager.c \ gsd-wacom-osd-window.h \ gsd-wacom-osd-window.c \ gsd-wacom-device.c \ gsd-wacom-device.h \ gsd-wacom-resources.c libgsdwacom_la_CPPFLAGS = \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common/ \ -I$(top_srcdir)/data/ \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ $(AM_CPPFLAGS) libgsdwacom_la_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(WACOM_CFLAGS) \ $(AM_CFLAGS) libgsdwacom_la_LDFLAGS = \ $(GSD_PLUGIN_LDFLAGS) libgsdwacom_la_LIBADD = \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(SETTINGS_PLUGIN_LIBS) \ $(WACOM_LIBS) com.ubuntu.unity-settings-daemon.plugins.wacom.policy.in: com.ubuntu.unity-settings-daemon.plugins.wacom.policy.in.in Makefile $(AM_V_GEN) sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ gsd-wacom-resources.c: wacom.gresource.xml tablet-layout.css glib-compile-resources \ --target=$@ \ --sourcedir=$(srcdir) \ --generate-source \ --c-name gsd_wacom \ $(srcdir)/wacom.gresource.xml @INTLTOOL_POLICY_RULE@ polkit_policydir = $(datadir)/polkit-1/actions polkit_policy_in_files = com.ubuntu.unity-settings-daemon.plugins.wacom.policy.in polkit_policy_DATA = $(polkit_policy_in_files:.policy.in=.policy) # so it always gets included in the tarball usd_wacom_led_helper_SOURCES = gsd-wacom-led-helper.c EXTRA_DIST = $(usd_wacom_led_helper_SOURCES) wacom.gresource.xml tablet-layout.css if HAVE_GUDEV libexec_PROGRAMS = usd-wacom-led-helper usd_wacom_led_helper_LDFLAGS = \ $(BACKLIGHT_HELPER_LIBS) \ -lm usd_wacom_led_helper_CFLAGS = \ $(BACKLIGHT_HELPER_CFLAGS) else libexec_PROGRAMS = endif EXTRA_DIST += com.ubuntu.unity-settings-daemon.plugins.wacom.policy.in.in libexec_PROGRAMS += usd-test-wacom usd-list-wacom usd-test-wacom-osd usd_test_wacom_SOURCES = \ test-wacom.c \ gsd-wacom-manager.c \ gsd-wacom-manager.h \ gsd-wacom-osd-window.h \ gsd-wacom-osd-window.c \ gsd-wacom-device.c \ gsd-wacom-device.h \ gsd-wacom-resources.c usd_test_wacom_CPPFLAGS = \ -I$(top_srcdir)/data/ \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DBINDIR=\"$(bindir)\" \ -DPIXMAPDIR=\""$(pkgdatadir)"\" \ -DGTKBUILDERDIR=\""$(pkgdatadir)"\" \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ -DSCHEMA_NAME=\""gsdwacom"\" \ $(AM_CPPFLAGS) usd_test_wacom_CFLAGS = \ $(PLUGIN_CFLAGS) \ $(SETTINGS_PLUGIN_CFLAGS) \ $(WACOM_CFLAGS) \ $(AM_CFLAGS) usd_test_wacom_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(SETTINGS_DAEMON_LIBS) \ $(SETTINGS_PLUGIN_LIBS) \ $(WACOM_LIBS) \ -lm usd_list_wacom_SOURCES = \ list-wacom.c \ gsd-wacom-device.c \ gsd-wacom-device.h usd_list_wacom_CPPFLAGS = \ -I$(top_srcdir)/data/ \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DBINDIR=\"$(bindir)\" \ -DPIXMAPDIR=\""$(pkgdatadir)"\" \ -DGTKBUILDERDIR=\""$(pkgdatadir)"\" \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ $(AM_CPPFLAGS) usd_list_wacom_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(WACOM_CFLAGS) \ $(AM_CFLAGS) usd_list_wacom_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(SETTINGS_DAEMON_LIBS) \ $(SETTINGS_PLUGIN_LIBS) \ $(WACOM_LIBS) \ -lm usd_test_wacom_osd_SOURCES = \ test-osd-window.c \ gsd-wacom-osd-window.h \ gsd-wacom-osd-window.c \ gsd-wacom-device.c \ gsd-wacom-device.h \ gsd-wacom-resources.c usd_test_wacom_osd_CPPFLAGS = \ -I$(top_srcdir)/data/ \ -I$(top_srcdir)/gnome-settings-daemon \ -I$(top_srcdir)/plugins/common \ -DBINDIR=\"$(bindir)\" \ -DPIXMAPDIR=\""$(pkgdatadir)"\" \ -DGTKBUILDERDIR=\""$(pkgdatadir)"\" \ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DLIBEXECDIR=\""$(libexecdir)"\" \ $(AM_CPPFLAGS) usd_test_wacom_osd_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(WACOM_CFLAGS) \ $(AM_CFLAGS) usd_test_wacom_osd_LDADD = \ $(top_builddir)/gnome-settings-daemon/libgsd.la \ $(top_builddir)/plugins/common/libcommon.la \ $(top_builddir)/gnome-settings-daemon/libunity-settings-daemon.la \ $(SETTINGS_DAEMON_LIBS) \ $(SETTINGS_PLUGIN_LIBS) \ $(WACOM_LIBS) \ -lm plugin_in_files = wacom.gnome-settings-plugin.in plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin) EXTRA_DIST += $(plugin_in_files) README.config-storage CLEANFILES = \ $(plugin_DATA) \ gsd-wacom-resources.c \ com.ubuntu.unity-settings-daemon.plugins.wacom.policy \ com.ubuntu.unity-settings-daemon.plugins.wacom.policy.in @GSD_INTLTOOL_PLUGIN_RULE@ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1644246191.5605848 unity-settings-daemon-15.04.1+21.10.20220207/plugins/wacom/README.config-storage0000664000175000017500000000334300000000000025416 0ustar00jeremyjeremyConfiguration storage for Wacom tablets and styli Tablets ------- Configuration is stored on a per-device model basis, meaning that it's possible to use the same device, with same configuration on 2 machines with a shared home directory, or replace a malfunctioning device with the same model and have the same configuration. It does not allow having 2 separate tablets of the same model to have different configurations, whether on a single machine, or using a shared home directory. The configuration scheme is: schema: com.canonical.unity.settings-daemon.peripherals.wacom path: /com/canonical/unity/settings-daemon/peripherals/wacom/-/ where is the D-Bus machine-id for the machine, and is a unique identifier for the tablet. Stylus ------ Styli use a similar configuration scheme. The identifier for each stylus is the tool ID, for professional ranges, and a generic identifier for the consumer ranges that do not support tool ID. schema: com.canonical.unity.settings-daemon.peripherals.wacom.stylus or: com.canonical.unity.settings-daemon.peripherals.wacom.eraser path: /com/canonical/unity/settings-daemon/peripherals/wacom/// So each tool can be configured per tablet (so the compatible airbrush stylus will have different configurations on a Cintiq and an Intuos tablet) Buttons ------- schema: com.canonical.unity.settings-daemon.peripherals.wacom.tablet-button path: /com/canonical/unity/settings-daemon/peripherals/wacom//