diff -Nru deadbeef-statusnotifier-plugin-1.3.1/AUTHORS deadbeef-statusnotifier-plugin-1.6/AUTHORS --- deadbeef-statusnotifier-plugin-1.3.1/AUTHORS 1970-01-01 00:00:00.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/AUTHORS 2021-06-12 07:53:35.000000000 +0000 @@ -0,0 +1,11 @@ +DeadBeef Statusnotifier Plugin was originally written by: + + Vladimir Perepechin + +DeadBeef Statusnotifier Plugin uses statusnotifier library was originally written by: + + Olivier Brunel + +The following people have contributed code to DeadBeef Statusnotifier Plugin : + + Alexander Smirnov Binary files /tmp/tmpc93_uuzu/ioRboXVKNK/deadbeef-statusnotifier-plugin-1.3.1/builder/bundle.tar.xz and /tmp/tmpc93_uuzu/LO6VJCPurj/deadbeef-statusnotifier-plugin-1.6/builder/bundle.tar.xz differ diff -Nru deadbeef-statusnotifier-plugin-1.3.1/.clang-format deadbeef-statusnotifier-plugin-1.6/.clang-format --- deadbeef-statusnotifier-plugin-1.3.1/.clang-format 1970-01-01 00:00:00.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/.clang-format 2021-06-12 07:53:35.000000000 +0000 @@ -0,0 +1,9 @@ +Language: Cpp +BasedOnStyle: LLVM + +IndentWidth: 4 +ColumnLimit: 100 +AlwaysBreakAfterReturnType: All +IndentPPDirectives: BeforeHash + +SortIncludes: false diff -Nru deadbeef-statusnotifier-plugin-1.3.1/CMakeLists.txt deadbeef-statusnotifier-plugin-1.6/CMakeLists.txt --- deadbeef-statusnotifier-plugin-1.3.1/CMakeLists.txt 2020-05-25 00:00:59.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/CMakeLists.txt 2021-06-12 07:53:35.000000000 +0000 @@ -3,7 +3,7 @@ SET (PROJECT_NAME "StatusNotifier Plugin") -SET (VERSION "1.3") +SET (VERSION "1.6.0") SET (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") @@ -28,14 +28,19 @@ OPTION (USE_GTK "GTK+ 2.x interface" ON) OPTION (USE_GTK3 "GTK+ 3.x interface" ON) +OPTION (USE_CUSTOM "Custom glib-mkenums tool" ON) - -FIND_PROGRAM(MKENUMS_EXECUTABLE NAMES glib-mkenums) +IF (USE_CUSTOM) + SET(MKENUMS_EXECUTABLE ${PROJECT_SOURCE_DIR}/tools/glib-mkenums) +ELSE (USE_CUSTOM) + FIND_PROGRAM(MKENUMS_EXECUTABLE NAMES glib-mkenums) +ENDIF (USE_CUSTOM) SET (SNI_SOURCE_DIR ${PROJECT_SOURCE_DIR}/extras/statusnotifier/src) AUX_SOURCE_DIRECTORY (${SNI_SOURCE_DIR} SNI_SRCS) -AUX_SOURCE_DIRECTORY (${PROJECT_SOURCE_DIR}/src PLUGIN_SRCS) +SET (PLUGIN_SRCS ${PROJECT_SOURCE_DIR}/src/menu.c + ${PROJECT_SOURCE_DIR}/src/sni.c) PKG_CHECK_MODULES (DBUSMENU_GLIB REQUIRED dbusmenu-glib-0.4) PKG_CHECK_MODULES (X11 x11) @@ -85,7 +90,7 @@ ADD_DEFINITIONS(-DENABLE_NLS) ADD_DEFINITIONS(-DG_LOG_DOMAIN="plugin-sni") - +SET (CMAKE_C_VISIBILITY_PRESET hidden) IF (USE_GTK) PKG_CHECK_MODULES (GTK2 REQUIRED gtk+-2.0) @@ -101,7 +106,7 @@ IF (USE_GTK3) PKG_CHECK_MODULES (GTK3 REQUIRED gtk+-3.0) - + ADD_LIBRARY (sni_gtk3 MODULE ${PLUGIN_SRCS} ${SNI_SRCS}) SET_TARGET_PROPERTIES (sni_gtk3 PROPERTIES COMPILE_FLAGS "${GTK3_CFALFS}" @@ -118,4 +123,4 @@ "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) ADD_CUSTOM_TARGET(uninstall - "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake") \ No newline at end of file + "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake") diff -Nru deadbeef-statusnotifier-plugin-1.3.1/debian/changelog deadbeef-statusnotifier-plugin-1.6/debian/changelog --- deadbeef-statusnotifier-plugin-1.3.1/debian/changelog 2020-07-02 05:02:20.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/debian/changelog 2021-10-02 12:29:30.000000000 +0000 @@ -1,3 +1,9 @@ +deadbeef-statusnotifier-plugin (1.6-0ubuntu1) xenial; urgency=medium + + * New upstream release + + -- spvkgn Sat, 02 Oct 2021 17:29:30 +0500 + deadbeef-statusnotifier-plugin (1.3.1-ppa) xenial; urgency=medium * New upstream release diff -Nru deadbeef-statusnotifier-plugin-1.3.1/debian/control deadbeef-statusnotifier-plugin-1.6/debian/control --- deadbeef-statusnotifier-plugin-1.3.1/debian/control 2020-07-02 05:02:20.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/debian/control 2021-10-02 12:29:30.000000000 +0000 @@ -1,8 +1,8 @@ Source: deadbeef-statusnotifier-plugin Section: sound Priority: optional -Maintainer: spvkgn -Build-Depends: cmake, debhelper (>=9~), deadbeef-plugins-dev, libdbusmenu-glib-dev, libgtk-3-dev +Maintainer: spvkgn +Build-Depends: cmake, debhelper (>= 9~), deadbeef-plugins-dev, libdbusmenu-glib-dev, libgtk-3-dev Standards-Version: 3.9.8 Homepage: https://github.com/vovochka404/deadbeef-statusnotifier-plugin diff -Nru deadbeef-statusnotifier-plugin-1.3.1/debian/copyright deadbeef-statusnotifier-plugin-1.6/debian/copyright --- deadbeef-statusnotifier-plugin-1.3.1/debian/copyright 2019-07-15 10:43:45.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/debian/copyright 2021-10-02 12:29:30.000000000 +0000 @@ -3,7 +3,7 @@ Source: https://github.com/vovochka404/deadbeef-statusnotifier-plugin Files: debian/* -Copyright: 2019 Pavel Sofishchenko +Copyright: 2019 spvkgn License: GPL-3.0+ Files: extras/statusnotifier/src/closures.c @@ -13,23 +13,6 @@ extras/statusnotifier/src/statusnotifier.h Copyright: 2014 Olivier Brunel License: GPL-3.0+ - This file is part of statusnotifier. - . - statusnotifier is free software: you can 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. - . - statusnotifier is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - . - You should have received a copy of the GNU General Public License along with - statusnotifier. If not, see http://www.gnu.org/licenses/ - . - On Debian systems, the complete text of the GNU General Public License - Version 3 can be found in `/usr/share/common-licenses/GPL-3'. Files: * Copyright: 2014 Vladimir Perepechin @@ -51,685 +34,3 @@ . On Debian systems, the complete text of the GNU General Public License Version 3 can be found in `/usr/share/common-licenses/GPL-3'. - -#---------------------------------------------------------------------------- -# Files marked as NO_LICENSE_TEXT_FOUND may be covered by the following -# license/copyright files. - -#---------------------------------------------------------------------------- -# License file: LICENSE - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - . - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - . - Preamble - . - The GNU General Public License is a free, copyleft license for - software and other kinds of works. - . - The licenses for most software and other practical works are designed - to take away your freedom to share and change the works. By contrast, - the GNU General Public License is intended to guarantee your freedom to - share and change all versions of a program--to make sure it remains free - software for all its users. We, the Free Software Foundation, use the - GNU General Public License for most of our software; it applies also to - any other work released this way by its authors. You can apply it to - your programs, too. - . - When we speak of free software, we are referring to freedom, not - price. Our General Public Licenses are designed to make sure that you - have the freedom to distribute copies of free software (and charge for - them if you wish), that you receive source code or can get it if you - want it, that you can change the software or use pieces of it in new - free programs, and that you know you can do these things. - . - To protect your rights, we need to prevent others from denying you - these rights or asking you to surrender the rights. Therefore, you have - certain responsibilities if you distribute copies of the software, or if - you modify it: responsibilities to respect the freedom of others. - . - For example, if you distribute copies of such a program, whether - gratis or for a fee, you must pass on to the recipients the same - freedoms that you received. You must make sure that they, too, receive - or can get the source code. And you must show them these terms so they - know their rights. - . - Developers that use the GNU GPL protect your rights with two steps: - (1) assert copyright on the software, and (2) offer you this License - giving you legal permission to copy, distribute and/or modify it. - . - For the developers' and authors' protection, the GPL clearly explains - that there is no warranty for this free software. For both users' and - authors' sake, the GPL requires that modified versions be marked as - changed, so that their problems will not be attributed erroneously to - authors of previous versions. - . - Some devices are designed to deny users access to install or run - modified versions of the software inside them, although the manufacturer - can do so. This is fundamentally incompatible with the aim of - protecting users' freedom to change the software. The systematic - pattern of such abuse occurs in the area of products for individuals to - use, which is precisely where it is most unacceptable. Therefore, we - have designed this version of the GPL to prohibit the practice for those - products. If such problems arise substantially in other domains, we - stand ready to extend this provision to those domains in future versions - of the GPL, as needed to protect the freedom of users. - . - Finally, every program is threatened constantly by software patents. - States should not allow patents to restrict development and use of - software on general-purpose computers, but in those that do, we wish to - avoid the special danger that patents applied to a free program could - make it effectively proprietary. To prevent this, the GPL assures that - patents cannot be used to render the program non-free. - . - The precise terms and conditions for copying, distribution and - modification follow. - . - TERMS AND CONDITIONS - . - 0. Definitions. - . - "This License" refers to version 3 of the GNU General Public License. - . - "Copyright" also means copyright-like laws that apply to other kinds of - works, such as semiconductor masks. - . - "The Program" refers to any copyrightable work licensed under this - License. Each licensee is addressed as "you". "Licensees" and - "recipients" may be individuals or organizations. - . - To "modify" a work means to copy from or adapt all or part of the work - in a fashion requiring copyright permission, other than the making of an - exact copy. The resulting work is called a "modified version" of the - earlier work or a work "based on" the earlier work. - . - A "covered work" means either the unmodified Program or a work based - on the Program. - . - To "propagate" a work means to do anything with it that, without - permission, would make you directly or secondarily liable for - infringement under applicable copyright law, except executing it on a - computer or modifying a private copy. Propagation includes copying, - distribution (with or without modification), making available to the - public, and in some countries other activities as well. - . - To "convey" a work means any kind of propagation that enables other - parties to make or receive copies. Mere interaction with a user through - a computer network, with no transfer of a copy, is not conveying. - . - An interactive user interface displays "Appropriate Legal Notices" - to the extent that it includes a convenient and prominently visible - feature that (1) displays an appropriate copyright notice, and (2) - tells the user that there is no warranty for the work (except to the - extent that warranties are provided), that licensees may convey the - work under this License, and how to view a copy of this License. If - the interface presents a list of user commands or options, such as a - menu, a prominent item in the list meets this criterion. - . - 1. Source Code. - . - The "source code" for a work means the preferred form of the work - for making modifications to it. "Object code" means any non-source - form of a work. - . - A "Standard Interface" means an interface that either is an official - standard defined by a recognized standards body, or, in the case of - interfaces specified for a particular programming language, one that - is widely used among developers working in that language. - . - The "System Libraries" of an executable work include anything, other - than the work as a whole, that (a) is included in the normal form of - packaging a Major Component, but which is not part of that Major - Component, and (b) serves only to enable use of the work with that - Major Component, or to implement a Standard Interface for which an - implementation is available to the public in source code form. A - "Major Component", in this context, means a major essential component - (kernel, window system, and so on) of the specific operating system - (if any) on which the executable work runs, or a compiler used to - produce the work, or an object code interpreter used to run it. - . - The "Corresponding Source" for a work in object code form means all - the source code needed to generate, install, and (for an executable - work) run the object code and to modify the work, including scripts to - control those activities. However, it does not include the work's - System Libraries, or general-purpose tools or generally available free - programs which are used unmodified in performing those activities but - which are not part of the work. For example, Corresponding Source - includes interface definition files associated with source files for - the work, and the source code for shared libraries and dynamically - linked subprograms that the work is specifically designed to require, - such as by intimate data communication or control flow between those - subprograms and other parts of the work. - . - The Corresponding Source need not include anything that users - can regenerate automatically from other parts of the Corresponding - Source. - . - The Corresponding Source for a work in source code form is that - same work. - . - 2. Basic Permissions. - . - All rights granted under this License are granted for the term of - copyright on the Program, and are irrevocable provided the stated - conditions are met. This License explicitly affirms your unlimited - permission to run the unmodified Program. The output from running a - covered work is covered by this License only if the output, given its - content, constitutes a covered work. This License acknowledges your - rights of fair use or other equivalent, as provided by copyright law. - . - You may make, run and propagate covered works that you do not - convey, without conditions so long as your license otherwise remains - in force. You may convey covered works to others for the sole purpose - of having them make modifications exclusively for you, or provide you - with facilities for running those works, provided that you comply with - the terms of this License in conveying all material for which you do - not control copyright. Those thus making or running the covered works - for you must do so exclusively on your behalf, under your direction - and control, on terms that prohibit them from making any copies of - your copyrighted material outside their relationship with you. - . - Conveying under any other circumstances is permitted solely under - the conditions stated below. Sublicensing is not allowed; section 10 - makes it unnecessary. - . - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - . - No covered work shall be deemed part of an effective technological - measure under any applicable law fulfilling obligations under article - 11 of the WIPO copyright treaty adopted on 20 December 1996, or - similar laws prohibiting or restricting circumvention of such - measures. - . - When you convey a covered work, you waive any legal power to forbid - circumvention of technological measures to the extent such circumvention - is effected by exercising rights under this License with respect to - the covered work, and you disclaim any intention to limit operation or - modification of the work as a means of enforcing, against the work's - users, your or third parties' legal rights to forbid circumvention of - technological measures. - . - 4. Conveying Verbatim Copies. - . - You may convey verbatim copies of the Program's source code as you - receive it, in any medium, provided that you conspicuously and - appropriately publish on each copy an appropriate copyright notice; - keep intact all notices stating that this License and any - non-permissive terms added in accord with section 7 apply to the code; - keep intact all notices of the absence of any warranty; and give all - recipients a copy of this License along with the Program. - . - You may charge any price or no price for each copy that you convey, - and you may offer support or warranty protection for a fee. - . - 5. Conveying Modified Source Versions. - . - You may convey a work based on the Program, or the modifications to - produce it from the Program, in the form of source code under the - terms of section 4, provided that you also meet all of these conditions: - . - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - . - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - . - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - . - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - . - A compilation of a covered work with other separate and independent - works, which are not by their nature extensions of the covered work, - and which are not combined with it such as to form a larger program, - in or on a volume of a storage or distribution medium, is called an - "aggregate" if the compilation and its resulting copyright are not - used to limit the access or legal rights of the compilation's users - beyond what the individual works permit. Inclusion of a covered work - in an aggregate does not cause this License to apply to the other - parts of the aggregate. - . - 6. Conveying Non-Source Forms. - . - You may convey a covered work in object code form under the terms - of sections 4 and 5, provided that you also convey the - machine-readable Corresponding Source under the terms of this License, - in one of these ways: - . - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - . - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - . - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - . - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - . - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - . - A separable portion of the object code, whose source code is excluded - from the Corresponding Source as a System Library, need not be - included in conveying the object code work. - . - A "User Product" is either (1) a "consumer product", which means any - tangible personal property which is normally used for personal, family, - or household purposes, or (2) anything designed or sold for incorporation - into a dwelling. In determining whether a product is a consumer product, - doubtful cases shall be resolved in favor of coverage. For a particular - product received by a particular user, "normally used" refers to a - typical or common use of that class of product, regardless of the status - of the particular user or of the way in which the particular user - actually uses, or expects or is expected to use, the product. A product - is a consumer product regardless of whether the product has substantial - commercial, industrial or non-consumer uses, unless such uses represent - the only significant mode of use of the product. - . - "Installation Information" for a User Product means any methods, - procedures, authorization keys, or other information required to install - and execute modified versions of a covered work in that User Product from - a modified version of its Corresponding Source. The information must - suffice to ensure that the continued functioning of the modified object - code is in no case prevented or interfered with solely because - modification has been made. - . - If you convey an object code work under this section in, or with, or - specifically for use in, a User Product, and the conveying occurs as - part of a transaction in which the right of possession and use of the - User Product is transferred to the recipient in perpetuity or for a - fixed term (regardless of how the transaction is characterized), the - Corresponding Source conveyed under this section must be accompanied - by the Installation Information. But this requirement does not apply - if neither you nor any third party retains the ability to install - modified object code on the User Product (for example, the work has - been installed in ROM). - . - The requirement to provide Installation Information does not include a - requirement to continue to provide support service, warranty, or updates - for a work that has been modified or installed by the recipient, or for - the User Product in which it has been modified or installed. Access to a - network may be denied when the modification itself materially and - adversely affects the operation of the network or violates the rules and - protocols for communication across the network. - . - Corresponding Source conveyed, and Installation Information provided, - in accord with this section must be in a format that is publicly - documented (and with an implementation available to the public in - source code form), and must require no special password or key for - unpacking, reading or copying. - . - 7. Additional Terms. - . - "Additional permissions" are terms that supplement the terms of this - License by making exceptions from one or more of its conditions. - Additional permissions that are applicable to the entire Program shall - be treated as though they were included in this License, to the extent - that they are valid under applicable law. If additional permissions - apply only to part of the Program, that part may be used separately - under those permissions, but the entire Program remains governed by - this License without regard to the additional permissions. - . - When you convey a copy of a covered work, you may at your option - remove any additional permissions from that copy, or from any part of - it. (Additional permissions may be written to require their own - removal in certain cases when you modify the work.) You may place - additional permissions on material, added by you to a covered work, - for which you have or can give appropriate copyright permission. - . - Notwithstanding any other provision of this License, for material you - add to a covered work, you may (if authorized by the copyright holders of - that material) supplement the terms of this License with terms: - . - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - . - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - . - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - . - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - . - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - . - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - . - All other non-permissive additional terms are considered "further - restrictions" within the meaning of section 10. If the Program as you - received it, or any part of it, contains a notice stating that it is - governed by this License along with a term that is a further - restriction, you may remove that term. If a license document contains - a further restriction but permits relicensing or conveying under this - License, you may add to a covered work material governed by the terms - of that license document, provided that the further restriction does - not survive such relicensing or conveying. - . - If you add terms to a covered work in accord with this section, you - must place, in the relevant source files, a statement of the - additional terms that apply to those files, or a notice indicating - where to find the applicable terms. - . - Additional terms, permissive or non-permissive, may be stated in the - form of a separately written license, or stated as exceptions; - the above requirements apply either way. - . - 8. Termination. - . - You may not propagate or modify a covered work except as expressly - provided under this License. Any attempt otherwise to propagate or - modify it is void, and will automatically terminate your rights under - this License (including any patent licenses granted under the third - paragraph of section 11). - . - However, if you cease all violation of this License, then your - license from a particular copyright holder is reinstated (a) - provisionally, unless and until the copyright holder explicitly and - finally terminates your license, and (b) permanently, if the copyright - holder fails to notify you of the violation by some reasonable means - prior to 60 days after the cessation. - . - Moreover, your license from a particular copyright holder is - reinstated permanently if the copyright holder notifies you of the - violation by some reasonable means, this is the first time you have - received notice of violation of this License (for any work) from that - copyright holder, and you cure the violation prior to 30 days after - your receipt of the notice. - . - Termination of your rights under this section does not terminate the - licenses of parties who have received copies or rights from you under - this License. If your rights have been terminated and not permanently - reinstated, you do not qualify to receive new licenses for the same - material under section 10. - . - 9. Acceptance Not Required for Having Copies. - . - You are not required to accept this License in order to receive or - run a copy of the Program. Ancillary propagation of a covered work - occurring solely as a consequence of using peer-to-peer transmission - to receive a copy likewise does not require acceptance. However, - nothing other than this License grants you permission to propagate or - modify any covered work. These actions infringe copyright if you do - not accept this License. Therefore, by modifying or propagating a - covered work, you indicate your acceptance of this License to do so. - . - 10. Automatic Licensing of Downstream Recipients. - . - Each time you convey a covered work, the recipient automatically - receives a license from the original licensors, to run, modify and - propagate that work, subject to this License. You are not responsible - for enforcing compliance by third parties with this License. - . - An "entity transaction" is a transaction transferring control of an - organization, or substantially all assets of one, or subdividing an - organization, or merging organizations. If propagation of a covered - work results from an entity transaction, each party to that - transaction who receives a copy of the work also receives whatever - licenses to the work the party's predecessor in interest had or could - give under the previous paragraph, plus a right to possession of the - Corresponding Source of the work from the predecessor in interest, if - the predecessor has it or can get it with reasonable efforts. - . - You may not impose any further restrictions on the exercise of the - rights granted or affirmed under this License. For example, you may - not impose a license fee, royalty, or other charge for exercise of - rights granted under this License, and you may not initiate litigation - (including a cross-claim or counterclaim in a lawsuit) alleging that - any patent claim is infringed by making, using, selling, offering for - sale, or importing the Program or any portion of it. - . - 11. Patents. - . - A "contributor" is a copyright holder who authorizes use under this - License of the Program or a work on which the Program is based. The - work thus licensed is called the contributor's "contributor version". - . - A contributor's "essential patent claims" are all patent claims - owned or controlled by the contributor, whether already acquired or - hereafter acquired, that would be infringed by some manner, permitted - by this License, of making, using, or selling its contributor version, - but do not include claims that would be infringed only as a - consequence of further modification of the contributor version. For - purposes of this definition, "control" includes the right to grant - patent sublicenses in a manner consistent with the requirements of - this License. - . - Each contributor grants you a non-exclusive, worldwide, royalty-free - patent license under the contributor's essential patent claims, to - make, use, sell, offer for sale, import and otherwise run, modify and - propagate the contents of its contributor version. - . - In the following three paragraphs, a "patent license" is any express - agreement or commitment, however denominated, not to enforce a patent - (such as an express permission to practice a patent or covenant not to - sue for patent infringement). To "grant" such a patent license to a - party means to make such an agreement or commitment not to enforce a - patent against the party. - . - If you convey a covered work, knowingly relying on a patent license, - and the Corresponding Source of the work is not available for anyone - to copy, free of charge and under the terms of this License, through a - publicly available network server or other readily accessible means, - then you must either (1) cause the Corresponding Source to be so - available, or (2) arrange to deprive yourself of the benefit of the - patent license for this particular work, or (3) arrange, in a manner - consistent with the requirements of this License, to extend the patent - license to downstream recipients. "Knowingly relying" means you have - actual knowledge that, but for the patent license, your conveying the - covered work in a country, or your recipient's use of the covered work - in a country, would infringe one or more identifiable patents in that - country that you have reason to believe are valid. - . - If, pursuant to or in connection with a single transaction or - arrangement, you convey, or propagate by procuring conveyance of, a - covered work, and grant a patent license to some of the parties - receiving the covered work authorizing them to use, propagate, modify - or convey a specific copy of the covered work, then the patent license - you grant is automatically extended to all recipients of the covered - work and works based on it. - . - A patent license is "discriminatory" if it does not include within - the scope of its coverage, prohibits the exercise of, or is - conditioned on the non-exercise of one or more of the rights that are - specifically granted under this License. You may not convey a covered - work if you are a party to an arrangement with a third party that is - in the business of distributing software, under which you make payment - to the third party based on the extent of your activity of conveying - the work, and under which the third party grants, to any of the - parties who would receive the covered work from you, a discriminatory - patent license (a) in connection with copies of the covered work - conveyed by you (or copies made from those copies), or (b) primarily - for and in connection with specific products or compilations that - contain the covered work, unless you entered into that arrangement, - or that patent license was granted, prior to 28 March 2007. - . - Nothing in this License shall be construed as excluding or limiting - any implied license or other defenses to infringement that may - otherwise be available to you under applicable patent law. - . - 12. No Surrender of Others' Freedom. - . - If conditions are imposed on you (whether by court order, agreement or - otherwise) that contradict the conditions of this License, they do not - excuse you from the conditions of this License. If you cannot convey a - covered work so as to satisfy simultaneously your obligations under this - License and any other pertinent obligations, then as a consequence you may - not convey it at all. For example, if you agree to terms that obligate you - to collect a royalty for further conveying from those to whom you convey - the Program, the only way you could satisfy both those terms and this - License would be to refrain entirely from conveying the Program. - . - 13. Use with the GNU Affero General Public License. - . - Notwithstanding any other provision of this License, you have - permission to link or combine any covered work with a work licensed - under version 3 of the GNU Affero General Public License into a single - combined work, and to convey the resulting work. The terms of this - License will continue to apply to the part which is the covered work, - but the special requirements of the GNU Affero General Public License, - section 13, concerning interaction through a network will apply to the - combination as such. - . - 14. Revised Versions of this License. - . - The Free Software Foundation may publish revised and/or new versions of - the GNU General Public License from time to time. Such new versions will - be similar in spirit to the present version, but may differ in detail to - address new problems or concerns. - . - Each version is given a distinguishing version number. If the - Program specifies that a certain numbered version of the GNU General - Public License "or any later version" applies to it, you have the - option of following the terms and conditions either of that numbered - version or of any later version published by the Free Software - Foundation. If the Program does not specify a version number of the - GNU General Public License, you may choose any version ever published - by the Free Software Foundation. - . - If the Program specifies that a proxy can decide which future - versions of the GNU General Public License can be used, that proxy's - public statement of acceptance of a version permanently authorizes you - to choose that version for the Program. - . - Later license versions may give you additional or different - permissions. However, no additional obligations are imposed on any - author or copyright holder as a result of your choosing to follow a - later version. - . - 15. Disclaimer of Warranty. - . - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY - APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT - HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY - OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, - THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM - IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF - ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - . - 16. Limitation of Liability. - . - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING - WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS - THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY - GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE - USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF - DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD - PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), - EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF - SUCH DAMAGES. - . - 17. Interpretation of Sections 15 and 16. - . - If the disclaimer of warranty and limitation of liability provided - above cannot be given local legal effect according to their terms, - reviewing courts shall apply local law that most closely approximates - an absolute waiver of all civil liability in connection with the - Program, unless a warranty or assumption of liability accompanies a - copy of the Program in return for a fee. - . - END OF TERMS AND CONDITIONS - . - How to Apply These Terms to Your New Programs - . - If you develop a new program, and you want it to be of the greatest - possible use to the public, the best way to achieve this is to make it - free software which everyone can redistribute and change under these terms. - . - To do so, attach the following notices to the program. It is safest - to attach them to the start of each source file to most effectively - state the exclusion of warranty; and each file should have at least - the "copyright" line and a pointer to where the full notice is found. - . - {one line to give the program's name and a brief idea of what it does.} - Copyright (C) {year} {name of author} - . - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - . - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - . - You should have received a copy of the GNU General Public License - along with this program. If not, see . - . - Also add information on how to contact you by electronic and paper mail. - . - If the program does terminal interaction, make it output a short - notice like this when it starts in an interactive mode: - . - {project} Copyright (C) {year} {fullname} - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - . - The hypothetical commands `show w' and `show c' should show the appropriate - parts of the General Public License. Of course, your program's commands - might be different; for a GUI interface, you would use an "about box". - . - You should also get your employer (if you work as a programmer) or school, - if any, to sign a "copyright disclaimer" for the program, if necessary. - For more information on this, and how to apply and follow the GNU GPL, see - . - . - The GNU General Public License does not permit incorporating your program - into proprietary programs. If your program is a subroutine library, you - may consider it more useful to permit linking proprietary applications with - the library. If this is what you want to do, use the GNU Lesser General - Public License instead of this License. But first, please read - . - . diff -Nru deadbeef-statusnotifier-plugin-1.3.1/debian/docs deadbeef-statusnotifier-plugin-1.6/debian/docs --- deadbeef-statusnotifier-plugin-1.3.1/debian/docs 2019-07-15 08:34:52.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/debian/docs 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -LICENSE diff -Nru deadbeef-statusnotifier-plugin-1.3.1/debian/rules deadbeef-statusnotifier-plugin-1.6/debian/rules --- deadbeef-statusnotifier-plugin-1.3.1/debian/rules 2019-07-15 15:48:53.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/debian/rules 2021-10-02 12:29:30.000000000 +0000 @@ -1,9 +1,8 @@ #!/usr/bin/make -f -# You must remove unused comment lines for the released package. #export DH_VERBOSE = 1 export DEB_BUILD_MAINT_OPTIONS = hardening=+all #export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic -#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed +export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) @@ -11,7 +10,7 @@ DESTDIR = $(CURDIR)/debian/tmp %: - dh $@ + dh $@ override_dh_auto_clean: rm -rf $(BUILDDIR) @@ -21,7 +20,7 @@ dh_auto_configure -B$(BUILDDIR) -- -DCMAKE_INSTALL_PREFIX=/usr -DUSE_GTK=OFF override_dh_auto_build: - ${MAKE} -C $(BUILDDIR) + make -C $(BUILDDIR) override_dh_auto_install: install -vd $(DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/deadbeef diff -Nru deadbeef-statusnotifier-plugin-1.3.1/debian/watch deadbeef-statusnotifier-plugin-1.6/debian/watch --- deadbeef-statusnotifier-plugin-1.3.1/debian/watch 2020-07-02 05:01:48.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/debian/watch 2021-10-02 12:29:16.000000000 +0000 @@ -1,3 +1,3 @@ version=4 opts=filenamemangle=s/.+\/v?(\d\S+)\.tar\.gz/deadbeef-statusnotifier-plugin-$1\.tar\.gz/ \ - https://github.com/vovochka404/deadbeef-statusnotifier-plugin/tags .*/v?(\d\S+)\.tar\.gz + https://github.com/vovochka404/deadbeef-statusnotifier-plugin/tags .*/v?(\d\S+)\.tar\.gz debian uupdate diff -Nru deadbeef-statusnotifier-plugin-1.3.1/extras/statusnotifier/src/statusnotifier.c deadbeef-statusnotifier-plugin-1.6/extras/statusnotifier/src/statusnotifier.c --- deadbeef-statusnotifier-plugin-1.3.1/extras/statusnotifier/src/statusnotifier.c 2020-05-25 00:00:59.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/extras/statusnotifier/src/statusnotifier.c 2021-06-12 07:53:35.000000000 +0000 @@ -179,7 +179,7 @@ GParamSpec *pspec); static void status_notifier_finalize (GObject *object); -G_DEFINE_TYPE (StatusNotifier, status_notifier, G_TYPE_OBJECT) +G_DEFINE_TYPE_WITH_PRIVATE (StatusNotifier, status_notifier, G_TYPE_OBJECT) static void status_notifier_class_init (StatusNotifierClass *klass) @@ -645,15 +645,12 @@ 2, G_TYPE_INT, TYPE_STATUS_NOTIFIER_SCROLL_ORIENTATION); - - g_type_class_add_private (klass, sizeof (StatusNotifierPrivate)); } static void status_notifier_init (StatusNotifier *sn) { - sn->priv = G_TYPE_INSTANCE_GET_PRIVATE (sn, - TYPE_STATUS_NOTIFIER, StatusNotifierPrivate); + sn->priv = status_notifier_get_instance_private (sn); } static void @@ -730,6 +727,7 @@ break; case PROP_WINDOW_ID: status_notifier_set_window_id (sn, g_value_get_uint (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -810,6 +808,7 @@ break; case PROP_WINDOW_ID: g_value_set_uint (value, priv->window_id); + break; case PROP_STATE: g_value_set_enum (value, priv->state); break; @@ -1416,6 +1415,24 @@ status_notifier_set_tooltip_title (sn, title); status_notifier_set_tooltip_body (sn, body); status_notifier_thaw_tooltip (sn); +} + +void +status_notifier_set_tooltip2 (StatusNotifier *sn, + GdkPixbuf *pixbuf, + const gchar *title, + const gchar *body) +{ + StatusNotifierPrivate *priv; + + g_return_if_fail (IS_STATUS_NOTIFIER (sn)); + priv = sn->priv; + + ++priv->tooltip_freeze; + status_notifier_set_from_pixbuf (sn, STATUS_NOTIFIER_TOOLTIP_ICON, pixbuf); + status_notifier_set_tooltip_title (sn, title); + status_notifier_set_tooltip_body (sn, body); + status_notifier_thaw_tooltip (sn); } /** diff -Nru deadbeef-statusnotifier-plugin-1.3.1/extras/statusnotifier/src/statusnotifier.h deadbeef-statusnotifier-plugin-1.6/extras/statusnotifier/src/statusnotifier.h --- deadbeef-statusnotifier-plugin-1.3.1/extras/statusnotifier/src/statusnotifier.h 2020-05-25 00:00:59.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/extras/statusnotifier/src/statusnotifier.h 2021-06-12 07:53:35.000000000 +0000 @@ -288,6 +288,11 @@ const gchar *icon_name, const gchar *title, const gchar *body); +void status_notifier_set_tooltip2 ( + StatusNotifier *sn, + GdkPixbuf *pixbuf, + const gchar *title, + const gchar *body); void status_notifier_set_tooltip_title ( StatusNotifier *sn, const gchar *title); diff -Nru deadbeef-statusnotifier-plugin-1.3.1/.gitignore deadbeef-statusnotifier-plugin-1.6/.gitignore --- deadbeef-statusnotifier-plugin-1.3.1/.gitignore 2020-05-25 00:00:59.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/.gitignore 2021-06-12 07:53:35.000000000 +0000 @@ -1,6 +1,10 @@ CMakeCache.txt CMakeFiles -Makefile cmake_install.cmake +cmake_uninstall.cmake install_manifest.txt -build \ No newline at end of file +build +_build +*.so +*.swp +enums.[c,h] diff -Nru deadbeef-statusnotifier-plugin-1.3.1/Makefile deadbeef-statusnotifier-plugin-1.6/Makefile --- deadbeef-statusnotifier-plugin-1.3.1/Makefile 1970-01-01 00:00:00.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/Makefile 2021-06-12 07:53:35.000000000 +0000 @@ -0,0 +1,103 @@ +pkg_cflags ?= $(shell pkg-config --cflags $(1)) +pkg_ldflags ?= $(shell pkg-config --libs $(1)) + +CC ?= gcc + +PATH_SRC = src +PATH_EXTRA = extras/statusnotifier/src +PATH_BUILD ?= build +PATH_BUILD2 ?= $(PATH_BUILD)/gtk2 +PATH_BUILD3 ?= $(PATH_BUILD)/gtk3 + +OUT_GTK2 ?= sni_gtk2.so +OUT_GTK3 ?= sni_gtk3.so + +APP_GLIB_MKENUMS ?= $(abspath tools/glib-mkenums) + +LIST_CLEAN = CMakeCache.txt \ + CMakeFiles \ + cmake_install.cmake \ + cmake_uninstall.cmake \ + install_manifest.txt \ + build \ + _build \ + *.so \ + *.swp \ + enums.[c,h] \ + .ninja_deps \ + .ninja_log \ + *.ninja + +SNI_DEPS += dbusmenu-glib-0.4 +SNI_CFLAGS ?= $(call pkg_cflags, $(SNI_DEPS)) +SNI_LDFLAGS ?= $(call pkg_ldflags, $(SNI_DEPS)) + +SNI_CFLAGS += -DUSE_DBUSMENU -DENABLE_NLS -DG_LOG_DOMAIN=\"plugin-sni\" + +CFLAGS += -Wall -Wextra -fPIC -std=c99 -D_GNU_SOURCE -Wno-missing-field-initializers -Wno-unused -O2 -fvisibility=hidden +LDFLAGS += -shared -s -fdata-sections -ffunction-sections -Wl,-gc-sections -lX11 +INCLUDES += -I $(abspath ./) -I $(abspath $(PATH_SRC)) -I $(abspath $(PATH_EXTRA)) + + +GTK2 = gtk+-2.0 +GTK3 = gtk+-3.0 + +GTK2_CFLAGS ?= $(call pkg_cflags, $(GTK2)) +GTK2_LIBS ?= $(call pkg_ldflags, $(GTK2)) +GTK3_CFLAGS ?= $(call pkg_cflags, $(GTK3)) +GTK3_LIBS ?= $(call pkg_ldflags, $(GTK3)) + +SNI_SRC_LIST = menu.c sni.c +SNI_EXT_LIST = statusnotifier.c closures.c +SNI_SRC = enums.c $(addprefix $(PATH_SRC)/,$(SNI_SRC_LIST)) $(addprefix $(PATH_EXTRA)/,$(SNI_EXT_LIST)) +OBJ_GTK2 = $(patsubst %.c, $(PATH_BUILD2)/%.o, $(SNI_SRC)) +OBJ_GTK3 = $(patsubst %.c, $(PATH_BUILD3)/%.o, $(SNI_SRC)) + +### FUNCTIONS +define compile + $(CC) $(CFLAGS) $(INCLUDES) $(SNI_CFLAGS) $1 $(abspath $2) -c -o $(abspath $@) +endef +define link + $(CC) $(LDFLAGS) $(abspath $^) $(SNI_LDFLAGS) $1 -o $(abspath $@) +endef + +### TARGETS + +all: gtk3 + +mkenums: enums.c enums.h +enums.h: $(PATH_EXTRA)/enums.h.template $(PATH_EXTRA)/statusnotifier.h + @$(APP_GLIB_MKENUMS) --template $^ > $@ +enums.c: $(PATH_EXTRA)/enums.c.template $(PATH_EXTRA)/statusnotifier.h + @$(APP_GLIB_MKENUMS) --template $^ > $@ + +.PHONY: clean format mkdirs_gtk3 mkdirs_gtk3 +format: + @echo $(abspath $(PATH_SRC)) + @find $(abspath $(PATH_SRC)) -type f -name "*.[c,h]" -print0 | xargs -0 clang-format -i +clean: + @rm -rf $(LIST_CLEAN) + +gtk3: mkdirs_gtk3 mkenums $(PATH_BUILD)/$(OUT_GTK3) +gtk2: mkdirs_gtk2 mkenums $(PATH_BUILD)/$(OUT_GTK2) + +mkdirs_gtk3: + @mkdir -p $(abspath $(PATH_BUILD3)/$(PATH_SRC)) + @mkdir -p $(abspath $(PATH_BUILD3)/$(PATH_EXTRA)) +mkdirs_gtk2: + @mkdir -p $(abspath $(PATH_BUILD2)/$(PATH_SRC)) + @mkdir -p $(abspath $(PATH_BUILD2)/$(PATH_EXTRA)) + +## BUILD TARGETS + +$(PATH_BUILD)/$(OUT_GTK3): $(OBJ_GTK3) + @$(call link, $(GTK3_LIBS)) + +$(PATH_BUILD3)/%.o: $(SNI_SRC) + @$(call compile, $(GTK3_CFLAGS), $(filter %$(@F:%.o=%.c), $^)) + +$(PATH_BUILD)/$(OUT_GTK2): $(OBJ_GTK2) + @$(call link, $(GTK2_LIBS)) + +$(PATH_BUILD2)/%.o: $(SNI_SRC) + @$(call compile, $(GTK2_CFLAGS), $(filter %$(@F:%.o=%.c), $^)) diff -Nru deadbeef-statusnotifier-plugin-1.3.1/README.md deadbeef-statusnotifier-plugin-1.6/README.md --- deadbeef-statusnotifier-plugin-1.3.1/README.md 2020-05-25 00:00:59.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/README.md 2021-06-12 07:53:35.000000000 +0000 @@ -5,27 +5,41 @@ This plugin aims to implement the StatusNotifierItem for DeaDBeeF. It tends to replace default tray icon on DE that supports StatusNotifierIitem protocol. -It also aims to provide tray icon for deadbeef on KDE5/Plasma5, where old xmbedded icons aren't supported anymore. +It also aims to provide tray icon for deadbeef on DE where old xmbedded icons aren't supported anymore, such as KDE Plasma 5, GNOME(3+), Cinnamon, etc. -### Required packages -`cmake` +__WARNING!__ GNOME supported using the [Appindictor Extension](https://github.com/ubuntu/gnome-shell-extension-appindicator) or similar. + +__WARNING!__ Cinnamon supported using the XAppStatusIcons extension -`gtk 2.x` - for gtk 2 version -`gtk 3.x` - for gtk 3 version -`libdbusmenu-glib-0.4` - for dbusmenu -deadbeef development files. +#### Known DE comptibilty bugs +If you know how to fix certain bugs, patches are welcome. +* The window is not restored in Wayland-based environments because Wayland (and GTK3 Wayland backend) does not provide access to top-level window management. Provided the ability to block minimization using the option `Enable minimize on icon click` +* HTML notification tooltip style and icons is only supported by KDE Plasma +* GNOME don't support notifiction tooltips (at least for the Ubuntu Appindicator extension) +* GNOME SNI overlay icons work incorrect (update after refresh icon area) +* Cinnamon don't support SNI overlay icons +* In the new version of KDE Plasma (> = 5.19, Ubuntu 20.10), tooltip icons are not displayed. This is tested on KDE Plasma 5.5 (Ubuntu 16.04) and works correctly. + +### Required packages +* `cmake`(optional) +* `gtk 2.x` - for gtk 2 version +* `gtk 3.x` - for gtk 3 version +* `libdbusmenu-glib-0.4` - for dbusmenu +* deadbeef development files. #### openSUSE -You will need to add [packman](http://packman.links2linux.org/) repository for deadbeef itself (probably you already done this :) ). +You will need to add [packman](http://packman.links2linux.org/) repository for deadbeef itself (probably you already done this :) ). + `sudo zypper in cmake deadbeef-devel libdbusmenu-glib-devel gtk3-devel` #### Fedora -You will need to find any [repository](https://copr.fedorainfracloud.org/coprs/fulltext/?fulltext=deadbeef) with for deadbeef itself and add it to your system (probably you already done this :) ). +You will need to find any [repository](https://copr.fedorainfracloud.org/coprs/fulltext/?fulltext=deadbeef) with for deadbeef itself and add it to your system (probably you already done this :) ). + `sudo yum install cmake deadbeef-devel libdbusmenu-devel gtk3-devel` #### Debian/Ubuntu -You will need to find any [repository](https://launchpad.net/+search?field.text=deadbeef) with for deadbeef itself and add it to your system (probably you already done this :) ). -Package name with development files for deadbeef will depend on selected ppa. +You will need to find any [repository](https://launchpad.net/+search?field.text=deadbeef) with for deadbeef itself and add it to your system (probably you already done this :) ). +Package name with development files for deadbeef will depend on selected ppa. `sudo apt-get install cmake deadbeef-plugins-dev libdbusmenu-glib-dev libgtk-3-dev` @@ -35,26 +49,30 @@ ### How to build +#### With CMake (recommended) +``` Shell mkdir build && cd build cmake -DCMAKE_INSTALL_PREFIX=/usr -DUSE_GTK=OFF .. make make install +``` +#### With Makefile +``` Shell + make +``` +Use target `gtk2` or `gtk3` for separate build. Install target NOT support. Build only gtk3 with `all` target. +__WARNING!__ gtk2 build needed `glib >= 2.24` with `GVariant` data type support. ### Activation -Once the plugin is installed, restart (or start) deadbeef. -By default, this plugin will automatically replace default tray icon. -You can change this behaviour in plugins settings (open deadbeef's preference, select plugins tab, -select StatusNotifier plugin, select settings). - -Note, that by default, this plugin automatically enables "hide tray icon" option in deadbeef's settings (if disabled) -on startup and restores it's value on shutdown. But if shutdown was not clean (appliaction crashed, killed or something like this) -then value for "hide tray icon" won't be restored. +Once the plugin is installed, restart (or start) deadbeef. By default, this plugin will automatically replace default tray icon. You can change this behaviour in plugins settings (open deadbeef's preference, select plugins tab, select StatusNotifier plugin, select settings). -#### Possible cmake options +Note, that by default, this plugin automatically enables "hide tray icon" option in deadbeef's settings (if disabled) on startup and restores it's value on shutdown. But if shutdown was not clean (appliaction crashed, killed or something like this) then value for "hide tray icon" won't be restored. -`-DUSE_GTK` - Whether to build gtk2 verion or not. Default: ON -`-DUSE3_GTK` - Whether to build gtk3 verion or not. Default: ON -`-DCMAKE_INSTALL_PREFIX` - Where to install. Default: `/usr/local` +#### Possible cmake options -`-DLIB_INSTALL_DIR` - Name of system libdir. Default: `lib` +* `-DUSE_GTK` - Whether to build gtk2 verion or not. Default: ON +* `-DUSE_GTK3` - Whether to build gtk3 verion or not. Default: ON +* `-DUSE_CUSTOM` - Use custom (not system) glib-mkenums script. Default: ON +* `-DCMAKE_INSTALL_PREFIX` - Where to install. Default: `/usr/local` +* `-DLIB_INSTALL_DIR` - Name of system libdir. Default: `lib` diff -Nru deadbeef-statusnotifier-plugin-1.3.1/src/menu.c deadbeef-statusnotifier-plugin-1.6/src/menu.c --- deadbeef-statusnotifier-plugin-1.3.1/src/menu.c 2020-05-25 00:00:59.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/src/menu.c 2021-06-12 07:53:35.000000000 +0000 @@ -6,252 +6,414 @@ * * This file is part of deadbeef-statusnotifier-plugin. * - * deadbeef-statusnotifier-plugin is free software: you can 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. + * deadbeef-statusnotifier-plugin is free software: you can 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. * - * deadbeef-statusnotifier-plugin is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. + * deadbeef-statusnotifier-plugin is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. * * You should have received a copy of the GNU General Public License along with * deadbeef-statusnotifier-plugin. If not, see http://www.gnu.org/licenses/ */ - #include "sni.h" -DbusmenuMenuitem *menu; -DbusmenuMenuitem *quit_item; -DbusmenuMenuitem *play_item; -DbusmenuMenuitem *stop_item; -DbusmenuMenuitem *next_item; -DbusmenuMenuitem *prev_item; -DbusmenuMenuitem *pref_item; -DbusmenuMenuitem *random_item; - -DbusmenuMenuitem *pb_menu; -DbusmenuMenuitem *pb_order_linear; -DbusmenuMenuitem *pb_order_shuffle_tracks; -DbusmenuMenuitem *pb_order_random; -DbusmenuMenuitem *pb_order_shuffle_albums; -DbusmenuMenuitem *pb_loop_all; -DbusmenuMenuitem *pb_loop_none; -DbusmenuMenuitem *pb_loop_single; - -GSList *pb_order; -GSList *pb_loop; - -DbusmenuMenuitem* -create_menu_item (gchar *label, gchar *icon_name, SNIContextMenuItemType item_type); - -void -on_quit_activate (DbusmenuMenuitem *menuitem) { - deadbeef->sendmessage (DB_EV_TERMINATE, 0, 0, 0); -} +typedef struct { + DbusmenuMenuitem *menu; // root menu item + DbusmenuMenuitem *item_play; // play button + DbusmenuMenuitem *item_stop; // stop button + DbusmenuMenuitem *item_next; // next button + DbusmenuMenuitem *item_prev; // prev button + DbusmenuMenuitem *item_pref; // preference (settings) button + DbusmenuMenuitem *item_random; // shuffle button + DbusmenuMenuitem *item_show; // show/hide button + DbusmenuMenuitem *item_help; // about button + DbusmenuMenuitem *item_quit; // quit button + + DbusmenuMenuitem *pb_menu; // playback menu root item + /* Shuffle menu */ + struct { + DbusmenuMenuitem *item_linear; // DDB_SHUFFLE_OFF + DbusmenuMenuitem *item_shuffle_tracks; // DDB_SHUFFLE_TRACKS + DbusmenuMenuitem *item_random; // DDB_SHUFFLE_RANDOM + DbusmenuMenuitem *item_shuffle_albums; // DDB_SHUFFLE_ALBUMS + + // Private + DbusmenuMenuitem *active_now; // now playback state + } pb_order; + /* Repeat menu */ + struct { + DbusmenuMenuitem *item_all; // DDB_REPEAT_ALL + DbusmenuMenuitem *item_none; // DDB_REPEAT_NONE + DbusmenuMenuitem *item_single; // DDB_REPEAT_SINGLE + + // Private + DbusmenuMenuitem *active_now; // now playback state + } pb_loop; + + uintptr_t mlock; +} sni_menu_t; + +static sni_menu_t *sm = NULL; +static DB_functions_t *deadbeef; + +/* Generate actoion procedure name */ +#define SNI_CALLBACK_NAME(item) on_##item##_activate +/* Menu item callback declaration */ +#define SNI_MENU_ITEM_CALLBACK(item) void SNI_CALLBACK_NAME(item)(DbusmenuMenuitem * menuitem) + +/* Menu item simple messaging function macro */ +static inline void +sni_callback_message(unsigned msg) { + if (deadbeef == NULL) + return; + deadbeef->sendmessage(msg, 0, 0, 0); +} +#define SNI_MENU_ITEM_MESSAGE(item, MSG) \ + SNI_MENU_ITEM_CALLBACK(item) { \ + (void *)menuitem; /* unused messages cleanup */ \ + sni_callback_message(MSG); \ + } -void -on_play_activate (DbusmenuMenuitem *menuitem) { - deadbeef_toggle_play_pause (); +SNI_MENU_ITEM_MESSAGE(quit, DB_EV_TERMINATE); +SNI_MENU_ITEM_MESSAGE(play, DB_EV_TOGGLE_PAUSE); +SNI_MENU_ITEM_MESSAGE(stop, DB_EV_STOP); +SNI_MENU_ITEM_MESSAGE(next, DB_EV_NEXT); +SNI_MENU_ITEM_MESSAGE(prev, DB_EV_PREV); +SNI_MENU_ITEM_MESSAGE(random, DB_EV_PLAY_RANDOM); + +SNI_MENU_ITEM_CALLBACK(show) { deadbeef_toogle_window(); } + +SNI_MENU_ITEM_CALLBACK(pref) { deadbeef_preferences_activate(); } + +SNI_MENU_ITEM_CALLBACK(help) { deadbeef_help_activate(); } + +SNI_MENU_ITEM_CALLBACK(playback_order) { + DB_functions_t *deadbeef = deadbeef_get_instance(); + if (deadbeef == NULL) + return; + guint32 val = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(menuitem), "pb_data")); + deadbeef->conf_set_int("playback.order", val); + deadbeef->sendmessage(DB_EV_CONFIGCHANGED, 0, 0, 0); +} + +SNI_MENU_ITEM_CALLBACK(playback_loop) { + DB_functions_t *deadbeef = deadbeef_get_instance(); + if (deadbeef == NULL) + return; + guint32 val = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(menuitem), "pb_data")); + deadbeef->conf_set_int("playback.loop", val); + deadbeef->sendmessage(DB_EV_CONFIGCHANGED, 0, 0, 0); +} + +static inline void +change_toogle_items(DbusmenuMenuitem *old, DbusmenuMenuitem *new) { + if (old) + dbusmenu_menuitem_property_set_int(old, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); + dbusmenu_menuitem_property_set_int(new, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED); } void -on_stop_activate (DbusmenuMenuitem *menuitem) { - deadbeef->sendmessage (DB_EV_STOP, 0, 0, 0); +update_window_controls(void) { + if (deadbeef->conf_get_int(SNI_OPTION_MENU_TOGGLE, 1) == 0) + return; + if (sni_flag_get(SNI_FLAG_HIDDEN) && !deadbeef_window_is_visible()) + return; + if ((!sni_flag_get(SNI_FLAG_HIDDEN)) && deadbeef_window_is_visible()) + return; + + if (sni_flag_get(SNI_FLAG_HIDDEN)) { + g_debug("%s\n", "Update controls: SHOW"); + dbusmenu_menuitem_property_set(sm->item_show, DBUSMENU_MENUITEM_PROP_LABEL, + _("Hide Player Window")); + dbusmenu_menuitem_property_set(sm->item_show, DBUSMENU_MENUITEM_PROP_ICON_NAME, "go-down"); + sni_flag_unset(SNI_FLAG_HIDDEN); + } else { + g_debug("%s\n", "Update controls: HIDE"); + dbusmenu_menuitem_property_set(sm->item_show, DBUSMENU_MENUITEM_PROP_LABEL, + _("Show Player Window")); + dbusmenu_menuitem_property_set(sm->item_show, DBUSMENU_MENUITEM_PROP_ICON_NAME, "go-up"); + sni_flag_set(SNI_FLAG_HIDDEN); + } } -void -on_next_activate (DbusmenuMenuitem *menuitem) { - deadbeef->sendmessage (DB_EV_NEXT, 0, 0, 0); +static inline void +update_playback_orders(const guint32 state) { + DbusmenuMenuitem *item_changed = NULL; + switch (state) { + case DDB_SHUFFLE_OFF: + item_changed = sm->pb_order.item_linear; + break; + case DDB_SHUFFLE_TRACKS: + item_changed = sm->pb_order.item_shuffle_tracks; + break; + case DDB_SHUFFLE_RANDOM: + item_changed = sm->pb_order.item_random; + break; + case DDB_SHUFFLE_ALBUMS: + item_changed = sm->pb_order.item_shuffle_albums; + } + if (item_changed != sm->pb_order.active_now) { + change_toogle_items(sm->pb_order.active_now, item_changed); + sm->pb_order.active_now = item_changed; + } } -void -on_prev_activate (DbusmenuMenuitem *menuitem) { - deadbeef->sendmessage (DB_EV_PREV, 0, 0, 0); +static inline void +update_playback_loops(const guint32 state) { + DbusmenuMenuitem *item_changed = NULL; + switch (state) { + case DDB_REPEAT_ALL: + item_changed = sm->pb_loop.item_all; + break; + case DDB_REPEAT_OFF: + item_changed = sm->pb_loop.item_none; + break; + case DDB_REPEAT_SINGLE: + item_changed = sm->pb_loop.item_single; + break; + } + if (item_changed != sm->pb_loop.active_now) { + change_toogle_items(sm->pb_loop.active_now, item_changed); + sm->pb_loop.active_now = item_changed; + } } void -on_random_activate (DbusmenuMenuitem *menuitem) { - deadbeef->sendmessage (DB_EV_PLAY_RANDOM, 0, 0, 0); -} +update_playback_controls(void) { + if (deadbeef->conf_get_int(SNI_OPTION_MENU_PLAYBACK, 1) == 0) + return; + if ((sm == NULL) || (sm->pb_menu == NULL)) + return; -void -on_pref_activate (DbusmenuMenuitem *menuitem) { - deadbeef_preferences_activate (); -} + deadbeef->mutex_lock(sm->mlock); -void -on_playback_order_activate (DbusmenuMenuitem *menuitem) { - guint32 val = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (menuitem), "pb_data")); - deadbeef->conf_set_int ("playback.order", val); - deadbeef->sendmessage (DB_EV_CONFIGCHANGED, 0, 0, 0); -} + update_playback_orders(deadbeef->conf_get_int("playback.order", 0)); + update_playback_loops(deadbeef->conf_get_int("playback.loop", 0)); -void -on_playback_loop_activate (DbusmenuMenuitem *menuitem) { - guint32 val = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (menuitem), "pb_data")); - deadbeef->conf_set_int ("playback.loop", val); - deadbeef->sendmessage (DB_EV_CONFIGCHANGED, 0, 0, 0); + deadbeef->mutex_unlock(sm->mlock); } void -update_playback_controls (void) { - guint32 order = deadbeef->conf_get_int ("playback.order", 0); - guint32 loop = deadbeef->conf_get_int ("playback.loop", 0); - - void check_list (gpointer item, gpointer data) { - guint32 val = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (item), "pb_data")); - dbusmenu_menuitem_property_set_int (DBUSMENU_MENUITEM (item), DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, - val == GPOINTER_TO_UINT (data) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); - } +update_play_controls(int play) { - g_slist_foreach (pb_order, check_list, GUINT_TO_POINTER (order)); - g_slist_foreach (pb_loop, check_list, GUINT_TO_POINTER (loop)); -} + static int play_state = SNI_STATE_TOOGLE_PAUSE; -DbusmenuMenuitem * -get_context_menu (void) { - if (menu) - return menu; - - menu = create_menu_item (_("Deadbeef"), NULL, SNI_MENU_ITEM_TYPE_COMMON); - dbusmenu_menuitem_set_root (menu, TRUE); + if (play_state == play) + return; - pb_menu = create_menu_item (_("Playback"), NULL, SNI_MENU_ITEM_TYPE_COMMON); + deadbeef->mutex_lock(sm->mlock); - g_object_ref (menu); - - /** Common media controls **/ - - quit_item = create_menu_item (_("Quit"), "application-exit", SNI_MENU_ITEM_TYPE_COMMON); - play_item = create_menu_item (_("Play"), "media-playback-start", SNI_MENU_ITEM_TYPE_COMMON); - stop_item = create_menu_item (_("Stop"), "media-playback-stop", SNI_MENU_ITEM_TYPE_COMMON); - prev_item = create_menu_item (_("Previous"), "media-skip-backward", SNI_MENU_ITEM_TYPE_COMMON); - next_item = create_menu_item (_("Next"), "media-skip-forward", SNI_MENU_ITEM_TYPE_COMMON); - random_item = create_menu_item (_("Play Random"), NULL, SNI_MENU_ITEM_TYPE_COMMON); - - g_signal_connect (quit_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_quit_activate), NULL); - g_signal_connect (play_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_play_activate), NULL); - g_signal_connect (stop_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_stop_activate), NULL); - g_signal_connect (prev_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_prev_activate), NULL); - g_signal_connect (next_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_next_activate), NULL); - g_signal_connect (random_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_random_activate), NULL); - - dbusmenu_menuitem_child_append (menu, play_item); - dbusmenu_menuitem_child_append (menu, stop_item); - dbusmenu_menuitem_child_append (menu, prev_item); - dbusmenu_menuitem_child_append (menu, next_item); - dbusmenu_menuitem_child_append (menu, random_item); - dbusmenu_menuitem_child_append (menu, create_menu_item (NULL, NULL, SNI_MENU_ITEM_TYPE_SEPARATOR)); + play_state = play; + switch (play) { + case SNI_STATE_TOOGLE_PLAY: + dbusmenu_menuitem_property_set(sm->item_play, DBUSMENU_MENUITEM_PROP_LABEL, _("Pause")); + dbusmenu_menuitem_property_set(sm->item_play, DBUSMENU_MENUITEM_PROP_ICON_NAME, + "media-playback-pause"); + dbusmenu_menuitem_property_set_bool(sm->item_stop, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + break; + case SNI_STATE_TOOGLE_STOP: + dbusmenu_menuitem_property_set(sm->item_play, DBUSMENU_MENUITEM_PROP_LABEL, _("Play")); + dbusmenu_menuitem_property_set(sm->item_play, DBUSMENU_MENUITEM_PROP_ICON_NAME, + "media-playback-start"); + dbusmenu_menuitem_property_set_bool(sm->item_stop, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + break; + case SNI_STATE_TOOGLE_PAUSE: + dbusmenu_menuitem_property_set(sm->item_play, DBUSMENU_MENUITEM_PROP_LABEL, _("Play")); + dbusmenu_menuitem_property_set(sm->item_play, DBUSMENU_MENUITEM_PROP_ICON_NAME, + "media-playback-start"); + dbusmenu_menuitem_property_set_bool(sm->item_stop, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + break; + } - /** Playback settings controls **/ - /** Playback order **/ + deadbeef->mutex_unlock(sm->mlock); +} - pb_order_linear = create_menu_item (_("Linear"), NULL, SNI_MENU_ITEM_TYPE_RADIO); - g_object_set_data (G_OBJECT (pb_order_linear), "pb_data", GUINT_TO_POINTER (PLAYBACK_ORDER_LINEAR)); - pb_order = g_slist_append (pb_order, pb_order_linear); +static DbusmenuMenuitem * +create_menu_item(gchar *label, gchar *icon_name, SNIContextMenuItemType item_type) { + DbusmenuMenuitem *item; - pb_order_shuffle_tracks = create_menu_item (_("Shuffle tracks"), NULL, SNI_MENU_ITEM_TYPE_RADIO); - g_object_set_data (G_OBJECT (pb_order_shuffle_tracks), "pb_data", GUINT_TO_POINTER (PLAYBACK_ORDER_SHUFFLE_TRACKS)); - pb_order = g_slist_append (pb_order, pb_order_shuffle_tracks); + item = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, label); - pb_order_shuffle_albums = create_menu_item (_("Shuffle albums"), NULL, SNI_MENU_ITEM_TYPE_RADIO); - g_object_set_data (G_OBJECT (pb_order_shuffle_albums), "pb_data", GUINT_TO_POINTER (PLAYBACK_ORDER_SHUFFLE_ALBUMS)); - pb_order = g_slist_append (pb_order, pb_order_shuffle_albums); + switch (item_type) { + case SNI_MENU_ITEM_TYPE_SEPARATOR: + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TYPE, "separator"); + break; + case SNI_MENU_ITEM_TYPE_RADIO: + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, + DBUSMENU_MENUITEM_TOGGLE_RADIO); + break; + case SNI_MENU_ITEM_TYPE_CHECKBOX: + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, + DBUSMENU_MENUITEM_TOGGLE_CHECK); + break; + case SNI_MENU_ITEM_TYPE_COMMON: + default: + break; + } - pb_order_random = create_menu_item (_("Random"), NULL, SNI_MENU_ITEM_TYPE_RADIO); - g_object_set_data (G_OBJECT (pb_order_random), "pb_data", GUINT_TO_POINTER (PLAYBACK_ORDER_RANDOM)); - pb_order = g_slist_append (pb_order, pb_order_random); + if (icon_name) + dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_ICON_NAME, icon_name); - /** Playback loop **/ + dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - pb_loop_all = create_menu_item (_("Loop all"), NULL, SNI_MENU_ITEM_TYPE_RADIO); - g_object_set_data (G_OBJECT (pb_loop_all), "pb_data", GUINT_TO_POINTER (PLAYBACK_MODE_LOOP_ALL)); - pb_loop = g_slist_append (pb_loop, pb_loop_all); + return item; +} - pb_loop_single = create_menu_item (_("Loop single song"), NULL, SNI_MENU_ITEM_TYPE_RADIO); - g_object_set_data (G_OBJECT (pb_loop_single), "pb_data", GUINT_TO_POINTER (PLAYBACK_MODE_LOOP_SINGLE)); - pb_loop = g_slist_append (pb_loop, pb_loop_single); +#define CREATE_SEPARATOR_ITEM(menu) \ + dbusmenu_menuitem_child_append(menu, \ + create_menu_item(NULL, NULL, SNI_MENU_ITEM_TYPE_SEPARATOR)); + +#define CREATE_PLAYBACK_ITEM(menu, name, label, mode, callback) \ + do { \ + sm->pb_##menu.item_##name = create_menu_item(label, NULL, SNI_MENU_ITEM_TYPE_RADIO); \ + g_object_set_data(G_OBJECT(sm->pb_##menu.item_##name), "pb_data", GUINT_TO_POINTER(mode)); \ + g_signal_connect(sm->pb_##menu.item_##name, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, \ + G_CALLBACK(callback), NULL); \ + \ + dbusmenu_menuitem_child_append(sm->pb_menu, sm->pb_##menu.item_##name); \ + } while (0) + +static inline DbusmenuMenuitem * +create_menu_playback(void) { + sm->pb_menu = create_menu_item(_("Playback"), NULL, SNI_MENU_ITEM_TYPE_COMMON); + + CREATE_PLAYBACK_ITEM(order, linear, _("Shuffle - Off"), PLAYBACK_ORDER_LINEAR, + SNI_CALLBACK_NAME(playback_order)); + CREATE_PLAYBACK_ITEM(order, shuffle_tracks, _("Shuffle - Tracks"), + PLAYBACK_ORDER_SHUFFLE_TRACKS, SNI_CALLBACK_NAME(playback_order)); + CREATE_PLAYBACK_ITEM(order, shuffle_albums, _("Shuffle - Albums"), + PLAYBACK_ORDER_SHUFFLE_ALBUMS, SNI_CALLBACK_NAME(playback_order)); + CREATE_PLAYBACK_ITEM(order, random, _("Shuffle - Random Tracks"), PLAYBACK_ORDER_RANDOM, + SNI_CALLBACK_NAME(playback_order)); + + CREATE_SEPARATOR_ITEM(sm->pb_menu); + + CREATE_PLAYBACK_ITEM(loop, all, _("Repeat - All"), PLAYBACK_MODE_LOOP_ALL, + SNI_CALLBACK_NAME(playback_loop)); + CREATE_PLAYBACK_ITEM(loop, single, _("Repeat - Single Track"), PLAYBACK_MODE_LOOP_SINGLE, + SNI_CALLBACK_NAME(playback_loop)); + CREATE_PLAYBACK_ITEM(loop, none, _("Repeat - Off"), PLAYBACK_MODE_NOLOOP, + SNI_CALLBACK_NAME(playback_loop)); + + update_playback_controls(); + + return sm->pb_menu; +} + +#undef CREATE_PLAYBACK_ITEM + +#define CREATE_CONTEXT_ITEM(name, label, icon, callback) \ + do { \ + sm->item_##name = create_menu_item(label, icon, SNI_MENU_ITEM_TYPE_COMMON); \ + g_signal_connect(sm->item_##name, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, \ + G_CALLBACK(callback), NULL); \ + dbusmenu_menuitem_child_append(sm->menu, sm->item_##name); \ + } while (0) - pb_loop_none = create_menu_item (_("Don't loop"), NULL, SNI_MENU_ITEM_TYPE_RADIO); - g_object_set_data (G_OBJECT (pb_loop_none), "pb_data", GUINT_TO_POINTER (PLAYBACK_MODE_NOLOOP)); - pb_loop = g_slist_append (pb_loop, pb_loop_none); +static inline DbusmenuMenuitem * +create_context_menu(void) { - update_playback_controls (); + sm->menu = create_menu_item(_("Deadbeef"), NULL, SNI_MENU_ITEM_TYPE_COMMON); + dbusmenu_menuitem_set_root(sm->menu, TRUE); - g_signal_connect (pb_order_linear, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_playback_order_activate), NULL); - g_signal_connect (pb_order_shuffle_tracks, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_playback_order_activate), NULL); - g_signal_connect (pb_order_shuffle_albums, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_playback_order_activate), NULL); - g_signal_connect (pb_order_random, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_playback_order_activate), NULL); - g_signal_connect (pb_loop_all, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_playback_loop_activate), NULL); - g_signal_connect (pb_loop_single, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_playback_loop_activate), NULL); - g_signal_connect (pb_loop_none, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_playback_loop_activate), NULL); + /** Common media controls **/ - dbusmenu_menuitem_child_append (pb_menu, pb_order_linear); - dbusmenu_menuitem_child_append (pb_menu, pb_order_shuffle_tracks); - dbusmenu_menuitem_child_append (pb_menu, pb_order_shuffle_albums); - dbusmenu_menuitem_child_append (pb_menu, pb_order_random); - dbusmenu_menuitem_child_append (pb_menu, create_menu_item (NULL, NULL, SNI_MENU_ITEM_TYPE_SEPARATOR)); - dbusmenu_menuitem_child_append (pb_menu, pb_loop_all); - dbusmenu_menuitem_child_append (pb_menu, pb_loop_single); - dbusmenu_menuitem_child_append (pb_menu, pb_loop_none); + CREATE_CONTEXT_ITEM(play, _("Play"), "media-playback-start", SNI_CALLBACK_NAME(play)); + CREATE_CONTEXT_ITEM(stop, _("Stop"), "media-playback-stop", SNI_CALLBACK_NAME(stop)); + CREATE_CONTEXT_ITEM(prev, _("Previous"), "media-skip-backward", SNI_CALLBACK_NAME(prev)); + CREATE_CONTEXT_ITEM(next, _("Next"), "media-skip-forward", SNI_CALLBACK_NAME(next)); + CREATE_CONTEXT_ITEM(random, _("Play Random"), NULL, SNI_CALLBACK_NAME(random)); - dbusmenu_menuitem_child_append (menu, pb_menu); - dbusmenu_menuitem_child_append (menu, create_menu_item (NULL, NULL, SNI_MENU_ITEM_TYPE_SEPARATOR)); + CREATE_SEPARATOR_ITEM(sm->menu); - if (deadbeef_preferences_available ()) { - pref_item = create_menu_item (_("Preferences"), "configure", SNI_MENU_ITEM_TYPE_COMMON); - g_signal_connect (pref_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK (on_pref_activate), NULL); - dbusmenu_menuitem_child_append (menu, pref_item); + /** Playback settings controls **/ + if (deadbeef->conf_get_int(SNI_OPTION_MENU_PLAYBACK, 1)) { + dbusmenu_menuitem_child_append(sm->menu, create_menu_playback()); + CREATE_SEPARATOR_ITEM(sm->menu); } - dbusmenu_menuitem_child_append (menu, quit_item); - - return menu; -} - -DbusmenuMenuitem* -create_menu_item (gchar *label, gchar *icon_name, SNIContextMenuItemType item_type) { - DbusmenuMenuitem *item; - - item = dbusmenu_menuitem_new (); - dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_LABEL, label); - - if (item_type == SNI_MENU_ITEM_TYPE_SEPARATOR) - dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, "separator"); - else if (item_type == SNI_MENU_ITEM_TYPE_RADIO) - dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_RADIO); - else if (item_type == SNI_MENU_ITEM_TYPE_CHECKBOX) - dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_CHECK); + if (deadbeef->conf_get_int(SNI_OPTION_MENU_TOGGLE, 1)) { + if (deadbeef->conf_get_int("gtkui.hide_tray_icon", 0) == 0) { + CREATE_CONTEXT_ITEM(show, _("Show Player Window"), "go-up", SNI_CALLBACK_NAME(show)); + } else { + CREATE_CONTEXT_ITEM(show, _("Hide Player Window"), "go-down", SNI_CALLBACK_NAME(show)); + } + } + if (deadbeef_preferences_available()) + CREATE_CONTEXT_ITEM(pref, _("Preferences"), "preferences-system", SNI_CALLBACK_NAME(pref)); - if (icon_name) - dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_ICON_NAME, icon_name); + if (deadbeef_help_available()) + CREATE_CONTEXT_ITEM(help, _("Help"), "help-contents", SNI_CALLBACK_NAME(help)); - dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); - dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + CREATE_SEPARATOR_ITEM(sm->menu); + CREATE_CONTEXT_ITEM(quit, _("Quit"), "application-exit", SNI_CALLBACK_NAME(quit)); - return item; + return sm->menu; } -DbusmenuMenuitem * -get_context_menu_item (SNIContextMenuItem item) { - get_context_menu (); +#undef CREATE_CONTEXT_ITEM +#undef CREATE_SEPARATOR_ITEM - switch (item) { +DbusmenuMenuitem * +get_context_menu_item(SNIContextMenuItem item) { + if (sm) { + switch (item) { case SNI_MENU_ITEM_PLAY: - return play_item; + return sm->item_play; case SNI_MENU_ITEM_STOP: - return stop_item; + return sm->item_stop; case SNI_MENU_ITEM_NEXT: - return next_item; + return sm->item_next; case SNI_MENU_ITEM_PREV: - return prev_item; + return sm->item_prev; case SNI_MENU_ITEM_RANDOM: - return random_item; + return sm->item_random; case SNI_MENU_ITEM_QUIT: - return quit_item; + return sm->item_quit; + } } return NULL; } + +DbusmenuMenuitem * +get_context_menu(void) { + return (sm) ? sm->menu : NULL; +} + +int +sni_context_menu_create(void) { + deadbeef = deadbeef_get_instance(); + if (deadbeef == NULL) + return -1; + + sm = calloc(1, sizeof(sni_menu_t)); + if (sm == NULL) + return -1; + + sm->mlock = deadbeef->mutex_create(); + if (sm->mlock) { + create_context_menu(); + } else { + sni_free_null(sm); + return -1; + } + + return 0; +} + +void +sni_context_menu_release(void) { + if (sm) { + deadbeef->mutex_free(sm->mlock); + sni_free_null(sm); + } +} diff -Nru deadbeef-statusnotifier-plugin-1.3.1/src/sni.c deadbeef-statusnotifier-plugin-1.6/src/sni.c --- deadbeef-statusnotifier-plugin-1.3.1/src/sni.c 2020-05-25 00:00:59.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/src/sni.c 2021-06-12 07:53:35.000000000 +0000 @@ -6,458 +6,419 @@ * * This file is part of deadbeef-statusnotifier-plugin. * - * deadbeef-statusnotifier-plugin is free software: you can 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. + * deadbeef-statusnotifier-plugin is free software: you can 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. * - * deadbeef-statusnotifier-plugin is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. + * deadbeef-statusnotifier-plugin is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. * * You should have received a copy of the GNU General Public License along with * deadbeef-statusnotifier-plugin. If not, see http://www.gnu.org/licenses/ */ #include "sni.h" -#include "x11-force-focus.h" - - -#define TOOLTIP_FORMAT_WO_YEAR "%s"\ - "Title: %s
"\ - "Artist: %s
"\ - "Album: %s" -#define TOOLTIP_FORMAT "%s"\ - "Title: %s
"\ - "Artist: %s
"\ - "Album: %s [%s]" -#define TOOLTIP_MAX_LENGTH 1000 - -static gboolean auto_activated = FALSE; +#include static StatusNotifier *icon = NULL; static DB_plugin_action_t *toggle_mainwindow_action = NULL; static DB_plugin_action_t *preferences_action = NULL; +static DB_plugin_action_t *help_action = NULL; -void sni_update_status (); - -void -on_activate_requested (void) { - if (toggle_mainwindow_action && 0) { - toggle_mainwindow_action->callback2 (toggle_mainwindow_action, -1); - } - else { - GtkWidget *mainwin = gtkui_plugin->get_mainwin (); - GdkWindow *gdk_window = gtk_widget_get_window (mainwin); - - int iconified = gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_ICONIFIED; - if (gtk_widget_get_visible (mainwin) && !iconified) { - gtk_widget_hide (mainwin); - } - else { - if (iconified) { - gtk_window_deiconify (GTK_WINDOW (mainwin)); - } - else { - gtk_window_present (GTK_WINDOW (mainwin)); - } - gdk_x11_window_force_focus (gdk_window, 0); - } - } +static DB_functions_t *deadbeef = NULL; +static ddb_gtkui_t *gtkui_plugin; +static DB_misc_t plugin; + +DB_functions_t * +deadbeef_get_instance(void) { + return deadbeef; } void -on_sec_activate_requested (void) { - deadbeef_toggle_play_pause (); -} +deadbeef_toggle_play_pause(void); -void -on_scroll_requested (StatusNotifier *sn, - int diff, - StatusNotifierScrollOrientation direction) -{ - float vol = deadbeef->volume_get_db (); - int sens = deadbeef->conf_get_int ("gtkui.tray_volume_sensitivity", 1); +#include "sni_flags.c" +#include "sni_upd.c" +#include "sni_timer.c" +#include "x11-force-focus.c" - if (diff > 0) { - vol += sens; - } - else { - vol -= sens; - } +gboolean +deadbeef_window_is_visible(void) { + GtkWidget *mainwin = gtkui_plugin->get_mainwin(); + GdkWindow *gdk_window = gtk_widget_get_window(mainwin); - if (vol > 0) { - vol = 0; - } - else if (vol < deadbeef->volume_get_min_db ()) { - vol = deadbeef->volume_get_min_db (); - } + int iconified = gdk_window_get_state(gdk_window) & GDK_WINDOW_STATE_ICONIFIED; - deadbeef->volume_set_db (vol); + return gtk_widget_get_visible(mainwin) && !iconified; } void -sni_enable (int enable) { - if ((icon && enable) || (!icon && !enable)) - return; - - if (enable && !icon) { - icon = status_notifier_new_from_icon_name ("deadbeef", STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS, "deadbeef"); - status_notifier_set_status (icon, STATUS_NOTIFIER_STATUS_ACTIVE); - status_notifier_set_title (icon, "DeaDBeeF"); - status_notifier_set_context_menu (icon, get_context_menu ()); - - g_signal_connect (icon, "activate", (GCallback) on_activate_requested, NULL); - g_signal_connect (icon, "secondary-activate", (GCallback) on_sec_activate_requested, NULL); - g_signal_connect (icon, "scroll", (GCallback) on_scroll_requested, NULL); - - status_notifier_register (icon); - sni_update_status (); +deadbeef_toogle_window(void) { + GtkWidget *mainwin = gtkui_plugin->get_mainwin(); + GdkWindow *gdk_window = gtk_widget_get_window(mainwin); + + if (toggle_mainwindow_action) { + toggle_mainwindow_action->callback2(toggle_mainwindow_action, -1); + } else { + int iconified = gdk_window_get_state(gdk_window) & GDK_WINDOW_STATE_ICONIFIED; + if (gtk_widget_get_visible(mainwin) && !iconified) { + gtk_widget_hide(mainwin); + } else { + (iconified) ? gtk_window_deiconify(GTK_WINDOW(mainwin)) + : gtk_window_present(GTK_WINDOW(mainwin)); + } + gtk_window_move(GTK_WINDOW(mainwin), deadbeef->conf_get_int("mainwin.geometry.x", 0), + deadbeef->conf_get_int("mainwin.geometry.y", 0)); } - else { - g_object_unref (icon); - icon = NULL; + + if (gtk_widget_get_visible(mainwin)) { +#if defined(GDK_WINDOWING_WAYLAND) + GdkDisplay *display = gdk_display_get_default(); + if (GDK_IS_X11_DISPLAY(display)) +#endif + gdk_x11_window_force_focus(gdk_window, 0); } } +static void +on_activate_requested(void) { + GtkWidget *mainwin = gtkui_plugin->get_mainwin(); -void -sni_toggle_play_pause (int play) { - static int play_pause_state = 1; - DbusmenuMenuitem *play_item; + if (deadbeef->conf_get_int(SNI_OPTION_ICON_MINIMIZE, 1) == 0) { + if (gtk_widget_get_visible(mainwin)) + return; + } + deadbeef_toogle_window(); +} - if ((play_pause_state && play) || (!play_pause_state && !play)) - return; +static void +on_sec_activate_requested(void) { + deadbeef_toggle_play_pause(); +} - play_item = get_context_menu_item (SNI_MENU_ITEM_PLAY); +static void +on_scroll_requested(StatusNotifier *sn, int diff, StatusNotifierScrollOrientation direction) { + if (deadbeef->conf_get_int(SNI_OPTION_VOLUME_HORIZONTAL, 1)) + if (direction == STATUS_NOTIFIER_SCROLL_ORIENTATION_HORIZONTAL) + return; - if (play_pause_state && !play) { - dbusmenu_menuitem_property_set (play_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Pause")); - dbusmenu_menuitem_property_set (play_item, DBUSMENU_MENUITEM_PROP_ICON_NAME, "media-playback-pause"); + if (deadbeef->conf_get_int(SNI_OPTION_VOLUME_INVERSE, 0)) + diff *= -1; - play_pause_state = 0; + float vol = deadbeef->volume_get_db(); + int sens = deadbeef->conf_get_int("gtkui.tray_volume_sensitivity", 1); + + if (diff) { + vol = (diff > 0) ? vol + sens : vol - sens; + } + if (vol > 0) { + vol = 0; + } else if (vol < deadbeef->volume_get_min_db()) { + vol = deadbeef->volume_get_min_db(); } - else { - dbusmenu_menuitem_property_set (play_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Play")); - dbusmenu_menuitem_property_set (play_item, DBUSMENU_MENUITEM_PROP_ICON_NAME, "media-playback-start"); - play_pause_state = 1; + deadbeef->volume_set_db(vol); +} + +/* Protection against manual configuration changes */ +static inline int +get_gtkui_refresh_rate(void) { + int fps = deadbeef->conf_get_int("gtkui.refresh_rate", 10); + if (fps < 1) { + fps = 1; + } else if (fps > 30) { + fps = 30; } + return fps; } -void _sni_update_tooltip (void *user_date); +static void +callback_wait_notifier_register(void *ctx) { + StatusNotifierState state = STATUS_NOTIFIER_STATE_NOT_REGISTERED; -void -sni_update_tooltip (int state) { - if (!icon) + StatusNotifier *sni_ctx = (StatusNotifier *)ctx; + if (sni_ctx == NULL) return; - g_debug("sni_update_tooltip, status: %d", state); - DB_output_t *output; - output = deadbeef->get_output (); - - if (output) { - if (state < 0) - state = output->state (); - - switch (state) { - case OUTPUT_STATE_STOPPED: - status_notifier_set_tooltip (icon, "deadbeef", "DeaDBeeF", _("Playback stopped")); - break; - case OUTPUT_STATE_PAUSED: - case OUTPUT_STATE_PLAYING: - { - DB_playItem_t *track = deadbeef->streamer_get_playing_track (); - static gchar *ns = NULL; - if (!ns) - ns = _("not specified"); - - if (!track) { - status_notifier_set_tooltip (icon, "deadbeef", "DeaDBeeF", _("Playing")); - break; - } - - int64_t duration = (int64_t)deadbeef->pl_get_item_duration (track) * 1000000; - const char *album = deadbeef->pl_find_meta (track, "album"); - const char *albumArtist = deadbeef->pl_find_meta (track, "albumartist"); - if (albumArtist == NULL) - albumArtist = deadbeef->pl_find_meta (track, "album artist"); - if (albumArtist == NULL) - albumArtist = deadbeef->pl_find_meta (track, "band"); - const char *artist = deadbeef->pl_find_meta (track, "artist"); - const char *date = deadbeef->pl_find_meta_raw (track, "year"); - const char *title = deadbeef->pl_find_meta (track, "title"); - const char *trackNumber = deadbeef->pl_find_meta (track, "track"); - - gchar *escaped_title = title ? g_markup_escape_text (title, -1) : NULL; - gchar *escaped_artist = (artist ? artist : albumArtist) ? g_markup_escape_text (artist ? artist : albumArtist, -1) : NULL; - gchar *escaped_album = album ? g_markup_escape_text (album, -1) : NULL; - gchar *escaped_date = date ? g_markup_escape_text (date, -1) : NULL; - - gchar title_body[TOOLTIP_MAX_LENGTH]; - date ? - g_snprintf (title_body, TOOLTIP_MAX_LENGTH, _(TOOLTIP_FORMAT), state == OUTPUT_STATE_PAUSED ? _("Playback paused
\n") : "", - escaped_title ? escaped_title : ns, - escaped_artist ? escaped_artist : ns, - escaped_album ? escaped_album : ns, - escaped_date) : - g_snprintf (title_body, TOOLTIP_MAX_LENGTH, _(TOOLTIP_FORMAT_WO_YEAR), state == OUTPUT_STATE_PAUSED ? _("Playback paused
\n") : "", - escaped_title ? escaped_title : ns, - escaped_artist ? escaped_artist : ns, - escaped_album ? escaped_album : ns); - - g_free (escaped_title); - g_free (escaped_artist); - g_free (escaped_album); - g_free (escaped_date); - - g_debug("Going to query coverart"); -#if (DDB_GTKUI_API_LEVEL >= 202) - GdkPixbuf * buf = gtkui_plugin->get_cover_art_primary (deadbeef->pl_find_meta (track, ":URI"), artist, album, 128, NULL, NULL); -#else - GdkPixbuf * buf = gtkui_plugin->get_cover_art_pixbuf (deadbeef->pl_find_meta (track, ":URI"), artist, album, 128, NULL, NULL); -#endif - g_debug("Got GdbPixbuf: %d", buf); - if (!buf) { - buf = gtkui_plugin->cover_get_default_pixbuf (); - - if (buf) - status_notifier_set_from_pixbuf (icon, STATUS_NOTIFIER_TOOLTIP_ICON, buf); - else - status_notifier_set_from_icon_name (icon, STATUS_NOTIFIER_TOOLTIP_ICON, "deadbeef"); - } - else - status_notifier_set_from_pixbuf (icon, STATUS_NOTIFIER_TOOLTIP_ICON, buf); + status_notifier_register(sni_ctx); - status_notifier_set_tooltip_body (icon, title_body); - - deadbeef->pl_item_unref (track); - break; - } + uint32_t wait_time = deadbeef->conf_get_int(SNI_OPTION_TIMEOUT, 30); + for (uint32_t i = 0; i < wait_time; i++) { + state = status_notifier_get_state(sni_ctx); + if (state == STATUS_NOTIFIER_STATE_REGISTERED) { + + sni_flag_set(SNI_FLAG_LOADED); + sni_timer_init(icon, 1000 / get_gtkui_refresh_rate()); + + deadbeef->log_detailed((DB_plugin_t *)(&plugin), DDB_LOG_LAYER_INFO, "%s: %s\n", + "Status notifier register success", + status_notifier_get_id(sni_ctx)); + return; } + if (state == STATUS_NOTIFIER_STATE_FAILED) { + deadbeef->log_detailed((DB_plugin_t *)(&plugin), DDB_LOG_LAYER_DEFAULT, "%s: %s\n", + "Status notifier register failed", + status_notifier_get_id(sni_ctx)); + return; + } + sleep(1); // Timer tick } - else { - status_notifier_set_tooltip (icon, "deadbeef", "DeaDBeeF", NULL); - } + deadbeef->log_detailed((DB_plugin_t *)(&plugin), DDB_LOG_LAYER_DEFAULT, "%s: %s\n", + "Status notifier register failed (by timeout)", + status_notifier_get_id(sni_ctx)); } -void _sni_update_tooltip (void *user_date) { - sni_update_tooltip (-1); -} +static StatusNotifier * +sni_load_icon_portable(void) { + StatusNotifier *ret_icon = NULL; -void -sni_update_status (int state) { - g_debug("sni_update_status, status: %d", state); - DB_output_t *output; - DbusmenuMenuitem *stop_item; + char icon_path[PATH_MAX]; + const char *prefix = deadbeef->get_system_dir(DDB_SYS_DIR_PREFIX); - if (!icon) - return; + if (snprintf(icon_path, PATH_MAX, "%s/%s", prefix, "deadbeef.png") < 0) + return NULL; - output = deadbeef->get_output (); + struct stat st_file; + if (stat(icon_path, &st_file) != 0) + return NULL; - if (output) { - if (state < 0) - state = output->state (); - switch (state) { - case OUTPUT_STATE_PLAYING: - status_notifier_set_from_icon_name (icon, STATUS_NOTIFIER_OVERLAY_ICON, "media-playback-start"); - - stop_item = get_context_menu_item (SNI_MENU_ITEM_STOP); - dbusmenu_menuitem_property_set_bool (stop_item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); - - sni_toggle_play_pause (0); - break; - case OUTPUT_STATE_PAUSED: - status_notifier_set_from_icon_name (icon, STATUS_NOTIFIER_OVERLAY_ICON, "media-playback-pause"); - - sni_toggle_play_pause (1); - break; - case OUTPUT_STATE_STOPPED: - status_notifier_set_from_icon_name (icon, STATUS_NOTIFIER_OVERLAY_ICON, NULL); + GError *png_error = NULL; + GdkPixbuf *png_pixbuf = gdk_pixbuf_new_from_file(icon_path, &png_error); + if (png_pixbuf == NULL) { + deadbeef->log_detailed((DB_plugin_t *)(&plugin), DDB_LOG_LAYER_INFO, "%s\n", + png_error->message); + g_object_unref(png_error); + return NULL; + } - stop_item = get_context_menu_item (SNI_MENU_ITEM_STOP); - dbusmenu_menuitem_property_set_bool (stop_item, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + ret_icon = status_notifier_new_from_pixbuf( + "deadbeef", STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS, png_pixbuf); + g_object_unref(png_pixbuf); - sni_toggle_play_pause (1); - break; - } - } - sni_update_tooltip (state); + return ret_icon; } +static void +sni_reload_icon(gboolean enable) { + if ((icon && enable) || (!icon && !enable)) + return; + + if (enable && !icon) { + if (sni_context_menu_create() == 0) { + if (deadbeef->conf_get_int(SNI_OPTION_ICON_REPLACE, 0)) { + icon = status_notifier_new_from_icon_name( + "deadbeef", STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS, + "audio-x-generic"); + } else { + if ((icon = sni_load_icon_portable()) == NULL) { + icon = status_notifier_new_from_icon_name( + "deadbeef", STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS, "deadbeef"); + } + } + status_notifier_set_status(icon, STATUS_NOTIFIER_STATUS_ACTIVE); + status_notifier_set_title(icon, "DeaDBeeF"); + status_notifier_set_context_menu(icon, get_context_menu()); + + g_signal_connect(icon, "activate", (GCallback)on_activate_requested, NULL); + g_signal_connect(icon, "secondary-activate", (GCallback)on_sec_activate_requested, + NULL); + g_signal_connect(icon, "scroll", (GCallback)on_scroll_requested, NULL); + + // Waiting notifier register process in separate thread + deadbeef->thread_start(callback_wait_notifier_register, (void *)icon); + } else + deadbeef->log_detailed((DB_plugin_t *)(&plugin), DDB_LOG_LAYER_INFO, "%s\n", + "DBus menu don't create"); + } else { + sni_timer_free(); + g_object_unref(icon); + icon = NULL; + } +} /////////////////////////////////// // Common deadbeef plugin stuff /////////////////////////////////// void -deadbeef_toggle_play_pause (void) { - DB_output_t *output; - - output = deadbeef->get_output (); +deadbeef_toggle_play_pause(void) { + DB_output_t *output = deadbeef->get_output(); if (output) { - switch (output->state ()) { - case OUTPUT_STATE_PLAYING: - deadbeef->sendmessage (DB_EV_TOGGLE_PAUSE, 0, 0, 0); - return; - case OUTPUT_STATE_PAUSED: - deadbeef->sendmessage (DB_EV_TOGGLE_PAUSE, 0, 0, 0); - return; + switch (output->state()) { + case DDB_PLAYBACK_STATE_PLAYING: + case DDB_PLAYBACK_STATE_PAUSED: + deadbeef->sendmessage(DB_EV_TOGGLE_PAUSE, 0, 0, 0); + return; + case DDB_PLAYBACK_STATE_STOPPED: + break; } } - deadbeef->sendmessage (DB_EV_PLAY_CURRENT, 0, 0, 0); + deadbeef->sendmessage(DB_EV_PLAY_CURRENT, 0, 0, 0); } gboolean -deadbeef_preferences_available (void) { +deadbeef_preferences_available(void) { return preferences_action != NULL; } void -deadbeef_preferences_activate (void) { - preferences_action->callback2 (preferences_action, 0); +deadbeef_preferences_activate(void) { + preferences_action->callback2(preferences_action, 0); +} + +gboolean +deadbeef_help_available(void) { + return help_action != NULL; } void -sni_configchanged (void) { - int enabled = deadbeef->conf_get_int ("sni.enabled", 1); - int check_std_icon = deadbeef->conf_get_int ("sni.check_std_icon", 1); - int hide_tray_icon = deadbeef->conf_get_int ("gtkui.hide_tray_icon", 0); - sni_enable (enabled && ((check_std_icon && hide_tray_icon) || !check_std_icon)); +deadbeef_help_activate(void) { + help_action->callback2(help_action, 0); +} + +static void +sni_configchanged(void) { + if (deadbeef->conf_get_int(SNI_OPTION_ENABLE, 1)) { + sni_flag_set(SNI_FLAG_ENABLED); + deadbeef->conf_set_int("gtkui.hide_tray_icon", 1); + } else { + sni_flag_unset(SNI_FLAG_ENABLED); + deadbeef->conf_set_int("gtkui.hide_tray_icon", 0); + } + + sni_reload_icon(sni_flag_get(SNI_FLAG_ENABLED)); } static int -sni_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { +sni_message(uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { switch (id) { + case DB_EV_TERMINATE: + sni_flag_unset(SNI_FLAG_LOADED); + sni_context_menu_release(); + break; case DB_EV_CONFIGCHANGED: g_debug("Event: DB_EV_CONFIGCHANGED"); - sni_configchanged (); - update_playback_controls (); - break; - - case DB_EV_TRACKINFOCHANGED: - g_debug("Event: DB_EV_TRACKINFOCHANGED"); - sni_update_tooltip (-1); - break; - - case DB_EV_PAUSED: - g_debug("Event: DB_EV_PAUSED"); - sni_update_status (-1); - break; - - case DB_EV_STOP: - g_debug("Event: DB_EV_STOP"); - sni_update_status (OUTPUT_STATE_STOPPED); - break; + sni_configchanged(); - case DB_EV_SONGSTARTED: - g_debug("Event: DB_EV_SONGSTARTED"); - sni_update_status (OUTPUT_STATE_PLAYING); + if (sni_flag_get(SNI_FLAG_LOADED)) + update_playback_controls(); break; } return 0; } -int -sni_connect () { - gtkui_plugin = (ddb_gtkui_t *)deadbeef->plug_get_for_id (DDB_GTKUI_PLUGIN_ID); +static int +sni_connect() { + gtkui_plugin = (ddb_gtkui_t *)deadbeef->plug_get_for_id(DDB_GTKUI_PLUGIN_ID); if (!gtkui_plugin) { - fprintf (stderr, "sni: can't find gtkui plugin\n"); + deadbeef->log_detailed((DB_plugin_t *)(&plugin), DDB_LOG_LAYER_DEFAULT, + "sni: can't find gtkui plugin\n"); return -1; } - DB_plugin_action_t *actions = gtkui_plugin->gui.plugin.get_actions (NULL); + DB_plugin_action_t *actions = gtkui_plugin->gui.plugin.get_actions(NULL); while (actions) { - if (g_strcmp0 (actions->name, "toggle_player_window") == 0) { + if (g_strcmp0(actions->name, "toggle_player_window") == 0) { toggle_mainwindow_action = actions; - } - else if (g_strcmp0 (actions->name, "preferences") == 0) { + } else if (g_strcmp0(actions->name, "preferences") == 0) { preferences_action = actions; + } else if (g_strcmp0(actions->name, "help") == 0) { + help_action = actions; } actions = actions->next; } if (!toggle_mainwindow_action) { - fprintf (stderr, "sni: failed to find \"toggle_player_window\" gtkui plugin\n"); + deadbeef->log_detailed((DB_plugin_t *)(&plugin), DDB_LOG_LAYER_DEFAULT, + "sni: failed to find \"toggle_player_window\" gtkui plugin\n"); } - int enabled = deadbeef->conf_get_int ("sni.enabled", 1); - int enable_automaticaly = deadbeef->conf_get_int ("sni.enable_automaticaly", 1); - int hide_tray_icon = deadbeef->conf_get_int ("gtkui.hide_tray_icon", 0); - - if (enabled && enable_automaticaly && !hide_tray_icon) { - auto_activated = TRUE; - deadbeef->conf_set_int ("gtkui.hide_tray_icon", 1); - } - else - sni_configchanged (); + sni_configchanged(); return 0; } -int -sni_disconnect () { - if (auto_activated) { - deadbeef->conf_set_int ("gtkui.hide_tray_icon", 0); - } +static int +sni_disconnect() { + if (sni_flag_get(SNI_FLAG_ENABLED)) + sni_reload_icon(FALSE); return 0; } - +// clang-format off static const char settings_dlg[] = - "property \"Enable StatusNotifierItem\" checkbox sni.enabled 1;\n" - "property \"Allow only if standart GUI tray icon is disabled\" checkbox sni.check_std_icon 1;\n" - "property \"Automaticly disable standart GUI tray icon\" checkbox sni.enable_automaticaly 1;\n" + "property \"Enable Status Notifier\" checkbox "SNI_OPTION_ENABLE" 1;\n" + "property \"Enable minimize on icon click\" checkbox "SNI_OPTION_ICON_MINIMIZE" 1;\n" + "property \"Replace icon on native DE icon (if standart broken)\" checkbox "SNI_OPTION_ICON_REPLACE" 0;\n" + + "property \"Display playback status on icon (if DE support overlay icons)\" checkbox "SNI_OPTION_ICON_OVERLAY" 1;\n" + "property \"Display Status Notifier tooltip (if DE support this)\" checkbox "SNI_OPTION_TOOLTIP_ENABLE" 1;\n" + "property \"Use plain text tooltip (if DE not support HTML tooltips)\" checkbox "SNI_OPTION_TOOLTIP_ISTEXT" 0;\n" + "property \"Set tooltip icon (if DE support this)\" checkbox "SNI_OPTION_TOOLTIP_ICON" 1;\n" + + "property \"Enable playback options in menu (need restart)\" checkbox "SNI_OPTION_MENU_PLAYBACK" 1;\n" + "property \"Enable window mode options in menu (need restart)\" checkbox "SNI_OPTION_MENU_TOGGLE" 1;\n" + + "property \"Volume control ignore horizontal scroll\" checkbox "SNI_OPTION_VOLUME_HORIZONTAL" 1;\n" + "property \"Volume control use inverse scroll direction\" checkbox "SNI_OPTION_VOLUME_INVERSE" 0;\n" + + "property \"Notifier registration waiting time (sec.)\" spinbtn[10,120,5] "SNI_OPTION_TIMEOUT" 30;\n" ; - +// clang-format on static DB_misc_t plugin = { .plugin.type = DB_PLUGIN_MISC, .plugin.api_vmajor = 1, - .plugin.api_vminor = 5, + .plugin.api_vminor = 11, .plugin.version_major = 1, - .plugin.version_minor = 3, -#if GTK_CHECK_VERSION (3, 0, 0) + .plugin.version_minor = 6, + .plugin.flags = DDB_PLUGIN_FLAG_LOGGING, +#if GTK_CHECK_VERSION(3, 0, 0) .plugin.id = "sni_gtk3", - .plugin.name = "StatusNotifierItem for GTK3 UI", + .plugin.name = "Status Notifier GTK3 UI", #else .plugin.id = "sni_gtk2", - .plugin.name = "StatusNotifierItem for GTK2 UI", + .plugin.name = "Status Notifier GTK2 UI", #endif .plugin.descr = "StatusNotifierItem for DE without support for xembedded icons\n" - "(like plasma5). It also can be used for a better look&feel experience.\n", - .plugin.copyright = - "StatusNotifier plugin for DeaDBeeF Player\n" - "Copyright (C) 2015 Vladimir Perepechin \n" - "\n" - "This program is free software: you can redistribute it and/or modify\n" - "it under the terms of the GNU General Public License as published by\n" - "the Free Software Foundation, either version 3 of the License, or\n" - "(at your option) any later version.\n" - - "This program is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - "GNU General Public License for more details.\n" - - "You should have received a copy of the GNU General Public License\n" - "along with this program. If not, see .\n", + "(like Plasma5 or GNOME3+). It also can be used for a better \n" + "look&feel experience.\n" + "The functionality of the plugin depends on the quality and \n" + "completeness of the implementation of the SNI functionality \n" + "in a particular DE.", + .plugin.copyright = "StatusNotifier plugin for DeaDBeeF Player\n" + "Copyright (C) 2015 Vladimir Perepechin \n" + "Copyright (C) 2020 Alexander Smirnov \n" + "\n" + "This program is free software: you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation, either version 3 of the License, or\n" + "(at your option) any later version.\n" + + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n" + + "You should have received a copy of the GNU General Public License\n" + "along with this program. If not, see " + ".\n", .plugin.website = "https://github.com/vovochka404/deadbeef-statusnotifier-plugin", - .plugin.configdialog = settings_dlg, - .plugin.message = sni_message, .plugin.connect = sni_connect, .plugin.disconnect = sni_disconnect, -}; + .plugin.message = sni_message, + .plugin.configdialog = settings_dlg}; -DB_plugin_t * -#if GTK_CHECK_VERSION (3 ,0, 0) -sni_gtk3_load (DB_functions_t *api) { +SNI_EXPORT_FUNC DB_plugin_t * +#if GTK_CHECK_VERSION(3, 0, 0) +sni_gtk3_load(DB_functions_t *api) { #else -sni_gtk2_load (DB_functions_t *api) { +sni_gtk2_load(DB_functions_t *api) { #endif deadbeef = api; - return DB_PLUGIN (&plugin); + return DB_PLUGIN(&plugin); } diff -Nru deadbeef-statusnotifier-plugin-1.3.1/src/sni_flags.c deadbeef-statusnotifier-plugin-1.6/src/sni_flags.c --- deadbeef-statusnotifier-plugin-1.3.1/src/sni_flags.c 1970-01-01 00:00:00.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/src/sni_flags.c 2021-06-12 07:53:35.000000000 +0000 @@ -0,0 +1,45 @@ +/* + * deadbeef-statusnotifier-plugin - Copyright (C) 2015 Vladimir Perepechin + * + * sni_flags.c + * Copyright (C) 2014 Vladimir Perepechin + * + * This file is part of deadbeef-statusnotifier-plugin. + * + * deadbeef-statusnotifier-plugin is free software: you can 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. + * + * deadbeef-statusnotifier-plugin is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * deadbeef-statusnotifier-plugin. If not, see http://www.gnu.org/licenses/ + */ + +#include "sni.h" + +typedef struct { + uint32_t v1; +} sni_flags_t; + +static sni_flags_t sni_flags = {0}; + +gboolean +sni_flag_get(uint32_t code) { + int ret = (sni_flags.v1 & ((uint32_t)1 << code)); + return (ret > 0) ? TRUE : FALSE; +} + +void +sni_flag_set(uint32_t code) { + sni_flags.v1 |= ((uint32_t)1 << code); +} + +void +sni_flag_unset(uint32_t code) { + sni_flags.v1 &= ~((uint32_t)1 << code); +} diff -Nru deadbeef-statusnotifier-plugin-1.3.1/src/sni.h deadbeef-statusnotifier-plugin-1.6/src/sni.h --- deadbeef-statusnotifier-plugin-1.3.1/src/sni.h 2020-05-25 00:00:59.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/src/sni.h 2021-06-12 07:53:35.000000000 +0000 @@ -6,15 +6,15 @@ * * This file is part of deadbeef-statusnotifier-plugin. * - * deadbeef-statusnotifier-plugin is free software: you can 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. + * deadbeef-statusnotifier-plugin is free software: you can 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. * - * deadbeef-statusnotifier-plugin is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. + * deadbeef-statusnotifier-plugin is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. * * You should have received a copy of the GNU General Public License along with * deadbeef-statusnotifier-plugin. If not, see http://www.gnu.org/licenses/ @@ -24,17 +24,21 @@ #define SNI_H #if ENABLE_NLS - -#include -#define PACKAGE "deadbeef" -#define _(String) dgettext(PACKAGE, String) - + #include + #define PACKAGE "deadbeef" + #define _(String) dgettext(PACKAGE, String) #else + #define _(String) (String) +#endif -#define _(String) (String) - +#if defined(__GNUC__) && __GNUC__ >= 4 + #define SNI_EXPORT_FUNC __attribute__((visibility("default"))) +#else + #define SNI_EXPORT_FUNC #endif +#include + #include #include @@ -43,8 +47,8 @@ #include -DB_functions_t *deadbeef; -static ddb_gtkui_t *gtkui_plugin; +DB_functions_t * +deadbeef_get_instance(void); typedef enum { SNI_MENU_ITEM_PLAY, @@ -56,23 +60,85 @@ } SNIContextMenuItem; typedef enum { - SNI_MENU_ITEM_TYPE_COMMON, - SNI_MENU_ITEM_TYPE_CHECKBOX, - SNI_MENU_ITEM_TYPE_RADIO, - SNI_MENU_ITEM_TYPE_SEPARATOR + SNI_MENU_ITEM_TYPE_COMMON, + SNI_MENU_ITEM_TYPE_CHECKBOX, + SNI_MENU_ITEM_TYPE_RADIO, + SNI_MENU_ITEM_TYPE_SEPARATOR } SNIContextMenuItemType; -DbusmenuMenuitem *get_context_menu (void); +typedef enum { SNI_FLAG_ENABLED = 0, SNI_FLAG_LOADED = 1, SNI_FLAG_HIDDEN = 2 } SNIFlags; + +enum { + SNI_STATE_TOOGLE_PLAY = 0, + SNI_STATE_TOOGLE_PAUSE = 1, + SNI_STATE_TOOGLE_STOP = 2, +}; + +#define SNI_OPTION_ENABLE "sni.enabled" +#define SNI_OPTION_ICON_MINIMIZE "sni.icon_minimize_action" +#define SNI_OPTION_ICON_OVERLAY "sni.icon_overlay" +#define SNI_OPTION_ICON_REPLACE "sni.icon_replace" +#define SNI_OPTION_TOOLTIP_ENABLE "sni.tooltip_enable" +#define SNI_OPTION_TOOLTIP_ISTEXT "sni.tooltip_istext" +#define SNI_OPTION_TOOLTIP_ICON "sni.tooltip_icon" +#define SNI_OPTION_MENU_PLAYBACK "sni.menu_playback" +#define SNI_OPTION_MENU_TOGGLE "sni.menu_wmtoggle" +#define SNI_OPTION_VOLUME_HORIZONTAL "sni.volume_hdirect" +#define SNI_OPTION_VOLUME_INVERSE "sni.volume_inverse" +#define SNI_OPTION_TIMEOUT "sni.timeout" + +DbusmenuMenuitem * +get_context_menu(void); + +DbusmenuMenuitem * +get_context_menu_item(SNIContextMenuItem item); -DbusmenuMenuitem *get_context_menu_item (SNIContextMenuItem item); +gboolean +deadbeef_window_is_visible(void); -void update_playback_controls (void); +void +deadbeef_toogle_window(void); -void deadbeef_toggle_play_pause (void); +void +update_window_controls(void); -gboolean deadbeef_preferences_available (void); +void +update_playback_controls(void); -void deadbeef_preferences_activate (void); +void +update_play_controls(int play); +gboolean +deadbeef_preferences_available(void); -#endif \ No newline at end of file +void +deadbeef_preferences_activate(void); + +gboolean +deadbeef_help_available(void); + +void +deadbeef_help_activate(void); + +int +sni_context_menu_create(void); + +void +sni_context_menu_release(void); + +gboolean +sni_flag_get(uint32_t code); + +void +sni_flag_set(uint32_t code); + +void +sni_flag_unset(uint32_t code); + +#define sni_free_null(X) \ + do { \ + free(X); \ + X = NULL; \ + } while (0); + +#endif diff -Nru deadbeef-statusnotifier-plugin-1.3.1/src/sni_timer.c deadbeef-statusnotifier-plugin-1.6/src/sni_timer.c --- deadbeef-statusnotifier-plugin-1.3.1/src/sni_timer.c 1970-01-01 00:00:00.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/src/sni_timer.c 2021-06-12 07:53:35.000000000 +0000 @@ -0,0 +1,109 @@ +/* + * deadbeef-statusnotifier-plugin - Copyright (C) 2015 Vladimir Perepechin + * + * sni_timer.c + * Copyright (C) 2014 Vladimir Perepechin + * + * This file is part of deadbeef-statusnotifier-plugin. + * + * deadbeef-statusnotifier-plugin is free software: you can 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. + * + * deadbeef-statusnotifier-plugin is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * deadbeef-statusnotifier-plugin. If not, see http://www.gnu.org/licenses/ + */ + +#include "sni.h" + +typedef struct { + StatusNotifier *icon; + + unsigned playback; + DB_playItem_t *item; + + guint timer; +} sni_state_t; + +static sni_state_t *sni_state = NULL; + +void +sni_update_info(sni_state_t *st, unsigned state) { + + DB_playItem_t *tmp = deadbeef->streamer_get_playing_track(); + + if ((st->playback != state) || (st->item != tmp)) { + st->playback = state; + if (st->item) + deadbeef->pl_item_unref(st->item); + st->item = tmp; + + g_debug("Update status. State: %u\tItem:%p\n", st->playback, st->item); + sni_update_status(state); + } else { + if (tmp) + deadbeef->pl_item_unref(tmp); + } +} + +static gboolean +callback_timer_status_update(gpointer ctx) { + + if (sni_flag_get(SNI_FLAG_LOADED) == FALSE) + return TRUE; + + sni_state_t *sni_ctx = (sni_state_t *)ctx; + if (sni_ctx == NULL) + return FALSE; + + int state = playback_state_active_waiting(); + if (state < 0) { + return FALSE; + } + + sni_update_info(sni_ctx, state); + + update_window_controls(); + return TRUE; +} + +gboolean +sni_timer_enabled(void) { + return (sni_state) ? TRUE : FALSE; +} + +int +sni_timer_init(StatusNotifier *icon, guint interval) { + if (sni_state == NULL) { + + sni_state = calloc(1, sizeof(sni_state_t)); + if (sni_state == NULL) + return -1; + + sni_state->icon = icon; + // clang-format off + sni_state->timer = g_timeout_add_full( G_PRIORITY_DEFAULT, interval, + callback_timer_status_update, + (gpointer)sni_state, NULL); + // clang-format on + } + return 0; +} + +void +sni_timer_free(void) { + if (sni_state) { + g_source_remove(sni_state->timer); + + if (sni_state->item) + deadbeef->pl_item_unref(sni_state->item); + + sni_free_null(sni_state); + } +} diff -Nru deadbeef-statusnotifier-plugin-1.3.1/src/sni_upd.c deadbeef-statusnotifier-plugin-1.6/src/sni_upd.c --- deadbeef-statusnotifier-plugin-1.3.1/src/sni_upd.c 1970-01-01 00:00:00.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/src/sni_upd.c 2021-06-12 07:53:35.000000000 +0000 @@ -0,0 +1,246 @@ +/* + * deadbeef-statusnotifier-plugin - Copyright (C) 2015 Vladimir Perepechin + * + * sni_upd.c + * Copyright (C) 2014 Vladimir Perepechin + * + * This file is part of deadbeef-statusnotifier-plugin. + * + * deadbeef-statusnotifier-plugin is free software: you can 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. + * + * deadbeef-statusnotifier-plugin is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * deadbeef-statusnotifier-plugin. If not, see http://www.gnu.org/licenses/ + */ + +#include "sni.h" + +#define TOOLTIP_FORMAT \ + "[%s]
" \ + "%s: %s
" \ + "%s: %s
" \ + "%s: %s %c%s%c" +#define TOOLTIP_FORMAT_PLAIN \ + "[%s]" \ + "\n%s: %s" \ + "\n%s: %s" \ + "\n%s: %s %c%s%c" + +#define TOOLTIP_DEFAULT_TITLE "DeaDBeeF" + +#define STATE_WAITING_CYCLE 10000 +#define TOOLTIP_MAX_LENGTH 1000 + +#define GME_TEXT(X) (X) ? g_markup_escape_text((X), -1) : NULL + +/* This function is necessary because at the time of the call, + the output may be uninitialized and a data race will occur */ + +static inline int +playback_state_active_waiting(void) { + DB_output_t *out = deadbeef->get_output(); + if (out) { + ddb_playback_state_t state = 0; + for (;;) { + state = out->state(); + if ((state >= 0) && (state <= DDB_PLAYBACK_STATE_PAUSED)) + return state; + } + } + return -1; +} + +static inline const char * +get_track_info(DB_playItem_t *track, const char *info) { + return deadbeef->pl_find_meta(track, info); +} + +static inline const char * +get_track_artist(DB_playItem_t *track) { + const char *artist = NULL; + if ((artist = get_track_info(track, "artist")) == NULL) + if ((artist = get_track_info(track, "albumartist")) == NULL) + if ((artist = get_track_info(track, "album artist")) == NULL) + artist = get_track_info(track, "band"); + return artist; +} + +static void +sni_get_tooltip(DB_playItem_t *track, int state, const gchar *fmt, gchar *buf, size_t sz) { + const gchar *ns = _("not specified"); + + deadbeef->pl_lock(); + + gchar *escaped_artist = GME_TEXT(get_track_artist(track)); + gchar *escaped_title = GME_TEXT(get_track_info(track, "title")); + gchar *escaped_album = GME_TEXT(get_track_info(track, "album")); + gchar *escaped_date = GME_TEXT(get_track_info(track, "year")); + + deadbeef->pl_unlock(); + + // clang-format off + g_snprintf(buf, sz, fmt, + (state == OUTPUT_STATE_PAUSED) ? _("Paused") + : _("Playing"), + _("Title"), escaped_title ? escaped_title : ns, + _("Artist"), escaped_artist ? escaped_artist : ns, + _("Album"), escaped_album ? escaped_album : ns, + escaped_date ? '[' : 0, + escaped_date ? escaped_date : "", + escaped_date ? ']' : 0); + // clang-format on + + g_free(escaped_title); + g_free(escaped_artist); + g_free(escaped_album); + g_free(escaped_date); +} + +static inline GdkPixbuf * +sni_get_coverart(DB_playItem_t *track, void (*callback)(void *)) { + + deadbeef->pl_lock(); + + const char *uri = get_track_info(track, ":URI"); + const char *artist = get_track_artist(track); + const char *album = get_track_info(track, "album"); + + if (!album || !*album) { + album = get_track_info(track, "title"); + } + deadbeef->pl_unlock(); + +#if (DDB_GTKUI_API_LEVEL >= 202) + GdkPixbuf *buf = gtkui_plugin->get_cover_art_thumb(uri, artist, album, 128, callback, + (callback) ? (void *)icon : NULL); +#else + GdkPixbuf *buf = gtkui_plugin->get_cover_art_pixbuf(uri, artist, album, 128, NULL, NULL); +#endif + if (buf == NULL) + buf = gtkui_plugin->cover_get_default_pixbuf(); + + return buf; +} + +static void +callback_pixbuf_lazy_loading(void *ctx) { + StatusNotifier *icon = (StatusNotifier *)ctx; + + DB_playItem_t *track = deadbeef->streamer_get_playing_track(); + if (track) { + GdkPixbuf *pic = sni_get_coverart(track, NULL); + if (pic) { + g_debug("Pixbuf callback: %zu\n", gdk_pixbuf_get_byte_length(pic)); + status_notifier_set_from_pixbuf(icon, STATUS_NOTIFIER_TOOLTIP_ICON, pic); + g_object_unref(pic); + } + deadbeef->pl_item_unref(track); + } +} + +static void +pixbuf_lazy_load(void *ctx) { + StatusNotifier *icon = (StatusNotifier *)ctx; + if (icon == NULL) + return; + deadbeef->thread_start(callback_pixbuf_lazy_loading, (void *)icon); +} + +static inline void +sni_set_tooltip_textonly(DB_playItem_t *track, int state) { + gchar title_body[TOOLTIP_MAX_LENGTH]; + sni_get_tooltip(track, state, _(TOOLTIP_FORMAT_PLAIN), title_body, TOOLTIP_MAX_LENGTH); + status_notifier_set_tooltip(icon, NULL, TOOLTIP_DEFAULT_TITLE, title_body); +} + +static inline void +sni_set_tooltip_html(DB_playItem_t *track, int state) { + gchar title_body[TOOLTIP_MAX_LENGTH]; + sni_get_tooltip(track, state, _(TOOLTIP_FORMAT), title_body, TOOLTIP_MAX_LENGTH); + + if ((deadbeef->conf_get_int(SNI_OPTION_TOOLTIP_ICON, 1)) && + ((state == DDB_PLAYBACK_STATE_PLAYING) || (state == DDB_PLAYBACK_STATE_PAUSED))) { + GdkPixbuf *pic = sni_get_coverart(track, pixbuf_lazy_load); + if (pic) { + g_debug("Pixbuf cached: %zu\n", gdk_pixbuf_get_byte_length(pic)); + status_notifier_set_tooltip2(icon, pic, TOOLTIP_DEFAULT_TITLE, title_body); + g_object_unref(pic); + } else { + status_notifier_set_tooltip(icon, "deadbeef", TOOLTIP_DEFAULT_TITLE, title_body); + } + } else + status_notifier_set_tooltip(icon, NULL, TOOLTIP_DEFAULT_TITLE, title_body); +} + +/* === main update functions === */ + +static void +sni_update_tooltip(int state) { + + if (sni_flag_get(SNI_FLAG_LOADED) == FALSE) + return; + if (!icon) + return; + if (deadbeef->conf_get_int(SNI_OPTION_TOOLTIP_ENABLE, 0) == 0) + return; + + switch (state) { + case DDB_PLAYBACK_STATE_STOPPED: + status_notifier_set_tooltip(icon, "deadbeef", TOOLTIP_DEFAULT_TITLE, _("Stopped")); + break; + case DDB_PLAYBACK_STATE_PAUSED: + case DDB_PLAYBACK_STATE_PLAYING: { + DB_playItem_t *track = deadbeef->streamer_get_playing_track(); + if (track) { + deadbeef->conf_get_int(SNI_OPTION_TOOLTIP_ISTEXT, 0) + ? sni_set_tooltip_textonly(track, state) + : sni_set_tooltip_html(track, state); + + deadbeef->pl_item_unref(track); + } else { + status_notifier_set_tooltip(icon, "deadbeef", TOOLTIP_DEFAULT_TITLE, _("Playing")); + } + break; + } + } +} + +static void +sni_update_status(int state) { + + if (sni_flag_get(SNI_FLAG_LOADED) == FALSE) + return; + if (!icon) + return; + int enable_overlay = deadbeef->conf_get_int(SNI_OPTION_ICON_OVERLAY, 1); + + switch (state) { + case DDB_PLAYBACK_STATE_PLAYING: + if (enable_overlay) + status_notifier_set_from_icon_name(icon, STATUS_NOTIFIER_OVERLAY_ICON, + "media-playback-start"); + update_play_controls(SNI_STATE_TOOGLE_PLAY); + break; + + case DDB_PLAYBACK_STATE_PAUSED: + if (enable_overlay) + status_notifier_set_from_icon_name(icon, STATUS_NOTIFIER_OVERLAY_ICON, + "media-playback-pause"); + update_play_controls(SNI_STATE_TOOGLE_PAUSE); + break; + + case DDB_PLAYBACK_STATE_STOPPED: + if (enable_overlay) + status_notifier_set_from_icon_name(icon, STATUS_NOTIFIER_OVERLAY_ICON, NULL); + update_play_controls(SNI_STATE_TOOGLE_STOP); + break; + } + sni_update_tooltip(state); +} diff -Nru deadbeef-statusnotifier-plugin-1.3.1/src/x11-force-focus.c deadbeef-statusnotifier-plugin-1.6/src/x11-force-focus.c --- deadbeef-statusnotifier-plugin-1.3.1/src/x11-force-focus.c 2020-05-25 00:00:59.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/src/x11-force-focus.c 2021-06-12 07:53:35.000000000 +0000 @@ -6,67 +6,63 @@ * * This file is part of deadbeef-statusnotifier-plugin. * - * deadbeef-statusnotifier-plugin is free software: you can 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. + * deadbeef-statusnotifier-plugin is free software: you can 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. * - * deadbeef-statusnotifier-plugin is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. + * deadbeef-statusnotifier-plugin is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. * * You should have received a copy of the GNU General Public License along with * deadbeef-statusnotifier-plugin. If not, see http://www.gnu.org/licenses/ */ -#include "x11-force-focus.h" +#include -#if !GTK_CHECK_VERSION(3,0,0) || defined(GDK_WINDOWING_X11) +#if !GTK_CHECK_VERSION(3, 0, 0) || defined(GDK_WINDOWING_X11) -#include -#include -#include -#include /* memset */ + #include + #include + #include + #include /* memset */ -#define GDK_WINDOW_DISPLAY(win) gdk_screen_get_display (gdk_window_get_screen (win)) + #define GDK_WINDOW_DISPLAY(win) gdk_screen_get_display(gdk_window_get_screen(win)) -#define GDK_WINDOW_XROOTWIN(win) GDK_WINDOW_XID(gdk_screen_get_root_window (gdk_window_get_screen (win))) + #define GDK_WINDOW_XROOTWIN(win) \ + GDK_WINDOW_XID(gdk_screen_get_root_window(gdk_window_get_screen(win))) -#if defined(GDK_IS_DISPLAY) && !defined(GDK_IS_X11_DISPLAY) -#define GDK_IS_X11_DISPLAY(display) GDK_IS_DISPLAY(display) -#endif + #if defined(GDK_IS_DISPLAY) && !defined(GDK_IS_X11_DISPLAY) + #define GDK_IS_X11_DISPLAY(display) GDK_IS_DISPLAY(display) + #endif void -gdk_x11_window_force_focus (GdkWindow *window, - guint32 timestamp) -{ +gdk_x11_window_force_focus(GdkWindow *window, guint32 timestamp) { GdkDisplay *display; - g_return_if_fail (GDK_IS_WINDOW (window)); + g_return_if_fail(GDK_IS_WINDOW(window)); - display = GDK_WINDOW_DISPLAY (window); + display = GDK_WINDOW_DISPLAY(window); - if (GTK_CHECK_VERSION(3,0,0) && !GDK_IS_X11_DISPLAY (display)) + if (GTK_CHECK_VERSION(3, 0, 0) && !GDK_IS_X11_DISPLAY(display)) return; - if (gdk_x11_screen_supports_net_wm_hint (gdk_window_get_screen (window), - gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW"))) - { - if (!timestamp) - { - GTimeVal t; - g_get_current_time (&t); - timestamp = t.tv_sec; + if (gdk_x11_screen_supports_net_wm_hint(gdk_window_get_screen(window), + gdk_atom_intern_static_string("_NET_ACTIVE_WINDOW"))) { + if (!timestamp) { + #if defined(GDK_CURRENT_TIME) + timestamp = GDK_CURRENT_TIME; /* in fact it doesn't needed */ + #endif } XClientMessageEvent xclient; - memset (&xclient, 0, sizeof (xclient)); + memset(&xclient, 0, sizeof(xclient)); xclient.type = ClientMessage; - xclient.window = GDK_WINDOW_XID (window); - xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, - "_NET_ACTIVE_WINDOW"); + xclient.window = GDK_WINDOW_XID(window); + xclient.message_type = gdk_x11_get_xatom_by_name_for_display(display, "_NET_ACTIVE_WINDOW"); xclient.format = 32; xclient.data.l[0] = 2; /* requestor type; we're a tool */ xclient.data.l[1] = timestamp; @@ -74,17 +70,14 @@ xclient.data.l[3] = 0; xclient.data.l[4] = 0; - XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False, - SubstructureRedirectMask | SubstructureNotifyMask, - (XEvent *)&xclient); + XSendEvent(GDK_DISPLAY_XDISPLAY(display), GDK_WINDOW_XROOTWIN(window), False, + SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xclient); } } #else void -gdk_x11_window_force_focus (GdkWindow *window, - guint32 timestamp) -{ - +gdk_x11_window_force_focus(GdkWindow *window, guint32 timestamp) { + /* Dummy function */ } #endif diff -Nru deadbeef-statusnotifier-plugin-1.3.1/src/x11-force-focus.h deadbeef-statusnotifier-plugin-1.6/src/x11-force-focus.h --- deadbeef-statusnotifier-plugin-1.3.1/src/x11-force-focus.h 2020-05-25 00:00:59.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/src/x11-force-focus.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,32 +0,0 @@ -/* - * deadbeef-statusnotifier-plugin - Copyright (C) 2015 Vladimir Perepechin - * - * x11-force-focus.h - * Copyright (C) 2014 Vladimir Perepechin - * - * This file is part of deadbeef-statusnotifier-plugin. - * - * deadbeef-statusnotifier-plugin is free software: you can 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. - * - * deadbeef-statusnotifier-plugin is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * deadbeef-statusnotifier-plugin. If not, see http://www.gnu.org/licenses/ - */ - -#ifndef X11_FORCE_FOCUS_H -#define X11_FORCE_FOCUS_H - -#include "gtk/gtk.h" - -void gdk_x11_window_force_focus (GdkWindow *window, - guint32 timestamp); - - -#endif \ No newline at end of file diff -Nru deadbeef-statusnotifier-plugin-1.3.1/tools/glib-mkenums deadbeef-statusnotifier-plugin-1.6/tools/glib-mkenums --- deadbeef-statusnotifier-plugin-1.3.1/tools/glib-mkenums 1970-01-01 00:00:00.000000000 +0000 +++ deadbeef-statusnotifier-plugin-1.6/tools/glib-mkenums 2021-06-12 07:53:35.000000000 +0000 @@ -0,0 +1,565 @@ +#! /usr/bin/perl + +use warnings; +use File::Basename; +use Safe; + +# glib-mkenums.pl +# Information about the current enumeration +my $flags; # Is enumeration a bitmask? +my $option_underscore_name; # Overriden underscore variant of the enum name + # for example to fix the cases we don't get the + # mixed-case -> underscorized transform right. +my $option_lowercase_name; # DEPRECATED. A lower case name to use as part + # of the *_get_type() function, instead of the + # one that we guess. For instance, when an enum + # uses abnormal capitalization and we can not + # guess where to put the underscores. +my $seenbitshift; # Have we seen bitshift operators? +my $enum_prefix; # Prefix for this enumeration +my $enumname; # Name for this enumeration +my $enumshort; # $enumname without prefix +my $enumname_prefix; # prefix of $enumname +my $enumindex = 0; # Global enum counter +my $firstenum = 1; # Is this the first enumeration per file? +my @entries; # [ $name, $val ] for each entry +my $sandbox = Safe->new; # sandbox for safe evaluation of expressions + +sub parse_trigraph { + my $opts = shift; + my @opts; + + for $opt (split /\s*,\s*/, $opts) { + $opt =~ s/^\s*//; + $opt =~ s/\s*$//; + my ($key,$val) = $opt =~ /(\w+)(?:=(.+))?/; + defined $val or $val = 1; + push @opts, $key, $val; + } + @opts; +} +sub parse_entries { + my $file = shift; + my $file_name = shift; + my $looking_for_name = 0; + + while (<$file>) { + # read lines until we have no open comments + while (m@/\*([^*]|\*(?!/))*$@) { + my $new; + defined ($new = <$file>) || die "Unmatched comment in $ARGV"; + $_ .= $new; + } + # strip comments w/o options + s@/\*(?!<) + ([^*]+|\*(?!/))* + \*/@@gx; + + # strip newlines + s@\n@ @; + + # skip empty lines + next if m@^\s*$@; + + if ($looking_for_name) { + if (/^\s*(\w+)/) { + $enumname = $1; + return 1; + } + } + + # Handle include files + if (/^\#include\s*<([^>]*)>/ ) { + my $file= "../$1"; + open NEWFILE, $file or die "Cannot open include file $file: $!\n"; + + if (parse_entries (\*NEWFILE, $NEWFILE)) { + return 1; + } else { + next; + } + } + + if (/^\s*\}\s*(\w+)/) { + $enumname = $1; + $enumindex++; + return 1; + } + + if (/^\s*\}/) { + $enumindex++; + $looking_for_name = 1; + next; + } + + if (m@^\s* + (\w+)\s* # name + (?:=( # value + \s*\w+\s*\(.*\)\s* # macro with multiple args + | # OR + (?:[^,/]|/(?!\*))* # anything but a comma or comment + ))?,?\s* + (?:/\*< # options + (([^*]|\*(?!/))*) + >\s*\*/)?,? + \s*$ + @x) { + my ($name, $value, $options) = ($1,$2,$3); + + if (!defined $flags && defined $value && $value =~ /< Identifier prefix\n"; + print " --symbol-prefix Symbol prefix\n"; + print " --fhead Output file header\n"; + print " --fprod Per input file production\n"; + print " --ftail Output file trailer\n"; + print " --eprod Per enum text (produced prior to value iterations)\n"; + print " --vhead Value header, produced before iterating over enum values\n"; + print " --vprod Value text, produced for each enum value\n"; + print " --vtail Value tail, produced after iterating over enum values\n"; + print " --comments Comment structure\n"; + print " --template file Template file\n"; + print " -v, --version Print version informations\n\n"; + print "Production text substitutions:\n"; + print " \@EnumName\@ PrefixTheXEnum\n"; + print " \@enum_name\@ prefix_the_xenum\n"; + print " \@ENUMNAME\@ PREFIX_THE_XENUM\n"; + print " \@ENUMSHORT\@ THE_XENUM\n"; + print " \@ENUMPREFIX\@ PREFIX\n"; + print " \@VALUENAME\@ PREFIX_THE_XVALUE\n"; + print " \@valuenick\@ the-xvalue\n"; + print " \@valuenum\@ the integer value (limited support, Since: 2.26)\n"; + print " \@type\@ either enum or flags\n"; + print " \@Type\@ either Enum or Flags\n"; + print " \@TYPE\@ either ENUM or FLAGS\n"; + print " \@filename\@ name of current input file\n"; + print " \@basename\@ base name of the current input file (Since: 2.22)\n"; + exit 0; +} + +# production variables: +my $idprefix = ""; # "G", "Gtk", etc +my $symprefix = ""; # "g", "gtk", etc, if not just lc($idprefix) +my $fhead = ""; # output file header +my $fprod = ""; # per input file production +my $ftail = ""; # output file trailer +my $eprod = ""; # per enum text (produced prior to value itarations) +my $vhead = ""; # value header, produced before iterating over enum values +my $vprod = ""; # value text, produced for each enum value +my $vtail = ""; # value tail, produced after iterating over enum values +my $comment_tmpl = ""; # comment template + +sub read_template_file { + my ($file) = @_; + my %tmpl = ('file-header', $fhead, + 'file-production', $fprod, + 'file-tail', $ftail, + 'enumeration-production', $eprod, + 'value-header', $vhead, + 'value-production', $vprod, + 'value-tail', $vtail, + 'comment', $comment_tmpl); + my $in = 'junk'; + open (FILE, $file) || die "Can't open $file: $!\n"; + while () { + if (/^\/\*\*\*\s+(BEGIN|END)\s+([\w-]+)\s+\*\*\*\//) { + if (($in eq 'junk') && ($1 eq 'BEGIN') && (exists($tmpl{$2}))) { + $in = $2; + next; + } + elsif (($in eq $2) && ($1 eq 'END') && (exists($tmpl{$2}))) { + $in = 'junk'; + next; + } else { + die "Malformed template file $file\n"; + } + } + if (!($in eq 'junk')) { + $tmpl{$in} .= $_; + } + } + close (FILE); + if (!($in eq 'junk')) { + die "Malformed template file $file\n"; + } + $fhead = $tmpl{'file-header'}; + $fprod = $tmpl{'file-production'}; + $ftail = $tmpl{'file-tail'}; + $eprod = $tmpl{'enumeration-production'}; + $vhead = $tmpl{'value-header'}; + $vprod = $tmpl{'value-production'}; + $vtail = $tmpl{'value-tail'}; + $comment_tmpl = $tmpl{'comment'}; + + # default to C-style comments + $comment_tmpl = "/* \@comment\@ */" if $comment_tmpl eq ""; +} + +if (!defined $ARGV[0]) { + usage; +} +while ($_=$ARGV[0],/^-/) { + shift; + last if /^--$/; + if (/^--template$/) { read_template_file (shift); } + elsif (/^--identifier-prefix$/) { $idprefix = shift } + elsif (/^--symbol-prefix$/) { $symprefix = shift } + elsif (/^--fhead$/) { $fhead = $fhead . shift } + elsif (/^--fprod$/) { $fprod = $fprod . shift } + elsif (/^--ftail$/) { $ftail = $ftail . shift } + elsif (/^--eprod$/) { $eprod = $eprod . shift } + elsif (/^--vhead$/) { $vhead = $vhead . shift } + elsif (/^--vprod$/) { $vprod = $vprod . shift } + elsif (/^--vtail$/) { $vtail = $vtail . shift } + elsif (/^--comments$/) { $comment_tmpl = shift } + elsif (/^--help$/ || /^-h$/ || /^-\?$/) { usage; } + elsif (/^--version$/ || /^-v$/) { version; } + else { usage; } + last if not defined($ARGV[0]); +} + +# put auto-generation comment +{ + my $comment = $comment_tmpl; + $comment =~ s/\@comment\@/Generated data (by glib-mkenums)/; + print "\n" . $comment . "\n\n"; +} + +if (length($fhead)) { + my $prod = $fhead; + my $base = basename ($ARGV[0]); + + $prod =~ s/\@filename\@/$ARGV[0]/g; + $prod =~ s/\@basename\@/$base/g; + $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; + $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; + chomp ($prod); + + print "$prod\n"; +} + +while (<>) { + if (eof) { + close (ARGV); # reset line numbering + $firstenum = 1; # Flag to print filename at next enum + } + + # read lines until we have no open comments + while (m@/\*([^*]|\*(?!/))*$@) { + my $new; + defined ($new = <>) || die "Unmatched comment in $ARGV"; + $_ .= $new; + } + # strip comments w/o options + s@/\*(?!<) + ([^*]+|\*(?!/))* + \*/@@gx; + + # ignore forward declarations + next if /^\s*typedef\s+enum.*;/; + + if (m@^\s*typedef\s+enum\s* + (\{)?\s* + (?:/\*< + (([^*]|\*(?!/))*) + >\s*\*/)? + \s*(\{)? + @x) { + if (defined $2) { + my %options = parse_trigraph ($2); + next if defined $options{skip}; + $enum_prefix = $options{prefix}; + $flags = $options{flags}; + $option_lowercase_name = $options{lowercase_name}; + $option_underscore_name = $options{underscore_name}; + } else { + $enum_prefix = undef; + $flags = undef; + $option_lowercase_name = undef; + $option_underscore_name = undef; + } + if (defined $option_lowercase_name) { + if (defined $option_underscore_name) { + print STDERR "$0: $ARGV:$.: lowercase_name overriden with underscore_name\n"; + $option_lowercase_name = undef; + } else { + print STDERR "$0: $ARGV:$.: lowercase_name is deprecated, use underscore_name\n"; + } + } + # Didn't have trailing '{' look on next lines + if (!defined $1 && !defined $4) { + while (<>) { + if (eof) { + die "Hit end of file while parsing enum in $ARGV"; + } + if (s/^\s*\{//) { + last; + } + } + } + + $seenbitshift = 0; + @entries = (); + + # Now parse the entries + parse_entries (\*ARGV, $ARGV); + + # figure out if this was a flags or enums enumeration + if (!defined $flags) { + $flags = $seenbitshift; + } + + # Autogenerate a prefix + if (!defined $enum_prefix) { + for (@entries) { + my $nick = $_->[2]; + if (!defined $nick) { + my $name = $_->[0]; + if (defined $enum_prefix) { + my $tmp = ~ ($name ^ $enum_prefix); + ($tmp) = $tmp =~ /(^\xff*)/; + $enum_prefix = $enum_prefix & $tmp; + } else { + $enum_prefix = $name; + } + } + } + if (!defined $enum_prefix) { + $enum_prefix = ""; + } else { + # Trim so that it ends in an underscore + $enum_prefix =~ s/_[^_]*$/_/; + } + } else { + # canonicalize user defined prefixes + $enum_prefix = uc($enum_prefix); + $enum_prefix =~ s/-/_/g; + $enum_prefix =~ s/(.*)([^_])$/$1$2_/; + } + + for $entry (@entries) { + my ($name,$num,$nick) = @{$entry}; + if (!defined $nick) { + ($nick = $name) =~ s/^$enum_prefix//; + $nick =~ tr/_/-/; + $nick = lc($nick); + @{$entry} = ($name, $num, $nick); + } + } + + + # Spit out the output + if (defined $option_underscore_name) { + $enumlong = uc $option_underscore_name; + $enumsym = lc $option_underscore_name; + $enumshort = $enumlong; + $enumshort =~ s/^[A-Z][A-Z0-9]*_//; + + $enumname_prefix = $enumlong; + $enumname_prefix =~ s/_$enumshort$//; + } elsif (!$symprefix && !$idprefix) { + # enumname is e.g. GMatchType + $enspace = $enumname; + $enspace =~ s/^([A-Z][a-z]*).*$/$1/; + + $enumshort = $enumname; + $enumshort =~ s/^[A-Z][a-z]*//; + $enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g; + $enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g; + $enumshort = uc($enumshort); + + $enumname_prefix = $enumname; + $enumname_prefix =~ s/^([A-Z][a-z]*).*$/$1/; + $enumname_prefix = uc($enumname_prefix); + + $enumlong = uc($enspace) . "_" . $enumshort; + $enumsym = lc($enspace) . "_" . lc($enumshort); + + if (defined($option_lowercase_name)) { + $enumsym = $option_lowercase_name; + } + } else { + $enumshort = $enumname; + if ($idprefix) { + $enumshort =~ s/^${idprefix}//; + } else { + $enumshort =~ s/^[A-Z][a-z]*//; + } + $enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g; + $enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g; + $enumshort = uc($enumshort); + + $enumname_prefix = $symprefix && uc($symprefix) || uc($idprefix); + + $enumlong = $enumname_prefix . "_" . $enumshort; + $enumsym = lc($enumlong); + } + + if ($firstenum) { + $firstenum = 0; + + if (length($fprod)) { + my $prod = $fprod; + my $base = basename ($ARGV); + + $prod =~ s/\@filename\@/$ARGV/g; + $prod =~ s/\@basename\@/$base/g; + $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; + $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; + chomp ($prod); + + print "$prod\n"; + } + } + + if (length($eprod)) { + my $prod = $eprod; + + $prod =~ s/\@enum_name\@/$enumsym/g; + $prod =~ s/\@EnumName\@/$enumname/g; + $prod =~ s/\@ENUMSHORT\@/$enumshort/g; + $prod =~ s/\@ENUMNAME\@/$enumlong/g; + $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; + if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } + if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } + if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } + $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; + $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; + chomp ($prod); + + print "$prod\n"; + } + + if (length($vhead)) { + my $prod = $vhead; + + $prod =~ s/\@enum_name\@/$enumsym/g; + $prod =~ s/\@EnumName\@/$enumname/g; + $prod =~ s/\@ENUMSHORT\@/$enumshort/g; + $prod =~ s/\@ENUMNAME\@/$enumlong/g; + $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; + if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } + if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } + if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } + $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; + $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; + chomp ($prod); + + print "$prod\n"; + } + + if (length($vprod)) { + my $prod = $vprod; + my $next_num = 0; + + $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; + $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; + for (@entries) { + my ($name,$num,$nick) = @{$_}; + my $tmp_prod = $prod; + + if ($prod =~ /\@valuenum\@/) { + # only attempt to eval the value if it is requested + # this prevents us from throwing errors otherwise + if (defined $num) { + # use sandboxed perl evaluation as a reasonable + # approximation to C constant folding + $num = $sandbox->reval ($num); + + # make sure it parsed to an integer + if (!defined $num or $num !~ /^-?\d+$/) { + die "Unable to parse enum value '$num'"; + } + } else { + $num = $next_num; + } + + $tmp_prod =~ s/\@valuenum\@/$num/g; + $next_num = $num + 1; + } + + $tmp_prod =~ s/\@VALUENAME\@/$name/g; + $tmp_prod =~ s/\@valuenick\@/$nick/g; + if ($flags) { $tmp_prod =~ s/\@type\@/flags/g; } else { $tmp_prod =~ s/\@type\@/enum/g; } + if ($flags) { $tmp_prod =~ s/\@Type\@/Flags/g; } else { $tmp_prod =~ s/\@Type\@/Enum/g; } + if ($flags) { $tmp_prod =~ s/\@TYPE\@/FLAGS/g; } else { $tmp_prod =~ s/\@TYPE\@/ENUM/g; } + chomp ($tmp_prod); + + print "$tmp_prod\n"; + } + } + + if (length($vtail)) { + my $prod = $vtail; + + $prod =~ s/\@enum_name\@/$enumsym/g; + $prod =~ s/\@EnumName\@/$enumname/g; + $prod =~ s/\@ENUMSHORT\@/$enumshort/g; + $prod =~ s/\@ENUMNAME\@/$enumlong/g; + $prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g; + if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; } + if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; } + if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; } + $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; + $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; + chomp ($prod); + + print "$prod\n"; + } + } +} + +if (length($ftail)) { + my $prod = $ftail; + my $base = basename ($ARGV); + + $prod =~ s/\@filename\@/$ARGV/g; + $prod =~ s/\@basename\@/$base/g; + $prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g; + $prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g; + chomp ($prod); + + print "$prod\n"; +} + +# put auto-generation comment +{ + my $comment = $comment_tmpl; + $comment =~ s/\@comment\@/Generated data ends here/; + print "\n" . $comment . "\n\n"; +}