ether
DWL-based wayland compositor with lua support
git clone https://git.pi66.xyz/ether
About | Files | Commits | Refs | License
Init project
Author: pi66
Date: 2026-09-12 22:42
commit: 516efcf1
Stat
| A | LICENSES/LICENSE.dwl | 692 | +692 | -0 |
| A | LICENSES/LICENSE.dwm | 39 | +39 | -0 |
| A | LICENSES/LICENSE.sway | 19 | +19 | -0 |
| A | LICENSES/LICENSE.tinywl | 127 | +127 | -0 |
| A | Makefile | 88 | +88 | -0 |
| A | config.lua | 153 | +153 | -0 |
| A | config.mk | 36 | +36 | -0 |
| A | ether.desktop | 5 | +5 | -0 |
| A | protocols/wlr-layer-shell-unstable-v1.xml | 390 | +390 | -0 |
| A | protocols/wlr-output-power-management-unstable-v1.xml | 128 | +128 | -0 |
| A | src/client.h | 426 | +426 | -0 |
| A | src/clients.c | 1089 | +1089 | -0 |
| A | src/config.c | 1634 | +1634 | -0 |
| A | src/config.h | 108 | +108 | -0 |
| A | src/cursor.c | 188 | +188 | -0 |
| A | src/ether.h | 565 | +565 | -0 |
| A | src/input.c | 849 | +849 | -0 |
| A | src/layout.c | 427 | +427 | -0 |
| A | src/main.c | 585 | +585 | -0 |
| A | src/monitors.c | 450 | +450 | -0 |
| A | src/session-lock.c | 105 | +105 | -0 |
| A | src/shifttag.c | 132 | +132 | -0 |
| A | src/util.h | 61 | +61 | -0 |
| A | src/xwayland.c | 132 | +132 | -0 |
Diff
diff --git a/LICENSES/LICENSE.dwl b/LICENSES/LICENSE.dwl
new file mode 100644
index 0000000..658085a
--- /dev/null
+++ b/LICENSES/LICENSE.dwl
@@ -0,0 +1,692 @@
+dwl - dwm for Wayland
+
+Copyright © 2020 dwl team
+
+See also the files LICENSE.tinywl, LICENSE.dwm and LICENSE.sway.
+
+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
...
Show all
Show less
diff --git a/LICENSES/LICENSE.dwl b/LICENSES/LICENSE.dwl
new file mode 100644
index 0000000..658085a
--- /dev/null
+++ b/LICENSES/LICENSE.dwl
@@ -0,0 +1,692 @@
+dwl - dwm for Wayland
+
+Copyright © 2020 dwl team
+
+See also the files LICENSE.tinywl, LICENSE.dwm and LICENSE.sway.
+
+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
...
diff --git a/LICENSES/LICENSE.dwl b/LICENSES/LICENSE.dwl
new file mode 100644
index 0000000..658085a
--- /dev/null
+++ b/LICENSES/LICENSE.dwl
@@ -0,0 +1,692 @@
+dwl - dwm for Wayland
+
+Copyright © 2020 dwl team
+
+See also the files LICENSE.tinywl, LICENSE.dwm and LICENSE.sway.
+
+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.
+
+----
+
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<https://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<https://www.gnu.org/licenses/why-not-lgpl.html>.
diff --git a/LICENSES/LICENSE.dwm b/LICENSES/LICENSE.dwm
new file mode 100644
index 0000000..507e4dc
--- /dev/null
+++ b/LICENSES/LICENSE.dwm
@@ -0,0 +1,39 @@
+Portions of dwl based on dwm code are used under the following license:
+
+MIT/X Consortium License
+
+© 2006-2019 Anselm R Garbe <anselm@garbe.ca>
+© 2006-2009 Jukka Salmi <jukka at salmi dot ch>
+© 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
+© 2007-2011 Peter Hartlich <sgkkr at hartlich dot com>
+© 2007-2009 Szabolcs Nagy <nszabolcs at gmail dot com>
+© 2007-2009 Christof Musik <christof at sendfax dot de>
+© 2007-2009 Premysl Hruby <dfenze at gmail dot com>
+© 2007-2008 Enno Gottox Boland <gottox at s01 dot de>
+© 2008 Martin Hurton <martin dot hurton at gmail dot com>
+© 2008 Neale Pickett <neale dot woozle dot org>
+© 2009 Mate Nagy <mnagy at port70 dot net>
+© 2010-2016 Hiltjo Posthuma <hiltjo@codemadness.org>
+© 2010-2012 Connor Lane Smith <cls@lubutu.com>
+© 2011 Christoph Lohmann <20h@r-36.net>
+© 2015-2016 Quentin Rameau <quinq@fifth.space>
+© 2015-2016 Eric Pruitt <eric.pruitt@gmail.com>
+© 2016-2017 Markus Teich <markus.teich@stusta.mhn.de>
+
+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.
diff --git a/LICENSES/LICENSE.sway b/LICENSES/LICENSE.sway
new file mode 100644
index 0000000..3e0cacc
--- /dev/null
+++ b/LICENSES/LICENSE.sway
@@ -0,0 +1,19 @@
+Copyright (c) 2016-2017 Drew DeVault
+
+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.
diff --git a/LICENSES/LICENSE.tinywl b/LICENSES/LICENSE.tinywl
new file mode 100644
index 0000000..7023690
--- /dev/null
+++ b/LICENSES/LICENSE.tinywl
@@ -0,0 +1,127 @@
+dwl is originally based on TinyWL, which is used under the following license:
+
+This work is licensed under CC0, which effectively puts it in the public domain.
+
+---
+
+Creative Commons Legal Code
+
+CC0 1.0 Universal
+
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
+ HEREUNDER.
+
+Statement of Purpose
+
+The laws of most jurisdictions throughout the world automatically confer
+exclusive Copyright and Related Rights (defined below) upon the creator
+and subsequent owner(s) (each and all, an "owner") of an original work of
+authorship and/or a database (each, a "Work").
+
+Certain owners wish to permanently relinquish those rights to a Work for
+the purpose of contributing to a commons of creative, cultural and
+scientific works ("Commons") that the public can reliably and without fear
+of later claims of infringement build upon, modify, incorporate in other
+works, reuse and redistribute as freely as possible in any form whatsoever
+and for any purposes, including without limitation commercial purposes.
+These owners may contribute to the Commons to promote the ideal of a free
+culture and the further production of creative, cultural and scientific
+works, or to gain reputation or greater distribution for their Work in
+part through the use and efforts of others.
+
+For these and/or other purposes and motivations, and without any
+expectation of additional consideration or compensation, the person
+associating CC0 with a Work (the "Affirmer"), to the extent that he or she
+is an owner of Copyright and Related Rights in the Work, voluntarily
+elects to apply CC0 to the Work and publicly distribute the Work under its
+terms, with knowledge of his or her Copyright and Related Rights in the
+Work and the meaning and intended legal effect of CC0 on those rights.
+
+1. Copyright and Related Rights. A Work made available under CC0 may be
+protected by copyright and related or neighboring rights ("Copyright and
+Related Rights"). Copyright and Related Rights include, but are not
+limited to, the following:
+
+ i. the right to reproduce, adapt, distribute, perform, display,
+ communicate, and translate a Work;
+ ii. moral rights retained by the original author(s) and/or performer(s);
+iii. publicity and privacy rights pertaining to a person's image or
+ likeness depicted in a Work;
+ iv. rights protecting against unfair competition in regards to a Work,
+ subject to the limitations in paragraph 4(a), below;
+ v. rights protecting the extraction, dissemination, use and reuse of data
+ in a Work;
+ vi. database rights (such as those arising under Directive 96/9/EC of the
+ European Parliament and of the Council of 11 March 1996 on the legal
+ protection of databases, and under any national implementation
+ thereof, including any amended or successor version of such
+ directive); and
+vii. other similar, equivalent or corresponding rights throughout the
+ world based on applicable law or treaty, and any national
+ implementations thereof.
+
+2. Waiver. To the greatest extent permitted by, but not in contravention
+of, applicable law, Affirmer hereby overtly, fully, permanently,
+irrevocably and unconditionally waives, abandons, and surrenders all of
+Affirmer's Copyright and Related Rights and associated claims and causes
+of action, whether now known or unknown (including existing as well as
+future claims and causes of action), in the Work (i) in all territories
+worldwide, (ii) for the maximum duration provided by applicable law or
+treaty (including future time extensions), (iii) in any current or future
+medium and for any number of copies, and (iv) for any purpose whatsoever,
+including without limitation commercial, advertising or promotional
+purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
+member of the public at large and to the detriment of Affirmer's heirs and
+successors, fully intending that such Waiver shall not be subject to
+revocation, rescission, cancellation, termination, or any other legal or
+equitable action to disrupt the quiet enjoyment of the Work by the public
+as contemplated by Affirmer's express Statement of Purpose.
+
+3. Public License Fallback. Should any part of the Waiver for any reason
+be judged legally invalid or ineffective under applicable law, then the
+Waiver shall be preserved to the maximum extent permitted taking into
+account Affirmer's express Statement of Purpose. In addition, to the
+extent the Waiver is so judged Affirmer hereby grants to each affected
+person a royalty-free, non transferable, non sublicensable, non exclusive,
+irrevocable and unconditional license to exercise Affirmer's Copyright and
+Related Rights in the Work (i) in all territories worldwide, (ii) for the
+maximum duration provided by applicable law or treaty (including future
+time extensions), (iii) in any current or future medium and for any number
+of copies, and (iv) for any purpose whatsoever, including without
+limitation commercial, advertising or promotional purposes (the
+"License"). The License shall be deemed effective as of the date CC0 was
+applied by Affirmer to the Work. Should any part of the License for any
+reason be judged legally invalid or ineffective under applicable law, such
+partial invalidity or ineffectiveness shall not invalidate the remainder
+of the License, and in such case Affirmer hereby affirms that he or she
+will not (i) exercise any of his or her remaining Copyright and Related
+Rights in the Work or (ii) assert any associated claims and causes of
+action with respect to the Work, in either case contrary to Affirmer's
+express Statement of Purpose.
+
+4. Limitations and Disclaimers.
+
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
+ surrendered, licensed or otherwise affected by this document.
+ b. Affirmer offers the Work as-is and makes no representations or
+ warranties of any kind concerning the Work, express, implied,
+ statutory or otherwise, including without limitation warranties of
+ title, merchantability, fitness for a particular purpose, non
+ infringement, or the absence of latent or other defects, accuracy, or
+ the present or absence of errors, whether or not discoverable, all to
+ the greatest extent permissible under applicable law.
+ c. Affirmer disclaims responsibility for clearing rights of other persons
+ that may apply to the Work or any use thereof, including without
+ limitation any person's Copyright and Related Rights in the Work.
+ Further, Affirmer disclaims responsibility for obtaining any necessary
+ consents, permissions or other rights required for any use of the
+ Work.
+ d. Affirmer understands and acknowledges that Creative Commons is not a
+ party to this document and has no duty or obligation with respect to
+ this CC0 or use of the Work.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..605b380
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,88 @@
+.POSIX:
+.SUFFIXES:
+
+include config.mk
+
+SRCS = src/main.c src/input.c src/layout.c src/monitors.c src/clients.c \
+ src/cursor.c src/session-lock.c src/xwayland.c src/config.c \
+ src/shifttag.c
+OBJS = $(SRCS:.c=.o)
+
+# flags for compiling
+ETHERCPPFLAGS = -I. -I.. -DETHER_USE_UNSTABLE -DWLR_USE_UNSTABLE -D_POSIX_C_SOURCE=200809L \
+ -DVERSION=\"$(VERSION)\" $(XWAYLAND) $(CPPFLAGS)
+ETHERDEVCFLAGS = -g -Wpedantic -Wall -Wextra -Wdeclaration-after-statement \
+ -Wno-unused-parameter -Wshadow -Wunused-macros -Werror=strict-prototypes \
+ -Werror=implicit -Werror=return-type -Werror=incompatible-pointer-types \
+ -Wfloat-conversion
+
+# CFLAGS / LDFLAGS
+PKGS = wayland-server xkbcommon libinput lua5.5 $(XLIBS)
+ETHERCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(WLR_INCS) $(ETHERCPPFLAGS) $(ETHERDEVCFLAGS) $(CFLAGS)
+LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` $(WLR_LIBS) -lm $(LIBS)
+
+all: ether
+ether: $(OBJS) src/config.h src/util.h src/client.h src/ether.h config.mk cursor-shape-v1-protocol.h \
+ ext-image-copy-capture-v1-protocol.h \
+ pointer-constraints-unstable-v1-protocol.h wlr-layer-shell-unstable-v1-protocol.h \
+ wlr-output-power-management-unstable-v1-protocol.h xdg-shell-protocol.h \
+ tablet-v2-protocol.h
+ $(CC) $(OBJS) $(ETHERCFLAGS) $(LDFLAGS) $(LDLIBS) -o $@
+
+src/%.o: src/%.c cursor-shape-v1-protocol.h ext-image-copy-capture-v1-protocol.h \
+ pointer-constraints-unstable-v1-protocol.h wlr-layer-shell-unstable-v1-protocol.h \
+ wlr-output-power-management-unstable-v1-protocol.h xdg-shell-protocol.h \
+ tablet-v2-protocol.h
+ $(CC) -c $(ETHERCFLAGS) $< -o $@
+
+# wayland-scanner is a tool which generates C headers and rigging for Wayland
+# protocols, which are specified in XML. wlroots requires you to rig these up
+# to your build system yourself and provide them in the include path.
+WAYLAND_SCANNER = `$(PKG_CONFIG) --variable=wayland_scanner wayland-scanner`
+WAYLAND_PROTOCOLS = `$(PKG_CONFIG) --variable=pkgdatadir wayland-protocols`
+
+cursor-shape-v1-protocol.h:
+ $(WAYLAND_SCANNER) enum-header \
+ $(WAYLAND_PROTOCOLS)/staging/cursor-shape/cursor-shape-v1.xml $@
+ext-image-copy-capture-v1-protocol.h:
+ $(WAYLAND_SCANNER) enum-header \
+ $(WAYLAND_PROTOCOLS)/staging/ext-image-copy-capture/ext-image-copy-capture-v1.xml $@
+pointer-constraints-unstable-v1-protocol.h:
+ $(WAYLAND_SCANNER) enum-header \
+ $(WAYLAND_PROTOCOLS)/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml $@
+wlr-layer-shell-unstable-v1-protocol.h:
+ $(WAYLAND_SCANNER) enum-header \
+ protocols/wlr-layer-shell-unstable-v1.xml $@
+wlr-output-power-management-unstable-v1-protocol.h:
+ $(WAYLAND_SCANNER) server-header \
+ protocols/wlr-output-power-management-unstable-v1.xml $@
+xdg-shell-protocol.h:
+ $(WAYLAND_SCANNER) server-header \
+ $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
+tablet-v2-protocol.h:
+ $(WAYLAND_SCANNER) server-header \
+ $(WAYLAND_PROTOCOLS)/unstable/tablet/tablet-unstable-v2.xml $@
+
+clean:
+ rm -f ether $(OBJS) *-protocol.h
+
+dist: clean
+ mkdir -p ether-$(VERSION)
+ cp -R LICENSES/* Makefile CHANGELOG.md README.md client.h config.lua \
+ config.mk protocols src util.h ether.desktop \
+ ether-$(VERSION)
+ tar -caf ether-$(VERSION).tar.gz ether-$(VERSION)
+ rm -rf ether-$(VERSION)
+
+install: ether
+ mkdir -p $(DESTDIR)$(PREFIX)/bin
+ rm -f $(DESTDIR)$(PREFIX)/bin/ether
+ cp -f ether $(DESTDIR)$(PREFIX)/bin
+ chmod 755 $(DESTDIR)$(PREFIX)/bin/ether
+ mkdir -p $(DESTDIR)$(MANDIR)/man1
+ mkdir -p $(DESTDIR)$(DATADIR)/wayland-sessions
+ cp -f ether.desktop $(DESTDIR)$(DATADIR)/wayland-sessions/ether.desktop
+ chmod 644 $(DESTDIR)$(DATADIR)/wayland-sessions/ether.desktop
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/bin/ether \
+ $(DESTDIR)$(DATADIR)/wayland-sessions/ether.desktop
diff --git a/config.lua b/config.lua
new file mode 100644
index 0000000..40b9bec
--- /dev/null
+++ b/config.lua
@@ -0,0 +1,153 @@
+-- ether configuration
+-- Copy this file to ~/.config/ether/config.lua and edit as needed.
+
+-- appearance
+ether.sloppy_focus(true)
+ether.bypass_surface_visibility(false)
+ether.border_width(1)
+ether.border_color("#444444ff")
+ether.focus_color("#005577ff")
+ether.urgent_color("#ff0000ff")
+ether.root_color("#222222ff")
+ether.fullscreen_bg("#00000000")
+ether.default_opacity(0.75)
+ether.smartgaps(true)
+ether.gaps(true)
+ether.gap_pixels(6)
+ether.smartborders(true)
+ether.respect_monitor_reserved_area(false)
+ether.enableautoswallow(true)
+ether.swallowborder(0.8)
+
+-- hide the cursor after this many seconds of inactivity
+ether.cursor_timeout(5)
+
+-- logging: "silent", "error", "info", "debug"
+ether.log_level("error")
+
+-- keyboard
+ether.xkb_rules({
+ -- rules = "base",
+ -- model = "pc105",
+ -- layout = "us",
+ -- variant = "",
+ -- options = "ctrl:nocaps",
+})
+ether.repeat_rate(25)
+ether.repeat_delay(600)
+
+-- trackpad
+ether.trackpad({
+ tap_to_click = true,
+ tap_and_drag = true,
+ drag_lock = true,
+ natural_scrolling = false,
+ disable_while_typing = true,
+ left_handed = false,
+ middle_button_emulation = false,
+ accel_speed = 0.0,
+ scroll_method = "2fg", -- "no_scroll", "2fg", "edge", "on_button_down"
+ click_method = "button_areas", -- "none", "button_areas", "clickfinger"
+ send_events = "enabled", -- "enabled", "disabled", "disabled_on_external_mouse"
+ accel_profile = "adaptive", -- "flat", "adaptive"
+ button_map = "lrm", -- "lrm", "lmr"
+})
+
+ether.tabletmaptosurface(false) -- map pen to the focused surface(1) or the monitor(0)
+ether.tablet_area(0.0, 0.0, 1.0, 1.0) -- active zone as a fraction {x, y, width, height}
+-- draw-tablet / pad button bindings; button is a numeric X11 button
+-- (BTN_STYLUS = 0x14b, BTN_STYLUS2 = 0x14c) or pad index
+
+-- ether.tablet_button({ button = "0x14b", state = "press", action = "spawn", arg = "foot" })
+-- ether.tablet_pad_button({ button = "0", state = "press", action = "togglefloating" })
+
+-- layouts
+ether.layout({ name = "[]=", arrange = "tile" })
+ether.layout({ name = "><>", arrange = "float" })
+ether.layout({ name = "[M]", arrange = "monocle" })
+ether.layout({ name = "[D]", arrange = "deck" })
+
+-- monitor rules
+ether.monitor({
+ -- name = "eDP-1", -- match by substring; nil = match all
+ mfact = 0.55,
+ nmaster = 1,
+ scale = 1.0,
+ layout = "[]=",
+ -- transform = "normal", -- "normal", "90", "180", "270", "flipped", etc.
+ -- x = -1, y = -1, -- -1 = auto
+})
+
+-- application rules
+ether.rule({ app_id = "firefox", tags = 1 << 8 })
+-- isterm marks a client as a terminal so child windows get swallowed into it
+ether.rule({ app_id = "foot", isterm = true })
+-- noswallow opts a client out of swallowing (in addition to floating windows)
+-- ether.rule({ app_id = "wezterm", noswallow = true })
+ether.rule({ app_id = "Gimp", float = true })
+
+-- keybindings
+local MOD = { "ALT" }
+
+ether.key({ mods = MOD, key = "p", action = "spawn", arg = "wmenu-run" })
+ether.key({ mods = { "ALT", "SHIFT" }, key = "Return", action = "spawn", arg = "foot" })
+
+ether.key({ mods = MOD, key = "j", action = "focusstack", arg = { delta = 1 } })
+ether.key({ mods = MOD, key = "k", action = "focusstack", arg = { delta = -1 } })
+
+ether.key({ mods = MOD, key = "i", action = "incnmaster", arg = { delta = 1 } })
+ether.key({ mods = MOD, key = "d", action = "incnmaster", arg = { delta = -1 } })
+
+ether.key({ mods = MOD, key = "h", action = "setmfact", arg = { delta = -0.05 } })
+ether.key({ mods = MOD, key = "l", action = "setmfact", arg = { delta = 0.05 } })
+
+ether.key({ mods = MOD, key = "Return", action = "zoom" })
+ether.key({ mods = MOD, key = "Tab", action = "view" })
+ether.key({ mods = { "ALT", "SHIFT" }, key = "c", action = "killclient" })
+
+ether.key({ mods = MOD, key = "t", action = "setlayout", arg = { layout = "[]=" } })
+ether.key({ mods = MOD, key = "f", action = "setlayout", arg = { layout = "><>" } })
+ether.key({ mods = MOD, key = "m", action = "setlayout", arg = { layout = "[M]" } })
+ether.key({ mods = MOD, key = "space", action = "setlayout" })
+
+ether.key({ mods = { "ALT", "SHIFT" }, key = "space", action = "togglefloating" })
+ether.key({ mods = MOD, key = "e", action = "togglefullscreen" })
+ether.key({ mods = { "ALT", "SHIFT" }, key = "g", action = "togglegaps" })
+ether.key({ mods = MOD, key = "o", action = "setopacity", arg = { delta = 0.1 } })
+ether.key({ mods = { "ALT", "SHIFT" }, key = "a", action = "toggleswallow" })
+ether.key({ mods = { "ALT", "SHIFT" }, key = "A", action = "toggleautoswallow" })
+
+-- wrap through the tag list, skipping unoccupied (occupied) tags on request
+ether.key({ mods = MOD, key = "apostrophe", action = "shifttag_occupied", arg = { delta = 1 } })
+ether.key({ mods = MOD, key = "semicolon", action = "shifttag_occupied", arg = { delta = -1 } })
+ether.key({ mods = { "ALT", "SHIFT" }, key = "apostrophe", action = "shifttag", arg = { delta = 1 } })
+ether.key({ mods = { "ALT", "SHIFT" }, key = "semicolon", action = "shifttag", arg = { delta = -1 } })
+ether.key({ mods = { "ALT", "CTRL" }, key = "apostrophe", action = "shifttag_unoccupied", arg = { delta = 1 } })
+ether.key({ mods = { "ALT", "CTRL" }, key = "semicolon", action = "shifttag_unoccupied", arg = { delta = -1 } })
+
+ether.key({ mods = MOD, key = "0", action = "view", arg = { tag = 0xFFFFFFFF } })
+ether.key({ mods = { "ALT", "SHIFT" }, key = "parenright", action = "tag", arg = { tag = 0xFFFFFFFF } })
+
+ether.key({ mods = MOD, key = "comma", action = "focusmon", arg = { direction = "left" } })
+ether.key({ mods = MOD, key = "period", action = "focusmon", arg = { direction = "right" } })
+ether.key({ mods = { "ALT", "SHIFT" }, key = "less", action = "tagmon", arg = { direction = "left" } })
+ether.key({ mods = { "ALT", "SHIFT" }, key = "greater", action = "tagmon", arg = { direction = "right" } })
+
+-- tag keybindings (view/toggleview/tag/toggletag for tags 1-9)
+ether.tags(9)
+
+ether.key({ mods = { "ALT", "SHIFT" }, key = "q", action = "quit" })
+ether.key({ mods = { "CTRL", "ALT" }, key = "BackSpace", action = "quit" })
+
+-- Ctrl+Alt+F1..F12 to switch virtual terminals
+for i = 1, 12 do
+ ether.key({ mods = { "CTRL", "ALT" }, key = string.format("XF86Switch_VT_%d", i), action = "chvt", arg = { vt = i } })
+end
+
+-- reload config at runtime (Super+R)
+ether.key({ mods = { "SUPER" }, key = "r", action = "reload" })
+
+-- mouse bindings
+ether.mouse({ mods = MOD, button = "left", action = "moveresize", arg = { mode = "move" } })
+ether.mouse({ mods = MOD, button = "middle", action = "togglefloating" })
+ether.mouse({ mods = MOD, button = "right", action = "moveresize", arg = { mode = "resize" } })
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..748b6da
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,36 @@
+_VERSION = 0.9-dev
+VERSION = `git describe --tags --dirty 2>/dev/null || echo $(_VERSION)`
+
+PKG_CONFIG = pkg-config
+
+# paths
+PREFIX = /usr/local
+MANDIR = $(PREFIX)/share/man
+DATADIR = $(PREFIX)/share
+
+WLR_INCS = `$(PKG_CONFIG) --cflags wlroots-0.20`
+WLR_LIBS = `$(PKG_CONFIG) --libs wlroots-0.20`
+
+# Allow using an alternative wlroots installation
+# This has to have all the includes required by wlroots, e.g:
+# Assuming wlroots git repo is "${PWD}/wlroots" and you only ran "meson setup build && ninja -C build"
+#WLR_INCS = -I/usr/include/pixman-1 -I/usr/include/elogind -I/usr/include/libdrm \
+# -I$(PWD)/wlroots/include
+# Set -rpath to avoid using the wrong library.
+#WLR_LIBS = -Wl,-rpath,$(PWD)/wlroots/build -L$(PWD)/wlroots/build -lwlroots-0.20
+
+# Assuming you ran "meson setup --prefix ${PWD}/0.20 build && ninja -C build install"
+#WLR_INCS = -I/usr/include/pixman-1 -I/usr/include/elogind -I/usr/include/libdrm \
+# -I$(PWD)/wlroots/0.20/include/wlroots-0.20
+#WLR_LIBS = -Wl,-rpath,$(PWD)/wlroots/0.20/lib64 -L$(PWD)/wlroots/0.20/lib64 -lwlroots-0.20
+
+XWAYLAND =
+XLIBS =
+# Uncomment to build XWayland support
+#XWAYLAND = -DXWAYLAND
+#XLIBS = xcb xcb-icccm
+
+# ether itself only uses C99 features, but wlroots' headers use anonymous unions (C11).
+# To avoid warnings about them, we do not use -std=c99 and instead of using the
+# gmake default 'CC=c99', we use cc.
+CC = cc
diff --git a/ether.desktop b/ether.desktop
new file mode 100644
index 0000000..3d00dc1
--- /dev/null
+++ b/ether.desktop
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Name=Ether
+Comment=DWL-based Wayland WM with Lua configuration
+Exec=Ether
+Type=Application
diff --git a/protocols/wlr-layer-shell-unstable-v1.xml b/protocols/wlr-layer-shell-unstable-v1.xml
new file mode 100644
index 0000000..d62fd51
--- /dev/null
+++ b/protocols/wlr-layer-shell-unstable-v1.xml
@@ -0,0 +1,390 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="wlr_layer_shell_unstable_v1">
+ <copyright>
+ Copyright © 2017 Drew DeVault
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that copyright notice and this permission
+ notice appear in supporting documentation, and that the name of
+ the copyright holders not be used in advertising or publicity
+ pertaining to distribution of the software without specific,
+ written prior permission. The copyright holders make no
+ representations about the suitability of this software for any
+ purpose. It is provided "as is" without express or implied
+ warranty.
+
+ THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ THIS SOFTWARE.
+ </copyright>
+
+ <interface name="zwlr_layer_shell_v1" version="4">
+ <description summary="create surfaces that are layers of the desktop">
+ Clients can use this interface to assign the surface_layer role to
+ wl_surfaces. Such surfaces are assigned to a "layer" of the output and
+ rendered with a defined z-depth respective to each other. They may also be
+ anchored to the edges and corners of a screen and specify input handling
+ semantics. This interface should be suitable for the implementation of
+ many desktop shell components, and a broad number of other applications
+ that interact with the desktop.
+ </description>
+
+ <request name="get_layer_surface">
+ <description summary="create a layer_surface from a surface">
+ Create a layer surface for an existing surface. This assigns the role of
+ layer_surface, or raises a protocol error if another role is already
+ assigned.
+
+ Creating a layer surface from a wl_surface which has a buffer attached
+ or committed is a client error, and any attempts by a client to attach
+ or manipulate a buffer prior to the first layer_surface.configure call
+ must also be treated as errors.
+
+ After creating a layer_surface object and setting it up, the client
+ must perform an initial commit without any buffer attached.
+ The compositor will reply with a layer_surface.configure event.
+ The client must acknowledge it and is then allowed to attach a buffer
+ to map the surface.
+
+ You may pass NULL for output to allow the compositor to decide which
+ output to use. Generally this will be the one that the user most
+ recently interacted with.
+
+ Clients can specify a namespace that defines the purpose of the layer
+ surface.
+ </description>
+ <arg name="id" type="new_id" interface="zwlr_layer_surface_v1"/>
+ <arg name="surface" type="object" interface="wl_surface"/>
+ <arg name="output" type="object" interface="wl_output" allow-null="true"/>
+ <arg name="layer" type="uint" enum="layer" summary="layer to add this surface to"/>
+ <arg name="namespace" type="string" summary="namespace for the layer surface"/>
+ </request>
+
+ <enum name="error">
+ <entry name="role" value="0" summary="wl_surface has another role"/>
+ <entry name="invalid_layer" value="1" summary="layer value is invalid"/>
+ <entry name="already_constructed" value="2" summary="wl_surface has a buffer attached or committed"/>
+ </enum>
+
+ <enum name="layer">
+ <description summary="available layers for surfaces">
+ These values indicate which layers a surface can be rendered in. They
+ are ordered by z depth, bottom-most first. Traditional shell surfaces
+ will typically be rendered between the bottom and top layers.
+ Fullscreen shell surfaces are typically rendered at the top layer.
+ Multiple surfaces can share a single layer, and ordering within a
+ single layer is undefined.
+ </description>
+
+ <entry name="background" value="0"/>
+ <entry name="bottom" value="1"/>
+ <entry name="top" value="2"/>
+ <entry name="overlay" value="3"/>
+ </enum>
+
+ <!-- Version 3 additions -->
+
+ <request name="destroy" type="destructor" since="3">
+ <description summary="destroy the layer_shell object">
+ This request indicates that the client will not use the layer_shell
+ object any more. Objects that have been created through this instance
+ are not affected.
+ </description>
+ </request>
+ </interface>
+
+ <interface name="zwlr_layer_surface_v1" version="4">
+ <description summary="layer metadata interface">
+ An interface that may be implemented by a wl_surface, for surfaces that
+ are designed to be rendered as a layer of a stacked desktop-like
+ environment.
+
+ Layer surface state (layer, size, anchor, exclusive zone,
+ margin, interactivity) is double-buffered, and will be applied at the
+ time wl_surface.commit of the corresponding wl_surface is called.
+
+ Attaching a null buffer to a layer surface unmaps it.
+
+ Unmapping a layer_surface means that the surface cannot be shown by the
+ compositor until it is explicitly mapped again. The layer_surface
+ returns to the state it had right after layer_shell.get_layer_surface.
+ The client can re-map the surface by performing a commit without any
+ buffer attached, waiting for a configure event and handling it as usual.
+ </description>
+
+ <request name="set_size">
+ <description summary="sets the size of the surface">
+ Sets the size of the surface in surface-local coordinates. The
+ compositor will display the surface centered with respect to its
+ anchors.
+
+ If you pass 0 for either value, the compositor will assign it and
+ inform you of the assignment in the configure event. You must set your
+ anchor to opposite edges in the dimensions you omit; not doing so is a
+ protocol error. Both values are 0 by default.
+
+ Size is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="width" type="uint"/>
+ <arg name="height" type="uint"/>
+ </request>
+
+ <request name="set_anchor">
+ <description summary="configures the anchor point of the surface">
+ Requests that the compositor anchor the surface to the specified edges
+ and corners. If two orthogonal edges are specified (e.g. 'top' and
+ 'left'), then the anchor point will be the intersection of the edges
+ (e.g. the top left corner of the output); otherwise the anchor point
+ will be centered on that edge, or in the center if none is specified.
+
+ Anchor is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="anchor" type="uint" enum="anchor"/>
+ </request>
+
+ <request name="set_exclusive_zone">
+ <description summary="configures the exclusive geometry of this surface">
+ Requests that the compositor avoids occluding an area with other
+ surfaces. The compositor's use of this information is
+ implementation-dependent - do not assume that this region will not
+ actually be occluded.
+
+ A positive value is only meaningful if the surface is anchored to one
+ edge or an edge and both perpendicular edges. If the surface is not
+ anchored, anchored to only two perpendicular edges (a corner), anchored
+ to only two parallel edges or anchored to all edges, a positive value
+ will be treated the same as zero.
+
+ A positive zone is the distance from the edge in surface-local
+ coordinates to consider exclusive.
+
+ Surfaces that do not wish to have an exclusive zone may instead specify
+ how they should interact with surfaces that do. If set to zero, the
+ surface indicates that it would like to be moved to avoid occluding
+ surfaces with a positive exclusive zone. If set to -1, the surface
+ indicates that it would not like to be moved to accommodate for other
+ surfaces, and the compositor should extend it all the way to the edges
+ it is anchored to.
+
+ For example, a panel might set its exclusive zone to 10, so that
+ maximized shell surfaces are not shown on top of it. A notification
+ might set its exclusive zone to 0, so that it is moved to avoid
+ occluding the panel, but shell surfaces are shown underneath it. A
+ wallpaper or lock screen might set their exclusive zone to -1, so that
+ they stretch below or over the panel.
+
+ The default value is 0.
+
+ Exclusive zone is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="zone" type="int"/>
+ </request>
+
+ <request name="set_margin">
+ <description summary="sets a margin from the anchor point">
+ Requests that the surface be placed some distance away from the anchor
+ point on the output, in surface-local coordinates. Setting this value
+ for edges you are not anchored to has no effect.
+
+ The exclusive zone includes the margin.
+
+ Margin is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="top" type="int"/>
+ <arg name="right" type="int"/>
+ <arg name="bottom" type="int"/>
+ <arg name="left" type="int"/>
+ </request>
+
+ <enum name="keyboard_interactivity">
+ <description summary="types of keyboard interaction possible for a layer shell surface">
+ Types of keyboard interaction possible for layer shell surfaces. The
+ rationale for this is twofold: (1) some applications are not interested
+ in keyboard events and not allowing them to be focused can improve the
+ desktop experience; (2) some applications will want to take exclusive
+ keyboard focus.
+ </description>
+
+ <entry name="none" value="0">
+ <description summary="no keyboard focus is possible">
+ This value indicates that this surface is not interested in keyboard
+ events and the compositor should never assign it the keyboard focus.
+
+ This is the default value, set for newly created layer shell surfaces.
+
+ This is useful for e.g. desktop widgets that display information or
+ only have interaction with non-keyboard input devices.
+ </description>
+ </entry>
+ <entry name="exclusive" value="1">
+ <description summary="request exclusive keyboard focus">
+ Request exclusive keyboard focus if this surface is above the shell surface layer.
+
+ For the top and overlay layers, the seat will always give
+ exclusive keyboard focus to the top-most layer which has keyboard
+ interactivity set to exclusive. If this layer contains multiple
+ surfaces with keyboard interactivity set to exclusive, the compositor
+ determines the one receiving keyboard events in an implementation-
+ defined manner. In this case, no guarantee is made when this surface
+ will receive keyboard focus (if ever).
+
+ For the bottom and background layers, the compositor is allowed to use
+ normal focus semantics.
+
+ This setting is mainly intended for applications that need to ensure
+ they receive all keyboard events, such as a lock screen or a password
+ prompt.
+ </description>
+ </entry>
+ <entry name="on_demand" value="2" since="4">
+ <description summary="request regular keyboard focus semantics">
+ This requests the compositor to allow this surface to be focused and
+ unfocused by the user in an implementation-defined manner. The user
+ should be able to unfocus this surface even regardless of the layer
+ it is on.
+
+ Typically, the compositor will want to use its normal mechanism to
+ manage keyboard focus between layer shell surfaces with this setting
+ and regular toplevels on the desktop layer (e.g. click to focus).
+ Nevertheless, it is possible for a compositor to require a special
+ interaction to focus or unfocus layer shell surfaces (e.g. requiring
+ a click even if focus follows the mouse normally, or providing a
+ keybinding to switch focus between layers).
+
+ This setting is mainly intended for desktop shell components (e.g.
+ panels) that allow keyboard interaction. Using this option can allow
+ implementing a desktop shell that can be fully usable without the
+ mouse.
+ </description>
+ </entry>
+ </enum>
+
+ <request name="set_keyboard_interactivity">
+ <description summary="requests keyboard events">
+ Set how keyboard events are delivered to this surface. By default,
+ layer shell surfaces do not receive keyboard events; this request can
+ be used to change this.
+
+ This setting is inherited by child surfaces set by the get_popup
+ request.
+
+ Layer surfaces receive pointer, touch, and tablet events normally. If
+ you do not want to receive them, set the input region on your surface
+ to an empty region.
+
+ Keyboard interactivity is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="keyboard_interactivity" type="uint" enum="keyboard_interactivity"/>
+ </request>
+
+ <request name="get_popup">
+ <description summary="assign this layer_surface as an xdg_popup parent">
+ This assigns an xdg_popup's parent to this layer_surface. This popup
+ should have been created via xdg_surface::get_popup with the parent set
+ to NULL, and this request must be invoked before committing the popup's
+ initial state.
+
+ See the documentation of xdg_popup for more details about what an
+ xdg_popup is and how it is used.
+ </description>
+ <arg name="popup" type="object" interface="xdg_popup"/>
+ </request>
+
+ <request name="ack_configure">
+ <description summary="ack a configure event">
+ When a configure event is received, if a client commits the
+ surface in response to the configure event, then the client
+ must make an ack_configure request sometime before the commit
+ request, passing along the serial of the configure event.
+
+ If the client receives multiple configure events before it
+ can respond to one, it only has to ack the last configure event.
+
+ A client is not required to commit immediately after sending
+ an ack_configure request - it may even ack_configure several times
+ before its next surface commit.
+
+ A client may send multiple ack_configure requests before committing, but
+ only the last request sent before a commit indicates which configure
+ event the client really is responding to.
+ </description>
+ <arg name="serial" type="uint" summary="the serial from the configure event"/>
+ </request>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the layer_surface">
+ This request destroys the layer surface.
+ </description>
+ </request>
+
+ <event name="configure">
+ <description summary="suggest a surface change">
+ The configure event asks the client to resize its surface.
+
+ Clients should arrange their surface for the new states, and then send
+ an ack_configure request with the serial sent in this configure event at
+ some point before committing the new surface.
+
+ The client is free to dismiss all but the last configure event it
+ received.
+
+ The width and height arguments specify the size of the window in
+ surface-local coordinates.
+
+ The size is a hint, in the sense that the client is free to ignore it if
+ it doesn't resize, pick a smaller size (to satisfy aspect ratio or
+ resize in steps of NxM pixels). If the client picks a smaller size and
+ is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the
+ surface will be centered on this axis.
+
+ If the width or height arguments are zero, it means the client should
+ decide its own window dimension.
+ </description>
+ <arg name="serial" type="uint"/>
+ <arg name="width" type="uint"/>
+ <arg name="height" type="uint"/>
+ </event>
+
+ <event name="closed">
+ <description summary="surface should be closed">
+ The closed event is sent by the compositor when the surface will no
+ longer be shown. The output may have been destroyed or the user may
+ have asked for it to be removed. Further changes to the surface will be
+ ignored. The client should destroy the resource after receiving this
+ event, and create a new surface if they so choose.
+ </description>
+ </event>
+
+ <enum name="error">
+ <entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/>
+ <entry name="invalid_size" value="1" summary="size is invalid"/>
+ <entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
+ <entry name="invalid_keyboard_interactivity" value="3" summary="keyboard interactivity is invalid"/>
+ </enum>
+
+ <enum name="anchor" bitfield="true">
+ <entry name="top" value="1" summary="the top edge of the anchor rectangle"/>
+ <entry name="bottom" value="2" summary="the bottom edge of the anchor rectangle"/>
+ <entry name="left" value="4" summary="the left edge of the anchor rectangle"/>
+ <entry name="right" value="8" summary="the right edge of the anchor rectangle"/>
+ </enum>
+
+ <!-- Version 2 additions -->
+
+ <request name="set_layer" since="2">
+ <description summary="change the layer of the surface">
+ Change the layer that the surface is rendered on.
+
+ Layer is double-buffered, see wl_surface.commit.
+ </description>
+ <arg name="layer" type="uint" enum="zwlr_layer_shell_v1.layer" summary="layer to move this surface to"/>
+ </request>
+ </interface>
+</protocol>
diff --git a/protocols/wlr-output-power-management-unstable-v1.xml b/protocols/wlr-output-power-management-unstable-v1.xml
new file mode 100644
index 0000000..a977839
--- /dev/null
+++ b/protocols/wlr-output-power-management-unstable-v1.xml
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="wlr_output_power_management_unstable_v1">
+ <copyright>
+ Copyright © 2019 Purism SPC
+
+ 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 (including the next
+ paragraph) shall be included in all copies or substantial portions of the
+ Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND 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.
+ </copyright>
+
+ <description summary="Control power management modes of outputs">
+ This protocol allows clients to control power management modes
+ of outputs that are currently part of the compositor space. The
+ intent is to allow special clients like desktop shells to power
+ down outputs when the system is idle.
+
+ To modify outputs not currently part of the compositor space see
+ wlr-output-management.
+
+ Warning! The protocol described in this file is experimental and
+ backward incompatible changes may be made. Backward compatible changes
+ may be added together with the corresponding interface version bump.
+ Backward incompatible changes are done by bumping the version number in
+ the protocol and interface names and resetting the interface version.
+ Once the protocol is to be declared stable, the 'z' prefix and the
+ version number in the protocol and interface names are removed and the
+ interface version number is reset.
+ </description>
+
+ <interface name="zwlr_output_power_manager_v1" version="1">
+ <description summary="manager to create per-output power management">
+ This interface is a manager that allows creating per-output power
+ management mode controls.
+ </description>
+
+ <request name="get_output_power">
+ <description summary="get a power management for an output">
+ Create a output power management mode control that can be used to
+ adjust the power management mode for a given output.
+ </description>
+ <arg name="id" type="new_id" interface="zwlr_output_power_v1"/>
+ <arg name="output" type="object" interface="wl_output"/>
+ </request>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the manager">
+ All objects created by the manager will still remain valid, until their
+ appropriate destroy request has been called.
+ </description>
+ </request>
+ </interface>
+
+ <interface name="zwlr_output_power_v1" version="1">
+ <description summary="adjust power management mode for an output">
+ This object offers requests to set the power management mode of
+ an output.
+ </description>
+
+ <enum name="mode">
+ <entry name="off" value="0"
+ summary="Output is turned off."/>
+ <entry name="on" value="1"
+ summary="Output is turned on, no power saving"/>
+ </enum>
+
+ <enum name="error">
+ <entry name="invalid_mode" value="1" summary="inexistent power save mode"/>
+ </enum>
+
+ <request name="set_mode">
+ <description summary="Set an outputs power save mode">
+ Set an output's power save mode to the given mode. The mode change
+ is effective immediately. If the output does not support the given
+ mode a failed event is sent.
+ </description>
+ <arg name="mode" type="uint" enum="mode" summary="the power save mode to set"/>
+ </request>
+
+ <event name="mode">
+ <description summary="Report a power management mode change">
+ Report the power management mode change of an output.
+
+ The mode event is sent after an output changed its power
+ management mode. The reason can be a client using set_mode or the
+ compositor deciding to change an output's mode.
+ This event is also sent immediately when the object is created
+ so the client is informed about the current power management mode.
+ </description>
+ <arg name="mode" type="uint" enum="mode"
+ summary="the output's new power management mode"/>
+ </event>
+
+ <event name="failed">
+ <description summary="object no longer valid">
+ This event indicates that the output power management mode control
+ is no longer valid. This can happen for a number of reasons,
+ including:
+ - The output doesn't support power management
+ - Another client already has exclusive power management mode control
+ for this output
+ - The output disappeared
+
+ Upon receiving this event, the client should destroy this object.
+ </description>
+ </event>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy this power management">
+ Destroys the output power management mode control object.
+ </description>
+ </request>
+ </interface>
+</protocol>
diff --git a/src/client.h b/src/client.h
new file mode 100644
index 0000000..e37cbaa
--- /dev/null
+++ b/src/client.h
@@ -0,0 +1,426 @@
+/*
+ * Attempt to consolidate unavoidable suck into one file, away from ether.c. This
+ * file is not meant to be pretty. We use a .h file with static inline
+ * functions instead of a separate .c module, or function pointers like sway, so
+ * that they will simply compile out if the chosen #defines leave them unused.
+ */
+
+/* Leave these functions first; they're used in the others */
+static inline int
+client_is_x11(Client *c)
+{
+#ifdef XWAYLAND
+ return c->type == X11;
+#endif
+ return 0;
+}
+
+static inline struct wlr_surface *
+client_surface(Client *c)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c))
+ return c->surface.xwayland->surface;
+#endif
+ return c->surface.xdg->surface;
+}
+
+static inline int
+toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl)
+{
+ struct wlr_xdg_surface *xdg_surface, *tmp_xdg_surface;
+ struct wlr_surface *root_surface;
+ struct wlr_layer_surface_v1 *layer_surface;
+ Client *c = NULL;
+ LayerSurface *l = NULL;
+ int type = -1;
+#ifdef XWAYLAND
+ struct wlr_xwayland_surface *xsurface;
+#endif
+
+ if (!s)
+ return -1;
+ root_surface = wlr_surface_get_root_surface(s);
+
+#ifdef XWAYLAND
+ if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(root_surface))) {
+ c = xsurface->data;
+ type = c->type;
+ goto end;
+ }
+#endif
+
+ if ((layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) {
+ l = layer_surface->data;
+ type = LayerShell;
+ goto end;
+ }
+
+ xdg_surface = wlr_xdg_surface_try_from_wlr_surface(root_surface);
+ while (xdg_surface) {
+ tmp_xdg_surface = NULL;
+ switch (xdg_surface->role) {
+ case WLR_XDG_SURFACE_ROLE_POPUP:
+ if (!xdg_surface->popup || !xdg_surface->popup->parent)
+ return -1;
+
+ tmp_xdg_surface = wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent);
+
+ if (!tmp_xdg_surface)
+ return toplevel_from_wlr_surface(xdg_surface->popup->parent, pc, pl);
+
+ xdg_surface = tmp_xdg_surface;
+ break;
+ case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
+ c = xdg_surface->data;
+ type = c->type;
+ goto end;
+ case WLR_XDG_SURFACE_ROLE_NONE:
+ return -1;
+ }
+ }
+
+end:
+ if (pl)
+ *pl = l;
+ if (pc)
+ *pc = c;
+ return type;
+}
+
+/* The others */
+static inline void
+client_activate_surface(struct wlr_surface *s, int activated)
+{
+ struct wlr_xdg_toplevel *toplevel;
+#ifdef XWAYLAND
+ struct wlr_xwayland_surface *xsurface;
+ if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(s))) {
+ if (activated && xsurface->minimized)
+ wlr_xwayland_surface_set_minimized(xsurface, false);
+
+ wlr_xwayland_surface_activate(xsurface, activated);
+ return;
+ }
+#endif
+ if ((toplevel = wlr_xdg_toplevel_try_from_wlr_surface(s)))
+ wlr_xdg_toplevel_set_activated(toplevel, activated);
+}
+
+static inline uint32_t
+client_set_bounds(Client *c, int32_t width, int32_t height)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c))
+ return 0;
+#endif
+ if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
+ XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION && width >= 0 && height >= 0
+ && (c->bounds.width != width || c->bounds.height != height)) {
+ c->bounds.width = width;
+ c->bounds.height = height;
+ return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width, height);
+ }
+ return 0;
+}
+
+static inline const char *
+client_get_appid(Client *c)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c))
+ return c->surface.xwayland->class ? c->surface.xwayland->class : "broken";
+#endif
+ return c->surface.xdg->toplevel->app_id ? c->surface.xdg->toplevel->app_id : "broken";
+}
+
+static inline int
+client_get_pid(Client *c)
+{
+ pid_t pid;
+#ifdef XWAYLAND
+ if (client_is_x11(c))
+ return c->surface.xwayland->pid;
+#endif
+ wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL);
+ return pid;
+}
+
+static inline void
+client_get_clip(Client *c, struct wlr_box *clip)
+{
+ *clip = (struct wlr_box){
+ .x = 0,
+ .y = 0,
+ .width = c->geom.width - c->bw,
+ .height = c->geom.height - c->bw,
+ };
+
+#ifdef XWAYLAND
+ if (client_is_x11(c))
+ return;
+#endif
+
+ clip->x = c->surface.xdg->geometry.x;
+ clip->y = c->surface.xdg->geometry.y;
+}
+
+static inline void
+client_get_geometry(Client *c, struct wlr_box *geom)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c)) {
+ geom->x = c->surface.xwayland->x;
+ geom->y = c->surface.xwayland->y;
+ geom->width = c->surface.xwayland->width;
+ geom->height = c->surface.xwayland->height;
+ return;
+ }
+#endif
+ *geom = c->surface.xdg->geometry;
+}
+
+static inline Client *
+client_get_parent(Client *c)
+{
+ Client *p = NULL;
+#ifdef XWAYLAND
+ if (client_is_x11(c)) {
+ if (c->surface.xwayland->parent)
+ toplevel_from_wlr_surface(c->surface.xwayland->parent->surface, &p, NULL);
+ return p;
+ }
+#endif
+ if (c->surface.xdg->toplevel->parent)
+ toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface, &p, NULL);
+ return p;
+}
+
+static inline int
+client_has_children(Client *c)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c))
+ return !wl_list_empty(&c->surface.xwayland->children);
+#endif
+ /* surface.xdg->link is never empty because it always contains at least the
+ * surface itself. */
+ return wl_list_length(&c->surface.xdg->link) > 1;
+}
+
+static inline const char *
+client_get_title(Client *c)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c))
+ return c->surface.xwayland->title ? c->surface.xwayland->title : "broken";
+#endif
+ return c->surface.xdg->toplevel->title ? c->surface.xdg->toplevel->title : "broken";
+}
+
+static inline int
+client_is_float_type(Client *c)
+{
+ struct wlr_xdg_toplevel *toplevel;
+ struct wlr_xdg_toplevel_state state;
+
+#ifdef XWAYLAND
+ if (client_is_x11(c)) {
+ struct wlr_xwayland_surface *surface = c->surface.xwayland;
+ xcb_size_hints_t *size_hints = surface->size_hints;
+ if (surface->modal)
+ return 1;
+
+ if (wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG)
+ || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH)
+ || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR)
+ || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY)) {
+ return 1;
+ }
+
+ return size_hints && size_hints->min_width > 0 && size_hints->min_height > 0
+ && (size_hints->max_width == size_hints->min_width
+ || size_hints->max_height == size_hints->min_height);
+ }
+#endif
+
+ toplevel = c->surface.xdg->toplevel;
+ state = toplevel->current;
+ return toplevel->parent || (state.min_width != 0 && state.min_height != 0
+ && (state.min_width == state.max_width
+ || state.min_height == state.max_height));
+}
+
+static inline int
+client_is_rendered_on_mon(Client *c, Monitor *m)
+{
+ /* This is needed for when you don't want to check formal assignment,
+ * but rather actual displaying of the pixels.
+ * Usually VISIBLEON suffices and is also faster. */
+ struct wlr_surface_output *s;
+ int unused_lx, unused_ly;
+ if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly))
+ return 0;
+ wl_list_for_each(s, &client_surface(c)->current_outputs, link)
+ if (s->output == m->wlr_output)
+ return 1;
+ return 0;
+}
+
+static inline int
+client_is_stopped(Client *c)
+{
+ int pid;
+ siginfo_t in = {0};
+#ifdef XWAYLAND
+ if (client_is_x11(c))
+ return 0;
+#endif
+
+ wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL);
+ if (waitid(P_PID, pid, &in, WNOHANG|WCONTINUED|WSTOPPED|WNOWAIT) < 0) {
+ /* This process is not our child process, while is very unlikely that
+ * it is stopped, in order to do not skip frames, assume that it is. */
+ if (errno == ECHILD)
+ return 1;
+ } else if (in.si_pid) {
+ if (in.si_code == CLD_STOPPED || in.si_code == CLD_TRAPPED)
+ return 1;
+ if (in.si_code == CLD_CONTINUED)
+ return 0;
+ }
+
+ return 0;
+}
+
+static inline int
+client_is_unmanaged(Client *c)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c))
+ return c->surface.xwayland->override_redirect;
+#endif
+ return 0;
+}
+
+static inline void
+client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb)
+{
+ uint32_t filtered[WLR_KEYBOARD_KEYS_CAP];
+ size_t size = 0;
+ if (!kb) {
+ wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL);
+ return;
+ }
+ for (size_t i = 0; i < kb->num_keycodes; i++) {
+ uint32_t key = kb->keycodes[i];
+ if (!consumed[key])
+ filtered[size++] = key;
+ }
+ wlr_seat_keyboard_notify_enter(seat, s, filtered, size, &kb->modifiers);
+}
+
+static inline void
+client_send_close(Client *c)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c)) {
+ wlr_xwayland_surface_close(c->surface.xwayland);
+ return;
+ }
+#endif
+ wlr_xdg_toplevel_send_close(c->surface.xdg->toplevel);
+}
+
+static inline void
+client_set_border_color(Client *c, const float color[static 4])
+{
+ int i;
+ for (i = 0; i < 4; i++)
+ wlr_scene_rect_set_color(c->border[i], color);
+}
+
+static inline void
+client_set_fullscreen(Client *c, int fullscreen)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c)) {
+ wlr_xwayland_surface_set_fullscreen(c->surface.xwayland, fullscreen);
+ return;
+ }
+#endif
+ wlr_xdg_toplevel_set_fullscreen(c->surface.xdg->toplevel, fullscreen);
+}
+
+static inline void
+client_set_scale(struct wlr_surface *s, float scale)
+{
+ wlr_fractional_scale_v1_notify_scale(s, scale);
+ wlr_surface_set_preferred_buffer_scale(s, (int32_t)ceilf(scale));
+}
+
+static inline uint32_t
+client_set_size(Client *c, uint32_t width, uint32_t height)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c)) {
+ wlr_xwayland_surface_configure(c->surface.xwayland,
+ c->geom.x + c->bw, c->geom.y + c->bw, width, height);
+ return 0;
+ }
+#endif
+ if ((int32_t)width == c->surface.xdg->toplevel->current.width
+ && (int32_t)height == c->surface.xdg->toplevel->current.height)
+ return 0;
+ return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width, (int32_t)height);
+}
+
+static inline void
+client_set_tiled(Client *c, uint32_t edges)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c)) {
+ wlr_xwayland_surface_set_maximized(c->surface.xwayland,
+ edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE);
+ return;
+ }
+#endif
+ if (wl_resource_get_version(c->surface.xdg->toplevel->resource)
+ >= XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) {
+ wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges);
+ } else {
+ wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel, edges != WLR_EDGE_NONE);
+ }
+}
+
+static inline void
+client_set_suspended(Client *c, int suspended)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c))
+ return;
+#endif
+
+ wlr_xdg_toplevel_set_suspended(c->surface.xdg->toplevel, suspended);
+}
+
+static inline int
+client_wants_focus(Client *c)
+{
+#ifdef XWAYLAND
+ return client_is_unmanaged(c)
+ && wlr_xwayland_surface_override_redirect_wants_focus(c->surface.xwayland)
+ && wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) != WLR_ICCCM_INPUT_MODEL_NONE;
+#endif
+ return 0;
+}
+
+static inline int
+client_wants_fullscreen(Client *c)
+{
+#ifdef XWAYLAND
+ if (client_is_x11(c))
+ return c->surface.xwayland->fullscreen;
+#endif
+ return c->surface.xdg->toplevel->requested.fullscreen;
+}
diff --git a/src/clients.c b/src/clients.c
new file mode 100644
index 0000000..ba9d1bb
--- /dev/null
+++ b/src/clients.c
@@ -0,0 +1,1089 @@
+/*
+ * See LICENSE file for copyright and license details.
+ */
+#include <math.h>
+
+#include "ether.h"
+
+void
+applybounds(Client *c, struct wlr_box *bbox)
+{
+ /* set minimum possible */
+ c->geom.width = MAX(1 + 2 * (int)c->bw, c->geom.width);
+ c->geom.height = MAX(1 + 2 * (int)c->bw, c->geom.height);
+
+ if (c->geom.x >= bbox->x + bbox->width)
+ c->geom.x = bbox->x + bbox->width - c->geom.width;
+ if (c->geom.y >= bbox->y + bbox->height)
+ c->geom.y = bbox->y + bbox->height - c->geom.height;
+ if (c->geom.x + c->geom.width <= bbox->x)
+ c->geom.x = bbox->x;
+ if (c->geom.y + c->geom.height <= bbox->y)
+ c->geom.y = bbox->y;
+}
+
+void
+applyrules(Client *c)
+{
+ /* rule matching */
+ const char *appid, *title;
+ uint32_t newtags = 0;
+ int i;
+ const Rule *r;
+ Monitor *mon = selmon, *m;
+ int newwidth = 0, newheight = 0, newx = 0, newy = 0, apply_resize = 0;
+
+ appid = client_get_appid(c);
+ title = client_get_title(c);
+
+ c->pid = client_get_pid(c);
+
+ for (r = config.rules; r < config.rules + config.nrules; r++) {
+ if ((!r->title || strstr(title, r->title))
+ && (!r->id || strstr(appid, r->id))) {
+ c->isfloating = r->isfloating;
+ c->opacity = r->opacity;
+ newtags |= r->tags;
+ c->isterm = r->isterm;
+ c->noswallow = r->noswallow;
+ i = 0;
+ wl_list_for_each(m, &mons, link) {
+ if (r->monitor == i++)
+ mon = m;
+ if (c->isfloating || !mon->lt[mon->sellt]->arrange) {
+ /* client is floating or in floating layout */
+ struct wlr_box b = config.respect_monitor_reserved_area ? mon->w : mon->m;
+ newwidth = (int)round((r->w >= 0) ? (r->w <= 1 ? b.width * r->w : r->w) : c->geom.width);
+ newheight = (int)round((r->h >= 0) ? (r->h <= 1 ? b.height * r->h : r->h) : c->geom.height);
+ newx = (int)round((r->x >= 0) ? (r->x <= 1 ? b.width * r->x + b.x : r->x + b.x) : c->geom.x);
+ newy = (int)round((r->y >= 0) ? (r->y <= 1 ? b.height * r->y + b.y : r->y + b.y) : c->geom.y);
+ apply_resize = 1;
+ }
+ }
+ }
+ }
+
+ c->isfloating |= client_is_float_type(c);
+ if (config.enableautoswallow && !c->noswallow && !c->isfloating &&
+ !client_is_x11(c) && !c->surface.xdg->initial_commit) {
+ Client *p = termforwin(c);
+ if (p)
+ swallow(c, p);
+ }
+ setmon(c, mon, newtags);
+ if (apply_resize) {
+ resize(c, (struct wlr_box){
+ .x = newx,
+ .y = newy,
+ .width = newwidth,
+ .height = newheight,
+ }, 1, 1);
+ }
+}
+
+void
+checkidleinhibitor(struct wlr_surface *exclude)
+{
+ int inhibited = 0, unused_lx, unused_ly;
+ struct wlr_idle_inhibitor_v1 *inhibitor;
+ wl_list_for_each(inhibitor, &idle_inhibit_mgr->inhibitors, link) {
+ struct wlr_surface *surface = wlr_surface_get_root_surface(inhibitor->surface);
+ struct wlr_scene_tree *tree = surface->data;
+ if (exclude != surface && (config.bypass_surface_visibility || (!tree
+ || wlr_scene_node_coords(&tree->node, &unused_lx, &unused_ly)))) {
+ inhibited = 1;
+ break;
+ }
+ }
+
+ wlr_idle_notifier_v1_set_inhibited(idle_notifier, inhibited);
+}
+
+void
+commitlayersurfacenotify(struct wl_listener *listener, void *data)
+{
+ LayerSurface *l = wl_container_of(listener, l, surface_commit);
+ struct wlr_layer_surface_v1 *layer_surface = l->layer_surface;
+ struct wlr_scene_tree *scene_layer = layers[layermap[layer_surface->current.layer]];
+ struct wlr_layer_surface_v1_state old_state;
+
+ if (l->layer_surface->initial_commit) {
+ client_set_scale(layer_surface->surface, l->mon->wlr_output->scale);
+
+ /* Temporarily set the layer's current state to pending
+ * so that we can easily arrange it */
+ old_state = l->layer_surface->current;
+ l->layer_surface->current = l->layer_surface->pending;
+ arrangelayers(l->mon);
+ l->layer_surface->current = old_state;
+ return;
+ }
+
+ if (layer_surface->current.committed == 0 && l->mapped == layer_surface->surface->mapped)
+ return;
+ l->mapped = layer_surface->surface->mapped;
+
+ if (scene_layer != l->scene->node.parent) {
+ wlr_scene_node_reparent(&l->scene->node, scene_layer);
+ wl_list_remove(&l->link);
+ wl_list_insert(&l->mon->layers[layer_surface->current.layer], &l->link);
+ wlr_scene_node_reparent(&l->popups->node, (layer_surface->current.layer
+ < ZWLR_LAYER_SHELL_V1_LAYER_TOP ? layers[LyrTop] : scene_layer));
+ }
+
+ arrangelayers(l->mon);
+}
+
+void
+commitnotify(struct wl_listener *listener, void *data)
+{
+ Client *c = wl_container_of(listener, c, commit);
+
+ if (c->surface.xdg->initial_commit) {
+ /*
+ * Get the monitor this client will be rendered on
+ * Note that if the user set a rule in which the client is placed on
+ * a different monitor based on its title, this will likely select
+ * a wrong monitor.
+ */
+ applyrules(c);
+ if (c->mon) {
+ client_set_scale(client_surface(c), c->mon->wlr_output->scale);
+ }
+ setmon(c, NULL, 0); /* Make sure to reapply rules in mapnotify() */
+
+ wlr_xdg_toplevel_set_wm_capabilities(c->surface.xdg->toplevel,
+ WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN);
+ if (c->decoration)
+ requestdecorationmode(&c->set_decoration_mode, c->decoration);
+ wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, 0, 0);
+ return;
+ }
+
+ if (client_surface(c)->mapped && c->mon && c->mon->lt[c->mon->sellt]->arrange
+ && !c->isfullscreen && !c->isfloating)
+ c->mon->lt[c->mon->sellt]->arrange(c->mon);
+ else
+ resize(c, c->geom, (c->isfloating && !c->isfullscreen),
+ (c->isfloating && !c->isfullscreen));
+
+ /* mark a pending resize as completed */
+ if (c->resize && c->resize <= c->surface.xdg->current.configure_serial)
+ c->resize = 0;
+}
+
+void
+commitpopup(struct wl_listener *listener, void *data)
+{
+ struct wlr_surface *surface = data;
+ struct wlr_xdg_popup *popup = wlr_xdg_popup_try_from_wlr_surface(surface);
+ LayerSurface *l = NULL;
+ Client *c = NULL;
+ struct wlr_box box;
+ int type = -1;
+
+ if (!popup->base->initial_commit)
+ return;
+
+ type = toplevel_from_wlr_surface(popup->base->surface, &c, &l);
+ if (!popup->parent || type < 0)
+ return;
+ popup->base->surface->data = wlr_scene_xdg_surface_create(
+ popup->parent->data, popup->base);
+ if ((l && !l->mon) || (c && !c->mon)) {
+ wlr_xdg_popup_destroy(popup);
+ return;
+ }
+ box = type == LayerShell ? l->mon->m : c->mon->w;
+ box.x -= (type == LayerShell ? l->scene->node.x : c->geom.x);
+ box.y -= (type == LayerShell ? l->scene->node.y : c->geom.y);
+ wlr_xdg_popup_unconstrain_from_box(popup, &box);
+ wl_list_remove(&listener->link);
+ free(listener);
+}
+
+void
+createdecoration(struct wl_listener *listener, void *data)
+{
+ struct wlr_xdg_toplevel_decoration_v1 *deco = data;
+ Client *c = deco->toplevel->base->data;
+ c->decoration = deco;
+
+ LISTEN(&deco->events.request_mode, &c->set_decoration_mode, requestdecorationmode);
+ LISTEN(&deco->events.destroy, &c->destroy_decoration, destroydecoration);
+
+ requestdecorationmode(&c->set_decoration_mode, deco);
+}
+
+void
+createidleinhibitor(struct wl_listener *listener, void *data)
+{
+ struct wlr_idle_inhibitor_v1 *idle_inhibitor = data;
+ LISTEN_STATIC(&idle_inhibitor->events.destroy, destroyidleinhibitor);
+
+ checkidleinhibitor(NULL);
+}
+
+void
+createlayersurface(struct wl_listener *listener, void *data)
+{
+ struct wlr_layer_surface_v1 *layer_surface = data;
+ LayerSurface *l;
+ struct wlr_surface *surface = layer_surface->surface;
+ struct wlr_scene_tree *scene_layer = layers[layermap[layer_surface->pending.layer]];
+
+ if (!layer_surface->output
+ && !(layer_surface->output = selmon ? selmon->wlr_output : NULL)) {
+ wlr_layer_surface_v1_destroy(layer_surface);
+ return;
+ }
+
+ l = layer_surface->data = ecalloc(1, sizeof(*l));
+ l->type = LayerShell;
+ LISTEN(&surface->events.commit, &l->surface_commit, commitlayersurfacenotify);
+ LISTEN(&surface->events.unmap, &l->unmap, unmaplayersurfacenotify);
+ LISTEN(&layer_surface->events.destroy, &l->destroy, destroylayersurfacenotify);
+
+ l->layer_surface = layer_surface;
+ l->mon = layer_surface->output->data;
+ l->scene_layer = wlr_scene_layer_surface_v1_create(scene_layer, layer_surface);
+ l->scene = l->scene_layer->tree;
+ l->popups = surface->data = wlr_scene_tree_create(layer_surface->current.layer
+ < ZWLR_LAYER_SHELL_V1_LAYER_TOP ? layers[LyrTop] : scene_layer);
+ l->scene->node.data = l->popups->node.data = l;
+
+ wl_list_insert(&l->mon->layers[layer_surface->pending.layer],&l->link);
+ wlr_surface_send_enter(surface, layer_surface->output);
+}
+
+void
+createnotify(struct wl_listener *listener, void *data)
+{
+ /* This event is raised when a client creates a new toplevel (application window). */
+ struct wlr_xdg_toplevel *toplevel = data;
+ Client *c = NULL;
+
+ /* Allocate a Client for this surface */
+ c = toplevel->base->data = ecalloc(1, sizeof(*c));
+ c->surface.xdg = toplevel->base;
+ c->bw = config.borderpx;
+ c->opacity = config.default_opacity;
+
+ LISTEN(&toplevel->base->surface->events.commit, &c->commit, commitnotify);
+ LISTEN(&toplevel->base->surface->events.map, &c->map, mapnotify);
+ LISTEN(&toplevel->base->surface->events.unmap, &c->unmap, unmapnotify);
+ LISTEN(&toplevel->events.destroy, &c->destroy, destroynotify);
+ LISTEN(&toplevel->events.request_fullscreen, &c->fullscreen, fullscreennotify);
+ LISTEN(&toplevel->events.request_maximize, &c->maximize, maximizenotify);
+ LISTEN(&toplevel->events.set_title, &c->set_title, updatetitle);
+}
+
+void
+createpopup(struct wl_listener *listener, void *data)
+{
+ /* This event is raised when a client (either xdg-shell or layer-shell)
+ * creates a new popup. */
+ struct wlr_xdg_popup *popup = data;
+ LISTEN_STATIC(&popup->base->surface->events.commit, commitpopup);
+}
+
+void
+destroydecoration(struct wl_listener *listener, void *data)
+{
+ Client *c = wl_container_of(listener, c, destroy_decoration);
+ c->decoration = NULL;
+
+ wl_list_remove(&c->destroy_decoration.link);
+ wl_list_remove(&c->set_decoration_mode.link);
+}
+
+void
+destroydragicon(struct wl_listener *listener, void *data)
+{
+ /* Focus enter isn't sent during drag, so refocus the focused node. */
+ focusclient(focustop(selmon, 0), 1);
+ motionnotify(0, NULL, 0, 0, 0, 0);
+ wl_list_remove(&listener->link);
+ free(listener);
+}
+
+void
+destroyidleinhibitor(struct wl_listener *listener, void *data)
+{
+ /* `data` is the wlr_surface of the idle inhibitor being destroyed,
+ * at this point the idle inhibitor is still in the list of the manager */
+ checkidleinhibitor(wlr_surface_get_root_surface(data));
+ wl_list_remove(&listener->link);
+ free(listener);
+}
+
+void
+destroylayersurfacenotify(struct wl_listener *listener, void *data)
+{
+ LayerSurface *l = wl_container_of(listener, l, destroy);
+
+ wl_list_remove(&l->link);
+ wl_list_remove(&l->destroy.link);
+ wl_list_remove(&l->unmap.link);
+ wl_list_remove(&l->surface_commit.link);
+ wlr_scene_node_destroy(&l->scene->node);
+ wlr_scene_node_destroy(&l->popups->node);
+ free(l);
+}
+
+void
+destroynotify(struct wl_listener *listener, void *data)
+{
+ /* Called when the xdg_toplevel is destroyed. */
+ Client *c = wl_container_of(listener, c, destroy);
+ wl_list_remove(&c->destroy.link);
+ wl_list_remove(&c->set_title.link);
+ wl_list_remove(&c->fullscreen.link);
+#ifdef XWAYLAND
+ if (c->type != XDGShell) {
+ wl_list_remove(&c->activate.link);
+ wl_list_remove(&c->associate.link);
+ wl_list_remove(&c->configure.link);
+ wl_list_remove(&c->dissociate.link);
+ wl_list_remove(&c->minimize.link);
+ wl_list_remove(&c->set_hints.link);
+ } else
+#endif
+ {
+ wl_list_remove(&c->commit.link);
+ wl_list_remove(&c->map.link);
+ wl_list_remove(&c->unmap.link);
+ wl_list_remove(&c->maximize.link);
+ if (c->decoration) {
+ wl_list_remove(&c->set_decoration_mode.link);
+ wl_list_remove(&c->destroy_decoration.link);
+ }
+ }
+ free(c->output);
+ free(c);
+}
+
+void
+destroypointerconstraint(struct wl_listener *listener, void *data)
+{
+ PointerConstraint *pointer_constraint = wl_container_of(listener, pointer_constraint, destroy);
+
+ if (active_constraint == pointer_constraint->constraint) {
+ cursorwarptohint();
+ active_constraint = NULL;
+ }
+
+ wl_list_remove(&pointer_constraint->destroy.link);
+ free(pointer_constraint);
+}
+
+void
+destroykeyboardgroup(struct wl_listener *listener, void *data)
+{
+ KeyboardGroup *group = wl_container_of(listener, group, destroy);
+ wl_event_source_remove(group->key_repeat_source);
+ wl_list_remove(&group->key.link);
+ wl_list_remove(&group->modifiers.link);
+ wl_list_remove(&group->destroy.link);
+ wlr_keyboard_group_destroy(group->wlr_group);
+ free(group);
+}
+
+void
+focusclient(Client *c, int lift)
+{
+ struct wlr_surface *old = seat->keyboard_state.focused_surface;
+ int unused_lx, unused_ly, old_client_type;
+ Client *old_c = NULL;
+ LayerSurface *old_l = NULL;
+
+ if (locked)
+ return;
+
+ /* Warp cursor to center of client if it is outside */
+ if (lift)
+ warpcursor(c);
+
+ /* Raise client in stacking order if requested */
+ if (c && lift)
+ wlr_scene_node_raise_to_top(&c->scene->node);
+
+ if (c && client_surface(c) == old)
+ return;
+
+ if ((old_client_type = toplevel_from_wlr_surface(old, &old_c, &old_l)) == XDGShell) {
+ struct wlr_xdg_popup *popup, *tmp;
+ wl_list_for_each_safe(popup, tmp, &old_c->surface.xdg->popups, link)
+ wlr_xdg_popup_destroy(popup);
+ }
+
+ /* Put the new client atop the focus stack and select its monitor */
+ if (c && !client_is_unmanaged(c)) {
+ wl_list_remove(&c->flink);
+ wl_list_insert(&fstack, &c->flink);
+ selmon = c->mon;
+ c->isurgent = 0;
+ hidebehind(c->mon);
+
+ /* Don't change border color if there is an exclusive focus or we are
+ * handling a drag operation */
+ if (!exclusive_focus && !seat->drag)
+ client_set_border_color(c, config.focuscolor);
+ }
+
+ /* Deactivate old client if focus is changing */
+ if (old && (!c || client_surface(c) != old)) {
+ /* If an overlay is focused, don't focus or activate the client,
+ * but only update its position in fstack to render its border with focuscolor
+ * and focus it after the overlay is closed. */
+ if (old_client_type == LayerShell && wlr_scene_node_coords(
+ &old_l->scene->node, &unused_lx, &unused_ly)
+ && old_l->layer_surface->current.layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) {
+ return;
+ } else if (old_c && old_c == exclusive_focus && client_wants_focus(old_c)) {
+ return;
+ /* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg
+ * and probably other clients */
+ } else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) {
+ client_set_border_color(old_c, config.bordercolor);
+
+ client_activate_surface(old, 0);
+ }
+ }
+ printstatus();
+
+ if (!c) {
+ /* With no client, all we have left is to clear focus */
+ wlr_seat_keyboard_notify_clear_focus(seat);
+ return;
+ }
+
+ /* Change cursor surface */
+ motionnotify(0, NULL, 0, 0, 0, 0);
+
+ /* Have a client, so focus its top-level wlr_surface */
+ client_notify_enter(client_surface(c), wlr_seat_get_keyboard(seat));
+
+ /* Activate the new client */
+ client_activate_surface(client_surface(c), 1);
+}
+
+void
+focusmon(const Arg *arg)
+{
+ int i = 0, nmons = wl_list_length(&mons);
+ if (nmons) {
+ do /* don't switch to disabled mons */
+ selmon = dirtomon(arg->i);
+ while (!selmon->wlr_output->enabled && i++ < nmons);
+ }
+ focusclient(focustop(selmon, 0), 1);
+}
+
+void
+focusstack(const Arg *arg)
+{
+ /* Focus the next or previous client (in tiling order) on selmon */
+ Client *c, *sel = focustop(selmon, 0);
+ if (!sel || (sel->isfullscreen && !client_has_children(sel)))
+ return;
+ if (arg->i > 0) {
+ wl_list_for_each(c, &sel->link, link) {
+ if (&c->link == &clients)
+ continue; /* wrap past the sentinel node */
+ if (VISIBLEON(c, selmon))
+ break; /* found it */
+ }
+ } else {
+ wl_list_for_each_reverse(c, &sel->link, link) {
+ if (&c->link == &clients)
+ continue; /* wrap past the sentinel node */
+ if (VISIBLEON(c, selmon))
+ break; /* found it */
+ }
+ }
+ /* If only one client is visible on selmon, then c == sel */
+ focusclient(c, 1);
+}
+
+Client *
+focustop(Monitor *m, int onlytiled)
+{
+ Client *c;
+ wl_list_for_each(c, &fstack, flink) {
+ if (VISIBLEON(c, m)) {
+ if (onlytiled && c->isfloating)
+ continue;
+ return c;
+ }
+ }
+ return NULL;
+}
+
+void
+fullscreennotify(struct wl_listener *listener, void *data)
+{
+ Client *c = wl_container_of(listener, c, fullscreen);
+ setfullscreen(c, client_wants_fullscreen(c));
+}
+
+void
+mapnotify(struct wl_listener *listener, void *data)
+{
+ /* Called when the surface is mapped, or ready to display on-screen. */
+ Client *p = NULL;
+ Client *w, *c = wl_container_of(listener, c, map);
+ Monitor *m;
+ int i;
+
+ /* Create scene tree for this client and its border */
+ c->scene = client_surface(c)->data = wlr_scene_tree_create(layers[LyrTile]);
+ /* Enabled later by a call to arrange() */
+ wlr_scene_node_set_enabled(&c->scene->node, client_is_unmanaged(c));
+ c->scene_surface = c->type == XDGShell
+ ? wlr_scene_xdg_surface_create(c->scene, c->surface.xdg)
+ : wlr_scene_subsurface_tree_create(c->scene, client_surface(c));
+ c->scene->node.data = c->scene_surface->node.data = c;
+
+ client_get_geometry(c, &c->geom);
+
+ /* Handle unmanaged clients first so we can return prior create borders */
+ if (client_is_unmanaged(c)) {
+ /* Unmanaged clients always are floating */
+ wlr_scene_node_reparent(&c->scene->node, layers[LyrFloat]);
+ wlr_scene_node_set_position(&c->scene->node, c->geom.x, c->geom.y);
+ client_set_size(c, c->geom.width, c->geom.height);
+ if (client_wants_focus(c)) {
+ focusclient(c, 1);
+ exclusive_focus = c;
+ }
+ goto unset_fullscreen;
+ }
+
+ for (i = 0; i < 4; i++) {
+ c->border[i] = wlr_scene_rect_create(c->scene, 0, 0,
+ c->isurgent ? config.urgentcolor : config.bordercolor);
+ c->border[i]->node.data = c;
+ }
+
+ /* Initialize client geometry with room for border */
+ client_set_tiled(c, WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT);
+ c->geom.width += 2 * c->bw;
+ c->geom.height += 2 * c->bw;
+
+ /* Insert this client into client lists. */
+ wl_list_insert(&clients, &c->link);
+ wl_list_insert(&fstack, &c->flink);
+
+ /* Set initial monitor, tags, floating status, and focus:
+ * we always consider floating, clients that have parent and thus
+ * we set the same tags and monitor as its parent.
+ * If there is no parent, apply rules */
+ if ((p = client_get_parent(c))) {
+ c->isfloating = 1;
+ setmon(c, p->mon, p->tags);
+ } else {
+ applyrules(c);
+ }
+ c->output = strdup(c->mon->wlr_output->name);
+ if (c->output == NULL)
+ die("out of memory");
+ printstatus();
+
+unset_fullscreen:
+ m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y);
+ wl_list_for_each(w, &clients, link) {
+ if (w != c && w != p && w->isfullscreen && m == w->mon && (w->tags & c->tags))
+ setfullscreen(w, 0);
+ }
+}
+
+void
+maximizenotify(struct wl_listener *listener, void *data)
+{
+ /* This event is raised when a client would like to maximize itself,
+ * typically because the user clicked on the maximize button on
+ * client-side decorations. ether doesn't support maximization, but
+ * to conform to xdg-shell protocol we still must send a configure.
+ * Since xdg-shell protocol v5 we should ignore request of unsupported
+ * capabilities, just schedule a empty configure when the client uses <5
+ * protocol version
+ * wlr_xdg_surface_schedule_configure() is used to send an empty reply. */
+ Client *c = wl_container_of(listener, c, maximize);
+ if (c->surface.xdg->initialized
+ && wl_resource_get_version(c->surface.xdg->toplevel->resource)
+ < XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION)
+ wlr_xdg_surface_schedule_configure(c->surface.xdg);
+}
+
+void
+printstatus(void)
+{
+ Monitor *m = NULL;
+ Client *c;
+ uint32_t occ, urg, sel;
+
+ wl_list_for_each(m, &mons, link) {
+ occ = urg = 0;
+ wl_list_for_each(c, &clients, link) {
+ if (c->mon != m)
+ continue;
+ occ |= c->tags;
+ if (c->isurgent)
+ urg |= c->tags;
+ }
+ if ((c = focustop(m, 0))) {
+ printf("%s title %s\n", m->wlr_output->name, client_get_title(c));
+ printf("%s appid %s\n", m->wlr_output->name, client_get_appid(c));
+ printf("%s fullscreen %d\n", m->wlr_output->name, c->isfullscreen);
+ printf("%s floating %d\n", m->wlr_output->name, c->isfloating);
+ sel = c->tags;
+ } else {
+ printf("%s title \n", m->wlr_output->name);
+ printf("%s appid \n", m->wlr_output->name);
+ printf("%s fullscreen \n", m->wlr_output->name);
+ printf("%s floating \n", m->wlr_output->name);
+ sel = 0;
+ }
+
+ printf("%s selmon %u\n", m->wlr_output->name, m == selmon);
+ printf("%s tags %"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"\n",
+ m->wlr_output->name, occ, m->tagset[m->seltags], sel, urg);
+ printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
+ }
+ fflush(stdout);
+}
+
+void
+requestdecorationmode(struct wl_listener *listener, void *data)
+{
+ Client *c = wl_container_of(listener, c, set_decoration_mode);
+ if (c->surface.xdg->initialized)
+ wlr_xdg_toplevel_decoration_v1_set_mode(c->decoration,
+ WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
+}
+
+void
+requeststartdrag(struct wl_listener *listener, void *data)
+{
+ struct wlr_seat_request_start_drag_event *event = data;
+
+ if (wlr_seat_validate_pointer_grab_serial(seat, event->origin,
+ event->serial))
+ wlr_seat_start_pointer_drag(seat, event->drag, event->serial);
+ else
+ wlr_data_source_destroy(event->drag->source);
+}
+
+void
+setfloating(Client *c, int floating)
+{
+ Client *p = client_get_parent(c);
+ c->isfloating = floating;
+ /* If in floating layout do not change the client's layer */
+ if (!c->mon || !client_surface(c)->mapped || !c->mon->lt[c->mon->sellt]->arrange)
+ return;
+ wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen ||
+ (p && p->isfullscreen) ? LyrFS
+ : c->isfloating ? LyrFloat : LyrTile]);
+ if (c->isfloating && !c->bw)
+ resize(c, c->mon->m, 0, 1);
+ arrange(c->mon);
+ printstatus();
+}
+
+void
+setfullscreen(Client *c, int fullscreen)
+{
+ c->isfullscreen = fullscreen;
+ if (!c->mon || !client_surface(c)->mapped)
+ return;
+ c->bw = fullscreen ? 0 : BORDERPX(c);
+ client_set_fullscreen(c, fullscreen);
+ wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen
+ ? LyrFS : c->isfloating ? LyrFloat : LyrTile]);
+
+ if (fullscreen) {
+ c->prev = c->geom;
+ resize(c, c->mon->m, 0, 0);
+ } else {
+ /* restore previous size instead of arrange for floating windows since
+ * client positions are set by the user and cannot be recalculated */
+ resize(c, c->prev, 0, 1);
+ }
+ wlr_scene_node_for_each_buffer(&c->scene_surface->node, scenebuffersetopacity, c);
+ arrange(c->mon);
+ printstatus();
+}
+
+void
+scenebuffersetopacity(struct wlr_scene_buffer *buffer, int sx, int sy, void *data)
+{
+ Client *c = data;
+ /* xdg-popups are children of Client.scene, we do not have to worry about
+ messing with them. */
+ wlr_scene_buffer_set_opacity(buffer, c->isfullscreen ? 1 : c->opacity);
+}
+
+void
+setopacity(const Arg *arg)
+{
+ Client *sel = focustop(selmon, 0);
+ if (!sel)
+ return;
+
+ sel->opacity += arg->f;
+ if (sel->opacity > 1.0f)
+ sel->opacity = 1.0f;
+ if (sel->opacity < 0.1f)
+ sel->opacity = 0.1f;
+
+ wlr_scene_node_for_each_buffer(&sel->scene_surface->node, scenebuffersetopacity, sel);
+}
+
+void
+setmon(Client *c, Monitor *m, uint32_t newtags)
+{
+ Monitor *oldmon = c->mon;
+
+ if (oldmon == m)
+ return;
+ c->mon = m;
+ c->prev = c->geom;
+
+ /* Scene graph sends surface leave/enter events on move and resize */
+ if (oldmon)
+ arrange(oldmon);
+ if (m) {
+ /* Make sure window actually overlaps with the monitor */
+ resize(c, c->geom, 0, 1);
+ c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */
+ setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */
+ setfloating(c, c->isfloating);
+ }
+ focusclient(focustop(selmon, 0), 1);
+
+ if (c->swallowing)
+ setmon(c->swallowing, m, newtags);
+}
+
+void
+startdrag(struct wl_listener *listener, void *data)
+{
+ struct wlr_drag *drag = data;
+ if (!drag->icon)
+ return;
+
+ drag->icon->data = &wlr_scene_drag_icon_create(drag_icon, drag->icon)->node;
+ LISTEN_STATIC(&drag->icon->events.destroy, destroydragicon);
+}
+
+pid_t
+parentpid(pid_t pid)
+{
+ unsigned int v = 0;
+ FILE *f;
+ char buf[256];
+ snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)pid);
+ if (!(f = fopen(buf, "r")))
+ return 0;
+ fscanf(f, "%*u %*s %*c %u", &v);
+ fclose(f);
+ return (pid_t)v;
+}
+
+void
+swallow(Client *c, Client *toswallow)
+{
+ /* Do not allow a client to swallow itself */
+ if (c == toswallow)
+ return;
+
+ /* Swallow */
+ if (toswallow && !c->swallowing) {
+ c->swallowing = toswallow;
+ toswallow->swallowedby = c;
+ toswallow->mon = c->mon;
+ wl_list_remove(&c->link);
+ wl_list_insert(&c->swallowing->link, &c->link);
+ wl_list_remove(&c->flink);
+ wl_list_insert(&c->swallowing->flink, &c->flink);
+ c->bw = BORDERPX(c);
+ c->tags = toswallow->tags;
+ c->isfloating = toswallow->isfloating;
+ c->geom = toswallow->geom;
+ setfullscreen(toswallow, 0);
+ }
+
+ /* Unswallow */
+ else if (c->swallowing) {
+ wl_list_remove(&c->swallowing->link);
+ wl_list_insert(&c->link, &c->swallowing->link);
+ wl_list_remove(&c->swallowing->flink);
+ wl_list_insert(&c->flink, &c->swallowing->flink);
+ c->swallowing->tags = c->tags;
+ c->swallowing->swallowedby = NULL;
+ c->swallowing = NULL;
+ c->bw = BORDERPX(c);
+ setfullscreen(c, 0);
+ }
+}
+
+void
+tag(const Arg *arg)
+{
+ Client *sel = focustop(selmon, 0);
+ if (!sel || (arg->ui & TAGMASK) == 0)
+ return;
+
+ sel->tags = arg->ui & TAGMASK;
+ focusclient(focustop(selmon, 0), 1);
+ arrange(selmon);
+ printstatus();
+}
+
+void
+tagmon(const Arg *arg)
+{
+ Client *sel = focustop(selmon, 0);
+ if (!sel)
+ return;
+
+ setmon(sel, dirtomon(arg->i), 0);
+ free(sel->output);
+ sel->output = strdup(sel->mon->wlr_output->name);
+ if (sel->output == NULL)
+ die("out of memory");
+}
+
+Client *
+termforwin(Client *c)
+{
+ Client *p;
+ pid_t pid;
+ pid_t pids[32];
+ size_t i, pids_len;
+
+ if (!c->pid || c->isterm)
+ return NULL;
+
+ /* Get all parent pids */
+ pids_len = 0;
+ pid = c->pid;
+ while (pids_len < LENGTH(pids)) {
+ pid = parentpid(pid);
+ if (!pid)
+ break;
+ pids[pids_len++] = pid;
+ }
+
+ /* Find closest parent */
+ for (i = 0; i < pids_len; i++) {
+ wl_list_for_each(p, &clients, link) {
+ if (!p->pid || !p->isterm || p->swallowedby)
+ continue;
+ if (pids[i] == p->pid)
+ return p;
+ }
+ }
+
+ return NULL;
+}
+
+void
+togglefloating(const Arg *arg)
+{
+ Client *sel = focustop(selmon, 0);
+ /* return if fullscreen */
+ if (sel && !sel->isfullscreen)
+ setfloating(sel, !sel->isfloating);
+}
+
+void
+togglefullscreen(const Arg *arg)
+{
+ Client *sel = focustop(selmon, 0);
+ if (sel)
+ setfullscreen(sel, !sel->isfullscreen);
+}
+
+void
+toggleswallow(const Arg *arg)
+{
+ Client *c, *sel = focustop(selmon, 0);
+ if (!sel)
+ return;
+
+ if (sel->swallowing) {
+ swallow(sel, NULL);
+ } else {
+ wl_list_for_each(c, &sel->flink, flink) {
+ if (&c->flink == &fstack)
+ continue; /* wrap past the sentinel node */
+ if (VISIBLEON(c, selmon))
+ break; /* found it */
+ }
+ swallow(sel, c);
+ }
+}
+
+void
+toggleautoswallow(const Arg *arg)
+{
+ config.enableautoswallow = !config.enableautoswallow;
+}
+
+void
+toggletag(const Arg *arg)
+{
+ uint32_t newtags;
+ Client *sel = focustop(selmon, 0);
+ if (!sel || !(newtags = sel->tags ^ (arg->ui & TAGMASK)))
+ return;
+
+ sel->tags = newtags;
+ focusclient(focustop(selmon, 0), 1);
+ arrange(selmon);
+ printstatus();
+}
+
+void
+toggleview(const Arg *arg)
+{
+ uint32_t newtagset;
+ size_t i;
+ if (!(newtagset = selmon ? selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK) : 0))
+ return;
+
+ if (newtagset == (uint32_t)~0) {
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+ selmon->pertag->curtag = 0;
+ }
+
+ /* test if the user did not select the same tag */
+ if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+ for (i = 0; !(newtagset & 1 << i); i++) ;
+ selmon->pertag->curtag = i + 1;
+ }
+
+ /* apply settings for this view */
+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
+ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
+ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
+ selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
+
+ selmon->tagset[selmon->seltags] = newtagset;
+ focusclient(focustop(selmon, 0), 1);
+ arrange(selmon);
+ printstatus();
+}
+
+void
+unmaplayersurfacenotify(struct wl_listener *listener, void *data)
+{
+ LayerSurface *l = wl_container_of(listener, l, unmap);
+
+ l->mapped = 0;
+ wlr_scene_node_set_enabled(&l->scene->node, 0);
+ if (l == exclusive_focus)
+ exclusive_focus = NULL;
+ if (l->layer_surface->output && (l->mon = l->layer_surface->output->data))
+ arrangelayers(l->mon);
+ if (l->layer_surface->surface == seat->keyboard_state.focused_surface)
+ focusclient(focustop(selmon, 0), 1);
+ motionnotify(0, NULL, 0, 0, 0, 0);
+}
+
+void
+unmapnotify(struct wl_listener *listener, void *data)
+{
+ /* Called when the surface is unmapped, and should no longer be shown. */
+ Client *c = wl_container_of(listener, c, unmap);
+ if (c == grabc) {
+ cursor_mode = CurNormal;
+ grabc = NULL;
+ }
+
+ if (c->swallowing) {
+ swallow(c, NULL);
+ } else if (c->swallowedby) {
+ swallow(c->swallowedby, NULL);
+ }
+
+ if (client_is_unmanaged(c)) {
+ if (c == exclusive_focus) {
+ exclusive_focus = NULL;
+ focusclient(focustop(selmon, 0), 1);
+ }
+ } else {
+ wl_list_remove(&c->link);
+ setmon(c, NULL, 0);
+ wl_list_remove(&c->flink);
+ }
+
+ wlr_scene_node_destroy(&c->scene->node);
+ client_surface(c)->data = NULL;
+ printstatus();
+ motionnotify(0, NULL, 0, 0, 0, 0);
+}
+
+void
+updatetitle(struct wl_listener *listener, void *data)
+{
+ Client *c = wl_container_of(listener, c, set_title);
+ if (c == focustop(c->mon, 0))
+ printstatus();
+}
+
+void
+urgent(struct wl_listener *listener, void *data)
+{
+ struct wlr_xdg_activation_v1_request_activate_event *event = data;
+ Client *c = NULL;
+ toplevel_from_wlr_surface(event->surface, &c, NULL);
+ if (!c || c == focustop(selmon, 0))
+ return;
+
+ c->isurgent = 1;
+ printstatus();
+
+ if (client_surface(c)->mapped)
+ client_set_border_color(c, config.urgentcolor);
+}
+
+void
+view(const Arg *arg)
+{
+ size_t i, tmptag;
+
+ if (!selmon || (arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
+ return;
+ selmon->seltags ^= 1; /* toggle sel tagset */
+ if (arg->ui & ~0) {
+ selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+
+ if (arg->ui == TAGMASK)
+ selmon->pertag->curtag = 0;
+ else {
+ for (i = 0; !(arg->ui & 1 << i); i++) ;
+ selmon->pertag->curtag = i + 1;
+ }
+ } else {
+ tmptag = selmon->pertag->prevtag;
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+ selmon->pertag->curtag = tmptag;
+ }
+
+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
+ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
+ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
+ selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
+
+ focusclient(focustop(selmon, 0), 1);
+ arrange(selmon);
+ printstatus();
+}
diff --git a/src/config.c b/src/config.c
new file mode 100644
index 0000000..696574e
--- /dev/null
+++ b/src/config.c
@@ -0,0 +1,1634 @@
+/*
+ * See LICENSE file for copyright and license details.
+ *
+ * Lua configuration loader for ether.
+ */
+#include <lauxlib.h>
+#include <lua.h>
+#include <lualib.h>
+
+#include "ether.h"
+
+/* registry keys under which the parse target lives during config loading */
+#define BUILD_CFG_KEY "ether.build_cfg"
+#define BUILD_PENDING_KEY "ether.build_pending"
+
+/* layout functions available from Lua */
+typedef struct {
+ const char *name;
+ void (*arrange)(Monitor *);
+} LayoutFunc;
+
+static const LayoutFunc layout_funcs[] = {
+ { "tile", tile },
+ { "float", NULL },
+ { "monocle", monocle },
+ { "deck", deck },
+};
+
+#define NUM_LAYOUT_FUNCS (sizeof(layout_funcs) / sizeof(layout_funcs[0]))
+
+/* live configuration, populated on first config load */
+struct Config config;
+
+/* config file path, stored for reload */
+static char *current_config_path;
+
+/* defaults a fresh config is copied from before parsing; never modified */
+static const struct Config default_config = {
+ .sloppyfocus = 1,
+ .respect_monitor_reserved_area = 0,
+ .smartgaps = 0,
+ .gaps = 1,
+ .gappx = 10,
+ .smartborders = 1,
+ .borderpx = 1,
+ .rootcolor = {0.133f, 0.133f, 0.133f, 1.0f},
+ .bordercolor = {0.267f, 0.267f, 0.267f, 1.0f},
+ .focuscolor = {0.0f, 0.333f, 0.467f, 1.0f},
+ .urgentcolor = {1.0f, 0.0f, 0.0f, 1.0f},
+ .fullscreen_bg = {0.0f, 0.0f, 0.0f, 0.0f},
+ .default_opacity = 0.75f,
+ .enableautoswallow = 1,
+ .swallowborder = 1.0f,
+ .cursor_timeout = 5,
+ .tabletmaptosurface = 1,
+ .tablet_area = {0.4, 0.4, 0.4, 0.4},
+ .log_level = WLR_ERROR,
+ .repeat_rate = 25,
+ .repeat_delay = 600,
+ .tap_to_click = 1,
+ .tap_and_drag = 1,
+ .drag_lock = 1,
+ .disable_while_typing = 1,
+ .scroll_method = LIBINPUT_CONFIG_SCROLL_2FG,
+ .click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS,
+ .send_events_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED,
+ .accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE,
+ .accel_speed = 0.0,
+ .button_map = LIBINPUT_CONFIG_TAP_MAP_LRM,
+};
+
+/* parse a "#RRGGBB" or "#RRGGBBAA" color string into four floats */
+static int
+parse_color(lua_State *L, int idx, float color[4])
+{
+ const char *hex;
+ size_t len;
+ uint32_t rgba;
+
+ if (!lua_isstring(L, idx))
+ return 0;
+
+ hex = lua_tolstring(L, idx, &len);
+ if (len != 7 && len != 9)
+ return 0;
+ if (hex[0] != '#')
+ return 0;
+
+ rgba = (uint32_t)strtoul(hex + 1, NULL, 16);
+ if (len == 7)
+ rgba = (rgba << 8) | 0xFF;
+
+ color[0] = ((rgba >> 24) & 0xFF) / 255.0f;
+ color[1] = ((rgba >> 16) & 0xFF) / 255.0f;
+ color[2] = ((rgba >> 8) & 0xFF) / 255.0f;
+ color[3] = (rgba & 0xFF) / 255.0f;
+ return 1;
+}
+
+/* map an arrange-mode name to a layout function, NULL for the float layout */
+static void (*
+lookup_layout_func(const char *name))(Monitor *)
+{
+ size_t i;
+ for (i = 0; i < NUM_LAYOUT_FUNCS; i++)
+ if (strcmp(name, layout_funcs[i].name) == 0)
+ return layout_funcs[i].arrange;
+ return NULL;
+}
+
+/* find a layout by symbol in a config's layout list */
+static const Layout *
+find_layout(struct Config *cfg, const char *name)
+{
+ int i;
+ for (i = 0; i < cfg->nlayouts; i++)
+ if (cfg->layouts[i].symbol && strcmp(cfg->layouts[i].symbol, name) == 0)
+ return &cfg->layouts[i];
+ return NULL;
+}
+
+/* record an allocation as owned by cfg, torn down by config_free */
+static void
+config_own(struct Config *cfg, void *ptr, void (*dtor)(void *))
+{
+ struct ConfigOwned *o = ecalloc(1, sizeof(*o));
+
+ o->ptr = ptr;
+ o->dtor = dtor;
+ o->next = cfg->store;
+ cfg->store = o;
+}
+
+/* duplicate a string into cfg's ownership */
+static const char *
+own_string(struct Config *cfg, const char *s)
+{
+ char *p = strdup(s);
+
+ if (!p)
+ die("strdup:");
+ config_own(cfg, p, free);
+ return p;
+}
+
+/* free a registered spawn argv: the elements and the array are one allocation */
+static void
+free_argv(void *ptr)
+{
+ char **argv = ptr;
+ int i;
+
+ for (i = 0; argv[i]; i++)
+ free(argv[i]);
+ free(argv);
+}
+
+/* release everything a config owns */
+static void
+config_free(struct Config *cfg)
+{
+ struct ConfigOwned *o;
+
+ while ((o = cfg->store)) {
+ cfg->store = o->next;
+ o->dtor(o->ptr);
+ free(o);
+ }
+ cfg->store = NULL;
+
+ free(cfg->rules);
+ free(cfg->layouts);
+ free(cfg->monrules);
+ free(cfg->keys);
+ free(cfg->buttons);
+ cfg->rules = NULL;
+ cfg->layouts = NULL;
+ cfg->monrules = NULL;
+ cfg->keys = NULL;
+ cfg->buttons = NULL;
+ cfg->nrules = 0;
+ cfg->nlayouts = 0;
+ cfg->nmonrules = 0;
+ cfg->nkeys = 0;
+ cfg->nbuttons = 0;
+ cfg->xkb_rules = (struct xkb_rule_names){0};
+}
+
+/* the fresh config being built by the current parse */
+static struct Config *
+build_cfg(lua_State *L)
+{
+ struct Config *cfg;
+
+ lua_getfield(L, LUA_REGISTRYINDEX, BUILD_CFG_KEY);
+ cfg = lua_touserdata(L, -1);
+ lua_pop(L, 1);
+ return cfg;
+}
+
+/* handle to the deferred-layout-name list being extended during the parse */
+static char ***
+build_pending(lua_State *L)
+{
+ char ***pp;
+
+ lua_getfield(L, LUA_REGISTRYINDEX, BUILD_PENDING_KEY);
+ pp = lua_touserdata(L, -1);
+ lua_pop(L, 1);
+ return pp;
+}
+
+/* get a string field from a table, NULL if absent or not a string */
+static const char *
+lua_getfield_string(lua_State *L, int idx, const char *key)
+{
+ const char *s;
+
+ lua_getfield(L, idx, key);
+ if (lua_isnil(L, -1)) {
+ lua_pop(L, 1);
+ return NULL;
+ }
+ s = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ return s;
+}
+
+/* Lua API: ether.color("#RRGGBB[AA]") -> r, g, b, a */
+static int
+l_ether_color(lua_State *L)
+{
+ float color[4];
+
+ if (!parse_color(L, 1, color))
+ return luaL_error(L, "invalid color, expected '#RRGGBB' or '#RRGGBBAA'");
+ lua_pushnumber(L, color[0]);
+ lua_pushnumber(L, color[1]);
+ lua_pushnumber(L, color[2]);
+ lua_pushnumber(L, color[3]);
+ return 4;
+}
+
+/* Lua API: ether.sloppy_focus(enabled) */
+static int
+l_ether_sloppy_focus(lua_State *L)
+{
+ build_cfg(L)->sloppyfocus = lua_toboolean(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.bypass_surface_visibility(enabled) */
+static int
+l_ether_bypass_surface_visibility(lua_State *L)
+{
+ build_cfg(L)->bypass_surface_visibility = lua_toboolean(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.respect_monitor_reserved_area(enabled) */
+static int
+l_ether_respect_monitor_reserved_area(lua_State *L)
+{
+ build_cfg(L)->respect_monitor_reserved_area = lua_toboolean(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.border_width(px) */
+static int
+l_ether_border_width(lua_State *L)
+{
+ build_cfg(L)->borderpx = (unsigned int)luaL_checkinteger(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.smartgaps(enabled) */
+static int
+l_ether_smartgaps(lua_State *L)
+{
+ build_cfg(L)->smartgaps = lua_toboolean(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.gaps(enabled) */
+static int
+l_ether_gaps(lua_State *L)
+{
+ build_cfg(L)->gaps = lua_toboolean(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.gap_pixels(px) */
+static int
+l_ether_gappx(lua_State *L)
+{
+ build_cfg(L)->gappx = (unsigned int)luaL_checkinteger(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.smartborders(enabled) */
+static int
+l_ether_smartborders(lua_State *L)
+{
+ build_cfg(L)->smartborders = lua_toboolean(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.border_color(hex) */
+static int
+l_ether_border_color(lua_State *L)
+{
+ if (!parse_color(L, 1, build_cfg(L)->bordercolor))
+ return luaL_error(L, "invalid color");
+ return 0;
+}
+
+/* Lua API: ether.focus_color(hex) */
+static int
+l_ether_focus_color(lua_State *L)
+{
+ if (!parse_color(L, 1, build_cfg(L)->focuscolor))
+ return luaL_error(L, "invalid color");
+ return 0;
+}
+
+/* Lua API: ether.urgent_color(hex) */
+static int
+l_ether_urgent_color(lua_State *L)
+{
+ if (!parse_color(L, 1, build_cfg(L)->urgentcolor))
+ return luaL_error(L, "invalid color");
+ return 0;
+}
+
+/* Lua API: ether.root_color(hex) */
+static int
+l_ether_root_color(lua_State *L)
+{
+ if (!parse_color(L, 1, build_cfg(L)->rootcolor))
+ return luaL_error(L, "invalid color");
+ return 0;
+}
+
+/* Lua API: ether.fullscreen_bg(hex) */
+static int
+l_ether_fullscreen_bg(lua_State *L)
+{
+ if (!parse_color(L, 1, build_cfg(L)->fullscreen_bg))
+ return luaL_error(L, "invalid color");
+ return 0;
+}
+
+/* Lua API: ether.default_opacity(alpha) */
+static int
+l_ether_default_opacity(lua_State *L)
+{
+ build_cfg(L)->default_opacity = (float)luaL_checknumber(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.enableautoswallow(enabled) */
+static int
+l_ether_enableautoswallow(lua_State *L)
+{
+ build_cfg(L)->enableautoswallow = lua_toboolean(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.swallowborder(multiplier) */
+static int
+l_ether_swallowborder(lua_State *L)
+{
+ build_cfg(L)->swallowborder = (float)luaL_checknumber(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.cursor_timeout(seconds) */
+static int
+l_ether_cursor_timeout(lua_State *L)
+{
+ build_cfg(L)->cursor_timeout = (int)luaL_checkinteger(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.tabletmaptosurface(0|1) - map tablet input to surface(1) or
+ * monitor(0) */
+static int
+l_ether_tabletmaptosurface(lua_State *L)
+{
+ build_cfg(L)->tabletmaptosurface = (int)luaL_checkinteger(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.tablet_area(x, y, width, height) - active tablet zone as a
+ * fraction of the tablet surface (0.0 to 1.0) */
+static int
+l_ether_tablet_area(lua_State *L)
+{
+ struct Config *cfg = build_cfg(L);
+ int i;
+
+ for (i = 0; i < 4; i++)
+ cfg->tablet_area[i] = luaL_checknumber(L, i + 1);
+ return 0;
+}
+
+/* shared parser for one tablet button binding: ether.tablet_button({...}) and
+ * ether.tablet_pad_button({...}) */
+static void (*lookup_action(const char *name))(const Arg *);
+static Arg get_action_arg(struct Config *cfg, lua_State *L, int idx,
+ const char *action);
+static int
+parse_tablet_button(lua_State *L, int pad)
+{
+ struct Config *cfg = build_cfg(L);
+ TabletButton *tb;
+ const char *s;
+
+ if (!lua_istable(L, 1))
+ return luaL_error(L, "expected table");
+
+ if (pad) {
+ cfg->tabletpadbuttons = realloc(cfg->tabletpadbuttons,
+ (cfg->ntabletpadbuttons + 1) * sizeof(TabletPadButton));
+ if (!cfg->tabletpadbuttons)
+ die("realloc:");
+ tb = (TabletButton *)&cfg->tabletpadbuttons[cfg->ntabletpadbuttons];
+ } else {
+ cfg->tabletbuttons = realloc(cfg->tabletbuttons,
+ (cfg->ntabletbuttons + 1) * sizeof(TabletButton));
+ if (!cfg->tabletbuttons)
+ die("realloc:");
+ tb = &cfg->tabletbuttons[cfg->ntabletbuttons];
+ }
+ memset(tb, 0, sizeof(*tb));
+
+ s = lua_getfield_string(L, 1, "button");
+ if (!s)
+ return luaL_error(L, "tablet button requires 'button'");
+ tb->button = (uint32_t)strtoul(s, NULL, 0);
+
+ s = lua_getfield_string(L, 1, "state");
+ if (s && strcmp(s, "release") == 0)
+ tb->state = WLR_BUTTON_RELEASED;
+ else
+ tb->state = WLR_BUTTON_PRESSED;
+
+ s = lua_getfield_string(L, 1, "action");
+ if (s)
+ tb->func = lookup_action(s);
+
+ lua_getfield(L, 1, "arg");
+ if (s) {
+ Arg tmp = get_action_arg(cfg, L, -1, s);
+ memcpy((void *)&tb->arg, &tmp, sizeof(Arg));
+ }
+ lua_pop(L, 1);
+
+ if (pad)
+ cfg->ntabletpadbuttons++;
+ else
+ cfg->ntabletbuttons++;
+ return 0;
+}
+
+/* Lua API: ether.tablet_button({button, state, action, arg}) */
+static int
+l_ether_tablet_button(lua_State *L)
+{
+ return parse_tablet_button(L, 0);
+}
+
+/* Lua API: ether.tablet_pad_button({button, state, action, arg}) */
+static int
+l_ether_tablet_pad_button(lua_State *L)
+{
+ return parse_tablet_button(L, 1);
+}
+
+/* Lua API: ether.log_level(level) */
+static int
+l_ether_log_level(lua_State *L)
+{
+ struct Config *cfg = build_cfg(L);
+ const char *s = luaL_checkstring(L, 1);
+
+ if (strcmp(s, "silent") == 0 || strcmp(s, "SILENT") == 0)
+ cfg->log_level = WLR_SILENT;
+ else if (strcmp(s, "error") == 0 || strcmp(s, "ERROR") == 0)
+ cfg->log_level = WLR_ERROR;
+ else if (strcmp(s, "info") == 0 || strcmp(s, "INFO") == 0)
+ cfg->log_level = WLR_INFO;
+ else if (strcmp(s, "debug") == 0 || strcmp(s, "DEBUG") == 0)
+ cfg->log_level = WLR_DEBUG;
+ else
+ return luaL_error(L, "invalid log level: %s", s);
+ return 0;
+}
+
+/* Lua API: ether.xkb_rules(opts_table) */
+static int
+l_ether_xkb_rules(lua_State *L)
+{
+ struct Config *cfg = build_cfg(L);
+ const char *s;
+
+ if (!lua_istable(L, 1))
+ return luaL_error(L, "expected table");
+
+ s = lua_getfield_string(L, 1, "rules");
+ if (s) cfg->xkb_rules.rules = own_string(cfg, s);
+
+ s = lua_getfield_string(L, 1, "model");
+ if (s) cfg->xkb_rules.model = own_string(cfg, s);
+
+ s = lua_getfield_string(L, 1, "layout");
+ if (s) cfg->xkb_rules.layout = own_string(cfg, s);
+
+ s = lua_getfield_string(L, 1, "variant");
+ if (s) cfg->xkb_rules.variant = own_string(cfg, s);
+
+ s = lua_getfield_string(L, 1, "options");
+ if (s) cfg->xkb_rules.options = own_string(cfg, s);
+ return 0;
+}
+
+/* Lua API: ether.repeat_rate(rate) */
+static int
+l_ether_repeat_rate(lua_State *L)
+{
+ build_cfg(L)->repeat_rate = (int)luaL_checkinteger(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.repeat_delay(delay) */
+static int
+l_ether_repeat_delay(lua_State *L)
+{
+ build_cfg(L)->repeat_delay = (int)luaL_checkinteger(L, 1);
+ return 0;
+}
+
+/* Lua API: ether.trackpad(opts_table) */
+static int
+l_ether_trackpad(lua_State *L)
+{
+ struct Config *cfg = build_cfg(L);
+
+ if (!lua_istable(L, 1))
+ return luaL_error(L, "expected table");
+
+ lua_getfield(L, 1, "tap_to_click");
+ if (!lua_isnil(L, -1))
+ cfg->tap_to_click = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "tap_and_drag");
+ if (!lua_isnil(L, -1))
+ cfg->tap_and_drag = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "drag_lock");
+ if (!lua_isnil(L, -1))
+ cfg->drag_lock = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "natural_scrolling");
+ if (!lua_isnil(L, -1))
+ cfg->natural_scrolling = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "disable_while_typing");
+ if (!lua_isnil(L, -1))
+ cfg->disable_while_typing = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "left_handed");
+ if (!lua_isnil(L, -1))
+ cfg->left_handed = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "middle_button_emulation");
+ if (!lua_isnil(L, -1))
+ cfg->middle_button_emulation = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "accel_speed");
+ if (!lua_isnil(L, -1))
+ cfg->accel_speed = lua_tonumber(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "scroll_method");
+ if (!lua_isnil(L, -1)) {
+ const char *v = lua_tostring(L, -1);
+ if (v) {
+ if (strcmp(v, "no_scroll") == 0)
+ cfg->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
+ else if (strcmp(v, "2fg") == 0)
+ cfg->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG;
+ else if (strcmp(v, "edge") == 0)
+ cfg->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE;
+ else if (strcmp(v, "on_button_down") == 0)
+ cfg->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
+ }
+ }
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "click_method");
+ if (!lua_isnil(L, -1)) {
+ const char *v = lua_tostring(L, -1);
+ if (v) {
+ if (strcmp(v, "none") == 0)
+ cfg->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
+ else if (strcmp(v, "button_areas") == 0)
+ cfg->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
+ else if (strcmp(v, "clickfinger") == 0)
+ cfg->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
+ }
+ }
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "send_events");
+ if (!lua_isnil(L, -1)) {
+ const char *v = lua_tostring(L, -1);
+ if (v) {
+ if (strcmp(v, "enabled") == 0)
+ cfg->send_events_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
+ else if (strcmp(v, "disabled") == 0)
+ cfg->send_events_mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
+ else if (strcmp(v, "disabled_on_external_mouse") == 0)
+ cfg->send_events_mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
+ }
+ }
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "accel_profile");
+ if (!lua_isnil(L, -1)) {
+ const char *v = lua_tostring(L, -1);
+ if (v) {
+ if (strcmp(v, "flat") == 0)
+ cfg->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
+ else if (strcmp(v, "adaptive") == 0)
+ cfg->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
+ }
+ }
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "button_map");
+ if (!lua_isnil(L, -1)) {
+ const char *v = lua_tostring(L, -1);
+ if (v) {
+ if (strcmp(v, "lrm") == 0)
+ cfg->button_map = LIBINPUT_CONFIG_TAP_MAP_LRM;
+ else if (strcmp(v, "lmr") == 0)
+ cfg->button_map = LIBINPUT_CONFIG_TAP_MAP_LMR;
+ }
+ }
+ lua_pop(L, 1);
+
+ return 0;
+}
+
+/* Lua API: ether.rule(opts_table) */
+static int
+l_ether_rule(lua_State *L)
+{
+ struct Config *cfg = build_cfg(L);
+ const char *s;
+
+ if (!lua_istable(L, 1))
+ return luaL_error(L, "expected table");
+
+ cfg->rules = realloc(cfg->rules, (cfg->nrules + 1) * sizeof(Rule));
+ if (!cfg->rules)
+ die("realloc:");
+ memset(&cfg->rules[cfg->nrules], 0, sizeof(Rule));
+
+ s = lua_getfield_string(L, 1, "app_id");
+ if (s) cfg->rules[cfg->nrules].id = own_string(cfg, s);
+
+ s = lua_getfield_string(L, 1, "title");
+ if (s) cfg->rules[cfg->nrules].title = own_string(cfg, s);
+
+ lua_getfield(L, 1, "tags");
+ if (!lua_isnil(L, -1))
+ cfg->rules[cfg->nrules].tags = (uint32_t)lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "float");
+ if (!lua_isnil(L, -1))
+ cfg->rules[cfg->nrules].isfloating = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "isterm");
+ if (!lua_isnil(L, -1))
+ cfg->rules[cfg->nrules].isterm = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "noswallow");
+ if (!lua_isnil(L, -1))
+ cfg->rules[cfg->nrules].noswallow = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "opacity");
+ if (!lua_isnil(L, -1))
+ cfg->rules[cfg->nrules].opacity = (float)lua_tonumber(L, -1);
+ else
+ cfg->rules[cfg->nrules].opacity = cfg->default_opacity;
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "monitor");
+ if (!lua_isnil(L, -1))
+ cfg->rules[cfg->nrules].monitor = (int)lua_tointeger(L, -1);
+ else
+ cfg->rules[cfg->nrules].monitor = -1;
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "x");
+ if (!lua_isnil(L, -1))
+ cfg->rules[cfg->nrules].x = (int)lua_tointeger(L, -1);
+ else
+ cfg->rules[cfg->nrules].x = -1;
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "y");
+ if (!lua_isnil(L, -1))
+ cfg->rules[cfg->nrules].y = (int)lua_tointeger(L, -1);
+ else
+ cfg->rules[cfg->nrules].y = -1;
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "w");
+ if (!lua_isnil(L, -1))
+ cfg->rules[cfg->nrules].w = (float)lua_tonumber(L, -1);
+ else
+ cfg->rules[cfg->nrules].w = -1.0f;
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "h");
+ if (!lua_isnil(L, -1))
+ cfg->rules[cfg->nrules].h = (float)lua_tonumber(L, -1);
+ else
+ cfg->rules[cfg->nrules].h = -1.0f;
+ lua_pop(L, 1);
+
+ cfg->nrules++;
+ return 0;
+}
+
+/* Lua API: ether.layout(opts_table) */
+static int
+l_ether_layout(lua_State *L)
+{
+ struct Config *cfg = build_cfg(L);
+ const char *sym, *func_name;
+ void (*func)(Monitor *);
+
+ if (!lua_istable(L, 1))
+ return luaL_error(L, "expected table");
+
+ sym = lua_getfield_string(L, 1, "name");
+ if (!sym)
+ return luaL_error(L, "layout requires 'name'");
+
+ func_name = lua_getfield_string(L, 1, "arrange");
+ if (!func_name)
+ return luaL_error(L, "layout requires 'arrange'");
+
+ /* validate the arrange mode before allocating an entry */
+ if (strcmp(func_name, "float") == 0)
+ func = NULL;
+ else if ((func = lookup_layout_func(func_name)))
+ ;
+ else
+ return luaL_error(L, "unknown layout function: %s", func_name);
+
+ cfg->layouts = realloc(cfg->layouts, (cfg->nlayouts + 1) * sizeof(Layout));
+ if (!cfg->layouts)
+ die("realloc:");
+ cfg->layouts[cfg->nlayouts].symbol = own_string(cfg, sym);
+ cfg->layouts[cfg->nlayouts].arrange = func;
+ cfg->nlayouts++;
+ return 0;
+}
+
+/* Lua API: ether.monitor(opts_table) */
+static int
+l_ether_monitor(lua_State *L)
+{
+ struct Config *cfg = build_cfg(L);
+ const char *s, *layout_name;
+ char ***pp;
+ const Layout *lt;
+
+ if (!lua_istable(L, 1))
+ return luaL_error(L, "expected table");
+
+ cfg->monrules = realloc(cfg->monrules, (cfg->nmonrules + 1) * sizeof(MonitorRule));
+ if (!cfg->monrules)
+ die("realloc:");
+ memset(&cfg->monrules[cfg->nmonrules], 0, sizeof(MonitorRule));
+
+ /* slot for a layout name that is not resolvable yet; resolved once the
+ * whole file has been parsed */
+ pp = build_pending(L);
+ *pp = realloc(*pp, (cfg->nmonrules + 1) * sizeof(char *));
+ if (!*pp)
+ die("realloc:");
+ (*pp)[cfg->nmonrules] = NULL;
+
+ s = lua_getfield_string(L, 1, "name");
+ if (s) cfg->monrules[cfg->nmonrules].name = own_string(cfg, s);
+
+ lua_getfield(L, 1, "mfact");
+ if (!lua_isnil(L, -1))
+ cfg->monrules[cfg->nmonrules].mfact = (float)lua_tonumber(L, -1);
+ else
+ cfg->monrules[cfg->nmonrules].mfact = 0.55f;
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "nmaster");
+ if (!lua_isnil(L, -1))
+ cfg->monrules[cfg->nmonrules].nmaster = (int)lua_tointeger(L, -1);
+ else
+ cfg->monrules[cfg->nmonrules].nmaster = 1;
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "scale");
+ if (!lua_isnil(L, -1))
+ cfg->monrules[cfg->nmonrules].scale = (float)lua_tonumber(L, -1);
+ else
+ cfg->monrules[cfg->nmonrules].scale = 1.0f;
+ lua_pop(L, 1);
+
+ layout_name = lua_getfield_string(L, 1, "layout");
+ if (layout_name) {
+ if ((lt = find_layout(cfg, layout_name)))
+ cfg->monrules[cfg->nmonrules].lt = lt;
+ else
+ (*pp)[cfg->nmonrules] = strdup(layout_name);
+ } else if (cfg->nlayouts > 0) {
+ cfg->monrules[cfg->nmonrules].lt = &cfg->layouts[0];
+ }
+
+ lua_getfield(L, 1, "transform");
+ if (!lua_isnil(L, -1)) {
+ const char *t = lua_tostring(L, -1);
+ if (t) {
+ if (strcmp(t, "normal") == 0 || strcmp(t, "none") == 0)
+ cfg->monrules[cfg->nmonrules].rr = WL_OUTPUT_TRANSFORM_NORMAL;
+ else if (strcmp(t, "90") == 0)
+ cfg->monrules[cfg->nmonrules].rr = WL_OUTPUT_TRANSFORM_90;
+ else if (strcmp(t, "180") == 0)
+ cfg->monrules[cfg->nmonrules].rr = WL_OUTPUT_TRANSFORM_180;
+ else if (strcmp(t, "270") == 0)
+ cfg->monrules[cfg->nmonrules].rr = WL_OUTPUT_TRANSFORM_270;
+ else if (strcmp(t, "flipped") == 0)
+ cfg->monrules[cfg->nmonrules].rr = WL_OUTPUT_TRANSFORM_FLIPPED;
+ else if (strcmp(t, "flipped_90") == 0)
+ cfg->monrules[cfg->nmonrules].rr = WL_OUTPUT_TRANSFORM_FLIPPED_90;
+ else if (strcmp(t, "flipped_180") == 0)
+ cfg->monrules[cfg->nmonrules].rr = WL_OUTPUT_TRANSFORM_FLIPPED_180;
+ else if (strcmp(t, "flipped_270") == 0)
+ cfg->monrules[cfg->nmonrules].rr = WL_OUTPUT_TRANSFORM_FLIPPED_270;
+ }
+ }
+ lua_pop(L, 1);
+
+ cfg->monrules[cfg->nmonrules].x = -1;
+ cfg->monrules[cfg->nmonrules].y = -1;
+ lua_getfield(L, 1, "x");
+ if (!lua_isnil(L, -1))
+ cfg->monrules[cfg->nmonrules].x = (int)lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "y");
+ if (!lua_isnil(L, -1))
+ cfg->monrules[cfg->nmonrules].y = (int)lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ cfg->nmonrules++;
+ return 0;
+}
+
+/* parse a modifier name into a wlr modifier bit */
+static uint32_t
+parse_modifier(const char *s)
+{
+ if (strcmp(s, "ALT") == 0 || strcmp(s, "Mod1") == 0)
+ return WLR_MODIFIER_ALT;
+ if (strcmp(s, "CTRL") == 0 || strcmp(s, "Control") == 0 || strcmp(s, "Ctrl") == 0 || strcmp(s, "Mod4") == 0)
+ return WLR_MODIFIER_CTRL;
+ if (strcmp(s, "SHIFT") == 0 || strcmp(s, "Shift") == 0 || strcmp(s, "Mod1Shift") == 0)
+ return WLR_MODIFIER_SHIFT;
+ if (strcmp(s, "SUPER") == 0 || strcmp(s, "Mod4") == 0)
+ return WLR_MODIFIER_LOGO;
+ if (strcmp(s, "MODKEY") == 0)
+ return WLR_MODIFIER_ALT; /* default MODKEY is Alt */
+ return 0;
+}
+
+/* OR together the modifier names in a table */
+static uint32_t
+parse_modifiers(lua_State *L, int idx)
+{
+ uint32_t mods = 0;
+ int i, n;
+
+ if (!lua_istable(L, idx))
+ return 0;
+
+ n = (int)lua_rawlen(L, idx);
+ for (i = 1; i <= n; i++) {
+ lua_rawgeti(L, idx, i);
+ if (lua_isstring(L, -1))
+ mods |= parse_modifier(lua_tostring(L, -1));
+ lua_pop(L, 1);
+ }
+ return mods;
+}
+
+/* resolve a keysym name to its xkb symbol */
+static xkb_keysym_t
+resolve_keysym(const char *name)
+{
+ xkb_keysym_t sym;
+
+ sym = xkb_keysym_from_name(name, XKB_KEYSYM_NO_FLAGS);
+ if (sym != XKB_KEYSYM_NO_FLAGS)
+ return sym;
+ return xkb_keysym_from_name(name, XKB_KEYSYM_CASE_INSENSITIVE);
+}
+
+/* parse the arg table of a binding action */
+static Arg
+get_action_arg(struct Config *cfg, lua_State *L, int idx, const char *action)
+{
+ Arg arg = {0};
+
+ if (strcmp(action, "spawn") == 0) {
+ char **argv;
+ const char *cmd;
+ int n, i;
+
+ if (lua_istable(L, idx)) {
+ n = (int)lua_rawlen(L, idx);
+ argv = calloc(n + 1, sizeof(char *));
+ for (i = 0; i < n; i++) {
+ lua_rawgeti(L, idx, i + 1);
+ cmd = lua_tostring(L, -1);
+ argv[i] = cmd ? strdup(cmd) : strdup("");
+ lua_pop(L, 1);
+ }
+ argv[n] = NULL;
+ } else {
+ cmd = luaL_checkstring(L, idx);
+ argv = calloc(4, sizeof(char *));
+ argv[0] = strdup("/bin/sh");
+ argv[1] = strdup("-c");
+ argv[2] = strdup(cmd);
+ argv[3] = NULL;
+ }
+ if (!argv)
+ die("calloc:");
+ config_own(cfg, argv, free_argv);
+ arg.v = argv;
+ } else if (lua_istable(L, idx)) {
+ if (strcmp(action, "view") == 0 || strcmp(action, "toggleview") == 0
+ || strcmp(action, "tag") == 0 || strcmp(action, "toggletag") == 0) {
+ lua_getfield(L, idx, "tag");
+ if (!lua_isnil(L, -1))
+ arg.ui = 1u << (uint32_t)lua_tointeger(L, -1);
+ lua_pop(L, 1);
+ } else if (strcmp(action, "incnmaster") == 0) {
+ lua_getfield(L, idx, "delta");
+ if (!lua_isnil(L, -1))
+ arg.i = (int)lua_tointeger(L, -1);
+ lua_pop(L, 1);
+ } else if (strcmp(action, "setmfact") == 0) {
+ lua_getfield(L, idx, "delta");
+ if (!lua_isnil(L, -1))
+ arg.f = (float)lua_tonumber(L, -1);
+ lua_pop(L, 1);
+ } else if (strcmp(action, "focusmon") == 0 || strcmp(action, "tagmon") == 0) {
+ const char *dir;
+ lua_getfield(L, idx, "direction");
+ dir = lua_tostring(L, -1);
+ if (dir && strcmp(dir, "left") == 0)
+ arg.i = WLR_DIRECTION_LEFT;
+ else
+ arg.i = WLR_DIRECTION_RIGHT;
+ lua_pop(L, 1);
+ } else if (strcmp(action, "setlayout") == 0) {
+ const char *name;
+ const Layout *lt;
+ lua_getfield(L, idx, "layout");
+ name = lua_tostring(L, -1);
+ if (name && (lt = find_layout(cfg, name)))
+ arg.v = (void *)lt;
+ lua_pop(L, 1);
+ name = lua_tostring(L, -1);
+ if (name && (lt = find_layout(cfg, name)))
+ arg.v = (void *)lt;
+ lua_pop(L, 1);
+ } else if (strcmp(action, "focusstack") == 0) {
+ lua_getfield(L, idx, "delta");
+ if (!lua_isnil(L, -1))
+ arg.i = (int)lua_tointeger(L, -1);
+ else
+ arg.i = 1;
+ lua_pop(L, 1);
+ } else if (strcmp(action, "movestack") == 0) {
+ lua_getfield(L, idx, "delta");
+ if (!lua_isnil(L, -1))
+ arg.i = (int)lua_tointeger(L, -1);
+ else
+ arg.i = 1;
+ lua_pop(L, 1);
+ } else if (strcmp(action, "shifttag") == 0
+ || strcmp(action, "shifttag_occupied") == 0
+ || strcmp(action, "shifttag_unoccupied") == 0) {
+ lua_getfield(L, idx, "delta");
+ if (!lua_isnil(L, -1))
+ arg.i = (int)lua_tointeger(L, -1);
+ else
+ arg.i = 1;
+ lua_pop(L, 1);
+ } else if (strcmp(action, "moveresize") == 0) {
+ const char *mode;
+ lua_getfield(L, idx, "mode");
+ mode = lua_tostring(L, -1);
+ if (mode && strcmp(mode, "resize") == 0)
+ arg.ui = CurResize;
+ else
+ arg.ui = CurMove;
+ lua_pop(L, 1);
+ } else if (strcmp(action, "setopacity") == 0) {
+ lua_getfield(L, idx, "delta");
+ if (!lua_isnil(L, -1))
+ arg.f = (float)lua_tonumber(L, -1);
+ else
+ arg.f = 0.1f;
+ lua_pop(L, 1);
+ } else if (strcmp(action, "chvt") == 0) {
+ lua_getfield(L, idx, "vt");
+ if (!lua_isnil(L, -1))
+ arg.ui = (unsigned int)lua_tointeger(L, -1);
+ lua_pop(L, 1);
+ }
+ }
+ /* quit, killclient, zoom, togglefloating, togglefullscreen, reload and
+ * actions without an arg table keep arg as {0} */
+
+ return arg;
+}
+
+/* map an action name to its binding handler */
+static void (*
+lookup_action(const char *name))(const Arg *)
+{
+ static const struct {
+ const char *name;
+ void (*func)(const Arg *);
+ } actions[] = {
+ { "spawn", spawn },
+ { "focusstack", focusstack },
+ { "incnmaster", incnmaster },
+ { "setmfact", setmfact },
+ { "zoom", zoom },
+ { "view", view },
+ { "toggleview", toggleview },
+ { "tag", tag },
+ { "toggletag", toggletag },
+ { "focusmon", focusmon },
+ { "tagmon", tagmon },
+ { "shifttag", shifttag },
+ { "shifttag_occupied", shifttag_occupied },
+ { "shifttag_unoccupied", shifttag_unoccupied },
+ { "setlayout", setlayout },
+ { "togglefloating", togglefloating },
+ { "togglefullscreen", togglefullscreen },
+ { "togglegaps", togglegaps },
+ { "toggleswallow", toggleswallow },
+ { "toggleautoswallow", toggleautoswallow },
+ { "killclient", killclient },
+ { "movestack", movestack },
+ { "moveresize", moveresize },
+ { "setopacity", setopacity },
+ { "quit", quit },
+ { "reload", reload },
+ { "chvt", chvt },
+ };
+ size_t i;
+ for (i = 0; i < sizeof(actions) / sizeof(actions[0]); i++)
+ if (strcmp(name, actions[i].name) == 0)
+ return actions[i].func;
+ return NULL;
+}
+
+/* Lua API: ether.key(opts_table) */
+static int
+l_ether_key(lua_State *L)
+{
+ struct Config *cfg = build_cfg(L);
+ const char *s, *action;
+
+ if (!lua_istable(L, 1))
+ return luaL_error(L, "expected table");
+
+ cfg->keys = realloc(cfg->keys, (cfg->nkeys + 1) * sizeof(Key));
+ if (!cfg->keys)
+ die("realloc:");
+ memset(&cfg->keys[cfg->nkeys], 0, sizeof(Key));
+
+ lua_getfield(L, 1, "mods");
+ if (!lua_isnil(L, -1))
+ cfg->keys[cfg->nkeys].mod = parse_modifiers(L, -1);
+ lua_pop(L, 1);
+
+ s = lua_getfield_string(L, 1, "key");
+ if (!s)
+ return luaL_error(L, "key requires 'key'");
+ cfg->keys[cfg->nkeys].keysym = resolve_keysym(s);
+ if (cfg->keys[cfg->nkeys].keysym == XKB_KEYSYM_NO_FLAGS)
+ return luaL_error(L, "unknown keysym: %s", s);
+
+ action = lua_getfield_string(L, 1, "action");
+ if (!action)
+ return luaL_error(L, "key requires 'action'");
+ cfg->keys[cfg->nkeys].func = lookup_action(action);
+ if (!cfg->keys[cfg->nkeys].func)
+ return luaL_error(L, "unknown action: %s", action);
+
+ lua_getfield(L, 1, "arg");
+ {
+ Arg tmp = get_action_arg(cfg, L, -1, action);
+ memcpy((void *)&cfg->keys[cfg->nkeys].arg, &tmp, sizeof(Arg));
+ }
+ lua_pop(L, 1);
+
+ cfg->nkeys++;
+ return 0;
+}
+
+/* Lua API: ether.mouse(opts_table) */
+static int
+l_ether_mouse(lua_State *L)
+{
+ struct Config *cfg = build_cfg(L);
+ const char *s;
+
+ if (!lua_istable(L, 1))
+ return luaL_error(L, "expected table");
+
+ cfg->buttons = realloc(cfg->buttons, (cfg->nbuttons + 1) * sizeof(Button));
+ if (!cfg->buttons)
+ die("realloc:");
+ memset(&cfg->buttons[cfg->nbuttons], 0, sizeof(Button));
+
+ lua_getfield(L, 1, "mods");
+ if (!lua_isnil(L, -1))
+ cfg->buttons[cfg->nbuttons].mod = parse_modifiers(L, -1);
+ lua_pop(L, 1);
+
+ s = lua_getfield_string(L, 1, "button");
+ if (!s)
+ return luaL_error(L, "mouse requires 'button'");
+ if (strcmp(s, "left") == 0 || strcmp(s, "BTN_LEFT") == 0)
+ cfg->buttons[cfg->nbuttons].button = BTN_LEFT;
+ else if (strcmp(s, "middle") == 0 || strcmp(s, "BTN_MIDDLE") == 0)
+ cfg->buttons[cfg->nbuttons].button = BTN_MIDDLE;
+ else if (strcmp(s, "right") == 0 || strcmp(s, "BTN_RIGHT") == 0)
+ cfg->buttons[cfg->nbuttons].button = BTN_RIGHT;
+ else
+ cfg->buttons[cfg->nbuttons].button = (unsigned int)strtoul(s, NULL, 0);
+
+ s = lua_getfield_string(L, 1, "action");
+ if (s)
+ cfg->buttons[cfg->nbuttons].func = lookup_action(s);
+
+ lua_getfield(L, 1, "arg");
+ if (s) {
+ Arg tmp = get_action_arg(cfg, L, -1, s);
+ memcpy((void *)&cfg->buttons[cfg->nbuttons].arg, &tmp, sizeof(Arg));
+ }
+ lua_pop(L, 1);
+
+ cfg->nbuttons++;
+ return 0;
+}
+
+/* Lua API: ether.tags(count) or ether.tags({mods = {...}}, count) - generates
+ * the standard per-tag view/toggleview/tag/toggletag bindings */
+static int
+l_ether_tags(lua_State *L)
+{
+ struct Config *cfg = build_cfg(L);
+ uint32_t mod = WLR_MODIFIER_ALT; /* default MODKEY */
+ int ntags, i;
+
+ if (lua_istable(L, 1)) {
+ lua_getfield(L, 1, "mods");
+ if (!lua_isnil(L, -1) && lua_istable(L, -1))
+ mod = parse_modifiers(L, -1);
+ lua_pop(L, 1);
+ ntags = (int)luaL_checkinteger(L, 2);
+ } else {
+ ntags = (int)luaL_checkinteger(L, 1);
+ }
+
+ for (i = 0; i < ntags && i < 32; i++) {
+ uint32_t tag_mask = 1u << i;
+ Arg tmparg;
+
+ cfg->keys = realloc(cfg->keys, (cfg->nkeys + 1) * sizeof(Key));
+ if (!cfg->keys)
+ die("realloc:");
+ cfg->keys[cfg->nkeys].mod = mod;
+ cfg->keys[cfg->nkeys].func = view;
+ tmparg.ui = tag_mask;
+ memcpy((void *)&cfg->keys[cfg->nkeys].arg, &tmparg, sizeof(Arg));
+ cfg->nkeys++;
+
+ cfg->keys = realloc(cfg->keys, (cfg->nkeys + 1) * sizeof(Key));
+ if (!cfg->keys)
+ die("realloc:");
+ cfg->keys[cfg->nkeys].mod = mod | WLR_MODIFIER_CTRL;
+ cfg->keys[cfg->nkeys].func = toggleview;
+ tmparg.ui = tag_mask;
+ memcpy((void *)&cfg->keys[cfg->nkeys].arg, &tmparg, sizeof(Arg));
+ cfg->nkeys++;
+
+ cfg->keys = realloc(cfg->keys, (cfg->nkeys + 1) * sizeof(Key));
+ if (!cfg->keys)
+ die("realloc:");
+ cfg->keys[cfg->nkeys].mod = mod | WLR_MODIFIER_SHIFT;
+ cfg->keys[cfg->nkeys].func = tag;
+ tmparg.ui = tag_mask;
+ memcpy((void *)&cfg->keys[cfg->nkeys].arg, &tmparg, sizeof(Arg));
+ cfg->nkeys++;
+
+ cfg->keys = realloc(cfg->keys, (cfg->nkeys + 1) * sizeof(Key));
+ if (!cfg->keys)
+ die("realloc:");
+ cfg->keys[cfg->nkeys].mod = mod | WLR_MODIFIER_CTRL | WLR_MODIFIER_SHIFT;
+ cfg->keys[cfg->nkeys].func = toggletag;
+ tmparg.ui = tag_mask;
+ memcpy((void *)&cfg->keys[cfg->nkeys].arg, &tmparg, sizeof(Arg));
+ cfg->nkeys++;
+ }
+ return 0;
+}
+
+/* Lua API: ether.tags_with(mods, keysym_table, tag_mask) - bind specific keys
+ * to the tag actions for one tag mask */
+static int
+l_ether_tags_with(lua_State *L)
+{
+ struct Config *cfg = build_cfg(L);
+ uint32_t mod, tag_mask;
+ int i, n;
+
+ mod = parse_modifiers(L, 1);
+ tag_mask = (uint32_t)luaL_checkinteger(L, 3);
+
+ if (!lua_istable(L, 2))
+ return luaL_error(L, "expected keysym table");
+
+ n = (int)lua_rawlen(L, 2);
+ for (i = 1; i <= n; i++) {
+ const char *s;
+ xkb_keysym_t sym;
+ Arg tmparg;
+
+ lua_rawgeti(L, 2, i);
+ s = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ if (!s)
+ continue;
+
+ sym = resolve_keysym(s);
+ if (sym == XKB_KEYSYM_NO_FLAGS)
+ continue;
+
+ cfg->keys = realloc(cfg->keys, (cfg->nkeys + 1) * sizeof(Key));
+ if (!cfg->keys)
+ die("realloc:");
+ cfg->keys[cfg->nkeys].mod = mod;
+ cfg->keys[cfg->nkeys].keysym = sym;
+ cfg->keys[cfg->nkeys].func = view;
+ tmparg.ui = tag_mask;
+ memcpy((void *)&cfg->keys[cfg->nkeys].arg, &tmparg, sizeof(Arg));
+ cfg->nkeys++;
+
+ cfg->keys = realloc(cfg->keys, (cfg->nkeys + 1) * sizeof(Key));
+ if (!cfg->keys)
+ die("realloc:");
+ cfg->keys[cfg->nkeys].mod = mod | WLR_MODIFIER_CTRL;
+ cfg->keys[cfg->nkeys].keysym = sym;
+ cfg->keys[cfg->nkeys].func = toggleview;
+ tmparg.ui = tag_mask;
+ memcpy((void *)&cfg->keys[cfg->nkeys].arg, &tmparg, sizeof(Arg));
+ cfg->nkeys++;
+
+ cfg->keys = realloc(cfg->keys, (cfg->nkeys + 1) * sizeof(Key));
+ if (!cfg->keys)
+ die("realloc:");
+ cfg->keys[cfg->nkeys].mod = mod | WLR_MODIFIER_SHIFT;
+ cfg->keys[cfg->nkeys].keysym = sym;
+ cfg->keys[cfg->nkeys].func = tag;
+ tmparg.ui = tag_mask;
+ memcpy((void *)&cfg->keys[cfg->nkeys].arg, &tmparg, sizeof(Arg));
+ cfg->nkeys++;
+
+ cfg->keys = realloc(cfg->keys, (cfg->nkeys + 1) * sizeof(Key));
+ if (!cfg->keys)
+ die("realloc:");
+ cfg->keys[cfg->nkeys].mod = mod | WLR_MODIFIER_CTRL | WLR_MODIFIER_SHIFT;
+ cfg->keys[cfg->nkeys].keysym = sym;
+ cfg->keys[cfg->nkeys].func = toggletag;
+ tmparg.ui = tag_mask;
+ memcpy((void *)&cfg->keys[cfg->nkeys].arg, &tmparg, sizeof(Arg));
+ cfg->nkeys++;
+ }
+ return 0;
+}
+
+/* register the ether.* API in a Lua state */
+static void
+ether_lua_register(lua_State *L)
+{
+ static const luaL_Reg ether_funcs[] = {
+ { "color", l_ether_color },
+ { "sloppy_focus", l_ether_sloppy_focus },
+ { "bypass_surface_visibility", l_ether_bypass_surface_visibility },
+ { "respect_monitor_reserved_area", l_ether_respect_monitor_reserved_area },
+ { "smartgaps", l_ether_smartgaps },
+ { "gaps", l_ether_gaps },
+ { "gap_pixels", l_ether_gappx },
+ { "smartborders", l_ether_smartborders },
+ { "border_width", l_ether_border_width },
+ { "border_color", l_ether_border_color },
+ { "focus_color", l_ether_focus_color },
+ { "urgent_color", l_ether_urgent_color },
+ { "root_color", l_ether_root_color },
+ { "fullscreen_bg", l_ether_fullscreen_bg },
+ { "default_opacity", l_ether_default_opacity },
+ { "enableautoswallow", l_ether_enableautoswallow },
+ { "swallowborder", l_ether_swallowborder },
+ { "cursor_timeout", l_ether_cursor_timeout },
+ { "tabletmaptosurface", l_ether_tabletmaptosurface },
+ { "tablet_area", l_ether_tablet_area },
+ { "tablet_button", l_ether_tablet_button },
+ { "tablet_pad_button", l_ether_tablet_pad_button },
+ { "log_level", l_ether_log_level },
+ { "xkb_rules", l_ether_xkb_rules },
+ { "repeat_rate", l_ether_repeat_rate },
+ { "repeat_delay", l_ether_repeat_delay },
+ { "trackpad", l_ether_trackpad },
+ { "rule", l_ether_rule },
+ { "layout", l_ether_layout },
+ { "monitor", l_ether_monitor },
+ { "key", l_ether_key },
+ { "mouse", l_ether_mouse },
+ { "tags", l_ether_tags },
+ { "tags_with", l_ether_tags_with },
+ { NULL, NULL },
+ };
+
+ luaL_newlib(L, ether_funcs);
+ lua_setglobal(L, "ether");
+}
+
+/* publish the fresh config and its deferred-layout list to the ether.* handlers */
+static void
+build_register(lua_State *L, struct Config *cfg, char ***pending)
+{
+ lua_pushlightuserdata(L, cfg);
+ lua_setfield(L, LUA_REGISTRYINDEX, BUILD_CFG_KEY);
+ lua_pushlightuserdata(L, pending);
+ lua_setfield(L, LUA_REGISTRYINDEX, BUILD_PENDING_KEY);
+}
+
+/* commit config-derived settings to the running compositor state */
+static void
+apply_config(void)
+{
+ Client *c;
+ Monitor *m;
+ int i;
+
+ /* compositor not yet initialized (early call from main) */
+ if (!dpy)
+ return;
+
+ /* apply monitor rules to all existing monitors */
+ wl_list_for_each(m, &mons, link) {
+ const MonitorRule *r;
+ for (r = config.monrules; r < config.monrules + config.nmonrules; r++) {
+ if (!r->name || strstr(m->wlr_output->name, r->name)) {
+ struct wlr_output_state state;
+
+ m->mfact = r->mfact;
+ m->nmaster = r->nmaster;
+
+ wlr_output_state_init(&state);
+ if (r->scale > 0)
+ wlr_output_state_set_scale(&state, r->scale);
+ wlr_output_state_set_transform(&state, r->rr);
+ wlr_output_commit_state(m->wlr_output, &state);
+ wlr_output_state_finish(&state);
+
+ if (r->x >= 0 && r->y >= 0) {
+ wlr_output_layout_add(output_layout,
+ m->wlr_output, r->x, r->y);
+ m->m.x = r->x;
+ m->m.y = r->y;
+ }
+
+ m->lt[0] = r->lt;
+ m->lt[1] = (config.nlayouts > 1 && r->lt != &config.layouts[1])
+ ? &config.layouts[1] : &config.layouts[0];
+ strncpy(m->ltsymbol, m->lt[m->sellt]->symbol,
+ LENGTH(m->ltsymbol) - 1);
+ m->ltsymbol[LENGTH(m->ltsymbol) - 1] = '\0';
+ break;
+ }
+ }
+ }
+
+ /* apply border width and colors to all clients */
+ wl_list_for_each(c, &clients, link) {
+ c->bw = c->isfullscreen ? 0 : config.borderpx;
+ if (c == focustop(c->mon, 0))
+ client_set_border_color(c, config.focuscolor);
+ else
+ client_set_border_color(c, config.bordercolor);
+ }
+
+ /* apply root and fullscreen background colors */
+ wlr_scene_rect_set_color(root_bg, config.rootcolor);
+ wl_list_for_each(m, &mons, link)
+ wlr_scene_rect_set_color(m->fullscreen_bg, config.fullscreen_bg);
+
+ /* apply keyboard config (xkb keymap, repeat rate/delay) */
+ {
+ struct xkb_context *context;
+ struct xkb_keymap *keymap;
+
+ context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
+ if ((keymap = xkb_keymap_new_from_names(context, &config.xkb_rules,
+ XKB_KEYMAP_COMPILE_NO_FLAGS))) {
+ wlr_keyboard_set_keymap(&kb_group->wlr_group->keyboard, keymap);
+ xkb_keymap_unref(keymap);
+ }
+ xkb_context_unref(context);
+
+ wlr_keyboard_set_repeat_info(&kb_group->wlr_group->keyboard,
+ config.repeat_rate, config.repeat_delay);
+ }
+
+ /* reapply trackpad/libinput settings to all pointer devices */
+ for (i = 0; i < nptr_devs; i++)
+ createpointer(wlr_pointer_from_input_device(ptr_devs[i].device));
+
+ /* re-arrange all monitors (also resizes clients with the new border width) */
+ wl_list_for_each(m, &mons, link) {
+ if (m->wlr_output->enabled)
+ arrange(m);
+ }
+
+ printstatus();
+}
+
+/* free the live config's dynamically allocated data */
+void
+free_config(void)
+{
+ config_free(&config);
+}
+
+/* re-parse the config file and reapply it to the running compositor */
+void
+reload(const Arg *arg)
+{
+ Monitor *m;
+ char *path;
+ (void)arg;
+
+ /* save each monitor's layout symbol: m->lt[] points into the config being
+ * replaced and must be re-linked once the new config is swapped in */
+ wl_list_for_each(m, &mons, link)
+ strncpy(m->ltsymbol, m->lt[m->sellt]->symbol,
+ LENGTH(m->ltsymbol) - 1);
+
+ path = strdup(current_config_path);
+ if (lua_load_config(path)) {
+ free(path);
+ return;
+ }
+ free(path);
+
+ /* the layouts array was rebuilt: re-link by the saved symbols, falling
+ * back to the first layout */
+ wl_list_for_each(m, &mons, link) {
+ const Layout *lt = find_layout(&config, m->ltsymbol);
+ m->lt[0] = lt ? lt : &config.layouts[0];
+ m->lt[1] = (config.nlayouts > 1) ? &config.layouts[1]
+ : &config.layouts[0];
+ }
+
+ apply_config();
+}
+
+/* load the Lua config file into the live config */
+int
+lua_load_config(const char *path)
+{
+ lua_State *L;
+ struct Config next;
+ char **pending = NULL;
+ char *abspath, *configdir;
+ int status, i;
+
+ /* resolve the config file path, defaulting under XDG_CONFIG_HOME */
+ if (path) {
+ abspath = strdup(path);
+ } else {
+ const char *xdg = getenv("XDG_CONFIG_HOME");
+ char buf[PATH_MAX];
+
+ if (xdg && xdg[0])
+ snprintf(buf, sizeof(buf), "%s/ether/config.lua", xdg);
+ else
+ snprintf(buf, sizeof(buf), "%s/.config/ether/config.lua",
+ getenv("HOME") ? getenv("HOME") : ".");
+ abspath = strdup(buf);
+ }
+ if (!abspath)
+ die("strdup:");
+
+ /* parse into a fresh copy of the defaults, leaving the running config
+ * untouched until the whole file parses cleanly */
+ next = default_config;
+ next.store = NULL;
+
+ L = luaL_newstate();
+ if (!L) {
+ free(abspath);
+ fprintf(stderr, "ether: failed to create lua state\n");
+ return 1;
+ }
+
+ luaL_openlibs(L);
+ ether_lua_register(L);
+ build_register(L, &next, &pending);
+
+ /* make modules alongside the config file loadable */
+ configdir = strdup(abspath);
+ if (strrchr(configdir, '/'))
+ *(strrchr(configdir, '/')) = '\0';
+ lua_getglobal(L, "package");
+ lua_getfield(L, -1, "path");
+ {
+ const char *old = lua_tostring(L, -1);
+ char pkgpath[PATH_MAX];
+
+ snprintf(pkgpath, sizeof(pkgpath), "%s/?.lua;%s/?/init.lua;%s",
+ configdir, configdir, old ? old : "");
+ lua_pop(L, 1);
+ lua_pushstring(L, "path");
+ lua_pushstring(L, pkgpath);
+ lua_rawset(L, -3);
+ }
+ lua_pop(L, 1);
+ free(configdir);
+
+ /* load config file */
+ status = luaL_dofile(L, abspath);
+ if (status != LUA_OK) {
+ fprintf(stderr, "ether: %s\n", lua_tostring(L, -1));
+ /* append a traceback pointing at the offending line, if any */
+ luaL_traceback(L, L, NULL, 0);
+ if (strlen(lua_tostring(L, -1)) > strlen("stack traceback:\n"))
+ fprintf(stderr, "%s\n", lua_tostring(L, -1));
+ lua_close(L);
+ for (i = 0; i < next.nmonrules; i++)
+ free(pending[i]);
+ free(pending);
+ config_free(&next);
+ free(abspath);
+ return 1;
+ }
+ lua_close(L);
+
+ /* ensure at least one layout and one monitor rule exist */
+ if (next.nlayouts == 0) {
+ next.layouts = calloc(1, sizeof(Layout));
+ next.layouts[0].symbol = "[]=";
+ next.layouts[0].arrange = tile;
+ next.nlayouts = 1;
+ }
+ if (next.nmonrules == 0) {
+ next.monrules = calloc(1, sizeof(MonitorRule));
+ next.monrules[0].mfact = 0.55f;
+ next.monrules[0].nmaster = 1;
+ next.monrules[0].scale = 1.0f;
+ next.monrules[0].lt = &next.layouts[0];
+ next.monrules[0].rr = WL_OUTPUT_TRANSFORM_NORMAL;
+ next.monrules[0].x = -1;
+ next.monrules[0].y = -1;
+ next.nmonrules = 1;
+ }
+
+ /* resolve monitor rules whose layout was referenced before being defined */
+ for (i = 0; i < next.nmonrules; i++) {
+ if (pending[i]) {
+ next.monrules[i].lt = find_layout(&next, pending[i]);
+ if (!next.monrules[i].lt)
+ next.monrules[i].lt = &next.layouts[0];
+ free(pending[i]);
+ }
+ }
+ free(pending);
+
+ /* swap in the new config, freeing the previous one */
+ free_config();
+ config = next;
+ if (current_config_path)
+ free(current_config_path);
+ current_config_path = abspath;
+
+ return 0;
+}
\ No newline at end of file
diff --git a/src/config.h b/src/config.h
new file mode 100644
index 0000000..4748e3e
--- /dev/null
+++ b/src/config.h
@@ -0,0 +1,108 @@
+/*
+ * See LICENSE file for copyright and license details.
+ *
+ * Configuration state for ether. All settings live in a single Config struct;
+ * the live instance is the `config` global owned by config.c and read by every
+ * other subsystem. The Lua file is parsed into a fresh copy of the defaults and
+ * swapped into `config` only once the whole file parses cleanly, so a failed
+ * reload leaves the running config intact.
+ *
+ * This file is included from ether.h after all types are defined.
+ */
+#ifndef ETHER_CONFIG_H
+#define ETHER_CONFIG_H
+
+/* allocation registered for teardown (strings, spawn argv) */
+struct ConfigOwned {
+ struct ConfigOwned *next;
+ void (*dtor)(void *);
+ void *ptr;
+};
+
+struct Config {
+ /* appearance */
+ int sloppyfocus;
+ int bypass_surface_visibility;
+ int respect_monitor_reserved_area;
+ int smartgaps;
+ int gaps;
+ unsigned int gappx;
+ int smartborders;
+ unsigned int borderpx;
+ float rootcolor[4];
+ float bordercolor[4];
+ float focuscolor[4];
+ float urgentcolor[4];
+ float fullscreen_bg[4];
+ float default_opacity;
+ int enableautoswallow;
+ float swallowborder;
+ int cursor_timeout;
+
+ /* logging */
+ int log_level;
+
+ /* client rules */
+ Rule *rules;
+ int nrules;
+
+ /* layouts */
+ Layout *layouts;
+ int nlayouts;
+
+ /* monitor rules */
+ MonitorRule *monrules;
+ int nmonrules;
+
+ /* keyboard */
+ struct xkb_rule_names xkb_rules;
+ int repeat_rate;
+ int repeat_delay;
+
+ /* trackpad */
+ int tap_to_click;
+ int tap_and_drag;
+ int drag_lock;
+ int natural_scrolling;
+ int disable_while_typing;
+ int left_handed;
+ int middle_button_emulation;
+ enum libinput_config_scroll_method scroll_method;
+ enum libinput_config_click_method click_method;
+ uint32_t send_events_mode;
+ enum libinput_config_accel_profile accel_profile;
+ double accel_speed;
+ enum libinput_config_tap_button_map button_map;
+
+ /* tablet */
+ int tabletmaptosurface;
+ double tablet_area[4];
+ TabletButton *tabletbuttons;
+ int ntabletbuttons;
+ TabletPadButton *tabletpadbuttons;
+ int ntabletpadbuttons;
+
+ /* keybindings */
+ Key *keys;
+ int nkeys;
+ Button *buttons;
+ int nbuttons;
+
+ /* allocations owned by this config, freed by free_config */
+ struct ConfigOwned *store;
+};
+
+/* live configuration, owned by config.c */
+extern struct Config config;
+
+/* Load the Lua config file (default path when NULL) into a fresh copy of the
+ * defaults and swap it in only if the whole file parses. Returns 0 on success. */
+int lua_load_config(const char *path);
+
+/* Free the live config's dynamically allocated data. */
+void free_config(void);
+
+/* Re-parse the config file and reapply it to the running compositor. */
+void reload(const Arg *arg);
+
+#endif /* ETHER_CONFIG_H */
\ No newline at end of file
diff --git a/src/cursor.c b/src/cursor.c
new file mode 100644
index 0000000..7c1782e
--- /dev/null
+++ b/src/cursor.c
@@ -0,0 +1,188 @@
+/*
+ * See LICENSE file for copyright and license details.
+ */
+#include <math.h>
+#include <time.h>
+
+#include "ether.h"
+
+void
+cursorconstrain(struct wlr_pointer_constraint_v1 *constraint)
+{
+ if (active_constraint == constraint)
+ return;
+
+ if (active_constraint)
+ wlr_pointer_constraint_v1_send_deactivated(active_constraint);
+
+ active_constraint = constraint;
+ wlr_pointer_constraint_v1_send_activated(constraint);
+}
+
+void
+cursorframe(struct wl_listener *listener, void *data)
+{
+ /* This event is forwarded by the cursor when a pointer emits a frame
+ * event. Frame events are sent after regular pointer events to group
+ * multiple events together. For instance, two axis events may happen at the
+ * same time, in which case a frame event won't be sent in between. */
+ /* Notify the client with pointer focus of the frame event. */
+ wlr_seat_pointer_notify_frame(seat);
+}
+
+void
+cursorwarptohint(void)
+{
+ Client *c = NULL;
+ double sx = active_constraint->current.cursor_hint.x;
+ double sy = active_constraint->current.cursor_hint.y;
+
+ toplevel_from_wlr_surface(active_constraint->surface, &c, NULL);
+ if (c && active_constraint->current.cursor_hint.enabled) {
+ wlr_cursor_warp(cursor, NULL, sx + c->geom.x + c->bw, sy + c->geom.y + c->bw);
+ wlr_seat_pointer_warp(active_constraint->seat, sx, sy);
+ }
+}
+
+void
+createpointerconstraint(struct wl_listener *listener, void *data)
+{
+ PointerConstraint *pointer_constraint = ecalloc(1, sizeof(*pointer_constraint));
+ pointer_constraint->constraint = data;
+ LISTEN(&pointer_constraint->constraint->events.destroy,
+ &pointer_constraint->destroy, destroypointerconstraint);
+}
+
+void
+pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
+ uint32_t time)
+{
+ struct timespec now;
+
+ if (surface != seat->pointer_state.focused_surface &&
+ config.sloppyfocus && time && c && !client_is_unmanaged(c))
+ focusclient(c, 0);
+
+ /* If surface is NULL, clear pointer focus */
+ if (!surface) {
+ wlr_seat_pointer_notify_clear_focus(seat);
+ return;
+ }
+
+ if (!time) {
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ time = now.tv_sec * 1000 + now.tv_nsec / 1000000;
+ }
+
+ /* Let the client know that the mouse cursor has entered one
+ * of its surfaces, and make keyboard focus follow if desired.
+ * wlroots makes this a no-op if surface is already focused */
+ wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
+ wlr_seat_pointer_notify_motion(seat, time, sx, sy);
+}
+
+void
+setcursor(struct wl_listener *listener, void *data)
+{
+ /* This event is raised by the seat when a client provides a cursor image */
+ struct wlr_seat_pointer_request_set_cursor_event *event = data;
+ /* If we're "grabbing" the cursor, don't use the client's image, we will
+ * restore it after "grabbing" sending a leave event, followed by a enter
+ * event, which will result in the client requesting set the cursor surface */
+ if (cursor_mode != CurNormal && cursor_mode != CurPressed)
+ return;
+ /* This can be sent by any client, so we check to make sure this one
+ * actually has pointer focus first. If so, we can tell the cursor to
+ * use the provided surface as the cursor image. It will set the
+ * hardware cursor on the output that it's currently on and continue to
+ * do so as the cursor moves between outputs. */
+ if (event->seat_client == seat->pointer_state.focused_client) {
+ last_cursor.shape = 0;
+ last_cursor.surface = event->surface;
+ last_cursor.hotspot_x = event->hotspot_x;
+ last_cursor.hotspot_y = event->hotspot_y;
+
+ if (!cursor_hidden)
+ wlr_cursor_set_surface(cursor, event->surface,
+ event->hotspot_x, event->hotspot_y);
+ }
+}
+
+void
+setcursorshape(struct wl_listener *listener, void *data)
+{
+ struct wlr_cursor_shape_manager_v1_request_set_shape_event *event = data;
+ if (cursor_mode != CurNormal && cursor_mode != CurPressed)
+ return;
+ /* This can be sent by any client, so we check to make sure this one
+ * actually has pointer focus first. If so, we can tell the cursor to
+ * use the provided cursor shape. */
+ if (event->seat_client == seat->pointer_state.focused_client) {
+ last_cursor.shape = event->shape;
+ last_cursor.surface = NULL;
+
+ if (!cursor_hidden)
+ wlr_cursor_set_xcursor(cursor, cursor_mgr,
+ wlr_cursor_shape_v1_name(event->shape));
+ }
+}
+
+void
+warpcursor(const Client *c) {
+ if (cursor_mode != CurNormal) {
+ return;
+ }
+ if (!c && selmon) {
+ wlr_cursor_warp_closest(cursor,
+ NULL,
+ selmon->w.x + selmon->w.width / 2.0 ,
+ selmon->w.y + selmon->w.height / 2.0);
+ }
+ else if ( c && (cursor->x < c->geom.x ||
+ cursor->x > c->geom.x + c->geom.width ||
+ cursor->y < c->geom.y ||
+ cursor->y > c->geom.y + c->geom.height))
+ wlr_cursor_warp_closest(cursor,
+ NULL,
+ c->geom.x + c->geom.width / 2.0,
+ c->geom.y + c->geom.height / 2.0);
+}
+
+
+Monitor *
+xytomon(double x, double y)
+{
+ struct wlr_output *o = wlr_output_layout_output_at(output_layout, x, y);
+ return o ? o->data : NULL;
+}
+
+void
+xytonode(double x, double y, struct wlr_surface **psurface,
+ Client **pc, LayerSurface **pl, double *nx, double *ny)
+{
+ struct wlr_scene_node *node, *pnode;
+ struct wlr_surface *surface = NULL;
+ Client *c = NULL;
+ LayerSurface *l = NULL;
+ int layer;
+
+ for (layer = NUM_LAYERS - 1; !surface && layer >= 0; layer--) {
+ if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny)))
+ continue;
+
+ if (node->type == WLR_SCENE_NODE_BUFFER)
+ surface = wlr_scene_surface_try_from_buffer(
+ wlr_scene_buffer_from_node(node))->surface;
+ /* Walk the tree to find a node that knows the client */
+ for (pnode = node; pnode && !c; pnode = &pnode->parent->node)
+ c = pnode->data;
+ if (c && c->type == LayerShell) {
+ c = NULL;
+ l = pnode->data;
+ }
+ }
+
+ if (psurface) *psurface = surface;
+ if (pc) *pc = c;
+ if (pl) *pl = l;
+}
diff --git a/src/ether.h b/src/ether.h
new file mode 100644
index 0000000..fd9f51f
--- /dev/null
+++ b/src/ether.h
@@ -0,0 +1,565 @@
+/*
+ * See LICENSE file for copyright and license details.
+ */
+#ifndef ETHER_H
+#define ETHER_H
+
+#include <inttypes.h>
+#include <libinput.h>
+#include <linux/input-event-codes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <wayland-server-core.h>
+#include <wlr/backend.h>
+#include <wlr/backend/libinput.h>
+#include <wlr/backend/session.h>
+#include <wlr/render/allocator.h>
+#include <wlr/render/wlr_renderer.h>
+#include <wlr/types/wlr_alpha_modifier_v1.h>
+#include <wlr/types/wlr_compositor.h>
+#include <wlr/types/wlr_cursor.h>
+#include <wlr/types/wlr_cursor_shape_v1.h>
+#include <wlr/types/wlr_data_control_v1.h>
+#include <wlr/types/wlr_data_device.h>
+#include <wlr/types/wlr_drm.h>
+#include <wlr/types/wlr_export_dmabuf_v1.h>
+#include <wlr/types/wlr_ext_data_control_v1.h>
+#include <wlr/types/wlr_ext_image_capture_source_v1.h>
+#include <wlr/types/wlr_ext_image_copy_capture_v1.h>
+#include <wlr/types/wlr_fractional_scale_v1.h>
+#include <wlr/types/wlr_gamma_control_v1.h>
+#include <wlr/types/wlr_idle_inhibit_v1.h>
+#include <wlr/types/wlr_idle_notify_v1.h>
+#include <wlr/types/wlr_input_device.h>
+#include <wlr/types/wlr_keyboard.h>
+#include <wlr/types/wlr_keyboard_group.h>
+#include <wlr/types/wlr_layer_shell_v1.h>
+#include <wlr/types/wlr_linux_dmabuf_v1.h>
+#include <wlr/types/wlr_linux_drm_syncobj_v1.h>
+#include <wlr/types/wlr_output.h>
+#include <wlr/types/wlr_output_layout.h>
+#include <wlr/types/wlr_output_management_v1.h>
+#include <wlr/types/wlr_output_power_management_v1.h>
+#include <wlr/types/wlr_pointer.h>
+#include <wlr/types/wlr_pointer_constraints_v1.h>
+#include <wlr/types/wlr_presentation_time.h>
+#include <wlr/types/wlr_primary_selection.h>
+#include <wlr/types/wlr_primary_selection_v1.h>
+#include <wlr/types/wlr_relative_pointer_v1.h>
+#include <wlr/types/wlr_scene.h>
+#include <wlr/types/wlr_screencopy_v1.h>
+#include <wlr/types/wlr_seat.h>
+#include <wlr/types/wlr_server_decoration.h>
+#include <wlr/types/wlr_session_lock_v1.h>
+#include <wlr/types/wlr_single_pixel_buffer_v1.h>
+#include <wlr/types/wlr_subcompositor.h>
+#include <wlr/types/wlr_tablet_pad.h>
+#include <wlr/types/wlr_tablet_tool.h>
+#include <wlr/types/wlr_tablet_v2.h>
+#include <wlr/types/wlr_viewporter.h>
+#include <wlr/types/wlr_virtual_keyboard_v1.h>
+#include <wlr/types/wlr_virtual_pointer_v1.h>
+#include <wlr/types/wlr_xcursor_manager.h>
+#include <wlr/types/wlr_xdg_activation_v1.h>
+#include <wlr/types/wlr_xdg_decoration_v1.h>
+#include <wlr/types/wlr_xdg_output_v1.h>
+#include <wlr/types/wlr_xdg_shell.h>
+#include <wlr/util/log.h>
+#include <wlr/util/region.h>
+#include <xkbcommon/xkbcommon.h>
+#ifdef XWAYLAND
+#include <wlr/xwayland.h>
+#include <xcb/xcb.h>
+#include <xcb/xcb_icccm.h>
+#endif
+
+#include "xdg-shell-protocol.h"
+#include "util.h"
+
+/* enums */
+enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
+enum { XDGShell, LayerShell, X11 }; /* client types */
+enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */
+
+typedef union {
+ int i;
+ uint32_t ui;
+ float f;
+ const void *v;
+} Arg;
+
+typedef struct {
+ unsigned int mod;
+ unsigned int button;
+ void (*func)(const Arg *);
+ const Arg arg;
+} Button;
+
+typedef struct {
+ uint32_t button;
+ uint32_t state;
+ void (*func)(const Arg *);
+ const Arg arg;
+} TabletButton;
+
+typedef struct {
+ uint32_t button;
+ uint32_t state;
+ void (*func)(const Arg *);
+ const Arg arg;
+} TabletPadButton;
+
+typedef struct Monitor Monitor;
+typedef struct Pertag Pertag;
+typedef struct Client Client;
+struct Client {
+ /* Must keep this field first */
+ unsigned int type; /* XDGShell or X11* */
+
+ Monitor *mon;
+ char *output;
+ struct wlr_box floatgeom; /* saved geom for floating restore after monitor reconnect */
+ struct wlr_scene_tree *scene;
+ struct wlr_scene_rect *border[4]; /* top, bottom, left, right */
+ struct wlr_scene_tree *scene_surface;
+ struct wl_list link;
+ struct wl_list flink;
+ struct wlr_box geom; /* layout-relative, includes border */
+ struct wlr_box prev; /* layout-relative, includes border */
+ struct wlr_box bounds; /* only width and height are used */
+ union {
+ struct wlr_xdg_surface *xdg;
+ struct wlr_xwayland_surface *xwayland;
+ } surface;
+ struct wlr_xdg_toplevel_decoration_v1 *decoration;
+ struct wl_listener commit;
+ struct wl_listener map;
+ struct wl_listener maximize;
+ struct wl_listener unmap;
+ struct wl_listener destroy;
+ struct wl_listener set_title;
+ struct wl_listener fullscreen;
+ struct wl_listener set_decoration_mode;
+ struct wl_listener destroy_decoration;
+#ifdef XWAYLAND
+ struct wl_listener activate;
+ struct wl_listener associate;
+ struct wl_listener dissociate;
+ struct wl_listener configure;
+ struct wl_listener minimize;
+ struct wl_listener set_hints;
+#endif
+ unsigned int bw;
+ uint32_t tags;
+ int isfloating, isurgent, isfullscreen, ismaster;
+ int isterm, noswallow;
+ float opacity;
+ uint32_t resize; /* configure serial of a pending resize */
+ pid_t pid;
+ Client *swallowing; /* client being hidden */
+ Client *swallowedby;
+};
+
+typedef struct {
+ uint32_t mod;
+ xkb_keysym_t keysym;
+ void (*func)(const Arg *);
+ const Arg arg;
+} Key;
+
+typedef struct {
+ struct wlr_keyboard_group *wlr_group;
+
+ int nsyms;
+ const xkb_keysym_t *keysyms; /* invalid if nsyms == 0 */
+ uint32_t mods; /* invalid if nsyms == 0 */
+ struct wl_event_source *key_repeat_source;
+
+ struct wl_listener modifiers;
+ struct wl_listener key;
+ struct wl_listener destroy;
+} KeyboardGroup;
+
+typedef struct {
+ /* Must keep this field first */
+ unsigned int type; /* LayerShell */
+
+ Monitor *mon;
+ struct wlr_scene_tree *scene;
+ struct wlr_scene_tree *popups;
+ struct wlr_scene_layer_surface_v1 *scene_layer;
+ struct wl_list link;
+ int mapped;
+ struct wlr_layer_surface_v1 *layer_surface;
+
+ struct wl_listener destroy;
+ struct wl_listener unmap;
+ struct wl_listener surface_commit;
+} LayerSurface;
+
+typedef struct {
+ const char *symbol;
+ void (*arrange)(Monitor *);
+} Layout;
+
+struct Monitor {
+ struct wl_list link;
+ struct wlr_output *wlr_output;
+ struct wlr_scene_output *scene_output;
+ struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
+ struct wl_listener frame;
+ struct wl_listener destroy;
+ struct wl_listener request_state;
+ struct wl_listener destroy_lock_surface;
+ struct wlr_session_lock_surface_v1 *lock_surface;
+ struct wlr_box m; /* monitor area, layout-relative */
+ struct wlr_box w; /* window area, layout-relative */
+ struct wl_list layers[4]; /* LayerSurface.link */
+ const Layout *lt[2];
+ Pertag *pertag;
+ unsigned int seltags;
+ unsigned int sellt;
+ uint32_t tagset[2];
+ float mfact;
+ int gamma_lut_changed;
+ int nmaster;
+ char ltsymbol[16];
+ int asleep;
+ int gaps;
+};
+
+typedef struct {
+ const char *name;
+ float mfact;
+ int nmaster;
+ float scale;
+ const Layout *lt;
+ enum wl_output_transform rr;
+ int x, y;
+} MonitorRule;
+
+typedef struct {
+ struct wlr_pointer_constraint_v1 *constraint;
+ struct wl_listener destroy;
+} PointerConstraint;
+
+typedef struct {
+ const char *id;
+ const char *title;
+ uint32_t tags;
+ int isfloating;
+ int isterm;
+ int noswallow;
+ float opacity;
+ int monitor;
+ int x;
+ int y;
+ float w;
+ float h;
+} Rule;
+
+typedef struct {
+ struct wlr_scene_tree *scene;
+
+ struct wlr_session_lock_v1 *lock;
+ struct wl_listener new_surface;
+ struct wl_listener unlock;
+ struct wl_listener destroy;
+} SessionLock;
+
+/* variables (defined in ether.c) */
+extern struct rlimit oldrlimit;
+extern struct rlimit newrlimit;
+extern pid_t child_pid;
+extern int locked;
+extern void *exclusive_focus;
+extern struct wl_display *dpy;
+extern struct wl_event_loop *event_loop;
+extern struct wlr_backend *backend;
+extern struct wlr_scene *scene;
+extern struct wlr_scene_tree *layers[NUM_LAYERS];
+extern struct wlr_scene_tree *drag_icon;
+extern const int layermap[];
+extern struct wlr_renderer *drw;
+extern struct wlr_allocator *alloc;
+extern struct wlr_compositor *compositor;
+extern struct wlr_session *session;
+
+extern struct wlr_xdg_shell *xdg_shell;
+extern struct wlr_xdg_activation_v1 *activation;
+extern struct wlr_xdg_decoration_manager_v1 *xdg_decoration_mgr;
+extern struct wl_list clients; /* tiling order */
+extern struct wl_list fstack; /* focus order */
+extern struct wlr_idle_notifier_v1 *idle_notifier;
+extern struct wlr_idle_inhibit_manager_v1 *idle_inhibit_mgr;
+extern struct wlr_layer_shell_v1 *layer_shell;
+extern struct wlr_output_manager_v1 *output_mgr;
+extern struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr;
+extern struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr;
+extern struct wlr_cursor_shape_manager_v1 *cursor_shape_mgr;
+extern struct wlr_tablet_manager_v2 *tablet_mgr;
+extern struct wlr_output_power_manager_v1 *power_mgr;
+
+extern struct wlr_pointer_constraints_v1 *pointer_constraints;
+extern struct wlr_relative_pointer_manager_v1 *relative_pointer_mgr;
+extern struct wlr_pointer_constraint_v1 *active_constraint;
+
+extern struct wlr_cursor *cursor;
+extern struct wlr_xcursor_manager *cursor_mgr;
+extern struct wl_event_source *hide_source;
+extern int cursor_hidden;
+struct cursor_image_cache {
+ enum wp_cursor_shape_device_v1_shape shape;
+ struct wlr_surface *surface;
+ int hotspot_x;
+ int hotspot_y;
+};
+extern struct cursor_image_cache last_cursor;
+extern void handlecursoractivity(void);
+extern int hidecursor(void *data);
+
+extern struct wlr_scene_rect *root_bg;
+extern struct wlr_session_lock_manager_v1 *session_lock_mgr;
+extern struct wlr_scene_rect *locked_bg;
+extern struct wlr_session_lock_v1 *cur_lock;
+
+extern struct wlr_seat *seat;
+extern KeyboardGroup *kb_group;
+extern unsigned int cursor_mode;
+extern Client *grabc;
+extern Client initial_grabc;
+extern int grabcx, grabcy, grabx, graby, grabcenterx, grabcentery; /* client-relative */
+
+extern struct wlr_output_layout *output_layout;
+extern struct wlr_box sgeom;
+extern struct wl_list mons;
+extern Monitor *selmon;
+extern int consumed[];
+
+typedef struct {
+ struct wlr_input_device *device;
+ struct wl_listener destroy;
+} PtrDev;
+
+#define MAX_PTR_DEVS 64
+extern PtrDev ptr_devs[];
+extern int nptr_devs;
+
+/* global event listeners (defined in ether.c) */
+extern struct wl_listener cursor_axis;
+extern struct wl_listener cursor_button;
+extern struct wl_listener cursor_frame;
+extern struct wl_listener cursor_motion;
+extern struct wl_listener cursor_motion_absolute;
+extern struct wl_listener gpu_reset;
+extern struct wl_listener layout_change;
+extern struct wl_listener new_idle_inhibitor;
+extern struct wl_listener new_input_device;
+extern struct wl_listener new_virtual_keyboard;
+extern struct wl_listener new_virtual_pointer;
+extern struct wl_listener new_pointer_constraint;
+extern struct wl_listener new_output;
+extern struct wl_listener new_xdg_toplevel;
+extern struct wl_listener new_xdg_popup;
+extern struct wl_listener new_xdg_decoration;
+extern struct wl_listener new_layer_surface;
+extern struct wl_listener output_mgr_apply;
+extern struct wl_listener output_mgr_test;
+extern struct wl_listener output_power_mgr_set_mode;
+extern struct wl_listener request_activate;
+extern struct wl_listener request_cursor;
+extern struct wl_listener request_set_psel;
+extern struct wl_listener request_set_sel;
+extern struct wl_listener request_set_cursor_shape;
+extern struct wl_listener request_start_drag;
+extern struct wl_listener start_drag;
+extern struct wl_listener tablet_tool_axis;
+extern struct wl_listener tablet_tool_button;
+extern struct wl_listener tablet_tool_proximity;
+extern struct wl_listener tablet_tool_tip;
+extern struct wl_listener new_session_lock;
+#ifdef XWAYLAND
+extern struct wl_listener new_xwayland_surface;
+extern struct wl_listener xwayland_ready;
+extern struct wlr_xwayland *xwayland;
+#endif
+
+/* function declarations */
+void applybounds(Client *c, struct wlr_box *bbox);
+void applyrules(Client *c);
+void arrange(Monitor *m);
+void arrangelayer(Monitor *m, struct wl_list *list,
+ struct wlr_box *usable_area, int exclusive);
+void arrangelayers(Monitor *m);
+void axisnotify(struct wl_listener *listener, void *data);
+void buttonpress(struct wl_listener *listener, void *data);
+void chvt(const Arg *arg);
+void checkidleinhibitor(struct wlr_surface *exclude);
+void cleanup(void);
+void cleanupmon(struct wl_listener *listener, void *data);
+void cleanuplisteners(void);
+void closemon(Monitor *m);
+void commitlayersurfacenotify(struct wl_listener *listener, void *data);
+void commitnotify(struct wl_listener *listener, void *data);
+void commitpopup(struct wl_listener *listener, void *data);
+void createdecoration(struct wl_listener *listener, void *data);
+void createidleinhibitor(struct wl_listener *listener, void *data);
+void createkeyboard(struct wlr_keyboard *keyboard);
+KeyboardGroup *createkeyboardgroup(void);
+void createlayersurface(struct wl_listener *listener, void *data);
+void createlocksurface(struct wl_listener *listener, void *data);
+void createmon(struct wl_listener *listener, void *data);
+void createnotify(struct wl_listener *listener, void *data);
+void createpointer(struct wlr_pointer *pointer);
+void createpointerconstraint(struct wl_listener *listener, void *data);
+void createpopup(struct wl_listener *listener, void *data);
+void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
+void cursorframe(struct wl_listener *listener, void *data);
+void cursorwarptohint(void);
+void deck(Monitor *m);
+void destroydecoration(struct wl_listener *listener, void *data);
+void destroydragicon(struct wl_listener *listener, void *data);
+void destroyidleinhibitor(struct wl_listener *listener, void *data);
+void destroylayersurfacenotify(struct wl_listener *listener, void *data);
+void destroylock(SessionLock *lock, int unlocked);
+void destroylocksurface(struct wl_listener *listener, void *data);
+void destroynotify(struct wl_listener *listener, void *data);
+void destroypointerconstraint(struct wl_listener *listener, void *data);
+void destroysessionlock(struct wl_listener *listener, void *data);
+void destroykeyboardgroup(struct wl_listener *listener, void *data);
+Monitor *dirtomon(enum wlr_direction dir);
+void focusclient(Client *c, int lift);
+void focusmon(const Arg *arg);
+void focusstack(const Arg *arg);
+Client *focustop(Monitor *m, int onlytiled);
+void fullscreennotify(struct wl_listener *listener, void *data);
+void gpureset(struct wl_listener *listener, void *data);
+void handlesig(int signo);
+void hidebehind(Monitor *m);
+void incnmaster(const Arg *arg);
+void inputdevice(struct wl_listener *listener, void *data);
+const Key *keybinding(uint32_t mods, xkb_keysym_t sym);
+void keypress(struct wl_listener *listener, void *data);
+void keypressmod(struct wl_listener *listener, void *data);
+int keyrepeat(void *data);
+void killclient(const Arg *arg);
+void locksession(struct wl_listener *listener, void *data);
+void mapnotify(struct wl_listener *listener, void *data);
+void maximizenotify(struct wl_listener *listener, void *data);
+#ifdef XWAYLAND
+void minimizenotify(struct wl_listener *listener, void *data);
+#endif
+void monocle(Monitor *m);
+void movestack(const Arg *arg);
+void motionabsolute(struct wl_listener *listener, void *data);
+void motionnotify(uint32_t time, struct wlr_input_device *device, double sx,
+ double sy, double sx_unaccel, double sy_unaccel);
+void motionrelative(struct wl_listener *listener, void *data);
+void moveresize(const Arg *arg);
+void outputmgrapply(struct wl_listener *listener, void *data);
+void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test);
+void outputmgrtest(struct wl_listener *listener, void *data);
+pid_t parentpid(pid_t pid);
+void pointerfocus(Client *c, struct wlr_surface *surface,
+ double sx, double sy, uint32_t time);
+void printstatus(void);
+void powermgrsetmode(struct wl_listener *listener, void *data);
+void quit(const Arg *arg);
+void rendermon(struct wl_listener *listener, void *data);
+void requestdecorationmode(struct wl_listener *listener, void *data);
+void requeststartdrag(struct wl_listener *listener, void *data);
+void requestmonstate(struct wl_listener *listener, void *data);
+void resize(Client *c, struct wlr_box geo, int interact, int draw_borders);
+void run(char *startup_cmd);
+void scenebuffersetopacity(struct wlr_scene_buffer *buffer, int sx, int sy, void *data);
+void setcursor(struct wl_listener *listener, void *data);
+void setcursorshape(struct wl_listener *listener, void *data);
+void setfloating(Client *c, int floating);
+void setfullscreen(Client *c, int fullscreen);
+void setlayout(const Arg *arg);
+void setmfact(const Arg *arg);
+void setmon(Client *c, Monitor *m, uint32_t newtags);
+void setopacity(const Arg *arg);
+void shifttag(const Arg *arg);
+void shifttag_occupied(const Arg *arg);
+void shifttag_unoccupied(const Arg *arg);
+void setpsel(struct wl_listener *listener, void *data);
+void setsel(struct wl_listener *listener, void *data);
+void setup(void);
+void spawn(const Arg *arg);
+void startdrag(struct wl_listener *listener, void *data);
+void swallow(Client *c, Client *toswallow);
+void tag(const Arg *arg);
+void tagmon(const Arg *arg);
+Client *termforwin(Client *c);
+void tabletpadbutton(struct wl_listener *listener, void *data);
+void tablettoolaxis(struct wl_listener *listener, void *data);
+void tablettoolbutton(struct wl_listener *listener, void *data);
+void tablettoolproximity(struct wl_listener *listener, void *data);
+void tablettooltip(struct wl_listener *listener, void *data);
+void tile(Monitor *m);
+void togglefloating(const Arg *arg);
+void togglefullscreen(const Arg *arg);
+void togglegaps(const Arg *arg);
+void toggleswallow(const Arg *arg);
+void toggleautoswallow(const Arg *arg);
+void toggletag(const Arg *arg);
+void toggleview(const Arg *arg);
+void unlocksession(struct wl_listener *listener, void *data);
+void unmaplayersurfacenotify(struct wl_listener *listener, void *data);
+void unmapnotify(struct wl_listener *listener, void *data);
+void updatemons(struct wl_listener *listener, void *data);
+void updatetitle(struct wl_listener *listener, void *data);
+void urgent(struct wl_listener *listener, void *data);
+void view(const Arg *arg);
+void virtualkeyboard(struct wl_listener *listener, void *data);
+void virtualpointer(struct wl_listener *listener, void *data);
+void warpcursor(const Client *c);
+Monitor *xytomon(double x, double y);
+void xytonode(double x, double y, struct wlr_surface **psurface,
+ Client **pc, LayerSurface **pl, double *nx, double *ny);
+void zoom(const Arg *arg);
+
+#ifdef XWAYLAND
+void activatex11(struct wl_listener *listener, void *data);
+void associatex11(struct wl_listener *listener, void *data);
+void configurex11(struct wl_listener *listener, void *data);
+void createnotifyx11(struct wl_listener *listener, void *data);
+void dissociatex11(struct wl_listener *listener, void *data);
+void sethints(struct wl_listener *listener, void *data);
+void xwaylandready(struct wl_listener *listener, void *data);
+#endif
+
+/* macros that depend on types defined above */
+#define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS)
+#define BORDERPX(C) (config.borderpx + ((C)->swallowing ? (int)ceilf(config.swallowborder * (C)->swallowing->bw) : 0))
+#define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]) && !(C)->swallowedby)
+#define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
+#define LISTEN_STATIC(E, H) do { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0)
+
+/* TAGCOUNT: user-editable in config.h, default fallback here */
+#ifndef TAGCOUNT
+#define TAGCOUNT (9)
+#endif
+
+#define TAGMASK ((1u << TAGCOUNT) - 1)
+
+struct Pertag {
+ unsigned int curtag, prevtag; /* current and previous tag */
+ int nmasters[TAGCOUNT + 1]; /* number of windows in master area */
+ float mfacts[TAGCOUNT + 1]; /* mfacts per tag */
+ unsigned int sellts[TAGCOUNT + 1]; /* selected layouts */
+ const Layout *ltidxs[TAGCOUNT + 1][2]; /* matrix of tags and layouts indexes */
+};
+
+/* configuration (defined in config.c, loaded from Lua) */
+#include "config.h"
+
+/* client.h (uses types from above) */
+#include "client.h"
+
+#endif /* ETHER_H */
diff --git a/src/input.c b/src/input.c
new file mode 100644
index 0000000..f197af2
--- /dev/null
+++ b/src/input.c
@@ -0,0 +1,849 @@
+/*
+ * See LICENSE file for copyright and license details.
+ */
+#include "ether.h"
+
+/* tablet input */
+static void createtablet(struct wlr_input_device *device);
+static void destroytablet(struct wl_listener *listener, void *data);
+static void destroytabletpad(struct wl_listener *listener, void *data);
+static void destroytabletsurfacenotify(struct wl_listener *listener, void *data);
+static void destroytablettool(struct wl_listener *listener, void *data);
+static void tabletapplymap(double x, double y, struct wlr_input_device *dev);
+static void tablettoolmotion(struct wlr_tablet_v2_tablet_tool *tool, int change_x,
+ int change_y, double x, double y, double dx, double dy, uint32_t time);
+
+static struct wlr_tablet_v2_tablet *tablet;
+static struct wlr_tablet_v2_tablet_tool *tablet_tool;
+static struct wlr_tablet_v2_tablet_pad *tablet_pad;
+static struct wlr_surface *tablet_curr_surface;
+static struct wl_listener destroy_tablet_surface_listener = {.notify = destroytabletsurfacenotify};
+static struct wl_listener tablet_device_destroy = {.notify = destroytablet};
+static struct wl_listener tablet_pad_destroy = {.notify = destroytabletpad};
+static struct wl_listener tablet_pad_button = {.notify = tabletpadbutton};
+static struct wl_listener tablet_tool_destroy = {.notify = destroytablettool};
+static double tilt_x;
+static double tilt_y;
+
+static void
+handlepointerdestroy(struct wl_listener *listener, void *data)
+{
+ PtrDev *pd = wl_container_of(listener, pd, destroy);
+ int i;
+
+ for (i = 0; i < nptr_devs; i++) {
+ if (&ptr_devs[i] == pd) {
+ ptr_devs[i] = ptr_devs[--nptr_devs];
+ break;
+ }
+ }
+}
+
+void
+axisnotify(struct wl_listener *listener, void *data)
+{
+ /* This event is forwarded by the cursor when a pointer emits an axis event,
+ * for example when you move the scroll wheel. */
+ struct wlr_pointer_axis_event *event = data;
+ wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
+ handlecursoractivity();
+ /* TODO: allow usage of scroll wheel for mousebindings, it can be implemented
+ * by checking the event's orientation and the delta of the event */
+ /* Notify the client with pointer focus of the axis event. */
+ wlr_seat_pointer_notify_axis(seat,
+ event->time_msec, event->orientation, event->delta,
+ event->delta_discrete, event->source, event->relative_direction);
+}
+
+void
+buttonpress(struct wl_listener *listener, void *data)
+{
+ struct wlr_pointer_button_event *event = data;
+ struct wlr_keyboard *keyboard;
+ uint32_t mods;
+ Client *c;
+ const Button *b;
+
+ wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
+ handlecursoractivity();
+
+ switch (event->state) {
+ case WL_POINTER_BUTTON_STATE_PRESSED:
+ cursor_mode = CurPressed;
+ selmon = xytomon(cursor->x, cursor->y);
+ if (locked)
+ break;
+
+ /* Change focus if the button was _pressed_ over a client */
+ xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
+ if (c && (!client_is_unmanaged(c) || client_wants_focus(c)))
+ focusclient(c, 1);
+
+ keyboard = wlr_seat_get_keyboard(seat);
+ mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
+ for (b = config.buttons; b < config.buttons + config.nbuttons; b++) {
+ if (CLEANMASK(mods) == CLEANMASK(b->mod) &&
+ event->button == b->button && b->func) {
+ b->func(&b->arg);
+ return;
+ }
+ }
+ break;
+ case WL_POINTER_BUTTON_STATE_RELEASED:
+ /* If you released any buttons, we exit interactive move/resize mode. */
+ /* TODO: should reset to the pointer focus's current setcursor */
+ if (!locked && cursor_mode != CurNormal && cursor_mode != CurPressed) {
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "default");
+ cursor_mode = CurNormal;
+ /* Drop the window off on its new monitor */
+ selmon = xytomon(cursor->x, cursor->y);
+ setmon(grabc, selmon, 0);
+ grabc = NULL;
+ return;
+ }
+ cursor_mode = CurNormal;
+ break;
+ }
+ /* If the event wasn't handled by the compositor, notify the client with
+ * pointer focus that a button press has occurred */
+ wlr_seat_pointer_notify_button(seat,
+ event->time_msec, event->button, event->state);
+}
+
+void
+chvt(const Arg *arg)
+{
+ wlr_session_change_vt(session, arg->ui);
+}
+
+void
+createkeyboard(struct wlr_keyboard *keyboard)
+{
+ /* Set the keymap to match the group keymap */
+ wlr_keyboard_set_keymap(keyboard, kb_group->wlr_group->keyboard.keymap);
+
+ /* Add the new keyboard to the group */
+ wlr_keyboard_group_add_keyboard(kb_group->wlr_group, keyboard);
+}
+
+KeyboardGroup *
+createkeyboardgroup(void)
+{
+ KeyboardGroup *group = ecalloc(1, sizeof(*group));
+ struct xkb_context *context;
+ struct xkb_keymap *keymap;
+
+ group->wlr_group = wlr_keyboard_group_create();
+ group->wlr_group->data = group;
+
+ /* Prepare an XKB keymap and assign it to the keyboard group. */
+ context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
+ if (!(keymap = xkb_keymap_new_from_names(context, &config.xkb_rules,
+ XKB_KEYMAP_COMPILE_NO_FLAGS)))
+ die("failed to compile keymap");
+
+ wlr_keyboard_set_keymap(&group->wlr_group->keyboard, keymap);
+ xkb_keymap_unref(keymap);
+ xkb_context_unref(context);
+
+ wlr_keyboard_set_repeat_info(&group->wlr_group->keyboard, config.repeat_rate, config.repeat_delay);
+
+ /* Set up listeners for keyboard events */
+ LISTEN(&group->wlr_group->keyboard.events.key, &group->key, keypress);
+ LISTEN(&group->wlr_group->keyboard.events.modifiers, &group->modifiers, keypressmod);
+
+ group->key_repeat_source = wl_event_loop_add_timer(event_loop, keyrepeat, group);
+
+ /* A seat can only have one keyboard, but this is a limitation of the
+ * Wayland protocol - not wlroots. We assign all connected keyboards to the
+ * same wlr_keyboard_group, which provides a single wlr_keyboard interface for
+ * all of them. Set this combined wlr_keyboard as the seat keyboard.
+ */
+ wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard);
+ return group;
+}
+
+void
+createpointer(struct wlr_pointer *pointer)
+{
+ struct libinput_device *device;
+ if (wlr_input_device_is_libinput(&pointer->base)
+ && (device = wlr_libinput_get_device_handle(&pointer->base))) {
+
+ if (libinput_device_config_tap_get_finger_count(device)) {
+ libinput_device_config_tap_set_enabled(device, config.tap_to_click);
+ libinput_device_config_tap_set_drag_enabled(device, config.tap_and_drag);
+ libinput_device_config_tap_set_drag_lock_enabled(device, config.drag_lock);
+ libinput_device_config_tap_set_button_map(device, config.button_map);
+ }
+
+ if (libinput_device_config_scroll_has_natural_scroll(device))
+ libinput_device_config_scroll_set_natural_scroll_enabled(device, config.natural_scrolling);
+
+ if (libinput_device_config_dwt_is_available(device))
+ libinput_device_config_dwt_set_enabled(device, config.disable_while_typing);
+
+ if (libinput_device_config_left_handed_is_available(device))
+ libinput_device_config_left_handed_set(device, config.left_handed);
+
+ if (libinput_device_config_middle_emulation_is_available(device))
+ libinput_device_config_middle_emulation_set_enabled(device, config.middle_button_emulation);
+
+ if (libinput_device_config_scroll_get_methods(device) != LIBINPUT_CONFIG_SCROLL_NO_SCROLL)
+ libinput_device_config_scroll_set_method(device, config.scroll_method);
+
+ if (libinput_device_config_click_get_methods(device) != LIBINPUT_CONFIG_CLICK_METHOD_NONE)
+ libinput_device_config_click_set_method(device, config.click_method);
+
+ if (libinput_device_config_send_events_get_modes(device))
+ libinput_device_config_send_events_set_mode(device, config.send_events_mode);
+
+ if (libinput_device_config_accel_is_available(device)) {
+ libinput_device_config_accel_set_profile(device, config.accel_profile);
+ libinput_device_config_accel_set_speed(device, config.accel_speed);
+ }
+ }
+
+ wlr_cursor_attach_input_device(cursor, &pointer->base);
+}
+
+void
+inputdevice(struct wl_listener *listener, void *data)
+{
+ /* This event is raised by the backend when a new input device becomes
+ * available. */
+ struct wlr_input_device *device = data;
+ struct wlr_tablet_pad *pad = NULL;
+ uint32_t caps;
+
+ switch (device->type) {
+ case WLR_INPUT_DEVICE_KEYBOARD:
+ createkeyboard(wlr_keyboard_from_input_device(device));
+ break;
+ case WLR_INPUT_DEVICE_POINTER:
+ createpointer(wlr_pointer_from_input_device(device));
+ if (nptr_devs < MAX_PTR_DEVS) {
+ ptr_devs[nptr_devs].device = device;
+ ptr_devs[nptr_devs].destroy.notify = handlepointerdestroy;
+ wl_signal_add(&device->events.destroy,
+ &ptr_devs[nptr_devs].destroy);
+ nptr_devs++;
+ }
+ break;
+ case WLR_INPUT_DEVICE_TABLET:
+ createtablet(device);
+ break;
+ case WLR_INPUT_DEVICE_TABLET_PAD:
+ pad = wlr_tablet_pad_from_input_device(device);
+ tablet_pad = wlr_tablet_pad_create(tablet_mgr, seat, device);
+ wl_signal_add(&pad->events.button, &tablet_pad_button);
+ wl_signal_add(&device->events.destroy, &tablet_pad_destroy);
+ break;
+ default:
+ /* TODO handle other input device types */
+ break;
+ }
+
+ /* We need to let the wlr_seat know what our capabilities are, which is
+ * communiciated to the client. In ether we always have a cursor, even if
+ * there are no pointer devices, so we always include that capability. */
+ /* TODO do we actually require a cursor? */
+ caps = WL_SEAT_CAPABILITY_POINTER;
+ if (!wl_list_empty(&kb_group->wlr_group->devices))
+ caps |= WL_SEAT_CAPABILITY_KEYBOARD;
+ wlr_seat_set_capabilities(seat, caps);
+}
+
+const Key *
+keybinding(uint32_t mods, xkb_keysym_t sym)
+{
+ /*
+ * Here we handle compositor keybindings. This is when the compositor is
+ * processing keys, rather than passing them on to the client for its own
+ * processing.
+ */
+ const Key *k;
+ for (k = config.keys; k < config.keys + config.nkeys; k++) {
+ if (CLEANMASK(mods) == CLEANMASK(k->mod)
+ && xkb_keysym_to_lower(sym) == xkb_keysym_to_lower(k->keysym)
+ && k->func) {
+ return k;
+ }
+ }
+ return NULL;
+}
+
+void
+keypress(struct wl_listener *listener, void *data)
+{
+ int i;
+ /* This event is raised when a key is pressed or released. */
+ KeyboardGroup *group = wl_container_of(listener, group, key);
+ struct wlr_keyboard_key_event *event = data;
+
+ /* Translate libinput keycode -> xkbcommon */
+ uint32_t keycode = event->keycode + 8;
+ /* Get a list of keysyms based on the keymap for this keyboard */
+ const xkb_keysym_t *syms;
+ int nsyms = xkb_state_key_get_syms(
+ group->wlr_group->keyboard.xkb_state, keycode, &syms);
+
+ int handled = 0;
+ uint32_t mods = wlr_keyboard_get_modifiers(&group->wlr_group->keyboard);
+
+ wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
+
+ /* On _press_ if there is no active screen locker,
+ * attempt to process a compositor keybinding. */
+ if (!locked && event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
+ for (i = 0; i < nsyms; i++) {
+ const Key *key = keybinding(mods, syms[i]);
+ if (key) {
+ consumed[event->keycode] = 1;
+ key->func(&key->arg);
+ handled = 1;
+ }
+ }
+ }
+
+ if (handled && group->wlr_group->keyboard.repeat_info.delay > 0) {
+ group->mods = mods;
+ group->keysyms = syms;
+ group->nsyms = nsyms;
+ wl_event_source_timer_update(group->key_repeat_source,
+ group->wlr_group->keyboard.repeat_info.delay);
+ } else {
+ group->nsyms = 0;
+ wl_event_source_timer_update(group->key_repeat_source, 0);
+ }
+
+ if (handled)
+ return;
+
+ if (consumed[event->keycode]) {
+ if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED)
+ consumed[event->keycode] = 0;
+ return; /* Don't pass to the client the release event of a handled key-press */
+ }
+ wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard);
+ /* Pass unhandled keycodes along to the client. */
+ wlr_seat_keyboard_notify_key(seat, event->time_msec,
+ event->keycode, event->state);
+}
+
+void
+keypressmod(struct wl_listener *listener, void *data)
+{
+ /* This event is raised when a modifier key, such as shift or alt, is
+ * pressed. We simply communicate this to the client. */
+ KeyboardGroup *group = wl_container_of(listener, group, modifiers);
+
+ wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard);
+ /* Send modifiers to the client. */
+ wlr_seat_keyboard_notify_modifiers(seat,
+ &group->wlr_group->keyboard.modifiers);
+}
+
+int
+keyrepeat(void *data)
+{
+ KeyboardGroup *group = data;
+ int i;
+ if (!group->nsyms || group->wlr_group->keyboard.repeat_info.rate <= 0)
+ return 0;
+
+ wl_event_source_timer_update(group->key_repeat_source,
+ 1000 / group->wlr_group->keyboard.repeat_info.rate);
+
+ for (i = 0; i < group->nsyms; i++) {
+ const Key *key = keybinding(group->mods, group->keysyms[i]);
+ if (key)
+ key->func(&key->arg);
+ }
+
+ return 0;
+}
+
+void
+killclient(const Arg *arg)
+{
+ Client *sel = focustop(selmon, 0);
+ if (sel)
+ client_send_close(sel);
+}
+
+void
+motionabsolute(struct wl_listener *listener, void *data)
+{
+ /* This event is forwarded by the cursor when a pointer emits an _absolute_
+ * motion event, from 0..1 on each axis. This happens, for example, when
+ * wlroots is running under a Wayland window rather than KMS+DRM, and you
+ * move the mouse over the window. You could enter the window from any edge,
+ * so we have to warp the mouse there. Also, some hardware emits these events. */
+ struct wlr_pointer_motion_absolute_event *event = data;
+ double lx, ly, dx, dy;
+
+ if (!event->time_msec) /* this is 0 with virtual pointers */
+ wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, event->y);
+
+ wlr_cursor_absolute_to_layout_coords(cursor, &event->pointer->base, event->x, event->y, &lx, &ly);
+ dx = lx - cursor->x;
+ dy = ly - cursor->y;
+ motionnotify(event->time_msec, &event->pointer->base, dx, dy, dx, dy);
+}
+
+void
+motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy,
+ double dx_unaccel, double dy_unaccel)
+{
+ double sx = 0, sy = 0, sx_confined, sy_confined;
+ Client *c = NULL, *w = NULL;
+ LayerSurface *l = NULL;
+ struct wlr_surface *surface = NULL;
+ struct wlr_pointer_constraint_v1 *constraint;
+
+ /* Find the client under the pointer and send the event along. */
+ xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy);
+
+ if (cursor_mode == CurPressed && !seat->drag
+ && surface != seat->pointer_state.focused_surface
+ && toplevel_from_wlr_surface(seat->pointer_state.focused_surface, &w, &l) >= 0) {
+ c = w;
+ surface = seat->pointer_state.focused_surface;
+ sx = cursor->x - (l ? l->scene->node.x : w->geom.x);
+ sy = cursor->y - (l ? l->scene->node.y : w->geom.y);
+ }
+
+ /* time is 0 in internal calls meant to restore pointer focus. */
+ if (time) {
+ wlr_relative_pointer_manager_v1_send_relative_motion(
+ relative_pointer_mgr, seat, (uint64_t)time * 1000,
+ dx, dy, dx_unaccel, dy_unaccel);
+
+ wl_list_for_each(constraint, &pointer_constraints->constraints, link)
+ cursorconstrain(constraint);
+
+ if (active_constraint && cursor_mode != CurResize && cursor_mode != CurMove) {
+ toplevel_from_wlr_surface(active_constraint->surface, &c, NULL);
+ if (c && active_constraint->surface == seat->pointer_state.focused_surface) {
+ sx = cursor->x - c->geom.x - c->bw;
+ sy = cursor->y - c->geom.y - c->bw;
+ if (wlr_region_confine(&active_constraint->region, sx, sy,
+ sx + dx, sy + dy, &sx_confined, &sy_confined)) {
+ dx = sx_confined - sx;
+ dy = sy_confined - sy;
+ }
+
+ if (active_constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED)
+ return;
+ }
+ }
+
+ wlr_cursor_move(cursor, device, dx, dy);
+ wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
+ handlecursoractivity();
+
+ /* Update selmon (even while dragging a window) */
+ if (config.sloppyfocus)
+ selmon = xytomon(cursor->x, cursor->y);
+ }
+
+ /* Update drag icon's position */
+ wlr_scene_node_set_position(&drag_icon->node, (int)round(cursor->x), (int)round(cursor->y));
+
+ /* If we are currently grabbing the mouse, handle and return */
+ if (cursor_mode == CurMove) {
+ /* Move the grabbed client to the new position. */
+ resize(grabc, (struct wlr_box){.x = (int)round(cursor->x) - grabcx, .y = (int)round(cursor->y) - grabcy,
+ .width = grabc->geom.width, .height = grabc->geom.height}, 1, 1);
+ return;
+ } else if (cursor_mode == CurResize) {
+ if (grabcenterx < grabx) {
+ if (grabcentery < graby) {
+ /* bottom-right */
+ resize(grabc, (struct wlr_box){.x = initial_grabc.geom.x, .y = initial_grabc.geom.y,
+ .width = (int)round(cursor->x) - initial_grabc.geom.x, .height = (int)round(cursor->y) - initial_grabc.geom.y}, 1, 1);
+ } else {
+ /* top-right */
+ resize(grabc, (struct wlr_box){.x = initial_grabc.geom.x, .y = (int)round(cursor->y),
+ .width = (int)round(cursor->x) - initial_grabc.geom.x, .height = initial_grabc.geom.y + initial_grabc.geom.height - (int)round(cursor->y)}, 1, 1);
+ }
+ } else {
+ if (grabcentery < graby) {
+ /* bottom-left */
+ resize(grabc, (struct wlr_box){.x = (int)round(cursor->x), .y = initial_grabc.geom.y,
+ .width = initial_grabc.geom.x + initial_grabc.geom.width - (int)round(cursor->x), .height = (int)round(cursor->y) - initial_grabc.geom.y}, 1, 1);
+ } else {
+ /* top-left */
+ resize(grabc, (struct wlr_box){.x = (int)round(cursor->x), .y = (int)round(cursor->y),
+ .width = initial_grabc.geom.x + initial_grabc.geom.width - (int)round(cursor->x), .height = initial_grabc.geom.y + initial_grabc.geom.height - (int)round(cursor->y)}, 1, 1);
+ }
+ }
+ return;
+ }
+
+ /* If there's no client surface under the cursor, set the cursor image to a
+ * default. This is what makes the cursor image appear when you move it
+ * off of a client or over its border. */
+ if (!surface && !seat->drag && !cursor_hidden)
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "default");
+
+ pointerfocus(c, surface, sx, sy, time);
+}
+
+void
+motionrelative(struct wl_listener *listener, void *data)
+{
+ /* This event is forwarded by the cursor when a pointer emits a _relative_
+ * pointer motion event (i.e. a delta) */
+ struct wlr_pointer_motion_event *event = data;
+ /* The cursor doesn't move unless we tell it to. The cursor automatically
+ * handles constraining the motion to the output layout, as well as any
+ * special configuration applied for the specific input device which
+ * generated the event. You can pass NULL for the device if you want to move
+ * the cursor around without any input. */
+ motionnotify(event->time_msec, &event->pointer->base, event->delta_x, event->delta_y,
+ event->unaccel_dx, event->unaccel_dy);
+}
+
+void
+moveresize(const Arg *arg)
+{
+ if (cursor_mode != CurNormal && cursor_mode != CurPressed)
+ return;
+ xytonode(cursor->x, cursor->y, NULL, &grabc, NULL, NULL, NULL);
+ if (!grabc || client_is_unmanaged(grabc) || grabc->isfullscreen)
+ return;
+
+ /* Float the window and tell motionnotify to grab it */
+ setfloating(grabc, 1);
+ switch (cursor_mode = arg->ui) {
+ case CurMove:
+ grabcx = (int)round(cursor->x) - grabc->geom.x;
+ grabcy = (int)round(cursor->y) - grabc->geom.y;
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "all-scroll");
+ break;
+ case CurResize:
+ initial_grabc = *grabc;
+ grabx = (int)round(cursor->x);
+ graby = (int)round(cursor->y);
+ grabcx = (int)round(cursor->x) - grabc->geom.x;
+ grabcy = (int)round(cursor->y) - grabc->geom.y;
+ grabcenterx = grabc->geom.width / 2 + grabc->geom.x;
+ grabcentery = grabc->geom.height / 2 + grabc->geom.y;
+ if (grabcenterx < grabx) {
+ if (grabcentery < graby) {
+ /* bottom-right */
+ wlr_cursor_warp_closest(cursor, NULL,
+ grabc->geom.x + grabc->geom.width,
+ grabc->geom.y + grabc->geom.height);
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "se-resize");
+ } else {
+ /* top-right */
+ wlr_cursor_warp_closest(cursor, NULL,
+ grabc->geom.x + grabc->geom.width,
+ grabc->geom.y);
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "ne-resize");
+ }
+ } else {
+ if (grabcentery < graby) {
+ /* bottom-left */
+ wlr_cursor_warp_closest(cursor, NULL,
+ grabc->geom.x,
+ grabc->geom.y + grabc->geom.height);
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "sw-resize");
+ } else {
+ /* top-left */
+ wlr_cursor_warp_closest(cursor, NULL,
+ grabc->geom.x,
+ grabc->geom.y);
+ wlr_cursor_set_xcursor(cursor, cursor_mgr, "nw-resize");
+ }
+ }
+ break;
+ }
+}
+
+void
+spawn(const Arg *arg)
+{
+ if (fork() == 0) {
+ setrlimit(RLIMIT_CORE, &oldrlimit);
+ dup2(STDERR_FILENO, STDOUT_FILENO);
+ setsid();
+ execvp(((char **)arg->v)[0], (char **)arg->v);
+ die("ether: execvp %s failed:", ((char **)arg->v)[0]);
+ }
+}
+
+void
+virtualkeyboard(struct wl_listener *listener, void *data)
+{
+ struct wlr_virtual_keyboard_v1 *kb = data;
+ /* virtual keyboards shouldn't share keyboard group */
+ KeyboardGroup *group = createkeyboardgroup();
+ /* Set the keymap to match the group keymap */
+ wlr_keyboard_set_keymap(&kb->keyboard, group->wlr_group->keyboard.keymap);
+ LISTEN(&kb->keyboard.base.events.destroy, &group->destroy, destroykeyboardgroup);
+
+ /* Add the new keyboard to the group */
+ wlr_keyboard_group_add_keyboard(group->wlr_group, &kb->keyboard);
+}
+
+void
+virtualpointer(struct wl_listener *listener, void *data)
+{
+ struct wlr_virtual_pointer_v1_new_pointer_event *event = data;
+ struct wlr_input_device *device = &event->new_pointer->pointer.base;
+
+ wlr_cursor_attach_input_device(cursor, device);
+ if (event->suggested_output)
+ wlr_cursor_map_input_to_output(cursor, device, event->suggested_output);
+ handlecursoractivity();
+}
+
+static void
+createtablet(struct wlr_input_device *device)
+{
+ if (!tablet) {
+ struct libinput_device *device_handle = NULL;
+ if (!wlr_input_device_is_libinput(device) ||
+ !(device_handle = wlr_libinput_get_device_handle(device)))
+ return;
+ tablet = wlr_tablet_create(tablet_mgr, seat, device);
+ wl_signal_add(&tablet->wlr_device->events.destroy, &tablet_device_destroy);
+ if (libinput_device_config_send_events_get_modes(device_handle)) {
+ libinput_device_config_send_events_set_mode(device_handle, config.send_events_mode);
+ wlr_cursor_attach_input_device(cursor, device);
+ }
+ } else if (device == tablet->wlr_device) {
+ wlr_log(WLR_ERROR, "createtablet: duplicate device");
+ } else {
+ wlr_log(WLR_ERROR, "createtablet: already have one tablet");
+ }
+}
+
+static void
+destroytablet(struct wl_listener *listener, void *data)
+{
+ wl_list_remove(&tablet_device_destroy.link);
+ wlr_cursor_detach_input_device(cursor, tablet->wlr_device);
+ tablet = NULL;
+}
+
+static void
+destroytabletpad(struct wl_listener *listener, void *data)
+{
+ wl_list_remove(&tablet_pad_button.link);
+ wl_list_remove(&tablet_pad_destroy.link);
+ tablet_pad = NULL;
+}
+
+static void
+destroytabletsurfacenotify(struct wl_listener *listener, void *data)
+{
+ if (tablet_curr_surface)
+ wl_list_remove(&destroy_tablet_surface_listener.link);
+ tablet_curr_surface = NULL;
+}
+
+static void
+destroytablettool(struct wl_listener *listener, void *data)
+{
+ destroytabletsurfacenotify(NULL, NULL);
+ tablet_tool = NULL;
+}
+
+static void
+tabletapplymap(double x, double y, struct wlr_input_device *dev)
+{
+ Client *p;
+ struct wlr_box geom = {0};
+ if (config.tabletmaptosurface && tablet_curr_surface) {
+ toplevel_from_wlr_surface(tablet_curr_surface, &p, NULL);
+ if (p) {
+ for (; client_get_parent(p); p = client_get_parent(p));
+ geom.x = p->geom.x + p->bw;
+ geom.y = p->geom.y + p->bw;
+ geom.width = p->geom.width - 2 * p->bw;
+ geom.height = p->geom.height - 2 * p->bw;
+ wlr_cursor_map_input_to_region(cursor, dev, &geom);
+ }
+ }
+ wlr_cursor_map_input_to_output(cursor, dev, selmon->wlr_output);
+}
+
+void
+tabletpadbutton(struct wl_listener *listener, void *data)
+{
+ struct wlr_tablet_pad_button_event *event = data;
+ const TabletPadButton *pb;
+
+ for (pb = config.tabletpadbuttons;
+ pb < config.tabletpadbuttons + config.ntabletpadbuttons; pb++) {
+ if (event->button == pb->button
+ && event->state == pb->state
+ && pb->func)
+ pb->func(&pb->arg);
+ }
+
+ if (tablet_pad)
+ wlr_tablet_v2_tablet_pad_notify_button(tablet_pad,
+ event->button, event->time_msec,
+ (enum zwp_tablet_pad_v2_button_state)event->state);
+}
+
+static void
+tablettoolmotion(struct wlr_tablet_v2_tablet_tool *tool, int change_x, int change_y,
+ double x, double y, double dx, double dy, uint32_t time)
+{
+ struct wlr_surface *surface = NULL;
+ double sx, sy;
+
+ if (!change_x && !change_y)
+ return;
+
+ tabletapplymap(x, y, tablet->wlr_device);
+
+ x = (MAX(config.tablet_area[0],
+ MIN(config.tablet_area[0] + config.tablet_area[2], x))
+ - config.tablet_area[0]) / config.tablet_area[2];
+ y = (MAX(config.tablet_area[1],
+ MIN(config.tablet_area[1] + config.tablet_area[3], y))
+ - config.tablet_area[1]) / config.tablet_area[3];
+
+ switch (tablet_tool->wlr_tool->type) {
+ case WLR_TABLET_TOOL_TYPE_LENS:
+ case WLR_TABLET_TOOL_TYPE_MOUSE:
+ wlr_cursor_move(cursor, tablet->wlr_device, dx, dy);
+ break;
+ default:
+ wlr_cursor_warp_absolute(cursor, tablet->wlr_device,
+ change_x ? x : NAN, change_y ? y : NAN);
+ break;
+ }
+
+ motionnotify(time, NULL, 0, 0, 0, 0);
+
+ xytonode(cursor->x, cursor->y, &surface, NULL, NULL, &sx, &sy);
+ if (surface && !wlr_surface_accepts_tablet_v2(surface, tablet))
+ surface = NULL;
+
+ if (surface != tablet_curr_surface) {
+ if (tablet_curr_surface) {
+ if (tablet_tool)
+ wlr_tablet_v2_tablet_tool_notify_proximity_out(tablet_tool);
+ if (tablet_pad)
+ wlr_tablet_v2_tablet_pad_notify_leave(tablet_pad, tablet_curr_surface);
+ wl_list_remove(&destroy_tablet_surface_listener.link);
+ }
+ if (surface) {
+ if (tablet_pad)
+ wlr_tablet_v2_tablet_pad_notify_enter(tablet_pad, tablet, surface);
+ if (tablet_tool)
+ wlr_tablet_v2_tablet_tool_notify_proximity_in(tablet_tool, tablet, surface);
+ wl_signal_add(&surface->events.destroy, &destroy_tablet_surface_listener);
+ }
+ tablet_curr_surface = surface;
+ }
+
+ if (surface)
+ wlr_tablet_v2_tablet_tool_notify_motion(tablet_tool, sx, sy);
+}
+
+void
+tablettoolproximity(struct wl_listener *listener, void *data)
+{
+ struct wlr_tablet_tool_proximity_event *event = data;
+ struct wlr_tablet_tool *tool = event->tool;
+
+ if (!tablet_tool) {
+ tablet_tool = wlr_tablet_tool_create(tablet_mgr, seat, tool);
+ wl_signal_add(&tablet_tool->wlr_tool->events.destroy, &tablet_tool_destroy);
+ wl_signal_add(&tablet_tool->events.set_cursor, &request_cursor);
+ }
+
+ switch (event->state) {
+ case WLR_TABLET_TOOL_PROXIMITY_OUT:
+ if (tablet_tool)
+ wlr_tablet_v2_tablet_tool_notify_proximity_out(tablet_tool);
+ destroytabletsurfacenotify(NULL, NULL);
+ break;
+ case WLR_TABLET_TOOL_PROXIMITY_IN:
+ tablettoolmotion(tablet_tool, 1, 1, event->x, event->y, 0, 0, event->time_msec);
+ break;
+ }
+}
+
+void
+tablettoolaxis(struct wl_listener *listener, void *data)
+{
+ struct wlr_tablet_tool_axis_event *event = data;
+ double x, y;
+
+ x = event->x;
+ y = event->y;
+
+ tablettoolmotion(tablet_tool,
+ event->updated_axes & WLR_TABLET_TOOL_AXIS_X,
+ event->updated_axes & WLR_TABLET_TOOL_AXIS_Y,
+ x, y, event->dx, event->dy, event->time_msec);
+
+ if (event->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE)
+ wlr_tablet_v2_tablet_tool_notify_pressure(tablet_tool, event->pressure);
+ if (event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE)
+ wlr_tablet_v2_tablet_tool_notify_distance(tablet_tool, event->distance);
+ if (event->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_X)
+ tilt_x = event->tilt_x;
+ if (event->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_Y)
+ tilt_y = event->tilt_y;
+ if (event->updated_axes & (WLR_TABLET_TOOL_AXIS_TILT_X | WLR_TABLET_TOOL_AXIS_TILT_Y))
+ wlr_tablet_v2_tablet_tool_notify_tilt(tablet_tool, tilt_x, tilt_y);
+ if (event->updated_axes & WLR_TABLET_TOOL_AXIS_ROTATION)
+ wlr_tablet_v2_tablet_tool_notify_rotation(tablet_tool, event->rotation);
+ if (event->updated_axes & WLR_TABLET_TOOL_AXIS_SLIDER)
+ wlr_tablet_v2_tablet_tool_notify_slider(tablet_tool, event->slider);
+ if (event->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL)
+ wlr_tablet_v2_tablet_tool_notify_wheel(tablet_tool, event->wheel_delta, 0);
+}
+
+void
+tablettoolbutton(struct wl_listener *listener, void *data)
+{
+ struct wlr_tablet_tool_button_event *event = data;
+ const TabletButton *tb;
+
+ for (tb = config.tabletbuttons; tb < config.tabletbuttons + config.ntabletbuttons; tb++) {
+ if (event->button == tb->button
+ && event->state == tb->state
+ && tb->func)
+ tb->func(&tb->arg);
+ }
+
+ wlr_tablet_v2_tablet_tool_notify_button(tablet_tool, event->button,
+ (enum zwp_tablet_pad_v2_button_state)event->state);
+}
+
+void
+tablettooltip(struct wl_listener *listener, void *data)
+{
+ struct wlr_tablet_tool_tip_event *event = data;
+
+ if (!tablet_curr_surface) {
+ struct wlr_pointer_button_event fakeptrbtnevent = {
+ .button = BTN_LEFT,
+ .state = event->state == WLR_TABLET_TOOL_TIP_UP ?
+ WL_POINTER_BUTTON_STATE_RELEASED : WL_POINTER_BUTTON_STATE_PRESSED,
+ .time_msec = event->time_msec,
+ };
+ buttonpress(NULL, (void *)&fakeptrbtnevent);
+ }
+
+ if (event->state == WLR_TABLET_TOOL_TIP_UP) {
+ wlr_tablet_v2_tablet_tool_notify_up(tablet_tool);
+ return;
+ }
+
+ wlr_tablet_v2_tablet_tool_notify_down(tablet_tool);
+ wlr_tablet_tool_v2_start_implicit_grab(tablet_tool);
+}
diff --git a/src/layout.c b/src/layout.c
new file mode 100644
index 0000000..7a55633
--- /dev/null
+++ b/src/layout.c
@@ -0,0 +1,427 @@
+/*
+ * See LICENSE file for copyright and license details.
+ */
+#include <math.h>
+
+#include "ether.h"
+
+void
+arrange(Monitor *m)
+{
+ LayerSurface *l;
+ Client *c, *sel = focustop(m, 0);
+ int i;
+
+ if (!m->wlr_output->enabled)
+ return;
+
+ wl_list_for_each(c, &clients, link) {
+ if (c->mon == m) {
+ wlr_scene_node_set_enabled(&c->scene->node, VISIBLEON(c, m));
+ client_set_suspended(c, !VISIBLEON(c, m));
+ }
+ }
+
+ wlr_scene_node_set_enabled(&m->fullscreen_bg->node,
+ (c = focustop(m, 0)) && c->isfullscreen);
+
+ strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol));
+
+ /* We move all clients (except fullscreen and unmanaged) to LyrTile while
+ * in floating layout to avoid "real" floating clients be always on top */
+ wl_list_for_each(c, &clients, link) {
+ if (c->mon != m || c->scene->node.parent == layers[LyrFS])
+ continue;
+
+ wlr_scene_node_reparent(&c->scene->node,
+ (!m->lt[m->sellt]->arrange && c->isfloating)
+ ? layers[LyrTile]
+ : (m->lt[m->sellt]->arrange && c->isfloating)
+ ? layers[LyrFloat]
+ : c->scene->node.parent);
+ }
+
+ if (sel && sel->isfullscreen && VISIBLEON(sel, m)) {
+ for (i = 2; i > ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; i--) {
+ wl_list_for_each(l, &sel->mon->layers[i], link)
+ wlr_scene_node_set_enabled(&l->scene->node, 0);
+ }
+
+ wl_list_for_each(c, &clients, link) {
+ if (c->mon != m)
+ continue;
+ wlr_scene_node_set_enabled(&c->scene->node, (sel->isfullscreen && c == sel)
+ || !sel->isfullscreen);
+ }
+ }
+ if (!sel || (!sel->isfullscreen && VISIBLEON(sel, m))) {
+ for (i = 2; i > ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; i--) {
+ wl_list_for_each(l, &m->layers[i], link)
+ wlr_scene_node_set_enabled(&l->scene->node, 1);
+ }
+ }
+
+ if (m->lt[m->sellt]->arrange)
+ m->lt[m->sellt]->arrange(m);
+ motionnotify(0, NULL, 0, 0, 0, 0);
+ checkidleinhibitor(NULL);
+}
+
+void
+arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area, int exclusive)
+{
+ LayerSurface *l;
+ struct wlr_box full_area = m->m;
+
+ wl_list_for_each(l, list, link) {
+ struct wlr_layer_surface_v1 *layer_surface = l->layer_surface;
+
+ if (!layer_surface->initialized)
+ continue;
+
+ if (exclusive != (layer_surface->current.exclusive_zone > 0))
+ continue;
+
+ wlr_scene_layer_surface_v1_configure(l->scene_layer, &full_area, usable_area);
+ wlr_scene_node_set_position(&l->popups->node, l->scene->node.x, l->scene->node.y);
+ }
+}
+
+void
+arrangelayers(Monitor *m)
+{
+ int i;
+ struct wlr_box usable_area = m->m;
+ LayerSurface *l;
+ uint32_t layers_above_shell[] = {
+ ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
+ ZWLR_LAYER_SHELL_V1_LAYER_TOP,
+ };
+ if (!m->wlr_output->enabled)
+ return;
+
+ /* Arrange exclusive surfaces from top->bottom */
+ for (i = 3; i >= 0; i--)
+ arrangelayer(m, &m->layers[i], &usable_area, 1);
+
+ if (!wlr_box_equal(&usable_area, &m->w)) {
+ m->w = usable_area;
+ arrange(m);
+ }
+
+ /* Arrange non-exclusive surfaces from top->bottom */
+ for (i = 3; i >= 0; i--)
+ arrangelayer(m, &m->layers[i], &usable_area, 0);
+
+ /* Find topmost keyboard interactive layer, if such a layer exists */
+ for (i = 0; i < (int)LENGTH(layers_above_shell); i++) {
+ wl_list_for_each_reverse(l, &m->layers[layers_above_shell[i]], link) {
+ if (locked || !l->layer_surface->current.keyboard_interactive || !l->mapped)
+ continue;
+ /* Deactivate the focused client. */
+ focusclient(NULL, 0);
+ exclusive_focus = l;
+ client_notify_enter(l->layer_surface->surface, wlr_seat_get_keyboard(seat));
+ return;
+ }
+ }
+}
+
+void
+incnmaster(const Arg *arg)
+{
+ if (!arg || !selmon)
+ return;
+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
+ arrange(selmon);
+}
+
+void
+monocle(Monitor *m)
+{
+ Client *c;
+ int n = 0;
+
+ wl_list_for_each(c, &clients, link) {
+ if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ continue;
+ resize(c, m->w, 0, !config.smartborders);
+ n++;
+ }
+ if (n)
+ snprintf(m->ltsymbol, LENGTH(m->ltsymbol), "[%d]", n);
+ hidebehind(m);
+}
+
+void
+resize(Client *c, struct wlr_box geo, int interact, int draw_borders)
+{
+ struct wlr_box *bbox;
+ struct wlr_box clip;
+
+ if (!c->mon || !client_surface(c)->mapped)
+ return;
+
+ bbox = interact ? &sgeom : &c->mon->w;
+
+ client_set_bounds(c, geo.width, geo.height);
+ c->geom = geo;
+ c->bw = draw_borders ? BORDERPX(c) : 0;
+ applybounds(c, bbox);
+
+ /* Update scene-graph, including borders */
+ wlr_scene_node_set_position(&c->scene->node, c->geom.x, c->geom.y);
+ wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw);
+ wlr_scene_rect_set_size(c->border[0], c->geom.width, c->bw);
+ wlr_scene_rect_set_size(c->border[1], c->geom.width, c->bw);
+ wlr_scene_rect_set_size(c->border[2], c->bw, c->geom.height - 2 * c->bw);
+ wlr_scene_rect_set_size(c->border[3], c->bw, c->geom.height - 2 * c->bw);
+ wlr_scene_node_set_position(&c->border[1]->node, 0, c->geom.height - c->bw);
+ wlr_scene_node_set_position(&c->border[2]->node, 0, c->bw);
+ wlr_scene_node_set_position(&c->border[3]->node, c->geom.width - c->bw, c->bw);
+
+ /* this is a no-op if size hasn't changed */
+ c->resize = client_set_size(c, c->geom.width - 2 * c->bw,
+ c->geom.height - 2 * c->bw);
+ client_get_clip(c, &clip);
+ wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip);
+}
+
+void
+setlayout(const Arg *arg)
+{
+ if (!selmon)
+ return;
+ if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
+ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
+ if (arg && arg->v)
+ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
+ strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol));
+ if (!selmon->lt[selmon->sellt]->arrange) {
+ Client *c;
+
+ /* floating layout, draw borders around all clients */
+ wl_list_for_each(c, &clients, link)
+ resize(c, c->mon->m, 0, 1);
+ }
+ arrange(selmon);
+ printstatus();
+}
+
+/* arg > 1.0 will set mfact absolutely */
+void
+setmfact(const Arg *arg)
+{
+ float f;
+
+ if (!arg || !selmon || !selmon->lt[selmon->sellt]->arrange)
+ return;
+ f = arg->f < 1.0f ? arg->f + selmon->mfact : arg->f - 1.0f;
+ if (f < 0.1 || f > 0.9)
+ return;
+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
+ arrange(selmon);
+}
+
+void
+togglegaps(const Arg *arg)
+{
+ if (!selmon)
+ return;
+ selmon->gaps = !selmon->gaps;
+ arrange(selmon);
+}
+
+void
+deck(Monitor *m)
+{
+ unsigned int mw, my;
+ int i, n = 0;
+ Client *c;
+
+ /* count tiled clients */
+ wl_list_for_each(c, &clients, link)
+ if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen)
+ n++;
+ if (n == 0)
+ return;
+
+ if (n > m->nmaster)
+ mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
+ else
+ mw = m->w.width;
+ i = my = 0;
+ wl_list_for_each(c, &clients, link) {
+ if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ continue;
+ if (i < m->nmaster) {
+ resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + my,
+ .width = mw,
+ .height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0, 1);
+ my += c->geom.height;
+ c->ismaster = 1;
+ } else {
+ /* deck clients: overlap in stack area */
+ resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y,
+ .width = m->w.width - mw, .height = m->w.height}, 0, 1);
+ c->ismaster = 0;
+ }
+ i++;
+ }
+
+ hidebehind(m);
+}
+
+void
+tile(Monitor *m)
+{
+ unsigned int h, r, e = m->gaps, mw, my, ty;
+ int i, n = 0;
+ Client *c;
+ unsigned int draw_borders = 1;
+
+ wl_list_for_each(c, &clients, link)
+ if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen)
+ n++;
+ if (n == 0)
+ return;
+ if (config.smartgaps == n)
+ e = 0;
+ if (n == config.smartborders)
+ draw_borders = 0;
+
+ if (n > m->nmaster)
+ mw = m->nmaster ? (int)roundf((m->w.width + config.gappx * e) * m->mfact) : 0;
+ else
+ mw = m->w.width;
+ i = 0;
+ my = ty = config.gappx * e;
+ wl_list_for_each(c, &clients, link) {
+ if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ continue;
+ if (i < m->nmaster) {
+ r = MIN(n, m->nmaster) - i;
+ h = (m->w.height - my - config.gappx * e
+ - config.gappx * e * (r - 1)) / r;
+ resize(c, (struct wlr_box){.x = m->w.x + config.gappx * e,
+ .y = m->w.y + my, .width = mw - 2 * config.gappx * e,
+ .height = h}, 0, draw_borders);
+ my += c->geom.height + config.gappx * e;
+ } else {
+ r = n - i;
+ h = (m->w.height - ty - config.gappx * e
+ - config.gappx * e * (r - 1)) / r;
+ resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y + ty,
+ .width = m->w.width - mw - config.gappx * e, .height = h}, 0,
+ draw_borders);
+ ty += c->geom.height + config.gappx * e;
+ }
+ i++;
+ }
+}
+
+void
+movestack(const Arg *arg)
+{
+ Client *c, *sel = focustop(selmon, 0);
+
+ if (!sel || wl_list_length(&clients) <= 1)
+ return;
+
+ if (arg->i > 0) {
+ wl_list_for_each(c, &sel->link, link) {
+ if (&c->link == &clients) {
+ c = wl_container_of(&clients, c, link);
+ break; /* wrap past the sentinel node */
+ }
+ if (VISIBLEON(c, selmon) || &c->link == &clients)
+ break; /* found it */
+ }
+ } else {
+ wl_list_for_each_reverse(c, &sel->link, link) {
+ if (&c->link == &clients) {
+ c = wl_container_of(&clients, c, link);
+ break; /* wrap past the sentinel node */
+ }
+ if (VISIBLEON(c, selmon) || &c->link == &clients)
+ break; /* found it */
+ }
+ /* backup one client */
+ c = wl_container_of(c->link.prev, c, link);
+ }
+
+ wl_list_remove(&sel->link);
+ wl_list_insert(&c->link, &sel->link);
+ arrange(selmon);
+}
+
+void
+zoom(const Arg *arg)
+{
+ Client *c, *sel = focustop(selmon, 0);
+
+ if (!sel || !selmon || !selmon->lt[selmon->sellt]->arrange || sel->isfloating)
+ return;
+
+ /* Search for the first tiled window that is not sel, marking sel as
+ * NULL if we pass it along the way */
+ wl_list_for_each(c, &clients, link) {
+ if (VISIBLEON(c, selmon) && !c->isfloating) {
+ if (c != sel)
+ break;
+ sel = NULL;
+ }
+ }
+
+ /* Return if no other tiled window was found */
+ if (&c->link == &clients)
+ return;
+
+ /* If we passed sel, move c to the front; otherwise, move sel to the
+ * front */
+ if (!sel)
+ sel = c;
+ wl_list_remove(&sel->link);
+ wl_list_insert(&clients, &sel->link);
+
+ focusclient(sel, 1);
+ arrange(selmon);
+}
+
+void
+hidebehind(Monitor *m)
+{
+ Client *c;
+ int check1 = 0;
+
+ if (m) {
+ if (m->lt[m->sellt]->arrange == monocle) {
+ wl_list_for_each(c, &clients, link) {
+ if (c->mon != m)
+ continue;
+ wlr_scene_node_set_enabled(&c->scene->node, VISIBLEON(c, m) && c->isfloating);
+ }
+
+ c = NULL;
+
+ /* Enable top tiled client, fullscreen is considered tiled */
+ if ((c = focustop(m, 1)))
+ wlr_scene_node_set_enabled(&c->scene->node, 1);
+ } else if (m->lt[m->sellt]->arrange == deck) {
+ wl_list_for_each(c, &fstack, flink) {
+ if (!VISIBLEON(c, m))
+ continue;
+ if (c->isfloating || c->ismaster) {
+ wlr_scene_node_set_enabled(&c->scene->node, 1);
+ continue;
+ }
+ if (!check1 && !c->ismaster) {
+ wlr_scene_node_set_enabled(&c->scene->node, 1);
+ check1 = 1;
+ continue;
+ }
+ wlr_scene_node_set_enabled(&c->scene->node, 0);
+ }
+ }
+ }
+}
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..d18ccf4
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,585 @@
+/*
+ * See LICENSE file for copyright and license details.
+ */
+#include <getopt.h>
+#include <signal.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+
+#include "ether.h"
+
+/* variables */
+struct rlimit oldrlimit;
+struct rlimit newrlimit;
+pid_t child_pid = -1;
+int locked;
+void *exclusive_focus;
+struct wl_display *dpy;
+struct wl_event_loop *event_loop;
+struct wlr_backend *backend;
+struct wlr_scene *scene;
+struct wlr_scene_tree *layers[NUM_LAYERS];
+struct wlr_scene_tree *drag_icon;
+/* Map from ZWLR_LAYER_SHELL_* constants to Lyr* enum */
+const int layermap[] = { LyrBg, LyrBottom, LyrTop, LyrOverlay };
+struct wlr_renderer *drw;
+struct wlr_allocator *alloc;
+struct wlr_compositor *compositor;
+struct wlr_session *session;
+
+struct wlr_xdg_shell *xdg_shell;
+struct wlr_xdg_activation_v1 *activation;
+struct wlr_xdg_decoration_manager_v1 *xdg_decoration_mgr;
+struct wl_list clients; /* tiling order */
+struct wl_list fstack; /* focus order */
+struct wlr_idle_notifier_v1 *idle_notifier;
+struct wlr_idle_inhibit_manager_v1 *idle_inhibit_mgr;
+struct wlr_layer_shell_v1 *layer_shell;
+struct wlr_output_manager_v1 *output_mgr;
+struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr;
+struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr;
+struct wlr_cursor_shape_manager_v1 *cursor_shape_mgr;
+struct wlr_tablet_manager_v2 *tablet_mgr;
+struct wlr_output_power_manager_v1 *power_mgr;
+
+struct wlr_pointer_constraints_v1 *pointer_constraints;
+struct wlr_relative_pointer_manager_v1 *relative_pointer_mgr;
+struct wlr_pointer_constraint_v1 *active_constraint;
+
+struct wlr_cursor *cursor;
+struct wlr_xcursor_manager *cursor_mgr;
+struct wl_event_source *hide_source;
+int cursor_hidden;
+struct cursor_image_cache last_cursor;
+
+struct wlr_scene_rect *root_bg;
+struct wlr_session_lock_manager_v1 *session_lock_mgr;
+struct wlr_scene_rect *locked_bg;
+struct wlr_session_lock_v1 *cur_lock;
+
+struct wlr_seat *seat;
+KeyboardGroup *kb_group;
+unsigned int cursor_mode;
+Client *grabc;
+Client initial_grabc;
+int grabcx, grabcy, grabx, graby, grabcenterx, grabcentery; /* client-relative */
+
+struct wlr_output_layout *output_layout;
+struct wlr_box sgeom;
+struct wl_list mons;
+Monitor *selmon;
+int consumed[KEY_MAX + 1];
+
+PtrDev ptr_devs[MAX_PTR_DEVS];
+int nptr_devs;
+
+/* global event listeners */
+struct wl_listener cursor_axis = {.notify = axisnotify};
+struct wl_listener cursor_button = {.notify = buttonpress};
+struct wl_listener cursor_frame = {.notify = cursorframe};
+struct wl_listener cursor_motion = {.notify = motionrelative};
+struct wl_listener cursor_motion_absolute = {.notify = motionabsolute};
+struct wl_listener tablet_tool_axis = {.notify = tablettoolaxis};
+struct wl_listener tablet_tool_button = {.notify = tablettoolbutton};
+struct wl_listener tablet_tool_proximity = {.notify = tablettoolproximity};
+struct wl_listener tablet_tool_tip = {.notify = tablettooltip};
+struct wl_listener gpu_reset = {.notify = gpureset};
+struct wl_listener layout_change = {.notify = updatemons};
+struct wl_listener new_idle_inhibitor = {.notify = createidleinhibitor};
+struct wl_listener new_input_device = {.notify = inputdevice};
+struct wl_listener new_virtual_keyboard = {.notify = virtualkeyboard};
+struct wl_listener new_virtual_pointer = {.notify = virtualpointer};
+struct wl_listener new_pointer_constraint = {.notify = createpointerconstraint};
+struct wl_listener new_output = {.notify = createmon};
+struct wl_listener new_xdg_toplevel = {.notify = createnotify};
+struct wl_listener new_xdg_popup = {.notify = createpopup};
+struct wl_listener new_xdg_decoration = {.notify = createdecoration};
+struct wl_listener new_layer_surface = {.notify = createlayersurface};
+struct wl_listener output_mgr_apply = {.notify = outputmgrapply};
+struct wl_listener output_mgr_test = {.notify = outputmgrtest};
+struct wl_listener output_power_mgr_set_mode = {.notify = powermgrsetmode};
+struct wl_listener request_activate = {.notify = urgent};
+struct wl_listener request_cursor = {.notify = setcursor};
+struct wl_listener request_set_psel = {.notify = setpsel};
+struct wl_listener request_set_sel = {.notify = setsel};
+struct wl_listener request_set_cursor_shape = {.notify = setcursorshape};
+struct wl_listener request_start_drag = {.notify = requeststartdrag};
+struct wl_listener start_drag = {.notify = startdrag};
+struct wl_listener new_session_lock = {.notify = locksession};
+#ifdef XWAYLAND
+struct wl_listener new_xwayland_surface = {.notify = createnotifyx11};
+struct wl_listener xwayland_ready = {.notify = xwaylandready};
+struct wlr_xwayland *xwayland;
+#endif
+
+void
+handlesig(int signo)
+{
+ if (signo == SIGCHLD)
+ while (waitpid(-1, NULL, WNOHANG) > 0);
+ else if (signo == SIGINT || signo == SIGTERM)
+ quit(NULL);
+}
+
+void
+handlecursoractivity(void)
+{
+ wl_event_source_timer_update(hide_source, config.cursor_timeout * 1000);
+
+ if (cursor_hidden) {
+ cursor_hidden = 0;
+
+ if (last_cursor.shape)
+ wlr_cursor_set_xcursor(cursor, cursor_mgr,
+ wlr_cursor_shape_v1_name(last_cursor.shape));
+ else
+ wlr_cursor_set_surface(cursor, last_cursor.surface,
+ last_cursor.hotspot_x, last_cursor.hotspot_y);
+ }
+}
+
+int
+hidecursor(void *data)
+{
+ wlr_cursor_unset_image(cursor);
+ cursor_hidden = 1;
+ return 1;
+}
+
+void
+cleanup(void)
+{
+ cleanuplisteners();
+ free_config();
+#ifdef XWAYLAND
+ wlr_xwayland_destroy(xwayland);
+ xwayland = NULL;
+#endif
+ wl_display_destroy_clients(dpy);
+ if (child_pid > 0) {
+ kill(-child_pid, SIGTERM);
+ waitpid(child_pid, NULL, 0);
+ }
+ wlr_xcursor_manager_destroy(cursor_mgr);
+
+ destroykeyboardgroup(&kb_group->destroy, NULL);
+
+ /* If it's not destroyed manually, it will cause a use-after-free of wlr_seat.
+ * Destroy it until it's fixed on the wlroots side */
+ wlr_backend_destroy(backend);
+
+ wl_display_destroy(dpy);
+ /* Destroy after the wayland display (when the monitors are already destroyed)
+ to avoid destroying them with an invalid scene output. */
+ wlr_scene_node_destroy(&scene->tree.node);
+}
+
+void
+cleanuplisteners(void)
+{
+ wl_list_remove(&cursor_axis.link);
+ wl_list_remove(&cursor_button.link);
+ wl_list_remove(&cursor_frame.link);
+ wl_list_remove(&cursor_motion.link);
+ wl_list_remove(&cursor_motion_absolute.link);
+ wl_list_remove(&gpu_reset.link);
+ wl_list_remove(&new_idle_inhibitor.link);
+ wl_list_remove(&layout_change.link);
+ wl_list_remove(&new_input_device.link);
+ wl_list_remove(&new_virtual_keyboard.link);
+ wl_list_remove(&new_virtual_pointer.link);
+ wl_list_remove(&new_pointer_constraint.link);
+ wl_list_remove(&new_output.link);
+ wl_list_remove(&new_xdg_toplevel.link);
+ wl_list_remove(&new_xdg_decoration.link);
+ wl_list_remove(&new_xdg_popup.link);
+ wl_list_remove(&new_layer_surface.link);
+ wl_list_remove(&output_mgr_apply.link);
+ wl_list_remove(&output_mgr_test.link);
+ wl_list_remove(&output_power_mgr_set_mode.link);
+ wl_list_remove(&request_activate.link);
+ wl_list_remove(&request_cursor.link);
+ wl_list_remove(&request_set_psel.link);
+ wl_list_remove(&request_set_sel.link);
+ wl_list_remove(&request_set_cursor_shape.link);
+ wl_list_remove(&request_start_drag.link);
+ wl_list_remove(&start_drag.link);
+ wl_list_remove(&new_session_lock.link);
+#ifdef XWAYLAND
+ wl_list_remove(&new_xwayland_surface.link);
+ wl_list_remove(&xwayland_ready.link);
+#endif
+}
+
+void
+quit(const Arg *arg)
+{
+ wl_display_terminate(dpy);
+}
+
+void
+setpsel(struct wl_listener *listener, void *data)
+{
+ /* This event is raised by the seat when a client wants to set the selection,
+ * usually when the user copies something. wlroots allows compositors to
+ * ignore such requests if they so choose, but in ether we always honor them
+ */
+ struct wlr_seat_request_set_primary_selection_event *event = data;
+ wlr_seat_set_primary_selection(seat, event->source, event->serial);
+}
+
+void
+setsel(struct wl_listener *listener, void *data)
+{
+ /* This event is raised by the seat when a client wants to set the selection,
+ * usually when the user copies something. wlroots allows compositors to
+ * ignore such requests if they so choose, but in ether we always honor them
+ */
+ struct wlr_seat_request_set_selection_event *event = data;
+ wlr_seat_set_selection(seat, event->source, event->serial);
+}
+
+void
+setup(void)
+{
+ int drm_fd, i, sig[] = {SIGCHLD, SIGINT, SIGTERM, SIGPIPE};
+ struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = handlesig};
+ sigemptyset(&sa.sa_mask);
+
+ for (i = 0; i < (int)LENGTH(sig); i++)
+ sigaction(sig[i], &sa, NULL);
+
+ wlr_log_init(config.log_level, NULL);
+
+ /* The Wayland display is managed by libwayland. It handles accepting
+ * clients from the Unix socket, managing Wayland globals, and so on. */
+ dpy = wl_display_create();
+ event_loop = wl_display_get_event_loop(dpy);
+
+ /* The backend is a wlroots feature which abstracts the underlying input and
+ * output hardware. The autocreate option will choose the most suitable
+ * backend based on the current environment, such as opening an X11 window
+ * if an X11 server is running. */
+ if (!(backend = wlr_backend_autocreate(event_loop, &session)))
+ die("couldn't create backend");
+
+ /* Initialize the scene graph used to lay out windows */
+ scene = wlr_scene_create();
+ root_bg = wlr_scene_rect_create(&scene->tree, 0, 0, config.rootcolor);
+ for (i = 0; i < NUM_LAYERS; i++)
+ layers[i] = wlr_scene_tree_create(&scene->tree);
+ drag_icon = wlr_scene_tree_create(&scene->tree);
+ wlr_scene_node_place_below(&drag_icon->node, &layers[LyrBlock]->node);
+
+ /* Autocreates a renderer, either Pixman, GLES2 or Vulkan for us. The user
+ * can also specify a renderer using the WLR_RENDERER env var.
+ * The renderer is responsible for defining the various pixel formats it
+ * supports for shared memory, this configures that for clients. */
+ if (!(drw = wlr_renderer_autocreate(backend)))
+ die("couldn't create renderer");
+ wl_signal_add(&drw->events.lost, &gpu_reset);
+
+ /* Create shm, drm and linux_dmabuf interfaces by ourselves.
+ * The simplest way is to call:
+ * wlr_renderer_init_wl_display(drw);
+ * but we need to create the linux_dmabuf interface manually to integrate it
+ * with wlr_scene. */
+ wlr_renderer_init_wl_shm(drw, dpy);
+
+ if (wlr_renderer_get_texture_formats(drw, WLR_BUFFER_CAP_DMABUF)) {
+ wlr_drm_create(dpy, drw);
+ wlr_scene_set_linux_dmabuf_v1(scene,
+ wlr_linux_dmabuf_v1_create_with_renderer(dpy, 5, drw));
+ }
+
+ if ((drm_fd = wlr_renderer_get_drm_fd(drw)) >= 0 && drw->features.timeline
+ && backend->features.timeline)
+ wlr_linux_drm_syncobj_manager_v1_create(dpy, 1, drm_fd);
+
+ /* Autocreates an allocator for us.
+ * The allocator is the bridge between the renderer and the backend. It
+ * handles the buffer creation, allowing wlroots to render onto the
+ * screen */
+ if (!(alloc = wlr_allocator_autocreate(backend, drw)))
+ die("couldn't create allocator");
+
+ /* This creates some hands-off wlroots interfaces. The compositor is
+ * necessary for clients to allocate surfaces and the data device manager
+ * handles the clipboard. Each of these wlroots interfaces has room for you
+ * to dig your fingers in and play with their behavior if you want. Note that
+ * the clients cannot set the selection directly without compositor approval,
+ * see the setsel() function. */
+ compositor = wlr_compositor_create(dpy, 6, drw);
+ wlr_subcompositor_create(dpy);
+ wlr_data_device_manager_create(dpy);
+ wlr_export_dmabuf_manager_v1_create(dpy);
+ wlr_screencopy_manager_v1_create(dpy);
+ wlr_ext_image_copy_capture_manager_v1_create(dpy, 1);
+ wlr_ext_output_image_capture_source_manager_v1_create(dpy, 1);
+ wlr_data_control_manager_v1_create(dpy);
+ wlr_ext_data_control_manager_v1_create(dpy, 1);
+ wlr_primary_selection_v1_device_manager_create(dpy);
+ wlr_viewporter_create(dpy);
+ wlr_single_pixel_buffer_manager_v1_create(dpy);
+ wlr_fractional_scale_manager_v1_create(dpy, 1);
+ wlr_presentation_create(dpy, backend, 2);
+ wlr_alpha_modifier_v1_create(dpy);
+
+ /* Initializes the interface used to implement urgency hints */
+ activation = wlr_xdg_activation_v1_create(dpy);
+ wl_signal_add(&activation->events.request_activate, &request_activate);
+
+ wlr_scene_set_gamma_control_manager_v1(scene, wlr_gamma_control_manager_v1_create(dpy));
+
+ power_mgr = wlr_output_power_manager_v1_create(dpy);
+ wl_signal_add(&power_mgr->events.set_mode, &output_power_mgr_set_mode);
+
+ /* Creates an output layout, which is a wlroots utility for working with an
+ * arrangement of screens in a physical layout. */
+ output_layout = wlr_output_layout_create(dpy);
+ wl_signal_add(&output_layout->events.change, &layout_change);
+
+ wlr_xdg_output_manager_v1_create(dpy, output_layout);
+
+ /* Configure a listener to be notified when new outputs are available on the
+ * backend. */
+ wl_list_init(&mons);
+ wl_signal_add(&backend->events.new_output, &new_output);
+
+ /* Set up our client lists, the xdg-shell and the layer-shell. The xdg-shell is a
+ * Wayland protocol which is used for application windows. For more
+ * detail on shells, refer to the article:
+ *
+ * https://drewdevault.com/2018/07/29/Wayland-shells.html
+ */
+ wl_list_init(&clients);
+ wl_list_init(&fstack);
+
+ xdg_shell = wlr_xdg_shell_create(dpy, 6);
+ wl_signal_add(&xdg_shell->events.new_toplevel, &new_xdg_toplevel);
+ wl_signal_add(&xdg_shell->events.new_popup, &new_xdg_popup);
+
+ layer_shell = wlr_layer_shell_v1_create(dpy, 3);
+ wl_signal_add(&layer_shell->events.new_surface, &new_layer_surface);
+
+ idle_notifier = wlr_idle_notifier_v1_create(dpy);
+
+ idle_inhibit_mgr = wlr_idle_inhibit_v1_create(dpy);
+ wl_signal_add(&idle_inhibit_mgr->events.new_inhibitor, &new_idle_inhibitor);
+
+ session_lock_mgr = wlr_session_lock_manager_v1_create(dpy);
+ wl_signal_add(&session_lock_mgr->events.new_lock, &new_session_lock);
+ locked_bg = wlr_scene_rect_create(layers[LyrBlock], sgeom.width, sgeom.height,
+ (float [4]){0.1f, 0.1f, 0.1f, 1.0f});
+ wlr_scene_node_set_enabled(&locked_bg->node, 0);
+
+ /* Use decoration protocols to negotiate server-side decorations */
+ wlr_server_decoration_manager_set_default_mode(
+ wlr_server_decoration_manager_create(dpy),
+ WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
+ xdg_decoration_mgr = wlr_xdg_decoration_manager_v1_create(dpy);
+ wl_signal_add(&xdg_decoration_mgr->events.new_toplevel_decoration, &new_xdg_decoration);
+
+ pointer_constraints = wlr_pointer_constraints_v1_create(dpy);
+ wl_signal_add(&pointer_constraints->events.new_constraint, &new_pointer_constraint);
+
+ relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy);
+ tablet_mgr = wlr_tablet_v2_create(dpy);
+
+ /*
+ * Creates a cursor, which is a wlroots utility for tracking the cursor
+ * image shown on screen.
+ */
+ cursor = wlr_cursor_create();
+ wlr_cursor_attach_output_layout(cursor, output_layout);
+
+ /* Creates an xcursor manager, another wlroots utility which loads up
+ * Xcursor themes to source cursor images from and makes sure that cursor
+ * images are available at all scale factors on the screen (necessary for
+ * HiDPI support). Scaled cursors will be loaded with each output. */
+ cursor_mgr = wlr_xcursor_manager_create(NULL, 24);
+ setenv("XCURSOR_SIZE", "24", 1);
+
+ /*
+ * wlr_cursor *only* displays an image on screen. It does not move around
+ * when the pointer moves. However, we can attach input devices to it, and
+ * it will generate aggregate events for all of them. In these events, we
+ * can choose how we want to process them, forwarding them to clients and
+ * moving the cursor around. More detail on this process is described in
+ * https://drewdevault.com/2018/07/17/Input-handling-in-wlroots.html
+ *
+ * And more comments are sprinkled throughout the notify functions above.
+ */
+ wl_signal_add(&cursor->events.motion, &cursor_motion);
+ wl_signal_add(&cursor->events.motion_absolute, &cursor_motion_absolute);
+ wl_signal_add(&cursor->events.button, &cursor_button);
+ wl_signal_add(&cursor->events.axis, &cursor_axis);
+ wl_signal_add(&cursor->events.frame, &cursor_frame);
+ wl_signal_add(&cursor->events.tablet_tool_proximity, &tablet_tool_proximity);
+ wl_signal_add(&cursor->events.tablet_tool_axis, &tablet_tool_
... diff truncated