commit 4d4136de81a6170f9492f0d6fc5e19e4d6685455 from: mtmn date: Fri Sep 25 19:57:48 2026 UTC disable csd, hardening anad licenses commit - d6baf4c8547ed0443d3a6e243dda9a0b96585fcb commit + 4d4136de81a6170f9492f0d6fc5e19e4d6685455 blob - f8456d19d4d421c81d40d8891fa32494c4fe889e blob + f7a63188b3f89ccbdbeda30f56b5c930a4a9b28f --- .gitignore +++ .gitignore @@ -1,4 +1,4 @@ .zig-cache/ zig-out/ zig-pkg/ -river-new +build/ blob - f288702d2fa16d3cdf0035b15a9fcbc552cd88e7 blob + 7d9be4ce1de04d19b57eae621a9775b0262f1215 --- LICENSE +++ LICENSE @@ -1,674 +1,11 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 +Copyright (c) 2026 mtmn - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Preamble +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - The GNU General Public License is a free, copyleft license for -software and other kinds of works. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. blob - 6d67ee0780c07b3536202775bb3c0f20d30acf15 (mode 644) blob + /dev/null --- PACKAGING.md +++ /dev/null @@ -1,33 +0,0 @@ -# Packaging river and laguna - -This repository contains laguna, a river window manager client. -Install upstream river separately. - -## Dependencies - -Build requires Zig 0.16, wayland, wayland-protocols, xkbcommon 1.12 or -newer, pkg-config, and scdoc for man pages. - -The exact Zig package versions are pinned in `build.zig.zon`. - -## Building - -```sh -zig build -Doptimize=ReleaseSafe -``` - -Use `-Dman-pages=false` when scdoc is unavailable. - -## Installing - -```sh -zig build -Doptimize=ReleaseSafe --prefix /usr install -``` - -Install the `laguna` binary. Install the example -configuration and generated man pages when packaging distribution files. - -## Runtime - -Start `river` from the session startup command. Start `laguna` from -`$XDG_CONFIG_HOME/river/init` or `$HOME/.config/river/init`. blob - /dev/null blob + ea890afbc70c94011b765722a95e2c8c7d4f1233 (mode 644) --- /dev/null +++ LICENSES/BSD-3-Clause.txt @@ -0,0 +1,11 @@ +Copyright (c) . + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. blob - /dev/null blob + d817195dad53ec992418c28ffca5fbd1cd86502a (mode 644) --- /dev/null +++ LICENSES/MIT.txt @@ -0,0 +1,18 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. blob - 09951de80c8396e6156f2c49334a016a3a669840 blob + d47c57f8a58c27c87e97280195ded4d0977e2a9b --- README.md +++ README.md @@ -1,35 +1,33 @@ + + # laguna -laguna is a dynamic tiling window manager for the non-monolithic `river` -compositor. It uses upstream river v0.4.8 and stable river protocols only. +laguna is a window manager client for the non-monolithic `river` compositor. +It requires river v0.4.8 or compatible and uses stable river protocols only. -`river` owns Wayland clients, rendering and frame synchronisation. `laguna` -owns tags, focus, keybindings, layout policy and window management -decisions. The two programs communicate through the stable -`river-window-management-v1` protocol. Input configuration uses stable river -input protocols. +This repository builds `laguna` only. Install river separately. -This repository builds `laguna`. Install upstream river separately. +## Design -Features without a protocol surface are not supported: +river owns Wayland clients, rendering and frame synchronisation. laguna owns +window management: tags, focus, keybindings, layout policy and window rules. +The two programs communicate over the stable `river-window-management-v1` +protocol. Input configuration uses stable river input protocols. -- external layout generators -- compositor background and cursor hiding -- lid-switch bindings -- keyboard groups +## Requirements -## Build - -You need: - - Zig 0.16 - wayland - wayland-protocols - xkbcommon 1.12 or newer - pkg-config -- scdoc for man pages +- scdoc (man pages) -Build and install with: +## Build and install ```text zig build -Doptimize=ReleaseSafe --prefix ~/.local install @@ -37,19 +35,78 @@ zig build -Doptimize=ReleaseSafe --prefix ~/.local ins ## Run -Start `river` from your session startup command. Start `laguna` from -`$XDG_CONFIG_HOME/river/init` or `$HOME/.config/river/init`. +1. Start `river` from your session startup command. +2. Start `laguna` from `$XDG_CONFIG_HOME/river/init` or + `$HOME/.config/river/init`. -## Configure +## Configuration -`laguna` reads its configuration from `$XDG_CONFIG_HOME/river/laguna.zon` -and falls back to `$HOME/.config/river/laguna.zon`. Unknown fields are -rejected, so typos fail loudly at startup. See `example/laguna.zon` for a -full configuration with keybindings, input settings, rules and theme. +laguna reads its configuration from `$XDG_CONFIG_HOME/river/laguna.zon`. It +falls back to `$HOME/.config/river/laguna.zon`. A missing file leaves +defaults in place. An invalid file is fatal: unknown fields are rejected, so +typos fail loudly at startup. -`laguna` supports protocol lifecycle, tiling layout with an adjustable main -area, tag visibility, focus cycling, keyboard and pointer bindings with -modes, interactive move and resize, float and fullscreen state, window -rules, input device configuration, keyboard layouts, layer-shell awareness, -floating window operations, multi-output focus and routing, cursor policy, -borders, `close` and `exit`. +Top-level options include `main_ratio`, `main_count`, `main_location`, +`attach_mode`, `output_attach_mode`, `spawn_tagmask`, `border_width`, +`border_color_focused`, `border_color_unfocused`, `gap_color`, +`focus_follows_cursor`, `csd`, `cursor_warp`, `xcursor_theme`, `repeat`, +`keyboard_layout`, `keyboard_layout_file`, `modes`, `inputs` and `rules`. + +See `example/laguna.zon` for a complete annotated configuration with +keybindings, input settings, rules and theme. + +Reload the configuration without restarting by sending SIGHUP to the laguna +process: + +```text +pkill -HUP laguna +``` + +## Commands + +Commands are bound in the `modes` section of the configuration or mapped at +runtime. Unknown commands fail synchronously. + +- exit, close +- focus-view, zoom, swap, snap +- set-focused-tags, toggle-focused-tags +- set-view-tags, toggle-view-tags +- focus-previous-tags, send-to-previous-tags +- focus-output, send-to-output +- declare-mode, enter-mode +- map, map-pointer, unmap, unmap-pointer +- main-ratio, main-count, main-location +- attach-mode, default-attach-mode, output-attach-mode +- move, resize, toggle-float, toggle-fullscreen +- rule-add, rule-del +- spawn, spawn-tagmask +- set-repeat, input, keyboard-layout, keyboard-layout-file +- border-width, border-color-focused, border-color-unfocused, gap-color +- focus-follows-cursor, set-cursor-warp, xcursor-theme, csd + +## Layout + +Tiled windows fill the usable output area with no gaps. Borders draw above +window content and do not change tile size. + +A terminal can snap to whole character cells and take fewer pixels than its +tile. laguna covers the remaining strip with a solid surface in `gap_color`. + +## Title bars + +Windows have no title bar by default. laguna asks every window to use +server-side decorations and draws none. It also tells clients when they are +tiled, so well-behaved clients drop their shadows as well. + +To let clients draw their own title bars, set `csd = true`. To do this for +some windows only, add a `csd` rule. A client that only supports client-side +decorations draws its own title bar whatever you set. + +## Limits + +Features without a protocol surface are not supported: + +- external layout generators +- compositor background and cursor hiding +- lid-switch bindings +- keyboard groups blob - b25daf4354c056a8d07b5021873de0d026a0ca0b blob + 83002ce4e72a54b9dd778c9aba21ed4aa459a339 --- build.zig +++ build.zig @@ -1,5 +1,6 @@ -// SPDX-FileCopyrightText: © 2020 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause const std = @import("std"); const Build = std.Build; @@ -9,7 +10,7 @@ pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const strip = b.option(bool, "strip", "Omit debug information") orelse false; - const pie = b.option(bool, "pie", "Build a Position Independent Executable") orelse false; + const pie = b.option(bool, "pie", "Build a Position Independent Executable") orelse true; const use_llvm = b.option(bool, "llvm", "Force use of Zig's LLVM backend and the lld linker"); const man_pages = b.option( @@ -25,6 +26,7 @@ pub fn build(b: *Build) !void { const scanner = Scanner.create(b, .{}); scanner.addSystemProtocol("stable/tablet/tablet-v2.xml"); + scanner.addSystemProtocol("stable/viewporter/viewporter.xml"); scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); scanner.addSystemProtocol("staging/color-management/color-management-v1.xml"); scanner.addSystemProtocol("staging/color-representation/color-representation-v1.xml"); @@ -54,27 +56,13 @@ pub fn build(b: *Build) !void { scanner.generate("wl_output", 4); scanner.generate("wl_seat", 7); scanner.generate("wl_data_device_manager", 3); - scanner.generate("xdg_wm_base", 2); - scanner.generate("zwp_pointer_gestures_v1", 3); - scanner.generate("zwp_pointer_constraints_v1", 1); - scanner.generate("zwp_tablet_manager_v2", 1); - scanner.generate("zxdg_decoration_manager_v1", 1); - scanner.generate("zxdg_importer_v2", 1); - scanner.generate("zxdg_exporter_v2", 1); - scanner.generate("ext_session_lock_manager_v1", 1); - scanner.generate("wp_cursor_shape_manager_v1", 1); - scanner.generate("wp_tearing_control_manager_v1", 1); - scanner.generate("wp_color_manager_v1", 2); - scanner.generate("wp_color_representation_manager_v1", 1); + scanner.generate("wp_viewporter", 1); scanner.generate("river_window_manager_v1", 5); scanner.generate("river_xkb_bindings_v1", 3); scanner.generate("river_layer_shell_v1", 1); scanner.generate("river_input_manager_v1", 2); scanner.generate("river_libinput_config_v1", 2); scanner.generate("river_xkb_config_v1", 2); - scanner.generate("zwlr_output_power_manager_v1", 1); - scanner.generate("zwlr_layer_shell_v1", 4); - scanner.generate("zwp_virtual_keyboard_manager_v1", 1); const wayland = b.createModule(.{ .root_source_file = scanner.result }); const xkbcommon = b.dependency("xkbcommon", .{}).module("xkbcommon"); @@ -113,6 +101,14 @@ pub fn build(b: *Build) !void { "src/Rule.zig", "src/Command.zig", "src/Config.zig", + // Window.zig owns the tile-grid reclaim decision; its tests must run. + "src/Window.zig", + // GapDecoration.zig owns gap detection and color packing; its + // tests must run. + "src/GapDecoration.zig", + // Input.zig needs its own root: tests in merely imported files + // do not execute, so its regression tests would silently never run. + "src/Input.zig", }) |source| { const test_module = b.createModule(.{ .root_source_file = b.path(source), @@ -121,6 +117,8 @@ pub fn build(b: *Build) !void { // Config.zig uses std.c.getenv, so libc is required. .link_libc = true, }); + test_module.addImport("wayland", wayland); + test_module.addImport("xkbcommon", xkbcommon); test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = test_module, .use_llvm = use_llvm, blob - /dev/null blob + 1b20278fceb832b4d5f45459e5249c0ff32486f3 (mode 644) --- /dev/null +++ REUSE.toml @@ -0,0 +1,13 @@ +version = 1 + +[[annotations]] +path = [ + ".gitignore", + "doc/laguna.1.scd", + "example/init", + "example/laguna.zon", + "justfile", +] +precedence = "aggregate" +SPDX-FileCopyrightText = "© 2026 mtmn" +SPDX-License-Identifier = "BSD-3-Clause" blob - 3aac6e783b2ce46ea9841babce81367ec0c92432 blob + c4d5e5d75679198f43946ac26d93a951731f9fe9 --- build.zig.zon +++ build.zig.zon @@ -1,5 +1,5 @@ -// SPDX-FileCopyrightText: © 2024 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// SPDX-License-Identifier: BSD-3-Clause .{ .name = .laguna, .version = "0.1.0", blob - 65752b5582ee2c2ed8ba8449d6c10c2a63eff934 blob + ad7ec78dc42679e820973a356a27843e4591efa4 --- doc/laguna.1.scd +++ doc/laguna.1.scd @@ -31,11 +31,22 @@ startup. Top-level options include main_ratio, main_count, main_location, attach_mode, output_attach_mode, spawn_tagmask, border_width, -border_color_focused, border_color_unfocused, focus_follows_cursor, -cursor_warp, xcursor_theme, repeat, keyboard_layout, -keyboard_layout_file, modes, inputs and rules. See example/laguna.zon -for a complete annotated configuration. +border_color_focused, border_color_unfocused, gap_color, +focus_follows_cursor, cursor_warp, xcursor_theme, repeat, +keyboard_layout, keyboard_layout_file, modes, inputs and rules. See +example/laguna.zon for a complete annotated configuration. +# LAYOUT + +Tiled windows fill the usable output area with no gaps: neighbours share +edges and the last window in each area takes any remainder from odd sizes. +Borders draw above window content and do not change tile size, so keep the +full placement size when proposing dimensions. laguna informs clients of +their tiled state, so well-behaved clients drop client-side title bars and +shadows while tiled. A terminal can still snap to whole character cells +and take fewer pixels than its tile: laguna covers the remaining strip +with a solid surface in gap_color drawn below the window. + # COMMANDS Commands are bound in the modes section of the config file or mapped at @@ -56,12 +67,22 @@ runtime. Unknown commands fail synchronously. Supporte - spawn, spawn-tagmask - set-repeat, input, keyboard-layout, keyboard-layout-file - border-width, border-color-focused, border-color-unfocused -- focus-follows-cursor, set-cursor-warp, xcursor-theme +- gap-color (0xRRGGBB[AA]): color of the surface drawn below tiled windows + whose real size is smaller than their tile, for example terminals that + snap to whole character cells. Defaults to opaque black. +- focus-follows-cursor (disabled, normal, always), set-cursor-warp, xcursor-theme +- csd (true, false): whether windows draw their own title bars. Defaults to + false. With false, laguna asks every window to use server-side decorations + and draws none, so windows have no title bar. To keep client-side title + bars for some windows, add a csd rule. A client that only supports + client-side decorations still draws its own. # RUNNING Start river from the session startup command, then start laguna from -$XDG_CONFIG_HOME/river/init or $HOME/.config/river/init. +$XDG_CONFIG_HOME/river/init or $HOME/.config/river/init. Send SIGHUP to +the laguna process (for example with pkill -HUP laguna) to reload the +config file without restarting. # SEE ALSO blob - e8f717df69b7dbceebea7b70a780c9dfc35f6277 blob + fba67bf9f310f0b19a4fb39afe4c77ed1e87dfb5 --- example/laguna.zon +++ example/laguna.zon @@ -1,8 +1,13 @@ .{ + // Tiles fill the usable area with no gaps. Borders draw above content + // and do not change tile size. Terminals with cell snapping can leave + // a background line when they round a proposal down, so set them to + // fill their allocation when exact tiles matter. .main_ratio = 0.5, .attach_mode = "top", .focus_follows_cursor = "normal", - .border_width = 1, + .csd = false, + .border_width = 0, .border_color_focused = "0x2fafff", .border_color_unfocused = "0x222222", .repeat = .{ .rate = 50, .delay = 300 }, @@ -25,10 +30,10 @@ } }, .{ .modifiers = .{"Mod1+Shift"}, .bindings = .{ .{ .keysym = "Return", .command = "spawn kitty --single-instance" }, - .{ .keysym = "o", .command = "spawn todomenu -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, - .{ .keysym = "m", .command = "spawn plsmenu -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, - .{ .keysym = "b", .command = "spawn btmenu con -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, - .{ .keysym = "p", .command = "spawn passmenu -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, + .{ .keysym = "o", .command = "spawn todomenu" }, + .{ .keysym = "m", .command = "spawn plsmenu" }, + .{ .keysym = "b", .command = "spawn btmenu con" }, + .{ .keysym = "p", .command = "spawn passmenu" }, .{ .keysym = "s", .command = "spawn screenshot" }, .{ .keysym = "t", .command = "spawn yank-to-todo" }, .{ .keysym = "c", .command = "close" }, @@ -51,14 +56,14 @@ } }, .{ .modifiers = .{"Mod4+Shift"}, .bindings = .{ .{ .keysym = "Return", .command = "spawn kitty --single-instance" }, - .{ .keysym = "d", .command = "spawn clipmenu -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, - .{ .keysym = "l", .command = "spawn langmenu -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, - .{ .keysym = "h", .command = "spawn huemenu -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, - .{ .keysym = "m", .command = "spawn plsmenu -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, - .{ .keysym = "b", .command = "spawn btmenu dis -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, - .{ .keysym = "p", .command = "spawn passmenu -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, + .{ .keysym = "d", .command = "spawn clipmenu" }, + .{ .keysym = "l", .command = "spawn langmenu" }, + .{ .keysym = "h", .command = "spawn huemenu" }, + .{ .keysym = "m", .command = "spawn plsmenu" }, + .{ .keysym = "b", .command = "spawn btmenu dis" }, + .{ .keysym = "p", .command = "spawn passmenu" }, .{ .keysym = "s", .command = "spawn screenshot" }, - .{ .keysym = "t", .command = "spawn tempmenu -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, + .{ .keysym = "t", .command = "spawn tempmenu" }, .{ .keysym = "c", .command = "close" }, .{ .keysym = "f", .command = "toggle-fullscreen" }, .{ .keysym = "1", .command = "set-view-tags 1" }, @@ -75,7 +80,7 @@ } }, .{ .modifiers = .{"Mod1"}, .bindings = .{ .{ .keysym = "Return", .command = "spawn tmuxc -n" }, - .{ .keysym = "p", .command = "spawn dmenu_run -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, + .{ .keysym = "p", .command = "spawn sh -c 'dmenu_path | fuzzel --dmenu -l 10 -p run | sh'" }, .{ .keysym = "equal", .command = "spawn tmuxc -l" }, .{ .keysym = "m", .command = "spawn tmuxc -M" }, .{ .keysym = "j", .command = "focus-view next" }, @@ -101,7 +106,7 @@ .{ .keysym = "Tab", .command = "focus-previous-tags" }, } }, .{ .modifiers = .{"Mod4"}, .bindings = .{ - .{ .keysym = "p", .command = "spawn dmenu_run -vi -fn 'Ttyp0 OTB:size=10' -l 10 -h 20 -nb '#101010' -nf '#999999' -sb '#999999' -sf '#101010' -nhb '#1b1b1b' -nhf '#8a8a8a'" }, + .{ .keysym = "p", .command = "spawn sh -c 'dmenu_path | fuzzel --dmenu -l 10 -p run | sh'" }, .{ .keysym = "equal", .command = "spawn tmuxc -l" }, .{ .keysym = "m", .command = "spawn tmuxc -M" }, .{ .keysym = "space", .command = "spawn fnottctl dismiss all" }, blob - daebd8175cc4d3fb42b9d386f0d7442bcb671a9d (mode 644) blob + /dev/null --- logo/LICENSE +++ /dev/null @@ -1,434 +0,0 @@ -River Wayland Compositor Logo Copyright (c) 2024 The River Developers - -River Wayland Compositor Logo is licensed under the Creative Commons -Attribution-ShareAlike 4.0 International License (CC BY-SA 4.0). - -Full license text below: - -Attribution-ShareAlike 4.0 International - -======================================================================= - -Creative Commons Corporation ("Creative Commons") is not a law firm and -does not provide legal services or legal advice. Distribution of -Creative Commons public licenses does not create a lawyer-client or -other relationship. Creative Commons makes its licenses and related -information available on an "as-is" basis. Creative Commons gives no -warranties regarding its licenses, any material licensed under their -terms and conditions, or any related information. Creative Commons -disclaims all liability for damages resulting from their use to the -fullest extent possible. - -Using Creative Commons Public Licenses - -Creative Commons public licenses provide a standard set of terms and -conditions that creators and other rights holders may use to share -original works of authorship and other material subject to copyright -and certain other rights specified in the public license below. The -following considerations are for informational purposes only, are not -exhaustive, and do not form part of our licenses. - - Considerations for licensors: Our public licenses are - intended for use by those authorized to give the public - permission to use material in ways otherwise restricted by - copyright and certain other rights. Our licenses are - irrevocable. Licensors should read and understand the terms - and conditions of the license they choose before applying it. - Licensors should also secure all rights necessary before - applying our licenses so that the public can reuse the - material as expected. Licensors should clearly mark any - material not subject to the license. This includes other CC- - licensed material, or material used under an exception or - limitation to copyright. More considerations for licensors: - wiki.creativecommons.org/Considerations_for_licensors - - Considerations for the public: By using one of our public - licenses, a licensor grants the public permission to use the - licensed material under specified terms and conditions. If - the licensor's permission is not necessary for any reason--for - example, because of any applicable exception or limitation to - copyright--then that use is not regulated by the license. Our - licenses grant only permissions under copyright and certain - other rights that a licensor has authority to grant. Use of - the licensed material may still be restricted for other - reasons, including because others have copyright or other - rights in the material. A licensor may make special requests, - such as asking that all changes be marked or described. - Although not required by our licenses, you are encouraged to - respect those requests where reasonable. More considerations - for the public: - wiki.creativecommons.org/Considerations_for_licensees - -======================================================================= - -Creative Commons Attribution-ShareAlike 4.0 International Public -License - -By exercising the Licensed Rights (defined below), You accept and agree -to be bound by the terms and conditions of this Creative Commons -Attribution-ShareAlike 4.0 International Public License ("Public -License"). To the extent this Public License may be interpreted as a -contract, You are granted the Licensed Rights in consideration of Your -acceptance of these terms and conditions, and the Licensor grants You -such rights in consideration of benefits the Licensor receives from -making the Licensed Material available under these terms and -conditions. - - -Section 1 -- Definitions. - - a. Adapted Material means material subject to Copyright and Similar - Rights that is derived from or based upon the Licensed Material - and in which the Licensed Material is translated, altered, - arranged, transformed, or otherwise modified in a manner requiring - permission under the Copyright and Similar Rights held by the - Licensor. For purposes of this Public License, where the Licensed - Material is a musical work, performance, or sound recording, - Adapted Material is always produced where the Licensed Material is - synched in timed relation with a moving image. - - b. Adapter's License means the license You apply to Your Copyright - and Similar Rights in Your contributions to Adapted Material in - accordance with the terms and conditions of this Public License. - - c. BY-SA Compatible License means a license listed at - creativecommons.org/compatiblelicenses, approved by Creative - Commons as essentially the equivalent of this Public License. - - d. Copyright and Similar Rights means copyright and/or similar rights - closely related to copyright including, without limitation, - performance, broadcast, sound recording, and Sui Generis Database - Rights, without regard to how the rights are labeled or - categorized. For purposes of this Public License, the rights - specified in Section 2(b)(1)-(2) are not Copyright and Similar - Rights. - - e. Effective Technological Measures means those measures that, in the - absence of proper authority, may not be circumvented under laws - fulfilling obligations under Article 11 of the WIPO Copyright - Treaty adopted on December 20, 1996, and/or similar international - agreements. - - f. Exceptions and Limitations means fair use, fair dealing, and/or - any other exception or limitation to Copyright and Similar Rights - that applies to Your use of the Licensed Material. - - g. License Elements means the license attributes listed in the name - of a Creative Commons Public License. The License Elements of this - Public License are Attribution and ShareAlike. - - h. Licensed Material means the artistic or literary work, database, - or other material to which the Licensor applied this Public - License. - - i. Licensed Rights means the rights granted to You subject to the - terms and conditions of this Public License, which are limited to - all Copyright and Similar Rights that apply to Your use of the - Licensed Material and that the Licensor has authority to license. - - j. Licensor means the individual(s) or entity(ies) granting rights - under this Public License. - - k. Share means to provide material to the public by any means or - process that requires permission under the Licensed Rights, such - as reproduction, public display, public performance, distribution, - dissemination, communication, or importation, and to make material - available to the public including in ways that members of the - public may access the material from a place and at a time - individually chosen by them. - - l. Sui Generis Database Rights means rights other than copyright - resulting from Directive 96/9/EC of the European Parliament and of - the Council of 11 March 1996 on the legal protection of databases, - as amended and/or succeeded, as well as other essentially - equivalent rights anywhere in the world. - - m. You means the individual or entity exercising the Licensed Rights - under this Public License. Your has a corresponding meaning. - - -Section 2 -- Scope. - - a. License grant. - - 1. Subject to the terms and conditions of this Public License, - the Licensor hereby grants You a worldwide, royalty-free, - non-sublicensable, non-exclusive, irrevocable license to - exercise the Licensed Rights in the Licensed Material to: - - a. reproduce and Share the Licensed Material, in whole or - in part; and - - b. produce, reproduce, and Share Adapted Material. - - 2. Exceptions and Limitations. For the avoidance of doubt, where - Exceptions and Limitations apply to Your use, this Public - License does not apply, and You do not need to comply with - its terms and conditions. - - 3. Term. The term of this Public License is specified in Section - 6(a). - - 4. Media and formats; technical modifications allowed. The - Licensor authorizes You to exercise the Licensed Rights in - all media and formats whether now known or hereafter created, - and to make technical modifications necessary to do so. The - Licensor waives and/or agrees not to assert any right or - authority to forbid You from making technical modifications - necessary to exercise the Licensed Rights, including - technical modifications necessary to circumvent Effective - Technological Measures. For purposes of this Public License, - simply making modifications authorized by this Section 2(a) - (4) never produces Adapted Material. - - 5. Downstream recipients. - - a. Offer from the Licensor -- Licensed Material. Every - recipient of the Licensed Material automatically - receives an offer from the Licensor to exercise the - Licensed Rights under the terms and conditions of this - Public License. - - b. Additional offer from the Licensor -- Adapted Material. - Every recipient of Adapted Material from You - automatically receives an offer from the Licensor to - exercise the Licensed Rights in the Adapted Material - under the conditions of the Adapter's License You apply. - - c. No downstream restrictions. You may not offer or impose - any additional or different terms or conditions on, or - apply any Effective Technological Measures to, the - Licensed Material if doing so restricts exercise of the - Licensed Rights by any recipient of the Licensed - Material. - - 6. No endorsement. Nothing in this Public License constitutes or - may be construed as permission to assert or imply that You - are, or that Your use of the Licensed Material is, connected - with, or sponsored, endorsed, or granted official status by, - the Licensor or others designated to receive attribution as - provided in Section 3(a)(1)(A)(i). - - b. Other rights. - - 1. Moral rights, such as the right of integrity, are not - licensed under this Public License, nor are publicity, - privacy, and/or other similar personality rights; however, to - the extent possible, the Licensor waives and/or agrees not to - assert any such rights held by the Licensor to the limited - extent necessary to allow You to exercise the Licensed - Rights, but not otherwise. - - 2. Patent and trademark rights are not licensed under this - Public License. - - 3. To the extent possible, the Licensor waives any right to - collect royalties from You for the exercise of the Licensed - Rights, whether directly or through a collecting society - under any voluntary or waivable statutory or compulsory - licensing scheme. In all other cases the Licensor expressly - reserves any right to collect such royalties. - - -Section 3 -- License Conditions. - -Your exercise of the Licensed Rights is expressly made subject to the -following conditions. - - a. Attribution. - - 1. If You Share the Licensed Material (including in modified - form), You must: - - a. retain the following if it is supplied by the Licensor - with the Licensed Material: - - i. identification of the creator(s) of the Licensed - Material and any others designated to receive - attribution, in any reasonable manner requested by - the Licensor (including by pseudonym if - designated); - - ii. a copyright notice; - - iii. a notice that refers to this Public License; - - iv. a notice that refers to the disclaimer of - warranties; - - v. a URI or hyperlink to the Licensed Material to the - extent reasonably practicable; - - b. indicate if You modified the Licensed Material and - retain an indication of any previous modifications; and - - c. indicate the Licensed Material is licensed under this - Public License, and include the text of, or the URI or - hyperlink to, this Public License. - - 2. You may satisfy the conditions in Section 3(a)(1) in any - reasonable manner based on the medium, means, and context in - which You Share the Licensed Material. For example, it may be - reasonable to satisfy the conditions by providing a URI or - hyperlink to a resource that includes the required - information. - - 3. If requested by the Licensor, You must remove any of the - information required by Section 3(a)(1)(A) to the extent - reasonably practicable. - - b. ShareAlike. - - In addition to the conditions in Section 3(a), if You Share - Adapted Material You produce, the following conditions also apply. - - 1. The Adapter's License You apply must be a Creative Commons - license with the same License Elements, this version or - later, or a BY-SA Compatible License. - - 2. You must include the text of, or the URI or hyperlink to, the - Adapter's License You apply. You may satisfy this condition - in any reasonable manner based on the medium, means, and - context in which You Share Adapted Material. - - 3. You may not offer or impose any additional or different terms - or conditions on, or apply any Effective Technological - Measures to, Adapted Material that restrict exercise of the - rights granted under the Adapter's License You apply. - - -Section 4 -- Sui Generis Database Rights. - -Where the Licensed Rights include Sui Generis Database Rights that -apply to Your use of the Licensed Material: - - a. for the avoidance of doubt, Section 2(a)(1) grants You the right - to extract, reuse, reproduce, and Share all or a substantial - portion of the contents of the database; - - b. if You include all or a substantial portion of the database - contents in a database in which You have Sui Generis Database - Rights, then the database in which You have Sui Generis Database - Rights (but not its individual contents) is Adapted Material, - including for purposes of Section 3(b); and - - c. You must comply with the conditions in Section 3(a) if You Share - all or a substantial portion of the contents of the database. - -For the avoidance of doubt, this Section 4 supplements and does not -replace Your obligations under this Public License where the Licensed -Rights include other Copyright and Similar Rights. - - -Section 5 -- Disclaimer of Warranties and Limitation of Liability. - - a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE - EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS - AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF - ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, - IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, - WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR - PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, - ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT - KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT - ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. - - b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE - TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, - NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, - INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, - COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR - USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN - ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR - DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR - IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. - - c. The disclaimer of warranties and limitation of liability provided - above shall be interpreted in a manner that, to the extent - possible, most closely approximates an absolute disclaimer and - waiver of all liability. - - -Section 6 -- Term and Termination. - - a. This Public License applies for the term of the Copyright and - Similar Rights licensed here. However, if You fail to comply with - this Public License, then Your rights under this Public License - terminate automatically. - - b. Where Your right to use the Licensed Material has terminated under - Section 6(a), it reinstates: - - 1. automatically as of the date the violation is cured, provided - it is cured within 30 days of Your discovery of the - violation; or - - 2. upon express reinstatement by the Licensor. - - For the avoidance of doubt, this Section 6(b) does not affect any - right the Licensor may have to seek remedies for Your violations - of this Public License. - - c. For the avoidance of doubt, the Licensor may also offer the - Licensed Material under separate terms or conditions or stop - distributing the Licensed Material at any time; however, doing so - will not terminate this Public License. - - d. Sections 1, 5, 6, 7, and 8 survive termination of this Public - License. - - -Section 7 -- Other Terms and Conditions. - - a. The Licensor shall not be bound by any additional or different - terms or conditions communicated by You unless expressly agreed. - - b. Any arrangements, understandings, or agreements regarding the - Licensed Material not stated herein are separate from and - independent of the terms and conditions of this Public License. - - -Section 8 -- Interpretation. - - a. For the avoidance of doubt, this Public License does not, and - shall not be interpreted to, reduce, limit, restrict, or impose - conditions on any use of the Licensed Material that could lawfully - be made without permission under this Public License. - - b. To the extent possible, if any provision of this Public License is - deemed unenforceable, it shall be automatically reformed to the - minimum extent necessary to make it enforceable. If the provision - cannot be reformed, it shall be severed from this Public License - without affecting the enforceability of the remaining terms and - conditions. - - c. No term or condition of this Public License will be waived and no - failure to comply consented to unless expressly agreed to by the - Licensor. - - d. Nothing in this Public License constitutes or may be interpreted - as a limitation upon, or waiver of, any privileges and immunities - that apply to the Licensor or You, including from the legal - processes of any jurisdiction or authority. - - -======================================================================= - -Creative Commons is not a party to its public -licenses. Notwithstanding, Creative Commons may elect to apply one of -its public licenses to material it publishes and in those instances -will be considered the “Licensor.” The text of the Creative Commons -public licenses is dedicated to the public domain under the CC0 Public -Domain Dedication. Except for the limited purpose of indicating that -material is shared under a Creative Commons public license or as -otherwise permitted by the Creative Commons policies published at -creativecommons.org/policies, Creative Commons does not authorize the -use of the trademark "Creative Commons" or any other trademark or logo -of Creative Commons without its prior written consent including, -without limitation, in connection with any unauthorized modifications -to any of its public licenses or any other arrangements, -understandings, or agreements concerning use of licensed material. For -the avoidance of doubt, this paragraph does not form part of the -public licenses. - -Creative Commons may be contacted at creativecommons.org. blob - 78468c2b2ef9d61439c83657e281a20c9d6638f2 (mode 644) blob + /dev/null --- logo/logo.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - blob - 64cb73f24268aaed318fae48da7a358baa092772 (mode 644) blob + /dev/null --- logo/logo_text.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - blob - 20aa71a68dfaf40b44bb3e50ee6739399d62b077 (mode 644) blob + /dev/null --- logo/logo_text_adaptive_color.svg +++ /dev/null @@ -1,8 +0,0 @@ - - - - blob - /dev/null blob + 0fd9e0061baa8a96cf7666df0174a811bc75056c (mode 644) --- /dev/null +++ justfile @@ -0,0 +1,19 @@ +help: + @just --list + +check: + zlint + zwanzig src/ + zig fmt src/ + +test: + zig build test --summary all + +build opt="Debug": + zig build -Doptimize={{ opt }} -p build/{{ opt }} + +install opt="ReleaseSafe" path="~/.local": + zig build -Doptimize={{ opt }} --prefix {{ path }} install + +clean: + rm -rf .zig-cache zig-pkg zig-out blob - f210d9ae57f31e596872fe6f52f6f5dd14feebd5 blob + 1fe29f73032179eaaf57c1d0a6c63df54e123a4b --- src/Binding.zig +++ src/Binding.zig @@ -1,5 +1,6 @@ -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause // Analyzer does not resolve method-call syntax to free functions. // Module type aliases use PascalCase per Zig convention. // zwanzig-disable: identifier-style, unused-decl blob - 5a9985cfe1e1a6cfd7813a4ff7268b68a2013716 blob + 02cb8e806f7bdf6cbdb0ef2e0ff9807183a1676b --- src/Command.zig +++ src/Command.zig @@ -1,5 +1,6 @@ -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause const Command = @This(); @@ -8,6 +9,11 @@ const std = @import("std"); pub const arguments_max = 32; pub const size_max = 4096; +// Word end offsets are u16, so the buffer must always fit. +comptime { + std.debug.assert(size_max <= std.math.maxInt(u16)); +} + buffer: [size_max]u8 = .{0} ** size_max, /// End offset of each word inside buffer. Offsets, not pointers, so the /// struct stays valid after a by-value copy into the pending queue. blob - 564c4c051d55937cf9340af781defc46b19efc65 blob + 6e0c1af6ceda890a084776845491bad734e13008 --- src/Config.zig +++ src/Config.zig @@ -1,5 +1,6 @@ -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause const Config = @This(); @@ -72,7 +73,9 @@ spawn_tagmask: ?u32 = null, border_width: ?i32 = null, border_color_focused: ?[]const u8 = null, border_color_unfocused: ?[]const u8 = null, +gap_color: ?[]const u8 = null, focus_follows_cursor: ?[]const u8 = null, +csd: ?bool = null, cursor_warp: ?[]const u8 = null, xcursor_theme: ?XcursorTheme = null, repeat: ?Repeat = null, blob - c2efa7f5b279c4630e5faad976f9a805a9fa4c44 blob + 2d91901c21b9e328f348393f79d4bdb493816310 --- src/Input.zig +++ src/Input.zig @@ -1,5 +1,6 @@ -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause // Analyzer does not resolve method-call syntax to free functions. // Module type aliases use PascalCase per Zig convention. // zwanzig-disable: identifier-style, unused-decl @@ -18,7 +19,15 @@ const log = std.log.scoped(.laguna); /// libwayland-client exports this, but zig-wayland 0.6.0 does not wrap it. /// The generated dispatcher passes the proxy user data to the Zig listener -/// on every event, so updating it retargets events between device records. +/// on every event (rather than copying it once at setListener time), so +/// updating it retargets events between device records. +/// +/// This relies on an undocumented implementation detail of zig-wayland's +/// generated dispatch trampoline. build.zig.zon pins zig-wayland to exactly +/// v0.6.0 for this reason. Before bumping that pin, re-check the generated +/// dispatcher in the new zig-wayland release still reads wl_proxy user data +/// live on each dispatch; if it copies it at setListener time instead, this +/// retargeting trick silently breaks (events stay bound to the old Device). extern fn wl_proxy_set_user_data(proxy: *anyopaque, user_data: ?*anyopaque) void; pub const Device = struct { @@ -234,6 +243,9 @@ fn merge(device: *Device, input_object: ?*river.InputD for (owner.devices.items) |other| { if (other == device or other.input != target) continue; if (device.libinput) |libinput| { + // A duplicate pairing event can route a new proxy here while + // other already holds one; destroy that one first or it leaks. + if (other.libinput) |old| old.destroy(); other.libinput = libinput; device.libinput = null; // The proxy keeps dispatching after the move. Point its user @@ -242,6 +254,7 @@ fn merge(device: *Device, input_object: ?*river.InputD wl_proxy_set_user_data(@ptrCast(libinput), other); } if (device.keyboard) |keyboard| { + if (other.keyboard) |old| old.destroy(); other.keyboard = keyboard; device.keyboard = null; wl_proxy_set_user_data(@ptrCast(keyboard), other); @@ -293,6 +306,18 @@ pub fn setRepeat(input: *Input, rate: i32, delay: i32) } } +/// Drop all stored input settings. Used before a config reload so removed +/// settings stop applying to devices that arrive later. +pub fn clearStoredConfigs(input: *Input) void { + for (input.stored_configs.items) |stored| { + gpa.free(stored.pattern); + if (stored.category) |category| gpa.free(category); + gpa.free(stored.setting); + if (stored.value) |value| gpa.free(value); + } + input.stored_configs.clearRetainingCapacity(); +} + /// Remember an input setting so devices arriving later receive it too. /// Strings are duplicated; the input owns them until deinit. pub fn storeConfig( @@ -640,10 +665,7 @@ pub fn configure(device: *Device, setting: []const u8, } else if (std.mem.eql(u8, setting, "scroll-factor")) { const input_object = device.input orelse return error.NoLibinputDevice; const text = value orelse return error.InvalidValue; - const factor = std.fmt.parseFloat(f64, text) catch return error.InvalidValue; - // NaN passes the range check below and is illegal behavior in the - // intFromFloat that follows, so reject non-finite values first. - if (!std.math.isFinite(factor) or factor < 0.0) return error.InvalidValue; + const factor = try parseScrollFactor(text); const Fn = @typeInfo(@TypeOf(river.InputDeviceV1.setScrollFactor)).@"fn"; const FixedT = Fn.params[1].type orelse return error.InvalidValue; const fixed: FixedT = @enumFromInt(@as(i32, @intFromFloat(factor * 256.0))); @@ -679,6 +701,25 @@ fn dashed(text: []const u8, expected: []const u8) bool return true; } +/// Parse a scroll factor. Rejects NaN, negatives, and anything past the +/// wl_fixed wire range so the intFromFloat at the call site cannot overflow. +fn parseScrollFactor(text: []const u8) error{InvalidValue}!f64 { + const factor = std.fmt.parseFloat(f64, text) catch return error.InvalidValue; + if (!std.math.isFinite(factor) or factor < 0.0 or factor > 8388607.0) return error.InvalidValue; + return factor; +} + +test "scroll factor rejects out-of-range values" { + const testing = std.testing; + try testing.expectEqual(@as(f64, 1.5), try parseScrollFactor("1.5")); + try testing.expectEqual(@as(f64, 0.0), try parseScrollFactor("0")); + try testing.expectError(error.InvalidValue, parseScrollFactor("-1")); + try testing.expectError(error.InvalidValue, parseScrollFactor("nan")); + try testing.expectError(error.InvalidValue, parseScrollFactor("inf")); + try testing.expectError(error.InvalidValue, parseScrollFactor("1e30")); + try testing.expectError(error.InvalidValue, parseScrollFactor("bogus")); +} + fn parseToggle(comptime T: type, value: ?[]const u8) error{InvalidValue}!T { const text = value orelse return error.InvalidValue; if (equal(text, "enabled") or std.mem.eql(u8, text, "enable")) return .enabled; blob - /dev/null blob + 7b8f3ab3d6d1c05923d95f5421076c2d3ac0e02a (mode 644) --- /dev/null +++ src/GapDecoration.zig @@ -0,0 +1,142 @@ +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause +// Analyzer does not resolve method-call syntax to free functions. +// zwanzig-disable: unused-decl + +/// A solid-color surface rendered below a window, covering the gap between +/// the tile and a client that snapped to a smaller size. The buffer is a +/// shared 1x1 pixel scaled to the tile size with wp_viewporter. +const GapDecoration = @This(); + +const std = @import("std"); +const wl = @import("wayland").client.wl; +const wp = @import("wayland").client.wp; +const river = @import("wayland").client.river; + +const log = std.log.scoped(.laguna); + +surface: *wl.Surface, +viewport: *wp.Viewport, +object: *river.DecorationV1, +/// Tile dimensions and buffer of the last commit, to skip redundant ones. +width: i32, +height: i32, +buffer: ?*wl.Buffer, + +pub fn create( + decoration: *GapDecoration, + window_object: *river.WindowV1, + compositor: *wl.Compositor, + viewporter: *wp.Viewporter, +) !void { + const surface = try compositor.createSurface(); + errdefer surface.destroy(); + const viewport = try viewporter.getViewport(surface); + errdefer viewport.destroy(); + const object = try window_object.getDecorationBelow(surface); + decoration.* = .{ + .surface = surface, + .viewport = viewport, + .object = object, + .width = 0, + .height = 0, + .buffer = null, + }; +} + +pub fn deinit(decoration: *GapDecoration) void { + decoration.object.destroy(); + decoration.viewport.destroy(); + decoration.surface.destroy(); +} + +/// True when a window needs a gap-covering decoration: a shown, layout- +/// controlled window whose real size is smaller than its tile. +pub fn needed( + controllable: bool, + shown: bool, + width: i32, + height: i32, + tile_width: i32, + tile_height: i32, +) bool { + if (!controllable) return false; + if (!shown) return false; + return width < tile_width or height < tile_height; +} + +test "gap decoration needed only for shrunken shown tiled windows" { + const testing = std.testing; + // Foot snapping 960x1200 down to 954x1188 leaves a gap: cover it. + try testing.expect(needed(true, true, 954, 1188, 960, 1200)); + try testing.expect(needed(true, true, 954, 1200, 960, 1200)); + try testing.expect(needed(true, true, 960, 1188, 960, 1200)); + // An exact fit needs nothing. + try testing.expect(!needed(true, true, 960, 1200, 960, 1200)); + // Floating, fullscreen or unplaced windows are exempt. + try testing.expect(!needed(false, true, 954, 1188, 960, 1200)); + // Hidden windows are exempt: hiding a window hides its decorations. + try testing.expect(!needed(true, false, 954, 1188, 960, 1200)); +} + +/// Pack full-range 32-bit RGBA channels into one premultiplied 8-bit +/// ARGB pixel for wl_shm. +pub fn packPixel(color: [4]u32) u32 { + const alpha: u32 = color[3] >> 24; + const red = ((color[0] >> 24) * alpha + 127) / 255; + const green = ((color[1] >> 24) * alpha + 127) / 255; + const blue = ((color[2] >> 24) * alpha + 127) / 255; + return (alpha << 24) | (red << 16) | (green << 8) | blue; +} + +test "pack pixel premultiplies into one argb value" { + const testing = std.testing; + // Opaque colors pass through unchanged. + const opaque_black = [4]u32{ 0, 0, 0, 0xffffffff }; + try testing.expectEqual(@as(u32, 0xff000000), packPixel(opaque_black)); + const opaque_white = [4]u32{ 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; + try testing.expectEqual(@as(u32, 0xffffffff), packPixel(opaque_white)); + // Half-alpha red halves the red channel. + const half_red = [4]u32{ 0xffffffff, 0, 0, 0x80000000 }; + try testing.expectEqual(@as(u32, 0x80800000), packPixel(half_red)); + // Fully transparent collapses to zero. + const clear = [4]u32{ 0xffffffff, 0xffffffff, 0xffffffff, 0 }; + try testing.expectEqual(@as(u32, 0), packPixel(clear)); +} + +/// Create the shared 1x1 ARGB shm buffer holding the gap color. The color +/// channels arrive as full-range 32-bit values and are premultiplied into +/// one pixel. Returns null with a logged error when shm is unavailable. +pub fn createBuffer(shm: *wl.Shm, color: [4]u32) ?*wl.Buffer { + const fd_raw = std.os.linux.memfd_create("laguna-gap", 0); + const fd: std.posix.fd_t = switch (std.posix.errno(fd_raw)) { + .SUCCESS => @intCast(@as(isize, @bitCast(fd_raw))), + else => { + log.err("memfd_create failed: {s}", .{@tagName(std.posix.errno(fd_raw))}); + return null; + }, + }; + defer _ = std.os.linux.close(fd); + if (std.posix.errno(std.os.linux.ftruncate(fd, 4)) != .SUCCESS) { + log.err("ftruncate failed", .{}); + return null; + } + const pixel = std.posix.mmap(null, 4, .{ .READ = true, .WRITE = true }, .{ .TYPE = .SHARED }, fd, 0) catch { + log.err("mmap failed", .{}); + return null; + }; + defer std.posix.munmap(pixel); + const argb = packPixel(color); + std.mem.writeInt(u32, pixel[0..4], argb, .little); + const pool = shm.createPool(fd, 4) catch { + log.err("wl_shm.create_pool failed", .{}); + return null; + }; + defer pool.destroy(); + const buffer = pool.createBuffer(0, 1, 1, 4, .argb8888) catch { + log.err("wl_shm_pool.create_buffer failed", .{}); + return null; + }; + return buffer; +} blob - 7da08d49b0d8e992dbe3d2fd46a758a8e5814079 blob + 21ce6b660918d104bd403c07555682dd0e2d4fcb --- src/Layout.zig +++ src/Layout.zig @@ -1,7 +1,8 @@ // zwanzig-disable: file-as-struct // Pure-function module keeps the PascalCase name per project convention. -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause const std = @import("std"); @@ -59,6 +60,13 @@ pub fn compute( const mains: usize = @min(@as(usize, @intCast(main_count)), count); const vertical = location == .left or location == .right; + + // Without secondary windows the main area spans the whole output, + // so a lone window (or exactly main_count windows) always fills it. + if (count <= mains) { + split(placements, output, vertical); + return; + } const output_width: f32 = @floatFromInt(@max(output.width, 0)); const output_height: f32 = @floatFromInt(@max(output.height, 0)); @@ -164,9 +172,22 @@ fn split(placements: []Placement, area: Rect, vertical test "single window fills output" { var placements: [1]Placement = undefined; compute(&placements, .{ .x = 0, .y = 0, .width = 1920, .height = 1080 }, 1, 0.6, .left); - try std.testing.expectEqualDeep(Placement{ .x = 0, .y = 0, .width = 1152, .height = 1080 }, placements[0]); + try std.testing.expectEqualDeep(Placement{ .x = 0, .y = 0, .width = 1920, .height = 1080 }, placements[0]); } +test "windows equal to main count fill output" { + var placements: [2]Placement = undefined; + compute(&placements, .{ .x = 0, .y = 0, .width = 1000, .height = 800 }, 2, 0.6, .left); + try std.testing.expectEqualDeep(Placement{ .x = 0, .y = 0, .width = 1000, .height = 400 }, placements[0]); + try std.testing.expectEqualDeep(Placement{ .x = 0, .y = 400, .width = 1000, .height = 400 }, placements[1]); +} + +test "single window fills output with top location" { + var placements: [1]Placement = undefined; + compute(&placements, .{ .x = 0, .y = 0, .width = 1920, .height = 1080 }, 1, 0.6, .top); + try std.testing.expectEqualDeep(Placement{ .x = 0, .y = 0, .width = 1920, .height = 1080 }, placements[0]); +} + test "no windows is a no-op" { compute(&.{}, .{ .x = 0, .y = 0, .width = 1920, .height = 1080 }, 1, 0.6, .left); } @@ -194,9 +215,10 @@ test "main count divides main area evenly" { } test "ratio clamps to sane bounds" { - var placements: [1]Placement = undefined; + var placements: [2]Placement = undefined; compute(&placements, .{ .x = 0, .y = 0, .width = 1000, .height = 800 }, 1, 99.0, .left); try std.testing.expectEqualDeep(Placement{ .x = 0, .y = 0, .width = 900, .height = 800 }, placements[0]); + try std.testing.expectEqualDeep(Placement{ .x = 900, .y = 0, .width = 100, .height = 800 }, placements[1]); } test "invalid dimensions produce non-negative placements" { @@ -214,3 +236,60 @@ test "non-finite ratio remains safe" { try std.testing.expect(placements[0].width >= 0); try std.testing.expect(placements[0].height >= 0); } + +// Gapless tiling: neighbours share edges and the union equals the area. +// Odd sizes and clamped ratios exercise the remainder paths. +test "odd width leaves no vertical seam" { + var placements: [2]Placement = undefined; + compute(&placements, .{ .x = 0, .y = 0, .width = 1001, .height = 800 }, 1, 0.5, .left); + try std.testing.expectEqualDeep(Placement{ .x = 0, .y = 0, .width = 500, .height = 800 }, placements[0]); + try std.testing.expectEqualDeep(Placement{ .x = 500, .y = 0, .width = 501, .height = 800 }, placements[1]); + try std.testing.expectEqual(placements[1].x, placements[0].x + placements[0].width); + try std.testing.expectEqual(1001, placements[0].width + placements[1].width); +} + +test "odd width mirrors with no seam on right" { + var placements: [2]Placement = undefined; + compute(&placements, .{ .x = 0, .y = 0, .width = 1001, .height = 800 }, 1, 0.5, .right); + try std.testing.expectEqual(placements[0].x, placements[1].x + placements[1].width); + try std.testing.expectEqual(1001, placements[0].width + placements[1].width); + try std.testing.expectEqual(800, placements[0].height); + try std.testing.expectEqual(800, placements[1].height); +} + +test "odd height leaves no horizontal seam on top" { + var placements: [2]Placement = undefined; + compute(&placements, .{ .x = 0, .y = 0, .width = 1000, .height = 801 }, 1, 0.5, .top); + try std.testing.expectEqualDeep(Placement{ .x = 0, .y = 0, .width = 1000, .height = 400 }, placements[0]); + try std.testing.expectEqualDeep(Placement{ .x = 0, .y = 400, .width = 1000, .height = 401 }, placements[1]); + try std.testing.expectEqual(placements[1].y, placements[0].y + placements[0].height); + try std.testing.expectEqual(801, placements[0].height + placements[1].height); +} + +test "secondary stack leaves no vertical gaps" { + var placements: [3]Placement = undefined; + compute(&placements, .{ .x = 0, .y = 0, .width = 1000, .height = 901 }, 1, 0.5, .left); + try std.testing.expectEqualDeep(Placement{ .x = 0, .y = 0, .width = 500, .height = 901 }, placements[0]); + try std.testing.expectEqualDeep(Placement{ .x = 500, .y = 0, .width = 500, .height = 450 }, placements[1]); + try std.testing.expectEqualDeep(Placement{ .x = 500, .y = 450, .width = 500, .height = 451 }, placements[2]); + try std.testing.expectEqual(placements[2].y, placements[1].y + placements[1].height); + try std.testing.expectEqual(901, placements[1].height + placements[2].height); +} + +test "both columns stack with no gaps" { + var placements: [4]Placement = undefined; + compute(&placements, .{ .x = 10, .y = 20, .width = 1000, .height = 901 }, 2, 0.5, .left); + try std.testing.expectEqual(placements[1].y, placements[0].y + placements[0].height); + try std.testing.expectEqual(placements[3].y, placements[2].y + placements[2].height); + try std.testing.expectEqual(placements[2].x, placements[0].x + placements[0].width); + try std.testing.expectEqual(1010, placements[3].x + placements[3].width); + try std.testing.expectEqual(921, placements[1].y + placements[1].height); + try std.testing.expectEqual(921, placements[3].y + placements[3].height); +} + +test "clamped ratio still covers output" { + var placements: [2]Placement = undefined; + compute(&placements, .{ .x = 0, .y = 0, .width = 1001, .height = 800 }, 1, 99.0, .left); + try std.testing.expectEqual(placements[1].x, placements[0].x + placements[0].width); + try std.testing.expectEqual(1001, placements[0].width + placements[1].width); +} blob - caf89f2afb8eb42284ba360cf8cbe78af50d659c blob + ae61f8127b04b035d95a743a36431e060f014cb9 --- src/Output.zig +++ src/Output.zig @@ -1,5 +1,6 @@ -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause // Analyzer does not resolve method-call syntax to free functions. // Module type aliases use PascalCase per Zig convention. // zwanzig-disable: identifier-style, unused-decl blob - 2fe65c83b1abb27cb3b534de0a870ea8ab050f95 blob + 757b511a9c93f8d8e9ace450612c503c048b63e9 --- src/PointerBinding.zig +++ src/PointerBinding.zig @@ -1,5 +1,6 @@ -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause // Module type aliases use PascalCase per Zig convention. // zwanzig-disable: identifier-style blob - 5e93c4ae77f6ef409894be7d08b6237dbdef3e1a blob + 20a8f17d1b216707de7bf5a04fa1d41757a36086 --- src/Rule.zig +++ src/Rule.zig @@ -1,7 +1,8 @@ // zwanzig-disable: file-as-struct // Pure-function module keeps the PascalCase name per project convention. -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause const std = @import("std"); const mem = std.mem; @@ -43,7 +44,6 @@ pub fn match(text: []const u8, glob: []const u8) bool pub const Action = enum { float, fullscreen, - ssd, csd, tags, }; blob - c0d8d9706c5d361c538b594791d064e27fbca8a4 blob + 3d8a8d96306986148157670d5075003737e972a1 --- src/Seat.zig +++ src/Seat.zig @@ -1,5 +1,6 @@ -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause // Module type aliases use PascalCase per Zig convention. // zwanzig-disable: identifier-style @@ -30,6 +31,9 @@ object: *river.SeatV1, layer_seat: ?*river.LayerShellSeatV1 = null, focused_output: ?*Output = null, hovered_window: ?*river.WindowV1 = null, +/// Hover target that last granted focus via focus-follows-cursor. +/// Lets normal mode fire once per pointer entry instead of every manage. +hover_applied: ?*river.WindowV1 = null, last_focused: ?*river.WindowV1 = null, focused_window: ?*river.WindowV1 = null, removed: bool = false, blob - cad833680126c28a668219afdb099dc1c40c175f blob + 7585dd6486820e7d1e80a48755f6403e5c2c926d --- src/Spawn.zig +++ src/Spawn.zig @@ -1,7 +1,8 @@ // zwanzig-disable: file-as-struct // Pure-function module keeps the PascalCase name per project convention. -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause const std = @import("std"); blob - 9ebfb53d5f10a270d85e1e6dd0563b163d0c4fb8 blob + a31feb1943ce10944a07136710a01bb65c01538a --- src/Window.zig +++ src/Window.zig @@ -1,5 +1,6 @@ -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause // Module type aliases use PascalCase per Zig convention. // zwanzig-disable: identifier-style @@ -13,6 +14,8 @@ const WindowManager = @import("WindowManager.zig"); const gpa = std.heap.c_allocator; +const GapDecoration = @import("GapDecoration.zig"); + object: ?*river.WindowV1, manager: *WindowManager, node: ?*river.NodeV1 = null, @@ -22,6 +25,9 @@ placed: bool = false, output: ?*Output = null, float: bool = false, fullscreen: bool = false, +/// Fullscreen change queued by a client request, applied at the start of +/// the next manage sequence where the fullscreen request is legal. +pending_fullscreen: ?bool = null, focused: bool = false, app_id: ?[]const u8 = null, title: ?[]const u8 = null, @@ -29,10 +35,42 @@ width: i32 = 800, height: i32 = 600, x: i32 = 0, y: i32 = 0, +/// Layout target dimensions from the last arrange. Unlike width/height, +/// which track the client's real size, these keep the tile size so the +/// gap between the two can be detected and covered. +tile_width: i32 = 0, +tile_height: i32 = 0, +/// Last tiled state sent with set_tiled, to avoid redundant requests. +tiled_sent: ?bool = null, +/// Last decoration mode sent with use_csd or use_ssd, so the same request is +/// not sent twice. True means CSD. +csd_sent: ?bool = null, +/// app_id and title events arrive outside a manage sequence, where rule +/// requests are a protocol error. The event handlers set these flags and +/// manageStart applies them. rules_pending re-runs every rule. +/// decorations_pending re-runs only csd rules. +rules_pending: bool = false, +decorations_pending: bool = false, +/// Set when a fullscreen window is hidden, for example on a tag switch. +/// The next manage sequence that sees the window visible again re-asserts +/// the compositor-side fullscreen state, which river may have dropped. +fullscreen_interrupted: bool = false, +/// Solid surface rendered below the window to cover the gap between the +/// tile and a client that snapped to a smaller size, such as a terminal +/// snapping to whole cells. +gap_decoration: ?*GapDecoration = null, /// Last border state sent to the compositor, to avoid redundant requests. rendered_border_width: i32 = -1, rendered_border_color: [4]u32 = .{ 0, 0, 0, 0 }, shown: bool = false, +/// True while a size proposal from the last manage sequence is awaiting the +/// compositor's confirmation. The reclaim logic uses it to tell the +/// compositor echoing our own proposal apart from the client resizing +/// itself. +proposal_outstanding: bool = false, +/// Set on creation, cleared after the first manage sequence that sees +/// the window. Lets manageStart give new windows focus. +just_created: bool = true, pub fn init(window: *Window, object: *river.WindowV1, manager: *WindowManager) void { window.* = .{ .object = object, .manager = manager }; @@ -40,6 +78,11 @@ pub fn init(window: *Window, object: *river.WindowV1, } pub fn deinit(window: *Window) void { + if (window.gap_decoration) |decoration| { + decoration.deinit(); + gpa.destroy(decoration); + window.gap_decoration = null; + } if (window.node) |node| { node.destroy(); window.node = null; @@ -58,9 +101,63 @@ pub fn configure(window: *Window, width: i32, height: const object = window.object orelse return; window.width = @max(width, 1); window.height = @max(height, 1); + window.proposal_outstanding = true; object.proposeDimensions(window.width, window.height); } +/// A placed, tiled window is under layout control: the manager owns its +/// geometry and must reclaim the tile if the client changes it. +pub fn controllable(window: *const Window) bool { + return !window.float and !window.fullscreen and window.placed; +} + +/// Decide whether a reported size means the client resized itself outside the +/// tile grid. True means the manager must request a re-arrange so the next +/// manage sequence re-proposes the tile geometry. +/// +/// A report that confirms a size we just proposed is the compositor echoing +/// our own arrange, not a client resize, so it never triggers a reclaim. A +/// window the manager does not control (floating, fullscreen or unplaced) is +/// exempt: its geometry is its own to choose. +pub fn shouldReclaim( + proposal_outstanding: bool, + is_controllable: bool, + width: i32, + height: i32, + reported_width: i32, + reported_height: i32, +) bool { + if (proposal_outstanding) return false; + if (!is_controllable) return false; + return width != reported_width or height != reported_height; +} + +test "off-grid client resize is reclaimed" { + const testing = std.testing; + // A placed tiled window whose reported size differs from the stored one + // was resized by the client: reclaim it. + try testing.expect(shouldReclaim(false, true, 1920, 1080, 640, 480)); + try testing.expect(shouldReclaim(false, true, 1920, 1080, 1921, 1080)); + try testing.expect(shouldReclaim(false, true, 1920, 1080, 1920, 1079)); +} + +test "confirmation of our own proposal is not reclaimed" { + const testing = std.testing; + // proposal_outstanding means this report echoes the size we proposed. + try testing.expect(!shouldReclaim(true, true, 1920, 1080, 1920, 1080)); +} + +test "unchanged size is not reclaimed" { + const testing = std.testing; + try testing.expect(!shouldReclaim(false, true, 1920, 1080, 1920, 1080)); +} + +test "uncontrolled windows are not reclaimed" { + const testing = std.testing; + // Floating, fullscreen or unplaced windows keep their own size. + try testing.expect(!shouldReclaim(false, false, 1920, 1080, 640, 480)); +} + pub fn render(window: *Window, border_width: i32, border_color: [4]u32) void { const object = window.object orelse return; const node = window.node orelse return; @@ -89,6 +186,10 @@ pub fn render(window: *Window, border_width: i32, bord pub fn hide(window: *Window) void { const object = window.object orelse return; if (!window.shown) return; + // Hiding is rendering state, but a compositor may drop the fullscreen + // window-management state of a hidden window. Flag it so the next + // manage sequence can re-assert fullscreen once the window is back. + if (window.fullscreen) window.fullscreen_interrupted = true; object.hide(); window.shown = false; } @@ -103,8 +204,20 @@ fn handleEvent(_: *river.WindowV1, event: river.Window } }, .dimensions => |dimensions| { - window.width = @max(dimensions.width, 1); - window.height = @max(dimensions.height, 1); + const width = @max(dimensions.width, 1); + const height = @max(dimensions.height, 1); + const reclaim = shouldReclaim( + window.proposal_outstanding, + window.controllable(), + window.width, + window.height, + width, + height, + ); + window.proposal_outstanding = false; + window.width = width; + window.height = height; + if (reclaim) window.manager.requestRearrange(); }, .app_id => |app_id| { const had_app_id = window.app_id != null; @@ -115,12 +228,13 @@ fn handleEvent(_: *river.WindowV1, event: river.Window null; // The first manage sequence may run before the app_id arrives, // so rules evaluated then missed it. Re-apply once the identity - // is known; later changes only update decorations. + // is known. Later changes only update decorations. Both run in + // the manage sequence that follows this event. if (window.node != null) { if (!had_app_id and window.app_id != null) { - window.manager.applyRules(window); + window.rules_pending = true; } else { - window.manager.applyDecorationRules(window); + window.decorations_pending = true; } } }, @@ -130,8 +244,16 @@ fn handleEvent(_: *river.WindowV1, event: river.Window gpa.dupe(u8, std.mem.sliceTo(name, 0)) catch null else null; - if (window.node != null) window.manager.applyDecorationRules(window); + if (window.node != null) window.decorations_pending = true; }, + .fullscreen_requested => { + window.pending_fullscreen = true; + window.manager.requestRearrange(); + }, + .exit_fullscreen_requested => { + window.pending_fullscreen = false; + window.manager.requestRearrange(); + }, .dimensions_hint, .parent, .decoration_hint, @@ -140,8 +262,6 @@ fn handleEvent(_: *river.WindowV1, event: river.Window .show_window_menu_requested, .maximize_requested, .unmaximize_requested, - .fullscreen_requested, - .exit_fullscreen_requested, .minimize_requested, .unreliable_pid, .presentation_hint, blob - 85384c83dda71601e22e92ab40f41b701545a035 blob + 1942e4bbd512697d303f664c4ab5887419d828bc --- src/WindowManager.zig +++ src/WindowManager.zig @@ -1,5 +1,6 @@ -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause // Analyzer does not resolve method-call syntax to free functions. // Module type aliases use PascalCase per Zig convention. // zwanzig-disable: identifier-style, unused-decl @@ -8,11 +9,13 @@ const WindowManager = @This(); const std = @import("std"); const wl = @import("wayland").client.wl; +const wp = @import("wayland").client.wp; const river = @import("wayland").client.river; const Binding = @import("Binding.zig"); const Command = @import("Command.zig"); const Config = @import("Config.zig"); +const GapDecoration = @import("GapDecoration.zig"); const Input = @import("Input.zig"); const Layout = @import("Layout.zig"); const Output = @import("Output.zig"); @@ -46,6 +49,16 @@ const Mode = struct { pointer_specifications: std.ArrayListUnmanaged(PointerSpecification) = .empty, }; +/// Focus-follows-cursor policy. Normal follows the pointer only when it +/// enters a window that has not granted focus yet, so a newly spawned +/// window keeps focus until the pointer moves. Always follows any visible +/// hover, even a stale one. +pub const FocusFollowsCursor = enum { + disabled, + normal, + always, +}; + pub const WlOutput = struct { global_name: u32, object: *wl.Output, @@ -64,16 +77,34 @@ object: *river.WindowManagerV1, default_attach: Layout.Attach = .top, spawn_tagmask: ?u32 = null, locked: bool = false, +/// Set by reload; the next manage sequence re-applies rules to live windows. +rules_dirty: bool = false, border_width: i32 = 2, border_focused: [4]u32 = expandHex(0x93a1a1ff), border_unfocused: [4]u32 = expandHex(0x586e75ff), -focus_follows_cursor: bool = false, +/// Color of the gap-covering decoration drawn below tiled windows whose +/// real size is smaller than their tile. +gap_color: [4]u32 = expandHex(0x000000ff), +focus_follows_cursor: FocusFollowsCursor = .disabled, +/// When true, every window draws its own decorations. When false, laguna +/// asks windows to use SSD and draws none, so they have no title bar. A csd +/// rule keeps client-side decorations for the windows it matches. +csd: bool = false, cursor_warp: bool = false, cursor_theme_name: ?[]const u8 = null, cursor_theme_size: u32 = 24, xkb: ?*river.XkbBindingsV1 = null, layer_shell: ?*river.LayerShellV1 = null, layer_default_set: bool = false, +// Globals used for gap-covering decoration surfaces. Gap filling is +// disabled when any of them is missing. +wl_compositor: ?*wl.Compositor = null, +wl_shm: ?*wl.Shm = null, +viewporter: ?*wp.Viewporter = null, +/// Shared 1x1 pixel buffer scaled onto every gap decoration. Recreated +/// when gap_color changes; gap_buffer_color records the color inside. +gap_buffer: ?*wl.Buffer = null, +gap_buffer_color: [4]u32 = .{ 0, 0, 0, 0 }, pub fn init( manager: *WindowManager, @@ -112,6 +143,8 @@ pub fn deinit(manager: *WindowManager) void { gpa.free(rule.title_glob); } manager.input.deinit(); + if (manager.gap_buffer) |buffer| buffer.destroy(); + manager.gap_buffer = null; manager.windows.deinit(gpa); manager.outputs.deinit(gpa); manager.seats.deinit(gpa); @@ -138,6 +171,14 @@ pub fn queueCommand(manager: *WindowManager, command: manager.object.manageDirty(); } +/// Request a manage sequence. Called when protocol state changed outside a +/// manage sequence: a tiled client resizing itself outside the assigned +/// geometry (the layout re-proposes the tile size, snapping it back), or a +/// client fullscreen request (applied at the start of the next sequence). +pub fn requestRearrange(manager: *WindowManager) void { + manager.object.manageDirty(); +} + const known_commands = [_][]const u8{ "exit", "close", "focus-view", "set-focused-tags", "toggle-focused-tags", "set-view-tags", @@ -152,8 +193,9 @@ const known_commands = [_][]const u8{ "keyboard-layout", "keyboard-layout-file", "attach-mode", "default-attach-mode", "output-attach-mode", "spawn-tagmask", "focus-previous-tags", "send-to-previous-tags", "border-width", - "border-color-focused", "border-color-unfocused", "focus-follows-cursor", - "set-cursor-warp", "xcursor-theme", + "border-color-focused", "border-color-unfocused", "gap-color", + "focus-follows-cursor", "set-cursor-warp", "xcursor-theme", + "csd", }; fn isKnownCommand(name: []const u8) bool { @@ -181,6 +223,83 @@ fn queueParsed(manager: *WindowManager, arguments: []c manager.pending.append(gpa, command) catch return error.OutOfMemory; } +/// Reload configuration after SIGHUP: reset running state to defaults, +/// apply the already-parsed config, restore seat modes by name, and flag +/// live windows for rule re-application in the next manage sequence. +pub fn reload(manager: *WindowManager, config: *const Config) void { + const SavedSeat = struct { + mode: []u8, + unlocked: ?[]u8, + }; + var saved: std.ArrayListUnmanaged(SavedSeat) = .empty; + defer { + for (saved.items) |entry| { + gpa.free(entry.mode); + if (entry.unlocked) |name| gpa.free(name); + } + saved.deinit(gpa); + } + for (manager.seats.items) |seat| { + std.debug.assert(seat.mode_index < manager.modes.items.len); + const mode_name = manager.modes.items[seat.mode_index].name; + const unlocked_name = + if (seat.unlocked_mode_index) |index| manager.modes.items[index].name else null; + saved.append(gpa, .{ + .mode = gpa.dupe(u8, mode_name) catch std.process.fatal("out of memory", .{}), + .unlocked = if (unlocked_name) |name| + gpa.dupe(u8, name) catch std.process.fatal("out of memory", .{}) + else + null, + }) catch std.process.fatal("out of memory", .{}); + } + + for (manager.modes.items) |*mode| { + for (mode.specifications.items) |specification| gpa.free(specification.command); + for (mode.pointer_specifications.items) |specification| gpa.free(specification.command); + mode.specifications.clearRetainingCapacity(); + mode.pointer_specifications.clearRetainingCapacity(); + gpa.free(mode.name); + } + manager.modes.clearRetainingCapacity(); + _ = manager.ensureMode("normal"); + for (manager.rules.items) |rule| { + gpa.free(rule.app_id_glob); + gpa.free(rule.title_glob); + } + manager.rules.clearRetainingCapacity(); + manager.input.clearStoredConfigs(); + manager.default_attach = .top; + manager.spawn_tagmask = null; + manager.border_width = 2; + manager.border_focused = expandHex(0x93a1a1ff); + manager.border_unfocused = expandHex(0x586e75ff); + manager.gap_color = expandHex(0x000000ff); + manager.focus_follows_cursor = .disabled; + manager.csd = false; + manager.cursor_warp = false; + if (manager.cursor_theme_name) |name| gpa.free(name); + manager.cursor_theme_name = null; + manager.cursor_theme_size = 24; + // Repeat rate and keymap have no default handle; a reload without + // those keys leaves the current ones in place. + manager.loadConfig(config) catch |err| { + log.err("cannot apply config: {s}", .{@errorName(err)}); + }; + + const normal_index = manager.modeIndex("normal") orelse 0; + for (manager.seats.items, 0..) |seat, seat_index| { + if (seat_index >= saved.items.len) break; + const index = manager.modeIndex(saved.items[seat_index].mode) orelse normal_index; + manager.setSeatMode(seat, index); + if (saved.items[seat_index].unlocked) |name| { + seat.unlocked_mode_index = manager.modeIndex(name); + } else { + seat.unlocked_mode_index = null; + } + } + manager.rules_dirty = true; +} + /// Format a number into the scratch buffer for command arguments. fn formatNumber(scratch: *[32]u8, value: anytype) error{NoSpaceLeft}![]const u8 { return std.fmt.bufPrint(scratch, "{d}", .{value}); @@ -225,9 +344,15 @@ pub fn loadConfig(manager: *WindowManager, config: *co if (config.border_color_unfocused) |color| { try manager.queueParsed(&.{ "border-color-unfocused", color }); } + if (config.gap_color) |color| { + try manager.queueParsed(&.{ "gap-color", color }); + } if (config.focus_follows_cursor) |mode| { try manager.queueParsed(&.{ "focus-follows-cursor", mode }); } + if (config.csd) |csd| { + try manager.queueParsed(&.{ "csd", if (csd) "true" else "false" }); + } if (config.cursor_warp) |mode| { try manager.queueParsed(&.{ "set-cursor-warp", mode }); } @@ -326,7 +451,10 @@ pub fn loadConfig(manager: *WindowManager, config: *co words[count + 2] = modifiers; words[count + 3] = binding.keysym; count += 4; - count += try splitCommand(binding.command, words[count..]); + count += splitCommand(binding.command, words[count..]) catch |err| { + log.warn("skipping oversized binding command: {s}", .{@errorName(err)}); + continue; + }; try manager.queueParsed(words[0..count]); } } @@ -340,7 +468,10 @@ pub fn loadConfig(manager: *WindowManager, config: *co words[count + 2] = modifiers; words[count + 3] = binding.button; count += 4; - count += try splitCommand(binding.action, words[count..]); + count += splitCommand(binding.action, words[count..]) catch |err| { + log.warn("skipping oversized pointer command: {s}", .{@errorName(err)}); + continue; + }; try manager.queueParsed(words[0..count]); } } @@ -471,6 +602,9 @@ fn execute(manager: *WindowManager, command: *const Co const window = manager.focusedWindow() orelse return; window.output = output; if (current_tags) window.tags = output.tags; + // The old coordinates belong to the source output's geometry and + // can land off-screen on the target; recenter like a fresh float. + if (window.float) window.placed = false; return; } if (std.mem.eql(u8, name, "set-view-tags")) { @@ -586,32 +720,45 @@ fn execute(manager: *WindowManager, command: *const Co if (std.mem.eql(u8, name, "border-width")) { const raw = arguments.next() orelse return error.InvalidArgument; if (arguments.next() != null) return error.InvalidArgument; - const width = std.fmt.parseInt(i32, raw, 10) catch return error.InvalidArgument; - if (width < 0) return error.InvalidArgument; - manager.border_width = width; + manager.border_width = try parseBoundedI32(raw, border_width_max); return; } - if (std.mem.eql(u8, name, "border-color-focused") or std.mem.eql(u8, name, "border-color-unfocused")) { + if (std.mem.eql(u8, name, "border-color-focused") or std.mem.eql(u8, name, "border-color-unfocused") or std.mem.eql(u8, name, "gap-color")) { const raw = arguments.next() orelse return error.InvalidArgument; if (arguments.next() != null) return error.InvalidArgument; const color = parseRGBA(raw) catch return error.InvalidArgument; if (std.mem.eql(u8, name, "border-color-focused")) { manager.border_focused = color; - } else { + } else if (std.mem.eql(u8, name, "border-color-unfocused")) { manager.border_unfocused = color; + } else { + manager.gap_color = color; } return; } if (std.mem.eql(u8, name, "focus-follows-cursor")) { const raw = arguments.next() orelse return error.InvalidArgument; if (arguments.next() != null) return error.InvalidArgument; - if (std.mem.eql(u8, raw, "always") or std.mem.eql(u8, raw, "normal")) { - manager.focus_follows_cursor = true; + if (std.mem.eql(u8, raw, "always")) { + manager.focus_follows_cursor = .always; + } else if (std.mem.eql(u8, raw, "normal")) { + manager.focus_follows_cursor = .normal; } else if (std.mem.eql(u8, raw, "disabled")) { - manager.focus_follows_cursor = false; + manager.focus_follows_cursor = .disabled; } else return error.InvalidArgument; return; } + if (std.mem.eql(u8, name, "csd")) { + const raw = arguments.next() orelse return error.InvalidArgument; + if (arguments.next() != null) return error.InvalidArgument; + if (std.mem.eql(u8, raw, "true")) { + manager.csd = true; + } else if (std.mem.eql(u8, raw, "false")) { + manager.csd = false; + } else return error.InvalidArgument; + manager.markDecorationsPending(); + return; + } if (std.mem.eql(u8, name, "set-cursor-warp")) { const raw = arguments.next() orelse return error.InvalidArgument; if (arguments.next() != null) return error.InvalidArgument; @@ -626,7 +773,7 @@ fn execute(manager: *WindowManager, command: *const Co const theme = arguments.next() orelse return error.InvalidArgument; const size_raw = arguments.next() orelse return error.InvalidArgument; if (arguments.next() != null) return error.InvalidArgument; - const size = std.fmt.parseInt(u32, size_raw, 10) catch return error.InvalidArgument; + const size = try parseBoundedU32(size_raw, cursor_theme_size_max); if (manager.cursor_theme_name) |old| gpa.free(old); manager.cursor_theme_name = gpa.dupe(u8, theme) catch return error.OutOfMemory; manager.cursor_theme_size = size; @@ -737,21 +884,12 @@ fn execute(manager: *WindowManager, command: *const Co if (manager.seats.items.len == 0) return; const focused = manager.seats.items[0].focused_window orelse return; const window = manager.findWindow(focused) orelse return; - window.fullscreen = !window.fullscreen; - if (window.object) |object| { - if (window.fullscreen) { - const target = window.output orelse manager.focusedOutput(); - if (target) |output| object.fullscreen(output.object); - object.informFullscreen(); - } else { - object.exitFullscreen(); - object.informNotFullscreen(); - } - } + manager.setFullscreen(window, !window.fullscreen); return; } if (std.mem.eql(u8, name, "rule-add") or std.mem.eql(u8, name, "rule-del")) { try manager.defineRule(&arguments, std.mem.eql(u8, name, "rule-del")); + manager.markDecorationsPending(); return; } return error.UnknownCommand; @@ -780,8 +918,6 @@ fn defineRule(manager: *WindowManager, arguments: *Com .float else if (std.mem.eql(u8, action_name, "fullscreen")) .fullscreen - else if (std.mem.eql(u8, action_name, "ssd")) - .ssd else if (std.mem.eql(u8, action_name, "csd")) .csd else if (std.mem.eql(u8, action_name, "tags")) @@ -1188,6 +1324,7 @@ fn createBinding( } fn setSeatMode(manager: *WindowManager, seat: *Seat, index: usize) void { + std.debug.assert(index < manager.modes.items.len); if (seat.operation) |*operation| { seat.object.opEnd(); if (operation.action == .resize) { @@ -1270,9 +1407,12 @@ fn attachMode(manager: *WindowManager) Layout.Attach { fn addWindow(manager: *WindowManager, object: *river.WindowV1) void { const window = gpa.create(Window) catch std.process.fatal("out of memory", .{}); Window.init(window, object, manager); + // The top of the stack is index 0: it gets the main layout area and + // renders last (visually on top). Attach mode picks where new windows + // land in the stack. switch (manager.attachMode()) { - .top => manager.windows.append(gpa, window) catch std.process.fatal("out of memory", .{}), - .bottom => manager.windows.insert(gpa, 0, window) catch std.process.fatal("out of memory", .{}), + .top => manager.windows.insert(gpa, 0, window) catch std.process.fatal("out of memory", .{}), + .bottom => manager.windows.append(gpa, window) catch std.process.fatal("out of memory", .{}), } } @@ -1491,6 +1631,10 @@ fn manageStart(manager: *WindowManager) void { } manager.pending.clearRetainingCapacity(); + // Client fullscreen requests arrive as events, outside any manage + // sequence. Apply them here, where the fullscreen request is legal. + manager.applyPendingFullscreen(); + for (manager.seats.items) |seat| { for (seat.bindings.items) |binding| { if (binding.enabled) continue; @@ -1519,10 +1663,37 @@ fn manageStart(manager: *WindowManager) void { } if (output != null) { manager.arrange(); - // Keep the current focus when the focused window is still valid and - // visible. Commands such as focus-view run earlier in this sequence - // and must not be stomped by the fallback below. - if (manager.seats.items.len > 0) { + if (manager.rules_dirty) { + // A config reload re-applies rules to live windows inside the + // manage sequence, where fullscreen requests are legal. + // Additive only: windows keep user-toggled float and tags that + // no rule touches. + manager.rules_dirty = false; + for (manager.windows.items) |window| manager.applyRules(window); + } + // Apply app_id and title changes queued by Window event handlers. + for (manager.windows.items) |window| { + if (window.node == null) continue; + if (window.rules_pending) { + manager.applyRules(window); + } else if (window.decorations_pending) { + manager.applyDecorationRules(window); + } + window.rules_pending = false; + window.decorations_pending = false; + } + // Windows created since the last manage sequence take focus. + // The stack top is index 0, so the newest window comes first. + for (manager.windows.items) |window| { + if (!window.just_created) continue; + window.just_created = false; + if (focused == null and manager.visibleOn(window)) focused = window; + } + // Keep the current focus when no new window claimed it and the + // focused window is still valid and visible. Commands such as + // focus-view run earlier in this sequence and must not be stomped + // by the fallback below. + if (focused == null and manager.seats.items.len > 0) { const seat = manager.seats.items[0]; if (seat.focused_window) |current| { if (manager.findWindow(current)) |window| { @@ -1542,10 +1713,17 @@ fn manageStart(manager: *WindowManager) void { if (manager.seats.items.len > 0) { const seat = manager.seats.items[0]; - if (manager.focus_follows_cursor) { + // Each pointer entry fires once: the edge is consumed even when the + // hovered window is hidden, so a stale hover cannot steal focus + // from a newly spawned window (e.g. dmenu) on a later sequence. + if (manager.focus_follows_cursor != .disabled) { if (seat.hovered_window) |hovered| { if (manager.findWindow(hovered)) |hovered_window| { - if (manager.visibleOn(hovered_window)) focused = hovered_window; + const fresh = hovered != seat.hover_applied; + seat.hover_applied = hovered; + if (hoverWins(manager.focus_follows_cursor, true, manager.visibleOn(hovered_window), fresh)) { + focused = hovered_window; + } } } } @@ -1574,19 +1752,57 @@ fn manageStart(manager: *WindowManager) void { } } + // A fullscreen window that was hidden since the last sequence (for + // example by a tag switch) may have lost its compositor-side + // fullscreen state. Re-assert it now that the window is visible. + for (manager.windows.items) |window| { + if (!window.fullscreen_interrupted) continue; + if (!window.fullscreen) { + window.fullscreen_interrupted = false; + continue; + } + if (!manager.visibleAnywhere(window)) continue; + window.fullscreen_interrupted = false; + manager.setFullscreen(window, true); + } + + // Clients draw their own title bars and shadows unless told they are + // tiled, so sync the tiled state with the layout once per sequence. + for (manager.windows.items) |window| { + const object = window.object orelse continue; + const tiled = window.controllable(); + if (window.tiled_sent) |sent| { + if (sent == tiled) continue; + } + if (tiled) { + object.setTiled(.{ .top = true, .bottom = true, .left = true, .right = true }); + } else { + object.setTiled(.{}); + } + window.tiled_sent = tiled; + } + manager.object.manageFinish(); } fn renderStart(manager: *WindowManager) void { + // Render in reverse stack order: every window calls placeTop, so the + // stack top (index 0) must render last to land visually on top. for (manager.outputs.items) |output| { - for (manager.windows.items) |window| { + var index = manager.windows.items.len; + while (index > 0) { + index -= 1; + const window = manager.windows.items[index]; if (window.fullscreen) continue; if (visibleOnOutput(window, output)) { window.render(manager.border_width, if (window.focused) manager.border_focused else manager.border_unfocused); } } } - for (manager.windows.items) |window| { + var index = manager.windows.items.len; + while (index > 0) { + index -= 1; + const window = manager.windows.items[index]; if (window.fullscreen and manager.visibleAnywhere(window)) { window.render(manager.border_width, if (window.focused) manager.border_focused else manager.border_unfocused); continue; @@ -1595,6 +1811,9 @@ fn renderStart(manager: *WindowManager) void { window.hide(); } } + for (manager.windows.items) |window| { + manager.syncGapDecoration(window); + } manager.object.renderFinish(); } @@ -1705,16 +1924,12 @@ fn snapFocused(manager: *WindowManager, direction: []c /// Saturating addition for window geometry. Overflow saturates to the /// fallback instead of wrapping, keeping windows within reachable bounds. fn addSaturating(a: i32, b: i32, fallback: i32) i32 { - // The fallback is the saturating result, not a swallowed error. - // zwanzig-disable-next-line: swallowed-error - return std.math.add(i32, a, b) catch fallback; + return std.math.cast(i32, @as(i64, a) + b) orelse fallback; } /// Saturating subtraction for window geometry. See addSaturating. fn subSaturating(a: i32, b: i32, fallback: i32) i32 { - // The fallback is the saturating result, not a swallowed error. - // zwanzig-disable-next-line: swallowed-error - return std.math.sub(i32, a, b) catch fallback; + return std.math.cast(i32, @as(i64, a) - b) orelse fallback; } /// Expand 0xRRGGBBAA into four full-range channel values. @@ -1739,13 +1954,13 @@ fn parseRGBA(raw: []const u8) error{InvalidArgument}![ fn zoom(manager: *WindowManager) void { if (manager.seats.items.len == 0) return; const focused = manager.seats.items[0].focused_window orelse return; - // Rendering places windows on top in list order, so the end of the - // list is the top of the stack. + // The top of the stack is index 0: it gets the main layout area and + // renders last (on top). Zoom bumps the focused window there. for (manager.windows.items, 0..) |window, index| { - if (window.object != focused or index == manager.windows.items.len - 1) continue; + if (window.object != focused or index == 0) continue; manager.windows.ensureUnusedCapacity(gpa, 1) catch return; _ = manager.windows.orderedRemove(index); - manager.windows.appendAssumeCapacity(window); + manager.windows.insertAssumeCapacity(0, window); return; } } @@ -1769,15 +1984,69 @@ fn parseRatio(raw: []const u8, current: f32) error{Inv } fn parseCount(raw: []const u8, current: u32) error{InvalidArgument}!u32 { + // Counts past i32 range would panic the intCast below, and no layout + // can show two billion windows, so cap there and saturate instead. + const capacity: u32 = @intCast(std.math.maxInt(i32)); + const clamped_current = @min(current, capacity); if (raw.len > 0 and (raw[0] == '+' or raw[0] == '-')) { const delta = std.fmt.parseInt(i32, raw, 10) catch return error.InvalidArgument; - const next = std.math.add(i32, @intCast(current), delta) catch return error.InvalidArgument; + const base: i32 = @intCast(clamped_current); + const next: i32 = std.math.add(i32, base, delta) catch blk: { + break :blk if (delta < 0) 1 else std.math.maxInt(i32); + }; return @intCast(@max(1, next)); } const value = std.fmt.parseInt(u32, raw, 10) catch return error.InvalidArgument; - return @max(1, value); + return @max(1, @min(value, capacity)); } +test "main-count stays inside i32 range" { + const testing = std.testing; + try testing.expectEqual(@as(u32, 1), try parseCount("0", 1)); + try testing.expectEqual(@as(u32, 5), try parseCount("5", 1)); + try testing.expectEqual(@as(u32, std.math.maxInt(i32)), try parseCount("4294967295", 1)); + try testing.expectEqual(@as(u32, 1), try parseCount("-99", 1)); + try testing.expectEqual(@as(u32, std.math.maxInt(i32)), try parseCount("+99", std.math.maxInt(u32))); + try testing.expectError(error.InvalidArgument, parseCount("bogus", 1)); +} + +/// Reasonable upper bound for a border in pixels; well above anything a +/// real theme would want, but small enough to catch fat-fingered config. +const border_width_max: i32 = 256; + +/// Reasonable upper bound for an xcursor theme size in pixels; covers all +/// common hicolor cursor theme sizes (24-256) with headroom for HiDPI. +const cursor_theme_size_max: u32 = 512; + +/// Parse a non-negative pixel dimension, clamping to [0, max] instead of +/// erroring on out-of-range input, matching parseRatio's clamp-not-reject +/// convention for scalar settings. +fn parseBoundedI32(raw: []const u8, max: i32) error{InvalidArgument}!i32 { + const value = std.fmt.parseInt(i32, raw, 10) catch return error.InvalidArgument; + return std.math.clamp(value, 0, max); +} + +/// Parse an unsigned pixel dimension, clamping to [0, max]. +fn parseBoundedU32(raw: []const u8, max: u32) error{InvalidArgument}!u32 { + const value = std.fmt.parseInt(u32, raw, 10) catch return error.InvalidArgument; + return @min(value, max); +} + +test "border-width clamps to a sane pixel range" { + const testing = std.testing; + try testing.expectEqual(@as(i32, 0), try parseBoundedI32("-5", border_width_max)); + try testing.expectEqual(@as(i32, 2), try parseBoundedI32("2", border_width_max)); + try testing.expectEqual(@as(i32, border_width_max), try parseBoundedI32("999999", border_width_max)); + try testing.expectError(error.InvalidArgument, parseBoundedI32("bogus", border_width_max)); +} + +test "xcursor-theme size clamps to a sane pixel range" { + const testing = std.testing; + try testing.expectEqual(@as(u32, 24), try parseBoundedU32("24", cursor_theme_size_max)); + try testing.expectEqual(@as(u32, cursor_theme_size_max), try parseBoundedU32("999999", cursor_theme_size_max)); + try testing.expectError(error.InvalidArgument, parseBoundedU32("bogus", cursor_theme_size_max)); +} + /// Apply matching rules to a newly managed window. pub fn applyRules(manager: *WindowManager, window: *Window) void { const app_id = window.app_id orelse ""; @@ -1788,36 +2057,93 @@ pub fn applyRules(manager: *WindowManager, window: *Wi switch (rule.action) { .float => window.float = true, .fullscreen => window.fullscreen = true, - .ssd, .csd => {}, + .csd => {}, .tags => window.tags = rule.tags, } } manager.applyDecorationRules(window); - if (window.object) |object| { - if (window.fullscreen) { - const target = window.output orelse manager.focusedOutput() orelse return; - object.fullscreen(target.object); - object.informFullscreen(); - } - } + if (window.fullscreen) manager.setFullscreen(window, true); } -/// Re-evaluate ssd and csd rules only. Idempotent, so safe to repeat when -/// app_id or title change after the window is already managed. +/// Ask the client to use CSD or SSD, based on the csd setting and csd rules. +/// laguna draws no server-side title bar, so SSD leaves only the border. +/// Clients that only support CSD ignore the SSD request. Safe to repeat: it +/// sends nothing when the mode has not changed. Call it only inside a manage +/// sequence. pub fn applyDecorationRules(manager: *WindowManager, window: *Window) void { const object = window.object orelse return; - const app_id = window.app_id orelse ""; - const title = window.title orelse ""; - var ssd = false; - for (manager.rules.items) |rule| { + const csd = wantsCsd( + manager.csd, + manager.rules.items, + window.app_id orelse "", + window.title orelse "", + ); + if (window.csd_sent) |sent| { + if (sent == csd) return; + } + if (csd) object.useCsd() else object.useSsd(); + window.csd_sent = csd; +} + +/// Queue a decoration update for every managed window after the csd setting +/// or a rule changes. manageStart applies it. +fn markDecorationsPending(manager: *WindowManager) void { + for (manager.windows.items) |window| window.decorations_pending = true; +} + +/// True when a window should draw client-side decorations: the global csd +/// setting is on or a csd rule matches it. +fn wantsCsd(csd: bool, rules: []const Rule.Rule, app_id: []const u8, title: []const u8) bool { + if (csd) return true; + for (rules) |rule| { + if (rule.action != .csd) continue; if (!Rule.match(app_id, rule.app_id_glob)) continue; if (!Rule.match(title, rule.title_glob)) continue; - if (rule.action == .ssd) ssd = true; - if (rule.action == .csd) ssd = false; + return true; } - if (ssd) object.useSsd() else object.useCsd(); + return false; } +test "decorations default to ssd unless csd is set or a csd rule matches" { + const testing = std.testing; + const rules = [_]Rule.Rule{ + .{ .app_id_glob = "firefox", .title_glob = "*", .action = .csd }, + .{ .app_id_glob = "*", .title_glob = "*", .action = .float }, + }; + try testing.expect(!wantsCsd(false, &.{}, "collier", "collier")); + try testing.expect(!wantsCsd(false, &rules, "collier", "collier")); + try testing.expect(wantsCsd(false, &rules, "firefox", "Mozilla Firefox")); + try testing.expect(wantsCsd(true, &.{}, "collier", "collier")); +} + +/// Set compositor-side fullscreen state and notify the client. The +/// fullscreen and exit_fullscreen requests are only legal inside a manage +/// sequence, so callers must run there. One helper keeps the state change +/// and the set/inform request pairing in sync for every caller: the +/// toggle-fullscreen command, fullscreen rules and client requests. +fn setFullscreen(manager: *WindowManager, window: *Window, fullscreen: bool) void { + window.fullscreen = fullscreen; + const object = window.object orelse return; + if (fullscreen) { + const target = window.output orelse manager.focusedOutput() orelse return; + object.fullscreen(target.object); + object.informFullscreen(); + } else { + window.fullscreen_interrupted = false; + object.exitFullscreen(); + object.informNotFullscreen(); + } +} + +/// Apply fullscreen changes clients requested between manage sequences. +fn applyPendingFullscreen(manager: *WindowManager) void { + for (manager.windows.items) |window| { + const requested = window.pending_fullscreen orelse continue; + window.pending_fullscreen = null; + if (window.fullscreen != requested) manager.setFullscreen(window, requested); + } +} + /// Tile visible windows across every output, skipping floating windows, /// fullscreen windows and windows with an active pointer operation. fn arrange(manager: *WindowManager) void { @@ -1850,41 +2176,116 @@ fn arrangeOutput(manager: *WindowManager, output: *Out if (manager.windowBusy(window)) continue; count += 1; } - if (count == 0) return; + if (count > 0) { + const placements = gpa.alloc(Layout.Placement, count) catch return; + defer gpa.free(placements); + const area: Layout.Rect = if (output.usable_valid) output.usable else .{ + .x = output.x, + .y = output.y, + .width = output.width, + .height = output.height, + }; + Layout.compute(placements, area, output.main_count, output.main_ratio, output.main_location); - const placements = gpa.alloc(Layout.Placement, count) catch return; - defer gpa.free(placements); - const area: Layout.Rect = if (output.usable_valid) output.usable else .{ - .x = output.x, - .y = output.y, - .width = output.width, - .height = output.height, - }; - Layout.compute(placements, area, output.main_count, output.main_ratio, output.main_location); - - var index: usize = 0; - for (manager.windows.items) |window| { - if (!visibleOnOutput(window, output) or manager.windowBusy(window)) continue; - if (window.float or window.fullscreen) continue; - const placement = placements[index]; - index += 1; - window.x = placement.x; - window.y = placement.y; - window.placed = true; - window.configure(placement.width, placement.height); + var index: usize = 0; + for (manager.windows.items) |window| { + if (!visibleOnOutput(window, output) or manager.windowBusy(window)) continue; + if (window.float or window.fullscreen) continue; + const placement = placements[index]; + index += 1; + window.x = placement.x; + window.y = placement.y; + window.placed = true; + window.tile_width = placement.width; + window.tile_height = placement.height; + window.configure(placement.width, placement.height); + } } for (manager.windows.items) |window| { if (!visibleOnOutput(window, output)) continue; if (!window.float and !window.fullscreen) continue; if (window.float and !window.placed) { - window.x = output.x; - window.y = output.y; + // Center the window on its output instead of piling floats + // in the top-left corner. + const offset_x = @divFloor(@max(output.width - window.width, 0), 2); + const offset_y = @divFloor(@max(output.height - window.height, 0), 2); + window.x = output.x + offset_x; + window.y = output.y + offset_y; window.placed = true; window.configure(window.width, window.height); } } } +/// Create the shared 1x1 gap-color buffer, recreating it when the color +/// changed since the current buffer was made. Returns null when the +/// compositor does not advertise wl_shm or allocation fails. +fn ensureGapBuffer(manager: *WindowManager) ?*wl.Buffer { + if (manager.gap_buffer) |buffer| { + if (std.mem.eql(u32, &manager.gap_buffer_color, &manager.gap_color)) return buffer; + buffer.destroy(); + manager.gap_buffer = null; + } + const shm = manager.wl_shm orelse return null; + const buffer = GapDecoration.createBuffer(shm, manager.gap_color) orelse return null; + manager.gap_buffer_color = manager.gap_color; + manager.gap_buffer = buffer; + return buffer; +} + +/// Keep the gap-covering decoration of one window in sync with its state: +/// created or resized while a layout-controlled window is smaller than its +/// tile, destroyed as soon as the gap or the tiling state goes away. +fn syncGapDecoration(manager: *WindowManager, window: *Window) void { + const wants = GapDecoration.needed( + window.controllable(), + window.shown, + window.width, + window.height, + window.tile_width, + window.tile_height, + ); + if (!wants) { + if (window.gap_decoration) |decoration| { + decoration.deinit(); + gpa.destroy(decoration); + window.gap_decoration = null; + } + return; + } + const compositor = manager.wl_compositor orelse return; + const viewporter = manager.viewporter orelse return; + const object = window.object orelse return; + const buffer = manager.ensureGapBuffer() orelse return; + if (window.gap_decoration == null) { + const decoration = gpa.create(GapDecoration) catch { + log.err("out of memory", .{}); + return; + }; + decoration.create(object, compositor, viewporter) catch { + gpa.destroy(decoration); + log.err("failed to create gap decoration", .{}); + return; + }; + window.gap_decoration = decoration; + } + const decoration = window.gap_decoration orelse return; + if (decoration.width == window.tile_width and + decoration.height == window.tile_height and + decoration.buffer == buffer) return; + // The window content sits at the tile origin, so an offset of 0,0 + // aligns the decoration with the tile. + decoration.viewport.setDestination(window.tile_width, window.tile_height); + decoration.object.setOffset(0, 0); + decoration.object.syncNextCommit(); + decoration.surface.attach(buffer, 0, 0); + decoration.surface.damageBuffer(0, 0, 1, 1); + decoration.surface.commit(); + decoration.width = window.tile_width; + decoration.height = window.tile_height; + decoration.buffer = buffer; +} + fn windowBusy(manager: *WindowManager, window: *const Window) bool { for (manager.seats.items) |seat| { if (seat.operation) |operation| { @@ -1914,9 +2315,8 @@ fn processPointerOperation(manager: *WindowManager, se .move => { operation.window.x = addSaturating(operation.start_x, delta.delta_x, operation.start_x); operation.window.y = addSaturating(operation.start_y, delta.delta_y, operation.start_y); - if (operation.window.node) |node| { - node.setPosition(operation.window.x, operation.window.y); - } + // set_position is render-sequence only; the render sequence + // following this manage sequence applies the new position. }, .resize => { const width: i32 = @max(1, std.math.add( @@ -1967,6 +2367,9 @@ fn purgeClosed(manager: *WindowManager) void { } for (manager.seats.items) |seat| { if (seat.focused_window == window.object) seat.focused_window = null; + if (seat.hovered_window == window.object) seat.hovered_window = null; + if (seat.hover_applied == window.object) seat.hover_applied = null; + if (seat.last_focused == window.object) seat.last_focused = null; if (seat.operation) |operation| { if (operation.window == window) seat.operation = null; } @@ -2016,3 +2419,26 @@ fn purgeClosed(manager: *WindowManager) void { gpa.destroy(seat); } } + +/// Pure focus-follows-cursor policy. has_hover and visible come from the +/// hovered window lookup, fresh means the pointer entered a window that has +/// not granted focus yet. +pub fn hoverWins(mode: FocusFollowsCursor, has_hover: bool, visible: bool, fresh: bool) bool { + if (!has_hover or !visible) return false; + return switch (mode) { + .disabled => false, + .always => true, + .normal => fresh, + }; +} + +test "hover follow policy" { + const testing = std.testing; + try testing.expect(!hoverWins(.disabled, true, true, true)); + try testing.expect(hoverWins(.always, true, true, false)); + try testing.expect(hoverWins(.always, true, true, true)); + try testing.expect(hoverWins(.normal, true, true, true)); + try testing.expect(!hoverWins(.normal, true, true, false)); + try testing.expect(!hoverWins(.normal, false, true, true)); + try testing.expect(!hoverWins(.always, true, false, true)); +} blob - d8e16dc086d4d22dc5cea0c314c858e81702f8af blob + c26e974962f192e5b7b6df22b06c8684a3e0be56 --- src/main.zig +++ src/main.zig @@ -1,5 +1,6 @@ -// SPDX-FileCopyrightText: © 2026 The River Developers -// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: © 2026 mtmn +// +// SPDX-License-Identifier: BSD-3-Clause // Module type aliases use PascalCase per Zig convention. // zwanzig-disable: identifier-style @@ -7,6 +8,7 @@ const std = @import("std"); const mem = std.mem; const wayland = @import("wayland"); const wl = wayland.client.wl; +const wp = wayland.client.wp; const river = wayland.client.river; const Config = @import("Config.zig"); @@ -21,11 +23,26 @@ const Globals = struct { input_manager: ?*river.InputManagerV1 = null, libinput_config: ?*river.LibinputConfigV1 = null, xkb_config: ?*river.XkbConfigV1 = null, + compositor: ?*wl.Compositor = null, + shm: ?*wl.Shm = null, + viewporter: ?*wp.Viewporter = null, wl_outputs: std.ArrayListUnmanaged(*WindowManager.WlOutput) = .empty, }; pub fn main() !void { const io = std.Io.Threaded.global_single_threaded.io(); + // Block SIGHUP process-wide so it arrives on the signalfd below + // instead of killing the process. Powers config hot reload. + const linux = std.os.linux; + var hup_mask = linux.sigemptyset(); + linux.sigaddset(&hup_mask, .HUP); + if (std.posix.errno(linux.sigprocmask(linux.SIG.BLOCK, &hup_mask, null)) != .SUCCESS) { + std.process.fatal("failed to mask SIGHUP", .{}); + } + const hup_fd = openHupSignalfd(&hup_mask); + defer { + if (hup_fd >= 0) _ = linux.close(hup_fd); + } const display = try wl.Display.connect(null); defer display.disconnect(); @@ -50,6 +67,12 @@ pub fn main() !void { globals.wl_outputs.deinit(gpa); } manager.input.setGlobals(globals.input_manager, globals.libinput_config, globals.xkb_config); + manager.wl_compositor = globals.compositor; + manager.wl_shm = globals.shm; + manager.viewporter = globals.viewporter; + if (globals.compositor == null or globals.shm == null or globals.viewporter == null) { + std.log.warn("wl_compositor, wl_shm or wp_viewporter missing, gap filling disabled", .{}); + } loadConfig(io, &manager); @@ -65,8 +88,13 @@ pub fn main() !void { var poll_file_descriptors = [_]std.posix.pollfd{ .{ .fd = wl.Display.getFd(display), .events = std.posix.POLL.IN, .revents = 0 }, + .{ .fd = hup_fd, .events = std.posix.POLL.IN, .revents = 0 }, }; - _ = try std.posix.poll(&poll_file_descriptors, -1); + const watched: usize = if (hup_fd >= 0) 2 else 1; + _ = try std.posix.poll(poll_file_descriptors[0..watched], -1); + if (watched == 2 and poll_file_descriptors[1].revents != 0) { + if (drainHup(hup_fd)) reloadConfig(io, &manager); + } if (poll_file_descriptors[0].revents != 0) { if (wl.Display.readEvents(display) != .SUCCESS) return error.DispatchFailed; } else { @@ -76,24 +104,49 @@ pub fn main() !void { } } -/// Load the static ZON config file. A missing file leaves default settings -/// in place; a malformed file is fatal so typos fail loudly instead of -/// silently leaving the window manager unconfigured. -fn loadConfig(io: std.Io, manager: *WindowManager) void { +/// Create a nonblocking signalfd for SIGHUP. Returns -1 with a logged +/// error when unavailable; the session then runs without hot reload. +fn openHupSignalfd(mask: *const std.os.linux.sigset_t) std.posix.fd_t { + const linux = std.os.linux; + const raw = linux.signalfd(-1, mask, linux.SFD.CLOEXEC | linux.SFD.NONBLOCK); + if (std.posix.errno(raw) != .SUCCESS) { + std.log.err("signalfd unavailable, SIGHUP reload disabled", .{}); + return -1; + } + return @intCast(@as(isize, @bitCast(raw))); +} + +/// Drain the SIGHUP signalfd. Returns true when a HUP arrived, coalescing +/// rapid repeats into one reload. +fn drainHup(fd: std.posix.fd_t) bool { + const linux = std.os.linux; + var infos: [16]linux.signalfd_siginfo = undefined; + var seen = false; + while (true) { + const raw = linux.read(fd, @ptrCast(&infos), @sizeOf(@TypeOf(infos))); + if (std.posix.errno(raw) != .SUCCESS) return seen; + const count = raw / @sizeOf(linux.signalfd_siginfo); + if (count == 0) return seen; + for (infos[0..count]) |info| { + if (info.signo == @intFromEnum(std.posix.SIG.HUP)) seen = true; + } + } +} + +/// Read and parse the config file. Returns null after logging when the +/// path cannot be resolved, the file is missing or unreadable, or the +/// contents are invalid. The result borrows from allocator. +fn readConfigFile(io: std.Io, allocator: std.mem.Allocator) ?Config { const path = Config.defaultPath(gpa) catch |err| { std.log.err("cannot resolve config path: {s}", .{@errorName(err)}); - return; + return null; }; defer if (path) |owned| gpa.free(owned); const config_path = path orelse { std.log.warn("no home directory found, running with default settings", .{}); - return; + return null; }; - var arena = std.heap.ArenaAllocator.init(gpa); - defer arena.deinit(); - const allocator = arena.allocator(); - const file_bytes = std.Io.Dir.cwd().readFileAlloc( io, config_path, @@ -108,24 +161,40 @@ fn loadConfig(io: std.Io, manager: *WindowManager) voi } else { std.log.err("cannot read config file at {s}: {s}", .{ config_path, @errorName(err) }); } - return; + return null; }; const source = allocator.dupeZ(u8, file_bytes) catch |err| { std.log.err("out of memory reading config: {s}", .{@errorName(err)}); - return; + return null; }; var diagnostics: std.zon.parse.Diagnostics = .{}; defer diagnostics.deinit(allocator); - const config = Config.parse(allocator, source, &diagnostics) catch { + return Config.parse(allocator, source, &diagnostics) catch { std.log.err("invalid laguna config at {s}: {f}", .{ config_path, diagnostics }); - return; + return null; }; +} +/// Load the static ZON config file at startup. A missing or invalid file +/// leaves default settings in place. +fn loadConfig(io: std.Io, manager: *WindowManager) void { + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const config = readConfigFile(io, arena.allocator()) orelse return; manager.loadConfig(&config) catch |err| { std.log.err("cannot apply config: {s}", .{@errorName(err)}); }; } +/// Reload the config file after SIGHUP. Any failure keeps the running +/// config untouched: parsing finishes before running state is reset. +fn reloadConfig(io: std.Io, manager: *WindowManager) void { + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const config = readConfigFile(io, arena.allocator()) orelse return; + manager.reload(&config); +} + fn handleWlOutputEvent(_: *wl.Output, event: wl.Output.Event, entry: *WindowManager.WlOutput) void { switch (event) { .name => |named| { @@ -175,6 +244,9 @@ fn registryListener(registry: *wl.Registry, event: wl. }; return; } + if (tryBind(registry, global.interface, global.name, global.version, wl.Compositor, &globals.compositor, "wl_compositor")) return; + if (tryBind(registry, global.interface, global.name, global.version, wl.Shm, &globals.shm, "wl_shm")) return; + if (tryBind(registry, global.interface, global.name, global.version, wp.Viewporter, &globals.viewporter, "wp_viewporter")) return; if (tryBind(registry, global.interface, global.name, global.version, river.WindowManagerV1, &globals.window_manager, "river window manager")) return; if (tryBind(registry, global.interface, global.name, global.version, river.InputManagerV1, &globals.input_manager, "river input manager")) return; if (tryBind(registry, global.interface, global.name, global.version, river.LibinputConfigV1, &globals.libinput_config, "river libinput config")) return;