├── LICENSE.md ├── README.md ├── assets ├── vinyl.png └── yawns-logo.png ├── install.sh ├── src ├── app.py ├── backends │ └── X11.py ├── config.ini ├── gtk_helpers.py ├── requierements.txt ├── style.qss ├── yawns_manager.py └── yawns_notifications.py └── uninstall.sh /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 |

Your Adaptable Widget Notification System

6 | 7 |

8 | 9 |

10 | 11 | 12 | ## Table of contents 13 | - [Introduction](#introduction) 14 | - [Features](#features) 15 | - [Examples](#examples) 16 | - [Installing](#installing) 17 | 18 | 19 | # Introduction 20 | 21 | Yawns is a notification manager (or daemon) written out of the necessity for highly customizable, adaptable notifications. Why would your notification for a brightness change look the same as your Spotify song change notification? Or even an email one? This is where Yawns introduces the concept of, uhm, well, __yawns__. 22 | 23 | A yawn is a window displaying the contents of a notification. So far, the following yawns are available: 24 | - __Corner yawn__: The most classic notification design. Shows up as a window anchored to one of the corners of your screen. Multiple notifications stack vertically. Ideal for things like e-mail notifications. 25 | - __Center yawn__: Show a notification in the center of the screen. Multiple notifications stack vertically one behind the other. Meant mostly for displaying quick settings changes like volume, brightness or keyboard layout. 26 | - __Media yawn__: Like a corner yawn, but this one shows the notification icon as a spinning vinyl disc and doesn't stack, each new yawn replaces the last one (if it's still open). Your Spotify notifications are gonna look amazing with this one. 27 | 28 | When a notification is received, if the hint `yawn_type` is provided (like when running `notify-send hello -h int:yawn_type:1`), the manager will use the specified yawn type to display the notification, following the order from the above list starting from 1. 29 | 30 | There are more yawn types to come but you're more than welcome to open an issue suggesting any cool ideas you might have :) 31 | 32 | You can read more about how Yawns work in the [wiki](https://github.com/ikz87/yawns/wiki) 33 | 34 | 35 | # Features 36 | - Full markup on summary and body 37 | - Full control of per-yawn QSS (kinda like CSS) 38 | - Scripting via an external command set in configs 39 | - Completely different yawns (notification windows) based on notification hints 40 | 41 | 42 | # Examples 43 | These are some of the cool notifications I'm currently using yawns for :) 44 | 45 | All the notifications below are either sent by applications or through the `notify-send` core util. No extra tool is needed 46 | 47 | ## A center yawn with a workspace change notification 48 | Featuring some markdown to change font size and color on certain characters, from this [script](https://github.com/ikz87/dots-2.0/blob/personal/Bscripts/wp_switcher.sh) 49 | 50 | ![image](https://github.com/user-attachments/assets/9187da2f-8f8c-4fd2-a724-f53bfbfaa173) 51 | 52 | 53 | ## A center yawn with a brightness/volume change notification 54 | With corresponding icon and bar percentage, from these [brightness](https://github.com/ikz87/dots-2.0/blob/personal/Bscripts/brightness.sh) and [volume](https://github.com/ikz87/dots-2.0/blob/personal/Bscripts/volume.sh) scripts 55 | 56 | ![image](https://github.com/user-attachments/assets/8bde0777-3b16-4762-88ae-886e2e1f0815) 57 | ![image](https://github.com/user-attachments/assets/1235ad6d-f6a9-4975-ab07-c840ad8c3e8e) 58 | 59 | ## A corner yawn with a text message with action buttons (Whatsapp) 60 | ![image](https://github.com/user-attachments/assets/5f4f4fdf-eeab-4e1b-84f0-b5ab99b43001) 61 | 62 | ## A corner yawn with a battery warning notification 63 | From this [script](https://github.com/ikz87/dots-2.0/blob/main/Configs/eww/mybar/scripts/battery_info) 64 | 65 | ![image](https://github.com/user-attachments/assets/bd98992a-9f3b-4af5-8ce8-9e0e4e08d506) 66 | 67 | ## A media yawn with a Spotify notification 68 | ![output](https://github.com/user-attachments/assets/4a584ca7-029f-45dc-874b-ff8cc08cb3db) 69 | 70 | 71 | 72 | # Installing 73 | Either install from the official [AUR package](https://aur.archlinux.org/packages/yawns) or run `install.sh` as root. 74 | -------------------------------------------------------------------------------- /assets/vinyl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ikz87/yawns/bbae9e73dfd38fbab89c2c7086bc05a3b26dd2ff/assets/vinyl.png -------------------------------------------------------------------------------- /assets/yawns-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ikz87/yawns/bbae9e73dfd38fbab89c2c7086bc05a3b26dd2ff/assets/yawns-logo.png -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | if [[ $EUID -ne 0 ]]; then 3 | echo "This script must be run as root. Exiting." 4 | exit 1 5 | fi 6 | pkgname=yawns 7 | program_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 8 | 9 | # Install the main program 10 | install -Dm755 "$program_dir/src/app.py" "/usr/share/$pkgname/app.py" 11 | 12 | # Install Python files 13 | install -Dm644 "$program_dir/src/yawns_manager.py" "/usr/share/$pkgname/yawns_manager.py" 14 | install -Dm644 "$program_dir/src/yawns_notifications.py" "/usr/share/$pkgname/yawns_notifications.py" 15 | install -Dm644 "$program_dir/src/gtk_helpers.py" "/usr/share/$pkgname/gtk_helpers.py" 16 | install -Dm644 "$program_dir/src/backends/X11.py" "/usr/share/$pkgname/backends/X11.py" 17 | 18 | # Install assets 19 | install -Dm644 "$program_dir/assets/yawns-logo.png" "/usr/share/$pkgname/assets/yawns-logo.png" 20 | install -Dm644 "$program_dir/assets/vinyl.png" "/usr/share/$pkgname/assets/vinyl.png" 21 | 22 | # Install configuration and style files to system-wide config directory 23 | install -Dm644 "$program_dir/src/style.qss" "/usr/share/$pkgname/style.qss" 24 | install -Dm644 "$program_dir/src/config.ini" "/usr/share/$pkgname/config.ini" 25 | 26 | # Create a wrapper script for first-run setup and execution 27 | install -Dm755 -d "$pkgdir/usr/bin" # Ensure the directory exists for the wrapper script 28 | echo '#!/bin/bash 29 | if [ ! -d "$HOME/.config/yawns" ]; then 30 | mkdir -p "$HOME/.config/yawns" 31 | cp -r /usr/share/yawns/* "$HOME/.config/yawns" 32 | fi 33 | exec python3 /usr/share/yawns/app.py "$@"' > "/usr/bin/$pkgname" 34 | chmod +x "/usr/bin/$pkgname" 35 | 36 | echo "Yawns has been installed. Be sure to also install all the python modules in src/requierements.txt" 37 | -------------------------------------------------------------------------------- /src/app.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import configparser 3 | import signal 4 | import os 5 | import subprocess 6 | import fnmatch 7 | from PyQt5.QtCore import QThread, pyqtSignal, QTimer, Qt 8 | from PyQt5.QtWidgets import QApplication 9 | from dbus_next.constants import MessageType 10 | from yawns_notifications import BaseYawn, YawnType, CornerYawn, CenterYawn, MediaYawn 11 | from yawns_manager import NotificationManager 12 | from dbus_next.aio import MessageBus 13 | from dbus_next.message import Message 14 | import argparse 15 | import asyncio 16 | 17 | def detect_compositor(): 18 | display = WDisplay() 19 | display.connect() 20 | registry = display.get_registry() 21 | 22 | compositor_name = None 23 | 24 | # Will finish later 25 | 26 | display.disconnect() 27 | return compositor_name 28 | 29 | class NotificationManagerThread(QThread): 30 | notification_received = pyqtSignal(dict) 31 | notification_closed = pyqtSignal(int) 32 | 33 | def __init__(self): 34 | super().__init__() 35 | self.loop = asyncio.new_event_loop() 36 | self.manager = None 37 | self.bus = None 38 | 39 | async def setup_dbus(self): 40 | """Set up the D-Bus manager and bind the signal.""" 41 | self.bus = await MessageBus().connect() 42 | self.manager = NotificationManager(self.bus) 43 | self.manager.notify_app = self.notify_app 44 | self.manager.close_notification = self.close_notification 45 | self.manager.do_action_on_notification = self.do_action_on_notification 46 | self.bus.export("/org/freedesktop/Notifications", self.manager) 47 | await self.bus.request_name("org.freedesktop.Notifications") 48 | print("Yawns manager running...") 49 | 50 | def notify_app(self, info_dict: dict): 51 | """Emit a PyQt signal when a notification is received.""" 52 | filtered_dict = {k: v for k, v in info_dict.items() if k != "pixmap_data"} 53 | # print(f"Received notification:\n{filtered_dict}") 54 | self.notification_received.emit(info_dict) 55 | 56 | def close_notification(self, id, reason, sender_id): 57 | """ 58 | Sends two signals, one (qt) to the yawns app to close the yawn with 59 | the id provided and another one (dbus) to the sender app to tell it 60 | the notification has been closed. 61 | """ 62 | message = Message( 63 | destination=sender_id, 64 | message_type=MessageType.SIGNAL, # Signal type 65 | signature="uu", 66 | interface="org.freedesktop.Notifications", 67 | path="/org/freedesktop/Notifications", 68 | member="NotificationClosed", 69 | body=[int(id), int(reason)], 70 | ) 71 | self.bus.send(message) 72 | self.notification_closed.emit(id) 73 | 74 | def do_action_on_notification(self, id, action, sender_id): 75 | """ 76 | Performs an action on notification 77 | The handling of the action depends on the sender app 78 | """ 79 | message = Message( 80 | destination=sender_id, 81 | message_type=MessageType.SIGNAL, # Signal type 82 | signature="us", 83 | interface="org.freedesktop.Notifications", 84 | path="/org/freedesktop/Notifications", 85 | member="ActionInvoked", 86 | body=[id, action], 87 | ) 88 | self.bus.send(message) 89 | 90 | def run(self): 91 | """Run the D-Bus manager in its own thread.""" 92 | asyncio.set_event_loop(self.loop) 93 | self.loop.run_until_complete(self.setup_dbus()) 94 | try: 95 | self.loop.run_forever() 96 | finally: 97 | self.loop.close() 98 | 99 | def stop(self): 100 | """Stop the event loop and thread.""" 101 | self.loop.call_soon_threadsafe(self.loop.stop) 102 | self.quit() 103 | 104 | 105 | class YawnsApp(QApplication): 106 | request_notification_closing = pyqtSignal(int, int, str) 107 | request_notification_action = pyqtSignal(int, str, str) 108 | 109 | def __init__(self, appname, display_info): 110 | self.setAttribute(Qt.AA_X11InitThreads) 111 | super().__init__(appname) 112 | self.display_info = display_info 113 | # Use local qss 114 | self.stylesheet = open(STYLE_PATH, "r").read() 115 | self.setStyleSheet(self.stylesheet) 116 | 117 | # Arrays for storing yawns 118 | self.yawn_arrays = { 119 | "CornerYawn": [], 120 | "CenterYawn": [], 121 | "MediaYawn": [], 122 | } 123 | self.fullscreen_detected = False 124 | 125 | def handle_fullscreen_change(self, fullscreen): 126 | """ 127 | Hide and show yawns depending on urgency and fullscreen state 128 | """ 129 | global CONFIG 130 | self.fullscreen_detected = fullscreen 131 | min_corner_urgency = CONFIG.getint("corner", "min_urgency", fallback=2) 132 | min_center_urgency = CONFIG.getint("center", "min_urgency", fallback=2) 133 | min_media_urgency = CONFIG.getint("media", "min_urgency", fallback=2) 134 | for yawn in self.yawn_arrays["CornerYawn"]: 135 | if yawn.urgency < min_corner_urgency and fullscreen: 136 | yawn.hide() 137 | else: 138 | yawn.show() 139 | yawn.update_position() 140 | 141 | for yawn in self.yawn_arrays["CenterYawn"]: 142 | if yawn.urgency < min_center_urgency and fullscreen: 143 | yawn.hide() 144 | else: 145 | yawn.show() 146 | yawn.update_position() 147 | 148 | for yawn in self.yawn_arrays["MediaYawn"]: 149 | if yawn.urgency < min_center_urgency and fullscreen: 150 | yawn.hide() 151 | else: 152 | yawn.show() 153 | yawn.update_position() 154 | 155 | def select_yawn_type(self, info_dict): 156 | """ 157 | Select the yawn type based on the yawn_type hint in info dict 158 | """ 159 | global CONFIG 160 | fallback = self.show_corner_yawn 161 | 162 | yawn_type = None 163 | if "yawn_type" in info_dict["hints"]: 164 | yawn_type = int(info_dict["hints"]["yawn_type"].value) 165 | # Modify yawn_type according to filters in config 166 | for yawn_type_value, section in enumerate(["corner", "center", "media"]): 167 | for section_filter in ["app_name", "summary", "body"]: 168 | filter_values = CONFIG.get(section, section_filter, fallback=None) 169 | if not filter_values: 170 | continue 171 | filter_values = filter_values.split() 172 | for filter_value in filter_values: 173 | notif_value = info_dict.get(section_filter, None) 174 | if not notif_value: 175 | break 176 | if fnmatch.fnmatch(notif_value, filter_value): 177 | yawn_type = yawn_type_value + 1 178 | break 179 | if yawn_type == YawnType.CORNER.value: 180 | self.show_corner_yawn(info_dict) 181 | elif yawn_type == YawnType.CENTER.value: 182 | self.show_center_yawn(info_dict) 183 | elif yawn_type == YawnType.MEDIA.value: 184 | self.show_media_yawn(info_dict) 185 | else: 186 | fallback(info_dict) 187 | 188 | # Run command after showing the yawn 189 | if "general" in CONFIG.sections() and "command" in CONFIG["general"]: 190 | command = os.path.expanduser(CONFIG["general"]["command"]) 191 | urgency_struct = info_dict["hints"].get("urgency", None) 192 | urgency = 1 193 | if urgency_struct: 194 | urgency = int(urgency_struct.value) 195 | try: 196 | subprocess.call( 197 | [ 198 | command, 199 | info_dict["app_name"], 200 | info_dict["summary"], 201 | info_dict["body"], 202 | info_dict["app_icon"], 203 | str(urgency), 204 | ] 205 | ) 206 | except Exception as e: 207 | print("Error running command:", command) 208 | print(e) 209 | 210 | def show_corner_yawn(self, info_dict): 211 | # First check the replace id 212 | if info_dict["replaces_id"] != 0: 213 | for notification in self.yawn_arrays["CenterYawn"]: 214 | if notification.info_dict["replaces_id"] == info_dict["replaces_id"]: 215 | notification.info_dict = info_dict 216 | notification.close() 217 | for notification in self.yawn_arrays["CornerYawn"]: 218 | if notification.info_dict["replaces_id"] == info_dict["replaces_id"]: 219 | notification.info_dict = info_dict 220 | notification.update_content() 221 | return 222 | global CONFIG 223 | yawn = CornerYawn(self, CONFIG, info_dict) 224 | min_urgency = CONFIG.getint("corner", "min_urgency", fallback=0) 225 | if yawn.urgency < min_urgency and self.fullscreen_detected: 226 | pass 227 | else: 228 | yawn.show() 229 | 230 | def show_center_yawn(self, info_dict): 231 | if info_dict["replaces_id"] != 0: 232 | for notification in self.yawn_arrays["CornerYawn"]: 233 | if notification.info_dict["replaces_id"] == info_dict["replaces_id"]: 234 | notification.info_dict = info_dict 235 | notification.close() 236 | for notification in self.yawn_arrays["CenterYawn"]: 237 | if notification.info_dict["replaces_id"] == info_dict["replaces_id"]: 238 | notification.info_dict = info_dict 239 | notification.update_content() 240 | return 241 | global CONFIG 242 | yawn = CenterYawn(self, CONFIG, info_dict) 243 | min_urgency = CONFIG.getint("center", "min_urgency", fallback=0) 244 | if yawn.urgency < min_urgency and self.fullscreen_detected: 245 | pass 246 | else: 247 | yawn.show() 248 | 249 | def show_media_yawn(self, info_dict): 250 | if self.yawn_arrays["MediaYawn"]: 251 | notification = self.yawn_arrays["MediaYawn"][0] 252 | notification.info_dict = info_dict 253 | notification.update_content() 254 | return 255 | 256 | global CONFIG 257 | yawn = MediaYawn(self, CONFIG, info_dict) 258 | min_urgency = CONFIG.getint("media", "min_urgency", fallback=0) 259 | if yawn.urgency < min_urgency and self.fullscreen_detected: 260 | pass 261 | else: 262 | yawn.show() 263 | 264 | def close_notification(self, notification_id): 265 | """ 266 | Close the notification with the given ID 267 | """ 268 | for key in self.yawn_arrays: 269 | for notification in self.yawn_arrays[key]: 270 | if notification.info_dict["notification_id"] == notification_id: 271 | notification.close() 272 | return 273 | 274 | 275 | def handle_sigint(): 276 | """Handle Ctrl+C to gracefully exit.""" 277 | print("\nCtrl+C pressed. Exiting...") 278 | manager_thread.stop() 279 | app.quit() 280 | 281 | def check_notification_service(): 282 | """ 283 | Check if there's already a notification service running 284 | """ 285 | # Define the actual asynchronous function 286 | async def async_check(): 287 | # Connect to the session bus 288 | bus = await MessageBus().connect() 289 | 290 | # Create a message to call the `GetNameOwner` method 291 | message = Message( 292 | destination="org.freedesktop.DBus", 293 | path="/org/freedesktop/DBus", 294 | interface="org.freedesktop.DBus", 295 | member="GetNameOwner", 296 | signature="s", 297 | body=["org.freedesktop.Notifications"] 298 | ) 299 | 300 | # Send the message and get a reply 301 | reply = await bus.call(message) 302 | 303 | if reply.message_type == MessageType.ERROR: 304 | # If there's an error, it usually means the name is not owned 305 | if "org.freedesktop.DBus.Error.NameHasNoOwner" in reply.error_name: 306 | return False # Name is not taken 307 | else: 308 | print(f"An unexpected error occurred: {reply.error_name}") 309 | sys.exit(1) # Exit on unexpected errors 310 | else: 311 | return True # Name is taken 312 | 313 | # Run the asynchronous function synchronously 314 | return asyncio.run(async_check()) 315 | 316 | 317 | if __name__ == "__main__": 318 | global CONFIG 319 | global STYLE_PATH 320 | global CONFIG_PATH 321 | global VERSION 322 | VERSION = "yawns v1.1.0" 323 | 324 | # Check if a notification service is already running 325 | if check_notification_service(): 326 | print("A notification service is already running. Exiting...") 327 | sys.exit(1) 328 | 329 | # Check the display server 330 | server = None 331 | compositor = None 332 | if "WAYLAND_DISPLAY" in os.environ: 333 | server = "Wayland" 334 | compositor = detect_compositor() # <- unfinished function 335 | 336 | match compositor: 337 | case "sway": 338 | pass 339 | case "hyprland": 340 | pass 341 | case None: 342 | print(f"Compositor not detected") 343 | case _: 344 | print(f"Compositor: {compositor} is not supported yet.") 345 | sys.exit(2) 346 | 347 | # Placeholder exit message to be removed when Wayland support is added 348 | print("Wayland is not supported yet. Exiting...") 349 | sys.exit(1) 350 | 351 | elif "DISPLAY" in os.environ: 352 | try: 353 | result = subprocess.run(["xdpyinfo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) 354 | if result.returncode == 0: 355 | server = "Xorg" 356 | except FileNotFoundError: 357 | # xdpyinfo is not installed 358 | pass 359 | if not server: 360 | print("Unable to detect the display server (Xorg or Wayland). Exiting...") 361 | sys.exit(1) 362 | 363 | # CL Arguments 364 | argparser = argparse.ArgumentParser( 365 | prog="yawns", 366 | description="Your Adaptable Widget Notification System") 367 | argparser.add_argument("-c", "--config", type=str, default=None, help="Path to the config.ini file") 368 | argparser.add_argument("-s", "--style", type=str, default=None, help="Path to the style.qss file") 369 | argparser.add_argument("-v", "--version", action="version", version=VERSION) 370 | args = argparser.parse_args() 371 | 372 | # Configuration 373 | CONFIG_DIR = os.path.expanduser("~/.config/yawns") 374 | if args.config: 375 | CONFIG_PATH = args.config 376 | 377 | # Check if the configuration exists 378 | if not os.path.isfile(CONFIG_PATH): 379 | print(f"Configuration file '{CONFIG_PATH}' does not exist. Exiting...") 380 | sys.exit(1) 381 | else: 382 | CONFIG_PATH = CONFIG_DIR + "/config.ini" 383 | if args.style: 384 | STYLE_PATH = args.style 385 | # Check if the style exists 386 | if not os.path.isfile(STYLE_PATH): 387 | print(f"Style file '{STYLE_PATH}' does not exist. Exiting...") 388 | sys.exit(1) 389 | else: 390 | STYLE_PATH = CONFIG_DIR + "/style.qss" 391 | 392 | CONFIG = configparser.ConfigParser() 393 | CONFIG.read(CONFIG_PATH) 394 | 395 | # Initialize the application 396 | # with display server dependent thingies 397 | if server == "Xorg": 398 | from backends.X11 import FullscreenMonitor, setup_yawn_window 399 | from Xlib.display import Display 400 | 401 | display = Display() 402 | app = YawnsApp(["yawns"], {"display_server": "Xorg", "X11_display": display}) 403 | app.setup_yawn_window = setup_yawn_window 404 | fullscreen_monitor_thread = FullscreenMonitor(display) 405 | else: 406 | sys.exit(1) 407 | fullscreen_monitor_thread.fullscreen_active.connect(app.handle_fullscreen_change) 408 | fullscreen_monitor_thread.start() 409 | app.setQuitOnLastWindowClosed(False) 410 | 411 | # Start the NotificationManager in a QThread 412 | manager_thread = NotificationManagerThread() 413 | 414 | # This is cumbersome, but we have to connect signals this way 415 | # because all notification closing should also be handled by the 416 | # manager primarily 417 | manager_thread.notification_received.connect(app.select_yawn_type) 418 | 419 | app.request_notification_closing.connect(manager_thread.close_notification) 420 | app.request_notification_action.connect(manager_thread.do_action_on_notification) 421 | 422 | manager_thread.notification_closed.connect(app.close_notification) 423 | manager_thread.start() 424 | 425 | 426 | # Handle Ctrl+C 427 | signal.signal(signal.SIGINT, lambda *_: handle_sigint()) 428 | timer = QTimer() 429 | timer.timeout.connect(lambda: None) # Allow the event loop to process signals 430 | timer.start(100) 431 | 432 | # Start the PyQt application 433 | try: 434 | sys.exit(app.exec_()) 435 | finally: 436 | manager_thread.stop() 437 | -------------------------------------------------------------------------------- /src/backends/X11.py: -------------------------------------------------------------------------------- 1 | from PyQt5.QtCore import QThread, pyqtSignal 2 | from Xlib import X 3 | from Xlib.Xatom import ATOM, STRING 4 | import Xlib.threaded 5 | from PyQt5.QtX11Extras import QX11Info 6 | from sys import path 7 | path.append("../") 8 | from yawns_notifications import BaseYawn 9 | 10 | class FullscreenMonitor(QThread): 11 | """ 12 | Monitors fullscreen windows and emits a signal when the state changes. 13 | """ 14 | fullscreen_active = pyqtSignal(bool) 15 | 16 | def __init__(self, x11_display): 17 | super().__init__() 18 | self.display = x11_display 19 | 20 | def run(self): 21 | root = self.display.screen().root 22 | screen = self.display.screen() 23 | 24 | # Select the events you want to listen to for the root window 25 | root.change_attributes(event_mask=X.FocusChangeMask | X.PropertyChangeMask) 26 | self.display.sync() 27 | 28 | # Create a loop to monitor the event queue 29 | while True: 30 | # Get the next event from the X event queue 31 | event = self.display.next_event() 32 | 33 | # Check for window state changes (PropertyNotify) 34 | if event.type == X.PropertyNotify: 35 | if event.atom == 352: 36 | num_of_fs = 0 37 | for window in root.query_tree()._data["children"]: 38 | self.display.sync() 39 | try: 40 | width = window.get_geometry()._data["width"] 41 | height = window.get_geometry()._data["height"] 42 | # Check if the window is mapped and fullscreen 43 | if window.get_attributes().map_state != 0: 44 | if ( 45 | width == screen.width_in_pixels 46 | and height == screen.height_in_pixels 47 | ): 48 | num_of_fs += 1 49 | except Xlib.error.BadDrawable as e: 50 | # Uhhhh 51 | # Ig this is a window that was destroyed? 52 | # Let's just ignore that 53 | pass 54 | 55 | if num_of_fs > 1: 56 | self.fullscreen_active.emit(True) 57 | else: 58 | self.fullscreen_active.emit(False) 59 | 60 | # Flush the display buffer if needed 61 | self.display.sync() 62 | 63 | 64 | def setup_yawn_window(yawn: BaseYawn): 65 | """ 66 | Set up X11 properties for a yawn. 67 | """ 68 | urgency_struct = yawn.info_dict["hints"].get("urgency", None) 69 | yawn.urgency = 1 70 | if urgency_struct: 71 | yawn.urgency = int(urgency_struct.value) 72 | 73 | if QX11Info.isPlatformX11(): 74 | # Use the previously open X display connection 75 | x11_display = yawn.app.display_info["X11_display"] 76 | 77 | x11_display.sync() 78 | 79 | # Get the window ID 80 | wid = int(yawn.winId()) 81 | window = x11_display.create_resource_object("window", wid) 82 | 83 | # Get atoms for the required properties 84 | WM_CLASS = x11_display.intern_atom("WM_CLASS") 85 | _NET_WM_STATE = x11_display.intern_atom("_NET_WM_STATE") 86 | _NET_WM_STATE_ABOVE = x11_display.intern_atom("_NET_WM_STATE_ABOVE") 87 | _NET_WM_WINDOW_TYPE = x11_display.intern_atom("_NET_WM_WINDOW_TYPE") 88 | _NET_WM_WINDOW_TYPE_NOTIFICATION = x11_display.intern_atom( 89 | "_NET_WM_WINDOW_TYPE_NOTIFICATION" 90 | ) 91 | 92 | # Set _NET_WM_STATE to ABOVE for high urgency 93 | # (even though that doesn't actually work) 94 | if yawn.urgency == 2: # High urgency 95 | window.change_property(_NET_WM_STATE, ATOM, 32, [_NET_WM_STATE_ABOVE]) 96 | else: # Normal or low urgency 97 | window.change_property(_NET_WM_STATE, ATOM, 32, []) 98 | 99 | # Set _NET_WM_WINDOW_TYPE to both NOTIFICATION and UTILITY 100 | window.change_property( 101 | _NET_WM_WINDOW_TYPE, ATOM, 32, [_NET_WM_WINDOW_TYPE_NOTIFICATION] 102 | ) 103 | 104 | # Set WM_CLASS 105 | window.change_property(WM_CLASS, STRING, 8, yawn.wm_class.encode("utf-8")) 106 | 107 | # Flush the display to apply changes 108 | x11_display.sync() 109 | -------------------------------------------------------------------------------- /src/config.ini: -------------------------------------------------------------------------------- 1 | [general] 2 | 3 | ; Optional command to run when a yawn 4 | ; is shown. Appname, summary, body, icon_path and 5 | ; urgency are passed as command line arguments in 6 | ; that order. 7 | command = ~/.bscripts/notif_sounds.sh 8 | 9 | ; Actions for when clicking a yawn. 10 | ; Can be none, one or multiple of: 11 | ; - default: Executes the default action 12 | ; - close: Closes the notification 13 | ; This doesn't take effect when clicking the 14 | ; actual action buttons 15 | mouse-left-click = close 16 | mouse-right-click = close 17 | mouse-middle-click = close 18 | 19 | [corner] 20 | ; Fallback timeout 21 | timeout = 5250 22 | 23 | ; Fixed width 24 | width = 400 25 | 26 | ; Max height 27 | height = 500 28 | 29 | ; Offsets. Positive offset means 30 | ; the corner yawn will be anchored top/left 31 | ; while negative ones mean bottom/right 32 | y-offset = -40 33 | x-offset = -40 34 | 35 | ; Size for the icon image 36 | icon-size = 76 37 | 38 | ; Gap between corner yawns 39 | gap = 15 40 | 41 | ; Minimum urgency to show the yawn 42 | ; over fullscreen windows 43 | ; 0 = Low 44 | ; 1 = Normal 45 | ; 2 = Critical 46 | fs_urgency = 2 47 | 48 | ; Whether to show the action buttons 49 | show_buttons = true 50 | 51 | [center] 52 | ; Fallback timeout 53 | timeout = 5250 54 | 55 | ; Min width 56 | width = 220 57 | 58 | ; Min height 59 | height = 220 60 | 61 | ; Size for the icon image 62 | icon-size = 64 63 | 64 | ; Minimum urgency to show the yawn 65 | ; over fullscreen windows 66 | ; 0 = Low 67 | ; 1 = Normal 68 | ; 2 = Critical 69 | fs_urgency = 0 70 | 71 | [media] 72 | ; Fallback timeout 73 | timeout = 5250 74 | 75 | ; FPS for the icon rotations 76 | fps = 30 77 | 78 | ; Fixed width 79 | width = 450 80 | 81 | ; Max height 82 | height = 500 83 | 84 | ; Offsets. Positive offset means 85 | ; the corner yawn will be anchored top/left 86 | ; while negative ones mean bottom/right 87 | y-offset = -40 88 | x-offset = 40 89 | 90 | ; Size for the icon image 91 | icon-size = 100 92 | 93 | ; Minimum urgency to show the yawn 94 | ; over fullscreen windows 95 | ; 0 = Low 96 | ; 1 = Normal 97 | ; 2 = Critical 98 | fs_urgency = 2 99 | 100 | ; Whether to show the action buttons 101 | show_buttons = true 102 | 103 | ; Path to the "texture" that the notification 104 | ; icon will overlay. The default is a vinyl disk 105 | bg_icon = /usr/share/yawns/assets/vinyl.png 106 | 107 | ; Filters. You can set any of these properties: 108 | ; - app_name 109 | ; - summary 110 | ; - body 111 | ; Under any yawn type section so that any notifications 112 | ; that match that property value get set to the corresponding 113 | ; yawn type. 114 | app_name = Spotify 115 | -------------------------------------------------------------------------------- /src/gtk_helpers.py: -------------------------------------------------------------------------------- 1 | import gi 2 | gi.require_version("Gtk", "3.0") # Ensure compatibility with GTK 3 3 | from gi.repository import Gtk 4 | 5 | def find_icon(icon_name, size=64): 6 | """ 7 | Search for an application icon in a freedesktop.org-compliant icon theme. 8 | 9 | Args: 10 | icon_name (str): Name of the application icon to search for. 11 | size (int): Size of the icon in pixels (default is 48). 12 | 13 | Returns: 14 | str: Full path to the icon image, or None if not found. 15 | """ 16 | # Load the default system icon theme 17 | icon_theme = Gtk.IconTheme.get_default() 18 | 19 | # Lookup the icon 20 | icon_info = icon_theme.lookup_icon(icon_name, size, Gtk.IconLookupFlags.USE_BUILTIN) 21 | 22 | if icon_info: 23 | return icon_info.get_filename() 24 | return None 25 | -------------------------------------------------------------------------------- /src/requierements.txt: -------------------------------------------------------------------------------- 1 | PyQt5 2 | dbus-next 3 | yawns-notifications 4 | pillow 5 | cssutils 6 | python-xlib 7 | PyGObject 8 | -------------------------------------------------------------------------------- /src/style.qss: -------------------------------------------------------------------------------- 1 | * { 2 | background-color: rgba(0, 0, 0, 0); 3 | color: #ffffff; 4 | font-family: Iosevka Curly; 5 | font-size: 16px; 6 | } 7 | 8 | #CornerYawn { 9 | background-color: rgba(36, 39, 47, 1); 10 | border-radius: 20px; 11 | border: 5px solid #FFE001; 12 | padding: 10px; 13 | } 14 | 15 | #CornerYawnIcon { 16 | margin-right: 10px; 17 | border-radius: 10px; 18 | padding: 10px; 19 | background-color: #0F1013; 20 | } 21 | 22 | #CornerYawnTextContainer { 23 | background-color: #0F1013; 24 | border-radius: 10px; 25 | padding: 10px; 26 | } 27 | 28 | #CornerYawnSummary { 29 | background-color: rgba(255, 255, 255, 0); 30 | font-weight: 700; 31 | } 32 | 33 | #CornerYawnBar { 34 | height: 5px; 35 | border-radius: 10px; 36 | margin-top: 10px; 37 | padding: 7.5px; 38 | background-color: #0F1013; 39 | } 40 | 41 | #CornerYawnButtonsContainer { 42 | background-color: #0F1013; 43 | margin-top: 10px; 44 | border-radius: 10px; 45 | padding: 5px; 46 | } 47 | 48 | #CornerYawnActionButton, #CornerYawnCloseButton { 49 | border-radius: 5px; 50 | margin: 5px; 51 | padding: 5px; 52 | background-color: #24272F; 53 | border: 2px solid #24272F; 54 | } 55 | 56 | #CornerYawnActionButton:hover, #CornerYawnCloseButton:hover { 57 | border-radius: 5px; 58 | margin: 5px; 59 | padding: 5px; 60 | border: 2px solid #ffffff; 61 | } 62 | 63 | #CornerYawnActionButton:pressed, #CornerYawnCloseButton:pressed { 64 | border-radius: 5px; 65 | margin: 5px; 66 | padding: 5px; 67 | margin-top: 7px; 68 | border: 2px solid #ffffff; 69 | margin-bottom: 3px; 70 | } 71 | 72 | #CornerYawnBar::chunk { 73 | width: 1px; 74 | background-color: #FFE001; 75 | } 76 | 77 | #CenterYawn { 78 | background-color: rgba(36, 39, 47, 1); 79 | border-radius: 20px; 80 | border: 5px solid #FFE001; 81 | padding: 10px 82 | } 83 | 84 | #CenterYawnIcon { 85 | margin-bottom: 10px; 86 | } 87 | 88 | #CenterYawnTextContainer { 89 | background-color: #0F1013; 90 | border-radius: 10px; 91 | padding: 10px; 92 | } 93 | 94 | #CenterYawnSummary { 95 | background-color: rgba(255, 255, 255, 0); 96 | font-weight: 700; 97 | } 98 | 99 | #CenterYawnBody { 100 | background-color: rgba(255, 255, 255, 0); 101 | } 102 | 103 | #CenterYawnBar { 104 | height: 5px; 105 | border-radius: 10px; 106 | margin-top: 6px; 107 | padding: 7.5px; 108 | background-color: #0F1013; 109 | } 110 | 111 | #CenterYawnBar::chunk { 112 | width: 1px; 113 | background-color: #FFE001; 114 | } 115 | 116 | #MediaYawn { 117 | background-color: rgba(36, 39, 47, 1); 118 | border-radius: 20px; 119 | border: 5px solid #FFE001; 120 | padding: 10px; 121 | } 122 | 123 | #MediaYawnIcon { 124 | margin-right: 10px; 125 | border-radius: 10px; 126 | padding: 10px; 127 | background-color: #0F1013; 128 | } 129 | 130 | #MediaYawnTextContainer { 131 | background-color: #0F1013; 132 | border-radius: 10px; 133 | padding: 10px; 134 | } 135 | 136 | #MediaYawnSummary { 137 | background-color: rgba(255, 255, 255, 0); 138 | font-weight: 700; 139 | } 140 | 141 | #MediaYawnBar { 142 | height: 5px; 143 | border-radius: 10px; 144 | margin-top: 10px; 145 | padding: 7.5px; 146 | background-color: #0F1013; 147 | } 148 | 149 | #MediaYawnButtonsContainer { 150 | background-color: #0F1013; 151 | margin-top: 10px; 152 | border-radius: 10px; 153 | padding: 5px; 154 | } 155 | 156 | #MediaYawnActionButton, #MediaYawnCloseButton { 157 | border-radius: 5px; 158 | margin: 5px; 159 | padding: 5px; 160 | background-color: #24272F; 161 | border: 2px solid #24272F; 162 | } 163 | 164 | #MediaYawnActionButton:hover, #MediaYawnCloseButton:hover { 165 | border-radius: 5px; 166 | margin: 5px; 167 | padding: 5px; 168 | border: 2px solid #ffffff; 169 | } 170 | 171 | #MediaYawnActionButton:pressed, #MediaYawnCloseButton:pressed { 172 | border-radius: 5px; 173 | margin: 5px; 174 | padding: 5px; 175 | margin-top: 7px; 176 | border: 2px solid #ffffff; 177 | margin-bottom: 3px; 178 | } 179 | -------------------------------------------------------------------------------- /src/yawns_manager.py: -------------------------------------------------------------------------------- 1 | import time 2 | from cssutils import os 3 | from dbus_next.constants import MessageType 4 | from dbus_next.service import ServiceInterface, method, dbus_property, signal 5 | from dbus_next.aio import MessageBus 6 | from dbus_next.message import Message 7 | from gtk_helpers import find_icon 8 | from PIL import Image 9 | import io 10 | import asyncio 11 | 12 | from yawns_notifications import BaseYawn 13 | 14 | 15 | class NotificationManager(ServiceInterface): 16 | def __init__(self, bus): 17 | super().__init__("org.freedesktop.Notifications") 18 | self.notification_id = 0 19 | self.bus = bus 20 | self.current_sender = "" 21 | 22 | def handle_message(message: Message): 23 | """Handle incoming D-Bus messages and log the sender.""" 24 | self.current_sender = message.sender # Save the sender somewhere 25 | 26 | self.bus.add_message_handler(handle_message) 27 | 28 | @method() 29 | def GetServerInformation(self) -> "ssss": 30 | return ["yawns", "kz87", "alpha", "0.1"] 31 | 32 | @method() 33 | def GetCapabilities(self) -> "as": 34 | return ["body", "actions", "icon-static"] 35 | 36 | @method() 37 | def Notify( 38 | self, 39 | app_name: "s", 40 | replaces_id: "u", 41 | app_icon: "s", 42 | summary: "s", 43 | body: "s", 44 | actions: "as", 45 | hints: "a{sv}", 46 | expire_timeout: "i", 47 | ) -> "u": 48 | 49 | def construct_image(image_data): 50 | image = Image.frombytes( 51 | "RGB", 52 | (image_data[0], image_data[1]), # width, height 53 | bytes(image_data[6]), # RGB data (ay) part 54 | "raw", 55 | "RGB", 56 | image_data[2], # rowstride 57 | image_data[3], # channels (3 or 4) 58 | ) 59 | if image_data[3]: # has_alpha 60 | image = image.convert("RGBA") 61 | # Save the image as PNG to a BytesIO object 62 | img_byte_arr = io.BytesIO() 63 | image.save(img_byte_arr, format="PNG") 64 | img_byte_arr = img_byte_arr.getvalue() 65 | return img_byte_arr 66 | 67 | # Load the image according to the freedesktop specification 68 | # See here: https://specifications.freedesktop.org/notification-spec/1.2/icons-and-images.html#icons-and-images-formats 69 | img_byte_arr = None 70 | if "image-data" in hints: 71 | try: 72 | img_byte_arr = construct_image(hints["image-data"].value) 73 | except Exception as e: 74 | print(f"Error loading image: {e}") 75 | 76 | elif not img_byte_arr and "image-path" in hints: 77 | image_path = hints["image-path"].value.replace("file://", "") 78 | if os.path.exists(image_path): 79 | try: 80 | with open(image_path, "rb") as img_file: 81 | img_byte_arr = img_file.read() 82 | except Exception as e: 83 | print(f"Error opening image file: {e}") 84 | else: 85 | fd_icon = find_icon(image_path) 86 | if fd_icon: 87 | try: 88 | with open(image_path, "rb") as img_file: 89 | img_byte_arr = img_file.read() 90 | except Exception as e: 91 | print(f"Error opening image file: {e}") 92 | else: 93 | print(f"Provided image-path is neither a valid image or name in a freedesktop.org-compliant icon theme: {image_path}") 94 | 95 | elif not img_byte_arr and app_icon: 96 | image_path = app_icon.replace("file://", "") 97 | if os.path.exists(image_path): 98 | try: 99 | with open(image_path, "rb") as img_file: 100 | img_byte_arr = img_file.read() 101 | except Exception as e: 102 | print(f"Error opening image file: {e}") 103 | else: 104 | fd_icon = find_icon(image_path) 105 | if fd_icon: 106 | try: 107 | with open(fd_icon, "rb") as img_file: 108 | img_byte_arr = img_file.read() 109 | except Exception as e: 110 | print(f"Error opening image file: {e}") 111 | else: 112 | print(f"Provided app_icon is neither a valid image or name in a freedesktop.org-compliant icon theme: {image_path}") 113 | 114 | elif not img_byte_arr and "icon_data" in hints: 115 | try: 116 | img_byte_arr = construct_image(hints["icon_data"].value) 117 | except Exception as e: 118 | print(f"Error loading image: {e}") 119 | 120 | 121 | self.notification_id += 1 122 | info_dict = { 123 | "app_name": app_name, 124 | "replaces_id": replaces_id, 125 | "notification_id": self.notification_id, 126 | "app_icon": app_icon, 127 | "summary": summary, 128 | "body": body, 129 | "actions": actions, 130 | "hints": hints, 131 | "expire_timeout": expire_timeout, 132 | "sender_id": self.current_sender, 133 | "img_byte_arr": img_byte_arr 134 | } 135 | 136 | # self.activate_notification(info_dict) 137 | self.notify_app(info_dict) 138 | 139 | return self.notification_id # Return the notification ID 140 | 141 | @method() 142 | def CloseNotification(self, id: "u"): 143 | # I don't even know if this will get used 144 | # but in theory the sender should be able to close 145 | # the notification by accessing this method 146 | # Edit: I am a fool, this does indeed get used quite a bit 147 | self.close_notification(id, 3, self.current_sender) 148 | 149 | def notify_app(self, info_dict): 150 | pass 151 | 152 | def close_notification(self, id, reason, sender_id): 153 | pass 154 | 155 | def do_action_on_notification(self, id, action, sender_id): 156 | pass 157 | 158 | 159 | async def main(): 160 | bus = await MessageBus().connect() 161 | daemon = NotificationManager(bus) 162 | 163 | # Export the service and request a name 164 | bus.export("/org/freedesktop/Notifications", daemon) 165 | await bus.request_name("org.freedesktop.Notifications") 166 | 167 | print("Notification manager running...") 168 | await asyncio.Future() # Run forever 169 | 170 | 171 | if __name__ == "__main__": 172 | asyncio.run(main()) 173 | -------------------------------------------------------------------------------- /src/yawns_notifications.py: -------------------------------------------------------------------------------- 1 | import os 2 | import cssutils 3 | from PyQt5.QtWidgets import ( 4 | QProgressBar, 5 | QHBoxLayout, 6 | QPushButton, 7 | QSizePolicy, 8 | QVBoxLayout, 9 | QWidget, 10 | QGridLayout, 11 | QLabel, 12 | QFrame, 13 | QStyle, 14 | ) 15 | from PyQt5.QtCore import QSize, Qt, QTimer, pyqtSignal 16 | from PyQt5.QtGui import QPainter, QPainterPath, QPixmap 17 | from enum import Enum 18 | import time 19 | import dbus 20 | 21 | 22 | class YawnType(Enum): 23 | CORNER = 1 24 | CENTER = 2 25 | MEDIA = 3 26 | 27 | 28 | class BaseYawn(QWidget): 29 | """Base class for all notification widgets""" 30 | 31 | yawn_activated = pyqtSignal(int) 32 | 33 | def __init__(self, app, config, info_dict, parent=None): 34 | super().__init__(parent) 35 | self.yawn_class = type(self).__name__ 36 | if "general" in config: 37 | self.general_config = config["general"] 38 | else: 39 | self.general_config = {} 40 | 41 | self.app = app 42 | self.info_dict = info_dict 43 | self.setAttribute(Qt.WA_TranslucentBackground) 44 | self.timer = QTimer(self) 45 | self.timer.setSingleShot(True) 46 | self.timer.timeout.connect( 47 | lambda: self.app.request_notification_closing.emit( 48 | self.info_dict["notification_id"], 1, self.info_dict["sender_id"] 49 | ) 50 | ) 51 | 52 | urgency_struct = self.info_dict["hints"].get("urgency", None) 53 | self.urgency = 1 54 | if urgency_struct: 55 | self.urgency = int(urgency_struct.value) 56 | 57 | self.app.setup_yawn_window(self) 58 | 59 | def setup_widgets(self): 60 | """ 61 | Setup all needed widgets for the yawn 62 | """ 63 | # Gotta use a QFrame to fill the whole widget 64 | # to allow bg transparency through QSS correctly 65 | self.main_container_layout = QVBoxLayout(self) 66 | self.main_container_layout.setContentsMargins(0, 0, 0, 0) 67 | self.main_container_layout.setSpacing(0) 68 | self.main_widget = QFrame() 69 | self.main_widget.setObjectName(self.yawn_class) 70 | self.main_container_layout.addWidget(self.main_widget) 71 | 72 | self.icon_label = QLabel() 73 | self.icon_label.setObjectName(self.yawn_class + "Icon") 74 | 75 | self.summary_label = QLabel() 76 | self.summary_label.setObjectName(self.yawn_class + "Summary") 77 | self.summary_label.setWordWrap(True) 78 | self.body_label = QLabel() 79 | self.body_label.setObjectName(self.yawn_class + "Body") 80 | self.body_label.setWordWrap(True) 81 | self.labels_layout = QVBoxLayout() 82 | self.labels_layout.setContentsMargins(0, 0, 0, 0) 83 | self.labels_layout.setSpacing(0) 84 | self.labels_layout.addWidget(self.summary_label) 85 | self.labels_layout.addWidget(self.body_label) 86 | self.text_container = QFrame() 87 | self.text_container.setObjectName(self.yawn_class + "TextContainer") 88 | self.text_container.setLayout(self.labels_layout) 89 | 90 | self.bar = QProgressBar() 91 | self.bar.setObjectName(self.yawn_class + "Bar") 92 | self.bar.setTextVisible(False) 93 | self.bar.setMaximum(100) 94 | self.bar.setMinimum(0) 95 | 96 | self.buttons_container = QFrame() 97 | self.buttons_container.setObjectName(self.yawn_class + "ButtonsContainer") 98 | self.buttons_layout = QHBoxLayout(self.buttons_container) 99 | self.buttons_layout.setContentsMargins(0, 0, 0, 0) 100 | self.buttons_layout.setSpacing(0) 101 | 102 | def restart_timer(self): 103 | """ 104 | Starts/Restarts the timer for closing the yawn. 105 | When a yawn gets replaced with another one, 106 | the timer gets reset with the updated timeout value 107 | """ 108 | if self.timer.isActive(): 109 | self.timer.stop() 110 | timeout = int(self.config.get("timeout", 5250)) 111 | if ( 112 | "expire_timeout" in self.info_dict 113 | and int(self.info_dict["expire_timeout"]) > 0 114 | ): 115 | timeout = int(self.info_dict["expire_timeout"]) 116 | self.timer.setInterval(timeout) 117 | self.timer.start() 118 | 119 | def update_icon(self): 120 | """ 121 | Updates the icon widget 122 | """ 123 | self.icon_size = 0 124 | if self.info_dict.get("img_byte_arr", None): 125 | image_pixmap = QPixmap() 126 | if image_pixmap.loadFromData(self.info_dict["img_byte_arr"]): 127 | self.icon_size = int(self.config.get("icon-size", 64)) 128 | image_pixmap = image_pixmap.scaled( 129 | self.icon_size, 130 | self.icon_size, 131 | Qt.KeepAspectRatio, 132 | Qt.SmoothTransformation, 133 | ) 134 | self.icon_label.setPixmap(image_pixmap) 135 | self.icon_label.setMinimumSize(0, 0) 136 | self.icon_label.setMaximumSize(100000, 100000) 137 | else: 138 | self.icon_label.clear() 139 | self.icon_label.setFixedSize(0, 0) 140 | else: 141 | self.icon_label.clear() 142 | self.icon_label.setFixedSize(0, 0) 143 | 144 | def update_text(self): 145 | """ 146 | Updates both the summary and body label 147 | """ 148 | if "summary" in self.info_dict and self.info_dict["summary"]: 149 | text = self.info_dict["summary"].replace("\n", "
") 150 | self.summary_label.setText(text) 151 | self.summary_label.setMinimumSize(0, 0) 152 | self.summary_label.setMaximumSize(100000, 100000) 153 | else: 154 | self.summary_label.clear() 155 | self.summary_label.setFixedSize(0, 0) 156 | 157 | if "body" in self.info_dict and self.info_dict["body"]: 158 | text = self.info_dict["body"].replace("\n", "
") 159 | self.body_label.setText(text) 160 | self.body_label.setMinimumSize(0, 0) 161 | self.body_label.setMaximumSize(100000, 100000) 162 | else: 163 | self.body_label.clear() 164 | self.body_label.setFixedSize(0, 0) 165 | 166 | def update_bar(self): 167 | """ 168 | Updates the bar widget 169 | """ 170 | if "value" in self.info_dict["hints"] and self.info_dict["hints"]["value"]: 171 | value = int(self.info_dict["hints"]["value"].value) 172 | value = min(100, max(0, value)) 173 | self.bar.setValue(value) 174 | self.bar.setMinimumSize(0, 0) 175 | self.bar.setMaximumSize(100000, 100000) 176 | else: 177 | self.bar.setValue(0) 178 | self.bar.setFixedSize(0, 0) 179 | 180 | 181 | def update_buttons(self): 182 | """ 183 | Updates the action buttons 184 | """ 185 | def empty_layout(layout): 186 | # Empties a layout recursively 187 | while layout.count(): 188 | to_delete = layout.itemAt(0) 189 | if to_delete is not None: 190 | child_layout = to_delete.layout() 191 | if child_layout is not None: 192 | empty_layout(child_layout) 193 | child_widget = to_delete.widget() 194 | if child_widget is not None: 195 | child_widget.deleteLater() 196 | layout.removeItem(to_delete) 197 | 198 | # Delete the current buttons before adding the new ones 199 | empty_layout(self.buttons_layout) 200 | if ("actions" in self.info_dict 201 | and self.info_dict["actions"] 202 | and self.config.get("show_buttons", "false") == "true" 203 | ): 204 | actions = self.info_dict["actions"] 205 | for action_index in range(1,len(actions),2): 206 | action_text = actions[action_index] 207 | action = actions[action_index - 1] 208 | action_button = QPushButton(action_text) 209 | action_button.setCursor(Qt.PointingHandCursor) 210 | action_button.setObjectName(self.yawn_class+"ActionButton") 211 | action_button.clicked.connect(lambda _, act=action: self.action_clicked(act)) 212 | self.buttons_layout.addWidget(action_button) 213 | close_button = QPushButton("Close") 214 | close_button.setObjectName(self.yawn_class+"CloseButton") 215 | close_button.setCursor(Qt.PointingHandCursor) 216 | close_button.clicked.connect(lambda: ( 217 | self.app.request_notification_closing.emit( 218 | self.info_dict["notification_id"], 1, self.info_dict["sender_id"] 219 | ))) 220 | self.buttons_layout.addWidget(close_button) 221 | else: 222 | self.buttons_container.setFixedSize(0, 0) 223 | 224 | def update_content(self): 225 | """ 226 | Update the content of the yawn using its info_dict 227 | """ 228 | self.restart_timer() 229 | 230 | # Below, no widget gets deleted or added. 231 | # if a info_dict has less content than expected, 232 | # then the empty widgets get "reset" and their 233 | # sizes are set to 0, 0 234 | self.update_icon() 235 | self.update_text() 236 | self.update_bar() 237 | self.update_buttons() 238 | 239 | def action_clicked(self, action): 240 | """ 241 | Called when an action button is clicked 242 | """ 243 | self.app.request_notification_action.emit( 244 | self.info_dict["notification_id"], 245 | action, 246 | self.info_dict["sender_id"], 247 | ) 248 | self.app.request_notification_closing.emit( 249 | self.info_dict["notification_id"], 1, self.info_dict["sender_id"] 250 | ) 251 | 252 | 253 | def show(self): 254 | # We move the yawn to where it's supposed to be 255 | # before showing it 256 | self.adjust_size() 257 | self.update_position() 258 | super().show() 259 | self.next_update_position() 260 | 261 | def adjust_size(self): 262 | self.main_layout.update() 263 | self.updateGeometry() 264 | self.adjustSize() 265 | 266 | def update_position(self): 267 | pass 268 | 269 | def next_update_position(self): 270 | pass 271 | 272 | def mousePressEvent(self, a0): 273 | """ 274 | Handle mouse clicks on the notification 275 | """ 276 | super().mousePressEvent(a0) 277 | 278 | def do_actions(actions): 279 | if "default" in actions: 280 | if "actions" in self.info_dict and self.info_dict["actions"]: 281 | self.app.request_notification_action.emit( 282 | self.info_dict["notification_id"], 283 | self.info_dict["actions"][0], 284 | self.info_dict["sender_id"], 285 | ) 286 | else: 287 | print(f"No actions available for notification {self.info_dict["notification_id"]}") 288 | if "close" in actions: 289 | self.app.request_notification_closing.emit( 290 | self.info_dict["notification_id"], 1, self.info_dict["sender_id"] 291 | ) 292 | 293 | if a0.button() == Qt.LeftButton: 294 | do_actions(self.general_config.get("mouse-left-click", "close")) 295 | elif a0.button() == Qt.RightButton: 296 | do_actions(self.general_config.get("mouse-right-click", "close")) 297 | elif a0.button() == Qt.MiddleButton: 298 | do_actions(self.general_config.get("mouse-middle-click", "close")) 299 | pass 300 | 301 | 302 | class CornerYawn(BaseYawn): 303 | """ 304 | The most classic notification design. 305 | Shows up as a window anchored to one of the corners of your screen. 306 | Multiple notifications stack vertically. 307 | """ 308 | 309 | def __init__(self, app, config, info_dict, parent=None): 310 | if "corner" in config: 311 | self.config = config["corner"] 312 | else: 313 | self.config = {} 314 | self.wm_class = "corner - yawn" 315 | super().__init__( 316 | app, config, info_dict, parent=parent 317 | ) 318 | self.setFixedWidth(int(self.config.get("width", 400))) 319 | self.setMaximumHeight(int(self.config.get("height", 500))) 320 | self.index = len(app.yawn_arrays["CornerYawn"]) 321 | app.yawn_arrays[self.yawn_class].append(self) 322 | 323 | # Set up window 324 | self.setWindowTitle("yawns - Corner") 325 | self.setup_widgets() 326 | self.icon_label.setAlignment(Qt.AlignCenter) 327 | self.summary_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) 328 | self.body_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) 329 | self.bar.setOrientation(Qt.Horizontal) 330 | self.text_container.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) 331 | 332 | self.main_layout = QVBoxLayout(self.main_widget) 333 | self.main_layout.setContentsMargins(0, 0, 0, 0) 334 | self.main_layout.setSpacing(0) 335 | self.upper_layout = QHBoxLayout() 336 | self.upper_layout.setContentsMargins(0, 0, 0, 0) 337 | self.upper_layout.setSpacing(0) 338 | self.main_layout.addLayout(self.upper_layout) 339 | 340 | self.icon_layout = QVBoxLayout() 341 | self.icon_layout.setContentsMargins(0, 0, 0, 0) 342 | self.icon_layout.setSpacing(0) 343 | self.icon_layout.addWidget(self.icon_label) 344 | self.icon_layout.addStretch() 345 | 346 | self.main_layout.addWidget(self.bar) 347 | self.main_layout.addWidget(self.buttons_container, stretch=1) 348 | self.upper_layout.addLayout(self.icon_layout) 349 | self.upper_layout.addWidget(self.text_container, stretch=1) 350 | 351 | self.update_content() 352 | 353 | def update_content(self): 354 | self.restart_timer() 355 | self.update_icon() 356 | # We gotta manually calculate how much space (width) the 357 | # text container should take up in the layout 358 | # because Qt kinda sucks and I'm starting to 359 | # realize it. 360 | 361 | # Parse the application stylesheet 362 | stylesheet = cssutils.parseString(self.app.stylesheet) 363 | 364 | # Helper function to expand shorthand properties 365 | def expand_shorthand(styles, property_name): 366 | if property_name in styles: 367 | values = styles[property_name].split() 368 | if len(values) == 1: # All sides same 369 | styles.update( 370 | { 371 | f"{property_name}-top": values[0], 372 | f"{property_name}-right": values[0], 373 | f"{property_name}-bottom": values[0], 374 | f"{property_name}-left": values[0], 375 | } 376 | ) 377 | elif len(values) == 2: # Vertical | Horizontal 378 | styles.update( 379 | { 380 | f"{property_name}-top": values[0], 381 | f"{property_name}-bottom": values[0], 382 | f"{property_name}-right": values[1], 383 | f"{property_name}-left": values[1], 384 | } 385 | ) 386 | elif len(values) == 3: # Top | Horizontal | Bottom 387 | styles.update( 388 | { 389 | f"{property_name}-top": values[0], 390 | f"{property_name}-right": values[1], 391 | f"{property_name}-left": values[1], 392 | f"{property_name}-bottom": values[2], 393 | } 394 | ) 395 | elif len(values) == 4: # Top | Right | Bottom | Left 396 | styles.update( 397 | { 398 | f"{property_name}-top": values[0], 399 | f"{property_name}-right": values[1], 400 | f"{property_name}-bottom": values[2], 401 | f"{property_name}-left": values[3], 402 | } 403 | ) 404 | del styles[property_name] 405 | return styles 406 | 407 | # Helper function to extract styles for a specific selector 408 | def get_styles(selector, properties): 409 | styles = {} 410 | for rule in stylesheet: 411 | if ( 412 | rule.type == rule.STYLE_RULE 413 | and rule.selectorText.strip() == selector 414 | ): 415 | for prop in rule.style: 416 | if prop.name in properties or any( 417 | prop.name.startswith(p) for p in properties 418 | ): 419 | styles[prop.name] = prop.value 420 | 421 | # Expand shorthand properties 422 | styles = expand_shorthand(styles, "margin") 423 | styles = expand_shorthand(styles, "padding") 424 | return styles 425 | 426 | # Extract relevant styles 427 | window_styles = get_styles("#CornerYawn", {"border", "margin", "padding"}) 428 | icon_styles = get_styles("#CornerYawnIcon", {"border", "margin", "padding"}) 429 | 430 | # Resolve shorthand and defaults for window styles 431 | window_border = int( 432 | window_styles.get("border", "0").split()[0].replace("px", "") 433 | ) 434 | window_padding_left = int( 435 | window_styles.get("padding-left", "0").replace("px", "") 436 | ) 437 | window_padding_right = int( 438 | window_styles.get("padding-right", "0").replace("px", "") 439 | ) 440 | total_horizontal_window_padding = window_padding_left + window_padding_right 441 | 442 | # Resolve shorthand and defaults for icon styles 443 | icon_margin_left = int(icon_styles.get("margin-left", "0").replace("px", "")) 444 | icon_margin_right = int(icon_styles.get("margin-right", "0").replace("px", "")) 445 | icon_padding_left = int(icon_styles.get("padding-left", "0").replace("px", "")) 446 | icon_padding_right = int( 447 | icon_styles.get("padding-right", "0").replace("px", "") 448 | ) 449 | icon_border = int(icon_styles.get("border", "0").split()[0].replace("px", "")) 450 | total_horizontal_icon_margin = ( 451 | icon_margin_left 452 | + icon_margin_right 453 | + icon_padding_left 454 | + icon_padding_right 455 | ) 456 | 457 | # Calculate layout width 458 | layout_remaining_width = ( 459 | self.width() 460 | - 2 * window_border 461 | - total_horizontal_window_padding 462 | - self.icon_size 463 | + 2 * icon_border 464 | - (total_horizontal_icon_margin if self.icon_size else 0) 465 | ) 466 | 467 | # Manually set the text container width so the label actually knows 468 | # how much it should expand 469 | self.text_container.setFixedWidth(layout_remaining_width) 470 | 471 | self.update_text() 472 | self.update_bar() 473 | self.update_buttons() 474 | 475 | def update_position(self): 476 | """ 477 | Update the position of the notification based on its size and config 478 | """ 479 | offset_x = int(self.config.get("x-offset", -40)) 480 | offset_y = int(self.config.get("y-offset", -40)) 481 | corner_width = self.width() 482 | corner_height = self.height() 483 | gap = int(self.config.get("gap", 10)) 484 | stacking_direction = 1 485 | screen = self.app.primaryScreen() 486 | if offset_x < 0: 487 | offset_x = screen.size().width() + offset_x - corner_width 488 | if offset_y < 0: 489 | offset_y = screen.size().height() + offset_y - corner_height 490 | stacking_direction = -1 491 | yawns_under_self = len(self.app.yawn_arrays["CornerYawn"]) - self.index - 1 492 | for i in range(yawns_under_self): 493 | if self.app.yawn_arrays["CornerYawn"][self.index + i + 1].isVisible(): 494 | offset_y += ( 495 | self.app.yawn_arrays["CornerYawn"][self.index + i + 1].height() + gap 496 | ) * stacking_direction 497 | self.move(offset_x, offset_y) 498 | 499 | def next_update_position(self): 500 | if self.index > 0: 501 | self.app.yawn_arrays["CornerYawn"][self.index - 1].update_position() 502 | self.app.yawn_arrays["CornerYawn"][self.index - 1].next_update_position() 503 | 504 | def close(self): 505 | """ 506 | Close widget and update the position the one 507 | stacked on it (if any). 508 | """ 509 | if self in self.app.yawn_arrays["CornerYawn"]: 510 | self.app.yawn_arrays["CornerYawn"].remove(self) 511 | for index in range(len(self.app.yawn_arrays["CornerYawn"])): 512 | self.app.yawn_arrays["CornerYawn"][index].index = index 513 | if self.app.yawn_arrays["CornerYawn"]: 514 | self.app.yawn_arrays["CornerYawn"][-1].update_position() 515 | self.app.yawn_arrays["CornerYawn"][-1].next_update_position() 516 | return super().close() 517 | 518 | 519 | class CenterYawn(BaseYawn): 520 | """ 521 | Show a notification in the center of the screen 522 | Multiple notifications stack vertically one behind the other. 523 | Meant mostly for displaying quick settings changes like 524 | volume, brightness or keyboard layout. 525 | """ 526 | 527 | def __init__(self, app, config, info_dict, parent=None): 528 | if "center" in config: 529 | self.config = config["center"] 530 | else: 531 | self.config = {} 532 | self.wm_class = "center - yawn" 533 | super().__init__( 534 | app, config, info_dict, parent=parent 535 | ) 536 | 537 | self.index = len(app.yawn_arrays["CenterYawn"]) 538 | app.yawn_arrays[self.yawn_class].append(self) 539 | 540 | # Set up window 541 | self.setWindowTitle("yawns - Center") 542 | self.setup_widgets() 543 | 544 | self.main_widget.setMinimumWidth(int(self.config.get("width", 220))) 545 | self.main_widget.setMaximumHeight(int(self.config.get("height", 220))) 546 | self.icon_label.setAlignment(Qt.AlignCenter) 547 | self.summary_label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) 548 | self.summary_label.setAlignment(Qt.AlignCenter) 549 | self.body_label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) 550 | self.body_label.setAlignment(Qt.AlignCenter) 551 | self.bar.setOrientation(Qt.Horizontal) 552 | 553 | self.main_layout = QVBoxLayout(self.main_widget) 554 | self.main_layout.setSpacing(0) 555 | self.main_layout.setContentsMargins(0, 0, 0, 0) 556 | 557 | self.main_layout.addWidget(self.icon_label, stretch=1) 558 | self.main_layout.addWidget(self.text_container, stretch=1) 559 | self.main_layout.addWidget(self.bar) 560 | 561 | self.update_content() 562 | 563 | def update_position(self): 564 | """ 565 | Update the position of the notification based on its size and config 566 | """ 567 | super().update_position() 568 | self_width = self.size().width() 569 | self_height = self.size().height() 570 | screen = self.app.primaryScreen() 571 | offset_x = int((screen.size().width() - self_width) / 2) 572 | offset_y = int((screen.size().height() - self_height) / 2) 573 | self.move(offset_x, offset_y) 574 | 575 | def close(self): 576 | """ 577 | Close widget 578 | """ 579 | if self in self.app.yawn_arrays["CenterYawn"]: 580 | self.app.yawn_arrays["CenterYawn"].remove(self) 581 | return super().close() 582 | 583 | class MediaYawn(BaseYawn): 584 | """ 585 | The most classic notification design. 586 | Shows up as a window anchored to one of the corners of your screen. 587 | Multiple notifications stack vertically. 588 | """ 589 | 590 | def __init__(self, app, config, info_dict, parent=None): 591 | if "media" in config: 592 | self.config = config["media"] 593 | else: 594 | self.config = {} 595 | self.wm_class = "media - yawn" 596 | super().__init__( 597 | app, config, info_dict, parent=parent 598 | ) 599 | self.setFixedWidth(int(self.config.get("width", 400))) 600 | self.setMaximumHeight(int(self.config.get("height", 500))) 601 | self.index = len(app.yawn_arrays["CornerYawn"]) 602 | app.yawn_arrays[self.yawn_class].append(self) 603 | 604 | # Set up window 605 | self.setWindowTitle("yawns - Media") 606 | self.setup_widgets() 607 | 608 | self.icon_label.setAlignment(Qt.AlignCenter) 609 | self.summary_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) 610 | self.body_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) 611 | self.bar.setOrientation(Qt.Horizontal) 612 | self.text_container.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) 613 | self.summary_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) 614 | self.body_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) 615 | self.bar.setOrientation(Qt.Horizontal) 616 | self.text_container.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) 617 | 618 | self.main_layout = QVBoxLayout(self.main_widget) 619 | self.main_layout.setContentsMargins(0, 0, 0, 0) 620 | self.main_layout.setSpacing(0) 621 | self.upper_layout = QHBoxLayout() 622 | self.upper_layout.setContentsMargins(0, 0, 0, 0) 623 | self.upper_layout.setSpacing(0) 624 | self.main_layout.addLayout(self.upper_layout) 625 | 626 | self.icon_layout = QVBoxLayout() 627 | self.icon_layout.setContentsMargins(0, 0, 0, 0) 628 | self.icon_layout.setSpacing(0) 629 | self.icon_layout.addWidget(self.icon_label) 630 | self.icon_layout.addStretch() 631 | 632 | self.main_layout.addWidget(self.bar) 633 | self.main_layout.addWidget(self.buttons_container, stretch=1) 634 | self.upper_layout.addLayout(self.icon_layout) 635 | self.upper_layout.addWidget(self.text_container, stretch=1) 636 | 637 | # Timer for rotating the icon 638 | self.icon_timer = QTimer() 639 | fps = int(self.config.get("fps", 30)) 640 | self.icon_timer.setInterval(round(1000/fps)) 641 | self.icon_timer.timeout.connect(lambda: self.rotate_icon(5)) 642 | self.result_pixmap = None 643 | self.angle = 0 644 | 645 | self.update_content() 646 | 647 | def rotate_icon(self, angle_increment): 648 | """ 649 | Rotates the pixmap displayed on self.icon_label by the given angle. 650 | 651 | :param angle: The angle in degrees to rotate the pixmap. 652 | """ 653 | if self.result_pixmap is None: 654 | return # Safeguard in case no pixmap is set 655 | # Create a new pixmap of the same size as the original 656 | rotated_pixmap = QPixmap(self.result_pixmap.size()) 657 | rotated_pixmap.fill(Qt.transparent) # Fill with transparent background 658 | 659 | # Use QPainter to rotate the pixmap 660 | painter = QPainter(rotated_pixmap) 661 | painter.setRenderHint(QPainter.Antialiasing) 662 | painter.setRenderHint(QPainter.SmoothPixmapTransform) 663 | 664 | # Translate to the center of the pixmap, rotate, and then draw the original pixmap 665 | center = self.result_pixmap.rect().center() 666 | painter.translate(center.x() + 1, center.y() + 1) 667 | self.angle += angle_increment 668 | painter.rotate(self.angle) 669 | painter.translate(-center.x() - 1, -center.y() - 1) 670 | 671 | # Draw the original pixmap 672 | painter.drawPixmap(0, 0, self.result_pixmap) 673 | 674 | painter.end() 675 | self.icon_label.setPixmap(rotated_pixmap) 676 | 677 | 678 | def update_icon(self): 679 | """ 680 | Update the spinning image on top of the vynil icon_label 681 | """ 682 | self.icon_size = 0 683 | if self.info_dict.get("img_byte_arr", None): 684 | image_pixmap = QPixmap() 685 | if image_pixmap.loadFromData(self.info_dict["img_byte_arr"]): 686 | self.icon_size = int(self.config.get("icon-size", 64)) 687 | # Crop the image to a square 688 | original_width = image_pixmap.width() 689 | original_height = image_pixmap.height() 690 | size = min(original_width, original_height) # Largest square size 691 | rect = ( 692 | (original_width - size) // 2, 693 | (original_height - size) // 2, 694 | size, 695 | size, 696 | ) 697 | image_pixmap = image_pixmap.copy(*rect) 698 | 699 | scaled_size = round(self.icon_size*0.5) 700 | # Scale the cropped square 701 | image_pixmap = image_pixmap.scaled( 702 | scaled_size, 703 | scaled_size, 704 | Qt.KeepAspectRatioByExpanding, 705 | Qt.SmoothTransformation, 706 | ) 707 | 708 | # Create a rounded pixmap 709 | rounded_pixmap = QPixmap(scaled_size, scaled_size) 710 | rounded_pixmap.fill(Qt.transparent) # Transparent background 711 | 712 | # Draw the rounded pixmap 713 | painter = QPainter(rounded_pixmap) 714 | painter.setRenderHint(QPainter.Antialiasing) 715 | path = QPainterPath() 716 | path.addEllipse(0, 0, scaled_size, scaled_size) # Circle bounds 717 | painter.setClipPath(path) 718 | painter.drawPixmap(0, 0, image_pixmap) 719 | painter.end() 720 | 721 | vinyl_path = "/usr/share/yawns/assets/vinyl.png" 722 | if self.config.get("bg_icon"): 723 | vinyl_path = os.path.expanduser(self.config["bg_icon"]) 724 | vinyl_pixmap = QPixmap() 725 | if not vinyl_pixmap.load(vinyl_path): 726 | print(f"Failed to load {vinyl_path} for a media yawn, defaulting to /usr/share/yawns/assets/vinyl.png") 727 | vinyl_path = "/usr/share/yawns/assets/vinyl.png" 728 | vinyl_pixmap.load(vinyl_path) 729 | 730 | vinyl_pixmap = vinyl_pixmap.scaled( 731 | self.icon_size, 732 | self.icon_size, 733 | Qt.IgnoreAspectRatio, 734 | Qt.SmoothTransformation, 735 | ) 736 | # Create a new QPixmap the same size as the background 737 | self.result_pixmap = QPixmap(vinyl_pixmap.size()) 738 | self.result_pixmap.fill(Qt.transparent) # Ensure the pixmap starts transparent 739 | 740 | # Create a QPainter to draw the images 741 | painter = QPainter(self.result_pixmap) 742 | painter.setRenderHint(QPainter.Antialiasing) 743 | 744 | # Draw the background 745 | painter.drawPixmap(0, 0, vinyl_pixmap) 746 | 747 | # Determine the position for the overlay 748 | x = (vinyl_pixmap.width() - rounded_pixmap.width()) // 2 749 | y = (vinyl_pixmap.height() - rounded_pixmap.height()) // 2 750 | 751 | # Draw the overlay 752 | painter.drawPixmap(x, y, rounded_pixmap) 753 | painter.end() 754 | self.icon_label.setPixmap(self.result_pixmap) 755 | self.icon_label.setMinimumSize(0, 0) 756 | self.icon_label.setMaximumSize(100000, 100000) 757 | 758 | self.icon_timer.start() 759 | else: 760 | self.result_pixmap = None 761 | self.icon_label.clear() 762 | self.icon_label.setFixedSize(0, 0) 763 | else: 764 | self.result_pixmap = None 765 | self.icon_label.clear() 766 | self.icon_label.setFixedSize(0, 0) 767 | 768 | def update_content(self): 769 | self.restart_timer() 770 | self.update_icon() 771 | # We gotta manually calculate how much space (width) the 772 | # text container should take up in the layout 773 | # because Qt kinda sucks and I'm starting to 774 | # realize it. 775 | 776 | # Parse the application stylesheet 777 | stylesheet = cssutils.parseString(self.app.stylesheet) 778 | 779 | # Helper function to expand shorthand properties 780 | def expand_shorthand(styles, property_name): 781 | if property_name in styles: 782 | values = styles[property_name].split() 783 | if len(values) == 1: # All sides same 784 | styles.update( 785 | { 786 | f"{property_name}-top": values[0], 787 | f"{property_name}-right": values[0], 788 | f"{property_name}-bottom": values[0], 789 | f"{property_name}-left": values[0], 790 | } 791 | ) 792 | elif len(values) == 2: # Vertical | Horizontal 793 | styles.update( 794 | { 795 | f"{property_name}-top": values[0], 796 | f"{property_name}-bottom": values[0], 797 | f"{property_name}-right": values[1], 798 | f"{property_name}-left": values[1], 799 | } 800 | ) 801 | elif len(values) == 3: # Top | Horizontal | Bottom 802 | styles.update( 803 | { 804 | f"{property_name}-top": values[0], 805 | f"{property_name}-right": values[1], 806 | f"{property_name}-left": values[1], 807 | f"{property_name}-bottom": values[2], 808 | } 809 | ) 810 | elif len(values) == 4: # Top | Right | Bottom | Left 811 | styles.update( 812 | { 813 | f"{property_name}-top": values[0], 814 | f"{property_name}-right": values[1], 815 | f"{property_name}-bottom": values[2], 816 | f"{property_name}-left": values[3], 817 | } 818 | ) 819 | del styles[property_name] 820 | return styles 821 | 822 | # Helper function to extract styles for a specific selector 823 | def get_styles(selector, properties): 824 | styles = {} 825 | for rule in stylesheet: 826 | if ( 827 | rule.type == rule.STYLE_RULE 828 | and rule.selectorText.strip() == selector 829 | ): 830 | for prop in rule.style: 831 | if prop.name in properties or any( 832 | prop.name.startswith(p) for p in properties 833 | ): 834 | styles[prop.name] = prop.value 835 | 836 | # Expand shorthand properties 837 | styles = expand_shorthand(styles, "margin") 838 | styles = expand_shorthand(styles, "padding") 839 | return styles 840 | 841 | # Extract relevant styles 842 | window_styles = get_styles("#MediaYawn", {"border", "margin", "padding"}) 843 | icon_styles = get_styles("#MediaYawnIcon", {"border", "margin", "padding"}) 844 | 845 | # Resolve shorthand and defaults for window styles 846 | window_border = int( 847 | window_styles.get("border", "0").split()[0].replace("px", "") 848 | ) 849 | window_padding_left = int( 850 | window_styles.get("padding-left", "0").replace("px", "") 851 | ) 852 | window_padding_right = int( 853 | window_styles.get("padding-right", "0").replace("px", "") 854 | ) 855 | total_horizontal_window_padding = window_padding_left + window_padding_right 856 | 857 | # Resolve shorthand and defaults for icon styles 858 | icon_margin_left = int(icon_styles.get("margin-left", "0").replace("px", "")) 859 | icon_margin_right = int(icon_styles.get("margin-right", "0").replace("px", "")) 860 | icon_padding_left = int(icon_styles.get("padding-left", "0").replace("px", "")) 861 | icon_padding_right = int( 862 | icon_styles.get("padding-right", "0").replace("px", "") 863 | ) 864 | icon_border = int(icon_styles.get("border", "0").split()[0].replace("px", "")) 865 | total_horizontal_icon_margin = ( 866 | icon_margin_left 867 | + icon_margin_right 868 | + icon_padding_left 869 | + icon_padding_right 870 | ) 871 | 872 | # Calculate layout width 873 | layout_remaining_width = ( 874 | self.width() 875 | - 2 * window_border 876 | - total_horizontal_window_padding 877 | - self.icon_size 878 | + 2 * icon_border 879 | - (total_horizontal_icon_margin if self.icon_size else 0) 880 | ) 881 | 882 | # Manually set the text container width so the label actually knows 883 | # how much it should expand 884 | self.text_container.setFixedWidth(layout_remaining_width) 885 | 886 | self.update_text() 887 | self.update_bar() 888 | self.update_buttons() 889 | 890 | def update_position(self): 891 | """ 892 | Update the position of the notification based on its size and config 893 | """ 894 | offset_x = int(self.config.get("x-offset", 40)) 895 | offset_y = int(self.config.get("y-offset", -40)) 896 | corner_width = self.width() 897 | corner_height = self.height() 898 | screen = self.app.primaryScreen() 899 | if offset_x < 0: 900 | offset_x = screen.size().width() + offset_x - corner_width 901 | if offset_y < 0: 902 | offset_y = screen.size().height() + offset_y - corner_height 903 | self.move(offset_x, offset_y) 904 | 905 | def close(self): 906 | """ 907 | Close widget and update the position the one 908 | stacked on it (if any). 909 | """ 910 | if self in self.app.yawn_arrays[self.yawn_class]: 911 | self.app.yawn_arrays[self.yawn_class].remove(self) 912 | return super().close() 913 | -------------------------------------------------------------------------------- /uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $EUID -ne 0 ]]; then 4 | echo "This script must be run as root. Exiting." 5 | exit 1 6 | fi 7 | 8 | pkgname=yawns 9 | 10 | rm -rf /usr/share/$pkgname 11 | rm -rf /usr/bin/$pkgname 12 | --------------------------------------------------------------------------------