diff --git a/pack.csv b/pack.csv
index 3d45a8b..c606e91 100644
--- a/pack.csv
+++ b/pack.csv
@@ -14,6 +14,7 @@ A,P,intel-ucode,Microcode update files for Intel CPUs
L,P,acpi,Client for battery power and thermal readings
L,P,acpid,A daemon for delivering ACPI power management events with netlink support
A,P,openssh,Premier connectivity tool for remote login with the SSH protocol
+A,P,smbclient,sambaclient to access network shares
# Package management
A,P,reflector,A script to retrieve and filter the latest Pacman mirror list.
@@ -37,7 +38,8 @@ A,M,st,Terminal Emulator compiled manually from dotfiles repo
# Window Management and eyecandy
A,P,i3-gaps,A fork of i3wm tiling window manager with more features including gaps
A,P,i3bar,statusbar which comes with i3
-A,P,i3status,sends systeminformation to the i3bar
+# A,P,i3status,sends systeminformation to the i3bar
+A,M,i3blocks-gaps,sends systeminformation to the i3bar
A,P,dmenu,Generic menu for X
A,P,feh,Image toolbelt
diff --git a/packages/i3blocks-gaps/.travis.yml b/packages/i3blocks-gaps/.travis.yml
new file mode 100644
index 0000000..843daf5
--- /dev/null
+++ b/packages/i3blocks-gaps/.travis.yml
@@ -0,0 +1,11 @@
+language: c
+
+env:
+ - TARGET=all
+ - TARGET=debug
+
+compiler:
+ - gcc
+
+script:
+ - make $TARGET
diff --git a/packages/i3blocks-gaps/CHANGELOG.md b/packages/i3blocks-gaps/CHANGELOG.md
new file mode 100644
index 0000000..0f20006
--- /dev/null
+++ b/packages/i3blocks-gaps/CHANGELOG.md
@@ -0,0 +1,37 @@
+# CHANGELOG
+
+## master
+
+## 1.4
+
+ * Several scripts improvements and additions.
+ * Add support for the "markup" property (GH #94).
+ * Merge contrib scripts into the defaults (GH #36).
+ * Add support for persistent blocks (GH #85).
+ * Add support for JSON output format (GH #85).
+
+## 1.3
+
+ * Fix click checking (GH #34).
+ * Use an alarm (if needed), which is more accurate.
+ * Use real-time signals (SIGRTMIN+1 to SIGRTMAX) for blocks, deprecate
+ SIGUSR1 and SIGUSR2.
+ * Implement asynchronous block updates (GH #23).
+ * Now check for config file ~/.config/i3blocks/config (or
+ $XDG_CONFIG_HOME/i3blocks/config if set) before ~/.i3blocks.conf (GH #32),
+ and similar with $XDG_CONFIG_DIRS.
+ * Add a cpu usage script (GH #11).
+
+## 1.2
+
+ * Always define env variables related to clicks. Thus, set them to an empty
+ string when no click happened (GH #9).
+
+## 1.1
+
+ * Change return code for urgency to 33 (GH #8).
+ * Do not setup stdin if it refers to a tty (GH #7).
+
+## 1.0
+
+Initial release
diff --git a/packages/i3blocks-gaps/COPYING b/packages/i3blocks-gaps/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/packages/i3blocks-gaps/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/packages/i3blocks-gaps/Makefile b/packages/i3blocks-gaps/Makefile
new file mode 100644
index 0000000..8c6fc1a
--- /dev/null
+++ b/packages/i3blocks-gaps/Makefile
@@ -0,0 +1,86 @@
+RELEASE_VERSION = 1.4
+
+ifndef PREFIX
+ PREFIX=/usr/local
+endif
+ifndef SYSCONFDIR
+ ifeq ($(PREFIX),/usr)
+ SYSCONFDIR=/etc
+ else
+ SYSCONFDIR=$(PREFIX)/etc
+ endif
+endif
+ifndef DATAROOTDIR
+ DATAROOTDIR=$(PREFIX)/share
+endif
+ifndef LIBEXECDIR
+ LIBEXECDIR=$(PREFIX)/libexec
+endif
+ifndef VERSION
+ VERSION = $(shell git describe --tags --always 2> /dev/null)
+ ifeq ($(strip $(VERSION)),)
+ VERSION = $(RELEASE_VERSION)
+ endif
+endif
+
+PROGRAM = i3blocks
+
+CPPFLAGS += -DSYSCONFDIR=\"$(SYSCONFDIR)\"
+CPPFLAGS += -DVERSION=\"${VERSION}\"
+CFLAGS += -std=gnu99 -Iinclude -Wall -Werror=format-security
+
+OBJS := $(sort $(wildcard src/*.c))
+OBJS := $(OBJS:.c=.o)
+
+%.o: %.c %.h
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+ @echo " CC $<"
+
+all: $(PROGRAM)
+
+debug: CPPFLAGS += -DDEBUG
+debug: CFLAGS += -g
+debug: $(PROGRAM)
+
+$(PROGRAM): ${OBJS}
+ $(CC) $(LDFLAGS) -o $@ $^
+ @echo " LD $@"
+
+man: $(PROGRAM).1
+
+$(PROGRAM).1: $(PROGRAM).1.md
+ pandoc --to man --standalone --output $@ $<
+
+clean:
+ rm -f src/*.o $(PROGRAM)
+
+install: all
+ install -m 755 -d $(DESTDIR)$(PREFIX)/bin
+ install -m 755 -d $(DESTDIR)$(SYSCONFDIR)
+ install -m 755 -d $(DESTDIR)$(LIBEXECDIR)/$(PROGRAM)
+ install -m 755 $(PROGRAM) $(DESTDIR)$(PREFIX)/bin/$(PROGRAM)
+ sed 's,$$SCRIPT_DIR,$(LIBEXECDIR)/$(PROGRAM),' $(PROGRAM).conf > $(DESTDIR)$(SYSCONFDIR)/$(PROGRAM).conf
+ chmod 644 $(DESTDIR)$(SYSCONFDIR)/$(PROGRAM).conf
+ install -m 755 scripts/* $(DESTDIR)$(LIBEXECDIR)/$(PROGRAM)/
+
+install-man: man
+ install -m 755 -d $(DESTDIR)$(DATAROOTDIR)/man/man1
+ install -m 644 $(PROGRAM).1 $(DESTDIR)$(DATAROOTDIR)/man/man1
+
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/bin/$(PROGRAM)
+ rm -f $(DESTDIR)$(SYSCONFDIR)/$(PROGRAM).conf
+ rm -rf $(DESTDIR)$(LIBEXECDIR)/$(PROGRAM)
+
+uninstall-man:
+ rm -f $(DESTDIR)$(DATAROOTDIR)/man/man1/$(PROGRAM).1
+
+dist: clean man
+ ( git ls-files * ; ls $(PROGRAM).1 ) | \
+ tar -czT - --transform 's,^,$(PROGRAM)-$(VERSION)/,' \
+ -f $(PROGRAM)-$(VERSION).tar.gz
+
+distclean: clean
+ rm -f $(PROGRAM).1 $(PROGRAM)-*.tar.gz
+
+.PHONY: all clean install uninstall install-man uninstall-man
diff --git a/packages/i3blocks-gaps/README.md b/packages/i3blocks-gaps/README.md
new file mode 100644
index 0000000..c5d24ff
--- /dev/null
+++ b/packages/i3blocks-gaps/README.md
@@ -0,0 +1,102 @@
+# i3blocks-gaps
+
+This repository is a fork of [i3blocks](https://github.com/vivien/i3blocks) made to be compatible with [i3-gaps](https://github.com/Airblader/i3), itself a fork of i3wm.
+
+***
+
+i3blocks is a highly flexible **status line** for the [i3](http://i3wm.org)
+window manager. It handles *clicks*, *signals* and *language-agnostic* user
+*scripts*.
+
+The content of each *block* (e.g. time, battery status, network state, ...) is
+the output of a *command* provided by the user. Blocks are updated on *click*,
+at a given *interval* of time or on a given *signal*, also specified by the
+user.
+
+It aims to respect the
+[i3bar protocol](http://i3wm.org/docs/i3bar-protocol.html), providing
+customization such as text alignment, urgency, color, and more.
+
+- - -
+
+Here is an example of status line, showing the time updated every 5 seconds,
+the volume updated only when i3blocks receives a SIGRTMIN+1, and click events.
+
+```` ini
+[volume]
+label=Volume:
+command=amixer get Master | grep -E -o '[0-9]{1,3}?%' | head -1
+interval=once
+signal=1
+# use 'pkill -RTMIN+1 i3blocks' after changing the volume
+
+[time]
+command=date '+%D %T'
+interval=5
+
+[clickme]
+full_text=Click me!
+command=echo button=$BLOCK_BUTTON x=$BLOCK_X y=$BLOCK_Y
+min_width=button=1 x=1366 y=768
+align=left
+````
+
+You can use your own scripts, or the
+[ones](https://github.com/Airblader/i3blocks-gaps/tree/master/scripts) provided with
+i3blocks. Many [community-contributed scripts](https://github.com/vivien/i3blocks-contrib) are also available. Feel free to contribute and improve them!
+
+The default config will look like this:
+
+![](http://i.imgur.com/p3d6MeK.png)
+
+The scripts provided by default may use external tools:
+
+ * `mpstat` (often provided by the *sysstat* package) used by `cpu_usage`.
+ * `acpi` (often provided by a package of the same name) used by `battery`.
+
+The user contributed scripts may also use external tools:
+
+ * `playerctl` (available [here](https://github.com/acrisci/playerctl)) used by `mediaplayer`.
+ * `sensors` (often provided by the *lm-sensors* package) used by `temperature`.
+
+## Documentation
+
+For more information about how it works, please refer to the
+[**manpage**](http://vivien.github.io/i3blocks).
+
+You can also take a look at the
+[i3bar protocol](http://i3wm.org/docs/i3bar-protocol.html) to see what
+possibilities it offers you.
+
+Take a look at the [wiki](https://github.com/vivien/i3blocks/wiki) for examples
+of blocks and screenshots. If you want to share your ideas and status line,
+feel free to edit it!
+
+## Installation
+
+Install i3blocks-gaps from source:
+
+ $ git clone https://github.com/Airblader/i3blocks-gaps i3blocks
+ $ cd i3blocks
+ $ make clean debug # or make clean all
+ # make install
+
+Note: the generation of the manpage requires the `pandoc` utility, packaged in
+common distributions as `pandoc`.
+
+### Usage
+
+ * Set your `status_command` in a bar block of your i3 config file:
+
+ bar {
+ status_command i3blocks
+ }
+
+ * For customization, copy the default i3blocks.conf into ~/.i3blocks.conf
+ (e.g. `cp /etc/i3blocks.conf ~/.i3blocks.conf`)
+ * Restart i3 (e.g. `i3-msg restart`)
+
+## Copying
+
+i3blocks is Copyright (C) 2014 Vivien Didelot
+See the file COPYING for information of licensing and distribution.
diff --git a/packages/i3blocks-gaps/i3blocks.1.md b/packages/i3blocks-gaps/i3blocks.1.md
new file mode 100644
index 0000000..7961afa
--- /dev/null
+++ b/packages/i3blocks-gaps/i3blocks.1.md
@@ -0,0 +1,276 @@
+% I3BLOCKS(1)
+
+# NAME
+i3blocks - A flexible scheduler for your i3bar blocks
+
+# SYNOPSIS
+
+i3blocks [*options*]
+
+# DESCRIPTION
+
+**i3blocks** allows one to easily describe blocks in a simple format, and
+generate a status line for i3bar(1). It handles clicks, signals and time
+interval for user scripts.
+
+#OPTIONS
+-c
+: Specifies an alternate configuration file path. By default, i3blocks looks
+ for configuration files in the following order (note that /etc may be
+ prefixed with /usr/local depending on the compilation flags):
+
+ 1. ~/.config/i3blocks/config (or $XDG_CONFIG_HOME/i3blocks/config if set)
+ 2. ~/.i3blocks.conf
+ 3. /etc/xdg/i3blocks/config (or $XDG_CONFIG_DIRS/i3blocks/config if set)
+ 4. /etc/i3blocks.conf
+
+-v
+: Log level. This option is cumulative. By default, error messages are
+ displayed on stderr. Passed once, a failure during an update is shown
+ within the block. Passed twice enables the debug messages on stderr.
+
+-V
+: Print the version and exit.
+
+-h
+: Print the help message and exit.
+
+# CONFIGURATION
+
+The configuration file is an ini file. Each section describes a new block.
+A line beginning with a `#` sign is a comment, and empty lines are ignored.
+A property is a `key=value` pair per line, with no space around the equal sign.
+Properties declared outside a block (i.e. at the beginning of the file)
+describe global settings.
+
+Here is an example config file:
+
+ # This is a comment
+ interval=5
+ color=#00FF00
+
+ [weather]
+ command=~/bin/weather.pl
+ interval=1800
+
+ [time]
+ command=date +%T
+
+To use i3blocks as your status line, define it in a *bar* block of your
+`~/i3/config` file:
+
+ bar {
+ status_command i3blocks
+ }
+
+# BLOCK
+
+The properties used to describe a block are the keys specified in the i3bar
+protocol http://i3wm.org/docs/i3bar-protocol.html , plus additional properties
+used by **i3blocks** to describe when and how to update a block.
+All the supported properties are described below.
+
+The following keys are standard, see
+http://i3wm.org/docs/i3bar-protocol.html
+for details.
+
+ - `full_text`
+
+ - `short_text`
+
+ - `color`
+
+ - `background`
+
+ - `border`
+
+ - `min_width`
+
+ - `align`
+
+ - `name`
+
+ - `instance`
+
+ - `urgent`
+
+ - `separator`
+
+ - `separator_block_width`
+
+ - `markup`
+
+The following keys are specific to **i3blocks**.
+
+`command`
+: The command executed by a shell, used to update the block. The expected
+ behavior is described below, in the **COMMAND** section.
+
+`interval`
+: If it is a positive integer, then the block is spawned on startup and the
+ value is used as a time interval in seconds to schedule future updates.
+ If unspecified or 0, the block won't be executed on startup (which is
+ useful to simulate buttons).
+
+ If "*once*" (or -1), the block will be executed only on startup (note that a
+ click or signal will still trigger an update).
+
+ If "*repeat*" (or -2), the block will be spawned on startup, and as soon as
+ it terminates (useful to repeat blocking commands). Use with caution!
+
+ If "*persist*" (or -3), the block will be executed only on startup, and
+ updated as soon as it outputs a line. Thus limited to single line updates.
+
+`signal`
+: The signal number used to update the block. All the real-time (think
+ prioritized and queueable) signals are available to the user. The number is
+ valid between 1 and N, where SIGRTMIN+N = SIGRTMAX. (Note: there are 31
+ real-time signals in Linux.) For instance, `signal=10` means that this
+ block will be updated when **i3blocks** receives SIGRTMIN+10.
+
+`label`
+: An optional label to preprend to the `full_text` after an update.
+
+`format`
+: This property specifies the format of the output text. The default format
+ is plain text, as described in the **COMMAND** section.
+ If "json" (or 1) is used, the block output is parsed as JSON.
+
+# COMMAND
+
+The value of the `command` key will be passed and executed as is by a shell.
+
+The standard output of the command line is used to update the block content.
+Each non-empty line of the output will overwrite the corresponding property:
+
+1. full_text
+2. short_text
+3. color
+
+For example, this script sets the `full_text` in blue but no `short_text`:
+
+ echo "Here's my label"
+ echo
+ echo \#0000FF
+
+If the command line returns 0 or 33, the block is updated. Otherwise, it is
+considered a failure and the first line (if any) is still displayed. Note that
+stderr is ignored. A return code of 33 will set the `urgent` flag to true.
+
+For example, this script prints the battery percentage and sets the urgent flag
+if it is below 10%:
+
+ BAT=`acpi -b | grep -E -o '[0-9][0-9]?%'`
+ echo "BAT: $BAT"
+ test ${BAT%?} -le 10 && exit 33 || exit 0
+
+When forking a block command, **i3blocks** will set the environment with some
+`BLOCK_*` variables. The following variables are always provided, with
+eventually an empty string as the value.
+
+`BLOCK_NAME`
+: The name of the block (usually the section name).
+
+`BLOCK_INSTANCE`
+: An optional argument to the script.
+
+`BLOCK_BUTTON`
+: Mouse button (1, 2 or 3) if the block was clicked.
+
+`BLOCK_X` and `BLOCK_Y`
+: Coordinates where the click occurred, if the block was clicked.
+
+Here is an example using the environment:
+
+ [block]
+ command=echo name=$BLOCK_NAME instance=$BLOCK_INSTANCE
+ interval=1
+
+ [clickme]
+ full_text=Click me!
+ command=echo button=$BLOCK_BUTTON x=$BLOCK_X y=$BLOCK_Y
+ min_width=button=1 x=1366 y=768
+ align=left
+
+Note that **i3blocks** provides a set of optional scripts for convenience, such
+as network status, battery check, cpu load, volume, etc.
+
+# EXAMPLES
+
+As an example, here is a close configuration to i3status(1) default settings:
+
+**TODO**
+
+ interval=5
+ signal=10
+
+ [ipv6]
+
+ [free]
+
+ [dhcp]
+
+ [vpn]
+
+ [wifi]
+
+ [ethernet]
+ min_width=E: 255.255.255.255 (1000 Mbit/s)
+
+ [battery]
+
+ [cpu]
+
+ [datetime]
+
+The following block shows the usage of `signal` with some i3(1) bindings
+which adjust the volume, before issuing a `pkill -RTMIN+1 i3blocks`:
+
+ [volume]
+ command=echo -n 'Volume: '; amixer get Master | grep -E -o '[0-9][0-9]?%'
+ interval=once
+ signal=1
+ # no interval, only check on SIGRTMIN+1
+
+Here is an example of a very minimalist config, assuming you have a bunch of
+scripts under `~/bin/blocks/` with the same name as the blocks:
+
+ command=~/bin/blocks/$BLOCK_NAME
+ interval=1
+
+ [free]
+ [wifi]
+ [ethernet]
+ [battery]
+ [cpu]
+ [datetime]
+
+# SEE ALSO
+
+The development of i3blocks takes place on [Github](https://github.com/vivien/i3blocks).
+
+The [wiki](https://github.com/vivien/i3blocks/wiki) is a good
+source of examples for blocks and screenshots.
+
+`i3` (1), `i3bar` (1), `i3status` (1)
+
+# Reporting Bugs
+
+Please report bugs on the [issue tracker](https://github.com/vivien/i3blocks/issues).
+
+# Known Bugs
+
+None.
+
+# AUTHOR
+
+Written by Vivien Didelot .
+
+# COPYRIGHT
+
+Copyright (C) 2014 Vivien Didelot
+
+License GPLv3+: GNU GPL version 3 or later .
+
+This is free software: you are free to change and redistribute it. There is NO
+WARRANTY, to the extent permitted by law.
diff --git a/packages/i3blocks-gaps/i3blocks.conf b/packages/i3blocks-gaps/i3blocks.conf
new file mode 100644
index 0000000..52a58e9
--- /dev/null
+++ b/packages/i3blocks-gaps/i3blocks.conf
@@ -0,0 +1,115 @@
+# i3blocks config file
+#
+# Please see man i3blocks for a complete reference!
+# The man page is also hosted at http://vivien.github.io/i3blocks
+#
+# List of valid properties:
+#
+# align
+# color
+# background
+# border
+# command
+# full_text
+# instance
+# interval
+# label
+# min_width
+# name
+# separator
+# separator_block_width
+# short_text
+# signal
+# urgent
+
+# Global properties
+#
+# The top properties below are applied to every block, but can be overridden.
+# Each block command defaults to the script name to avoid boilerplate.
+command=$SCRIPT_DIR/$BLOCK_NAME
+separator_block_width=15
+markup=none
+
+# Volume indicator
+#
+# The first parameter sets the step (and units to display)
+# The second parameter overrides the mixer selection
+# See the script for details.
+[volume]
+label=VOL
+#label=♪
+instance=Master
+#instance=PCM
+interval=once
+signal=10
+
+# Memory usage
+#
+# The type defaults to "mem" if the instance is not specified.
+[memory]
+label=MEM
+separator=false
+interval=30
+
+[memory]
+label=SWAP
+instance=swap
+separator=false
+interval=30
+
+# Disk usage
+#
+# The directory defaults to $HOME if the instance is not specified.
+# The script may be called with a optional argument to set the alert
+# (defaults to 10 for 10%).
+[disk]
+label=HOME
+#instance=/mnt/data
+interval=30
+
+# Network interface monitoring
+#
+# If the instance is not specified, use the interface used for default route.
+# The address can be forced to IPv4 or IPv6 with -4 or -6 switches.
+[iface]
+#instance=wlan0
+color=#00FF00
+interval=10
+separator=false
+
+[wifi]
+#instance=wlp3s0
+interval=10
+separator=false
+
+[bandwidth]
+#instance=eth0
+interval=5
+
+# CPU usage
+#
+# The script may be called with -w and -c switches to specify thresholds,
+# see the script for details.
+[cpu_usage]
+label=CPU
+interval=10
+min_width=CPU: 100.00%
+#separator=false
+
+#[load_average]
+#interval=10
+
+# Battery indicator
+#
+# The battery instance defaults to 0.
+[battery]
+label=BAT
+#label=⚡
+#instance=1
+interval=30
+
+# Date Time
+#
+[time]
+command=date '+%Y-%m-%d %H:%M:%S'
+interval=5
diff --git a/packages/i3blocks-gaps/include/bar.h b/packages/i3blocks-gaps/include/bar.h
new file mode 100644
index 0000000..ce62c4f
--- /dev/null
+++ b/packages/i3blocks-gaps/include/bar.h
@@ -0,0 +1,34 @@
+/*
+ * bar.h - definition of a status line handling functions
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#ifndef _BAR_H
+#define _BAR_H
+
+struct bar {
+ struct block *blocks;
+ unsigned int num;
+};
+
+void bar_poll_timed(struct bar *);
+void bar_poll_clicked(struct bar *);
+void bar_poll_outdated(struct bar *);
+void bar_poll_signaled(struct bar *, int);
+void bar_poll_exited(struct bar *);
+void bar_poll_readable(struct bar *, int);
+
+#endif /* _BAR_H */
diff --git a/packages/i3blocks-gaps/include/block.h b/packages/i3blocks-gaps/include/block.h
new file mode 100644
index 0000000..2ca7fb8
--- /dev/null
+++ b/packages/i3blocks-gaps/include/block.h
@@ -0,0 +1,113 @@
+/*
+ * block.h - definition of a block
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#ifndef _BLOCK_H
+#define _BLOCK_H
+
+#include
+
+#include "click.h"
+#include "log.h"
+
+#define PROP_I3BAR 1 /* See http://i3wm.org/docs/i3bar-protocol.html */
+#define PROP_GAPS 1 /* See https://github.com/Airblader/i3/blob/gaps/docs/i3bar-protocol */
+#define PROP_STRING 2
+#define PROP_NUMBER 4
+#define PROP_BOOLEAN 8
+
+#define INTER_ONCE -1
+#define INTER_REPEAT -2
+#define INTER_PERSIST -3
+
+#define FORMAT_PLAIN 0
+#define FORMAT_JSON 1
+
+/* Block command exit codes */
+#define EXIT_URGENT '!' /* 33 */
+#define EXIT_ERR_INTERNAL 66
+
+#define PROPERTIES(_) \
+ _(full_text, 1024, PROP_I3BAR | PROP_STRING) \
+ _(short_text, 512, PROP_I3BAR | PROP_STRING) \
+ _(color, 10, PROP_I3BAR | PROP_STRING) \
+ _(background, 10, PROP_I3BAR | PROP_STRING) \
+ _(border, 10, PROP_I3BAR | PROP_STRING) \
+ _(min_width, 1024, PROP_I3BAR | PROP_STRING | PROP_NUMBER) \
+ _(align, 8, PROP_I3BAR | PROP_STRING) \
+ _(name, 32, PROP_I3BAR | PROP_STRING) \
+ _(instance, 256, PROP_I3BAR | PROP_STRING) \
+ _(urgent, 8, PROP_I3BAR | PROP_BOOLEAN) \
+ _(separator, 8, PROP_I3BAR | PROP_BOOLEAN) \
+ _(separator_block_width, 8, PROP_I3BAR | PROP_NUMBER) \
+ _(markup, 8, PROP_I3BAR | PROP_STRING) \
+ _(command, 1024, PROP_STRING) \
+ _(interval, 8, PROP_STRING | PROP_NUMBER) \
+ _(signal, 8, PROP_NUMBER) \
+ _(label, 32, PROP_STRING) \
+ _(format, 8, PROP_STRING | PROP_NUMBER) \
+ _(border_top, 8, PROP_GAPS | PROP_NUMBER) \
+ _(border_bottom, 8, PROP_GAPS | PROP_NUMBER) \
+ _(border_left, 8, PROP_GAPS | PROP_NUMBER) \
+ _(border_right, 8, PROP_GAPS | PROP_NUMBER) \
+
+struct properties {
+#define DEFINE(_name, _size, _flags) char _name[_size];
+ PROPERTIES(DEFINE);
+#undef DEFINE
+};
+
+struct block {
+ struct properties default_props;
+ struct properties updated_props;
+
+ /* Shortcuts */
+ int interval;
+ unsigned signal;
+ unsigned format;
+
+ /* Runtime info */
+ unsigned long timestamp;
+ pid_t pid;
+ int out, err;
+};
+
+/* Shortcuts to config */
+#define NAME(_block) (_block->default_props.name)
+#define INSTANCE(_block) (_block->default_props.instance)
+#define COMMAND(_block) (_block->default_props.command)
+#define LABEL(_block) (_block->default_props.label)
+#define INTERVAL(_block) (_block->default_props.interval)
+
+/* Shortcuts to update */
+#define FULL_TEXT(_block) (_block->updated_props.full_text)
+
+#define bdebug(block, msg, ...) \
+ debug("[%s] " msg, NAME(block), ##__VA_ARGS__)
+
+#define berror(block, msg, ...) \
+ error("[%s] " msg, NAME(block), ##__VA_ARGS__)
+
+#define berrorx(block, msg, ...) \
+ errorx("[%s] " msg, NAME(block), ##__VA_ARGS__)
+
+void block_setup(struct block *);
+void block_spawn(struct block *, struct click *);
+void block_reap(struct block *);
+void block_update(struct block *);
+
+#endif /* _BLOCK_H */
diff --git a/packages/i3blocks-gaps/include/click.h b/packages/i3blocks-gaps/include/click.h
new file mode 100644
index 0000000..cd74960
--- /dev/null
+++ b/packages/i3blocks-gaps/include/click.h
@@ -0,0 +1,32 @@
+/*
+ * click.h - definition of click parsing functions
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#ifndef _CLICK_H
+#define _CLICK_H
+
+struct click {
+ char *name;
+ char *instance;
+ char *button;
+ char *x;
+ char *y;
+};
+
+void click_parse(char *, struct click *);
+
+#endif /* _CLICK_H */
diff --git a/packages/i3blocks-gaps/include/ini.h b/packages/i3blocks-gaps/include/ini.h
new file mode 100644
index 0000000..fb6fb6f
--- /dev/null
+++ b/packages/i3blocks-gaps/include/ini.h
@@ -0,0 +1,26 @@
+/*
+ * ini.h - INI parsing header
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#ifndef _INI_H
+#define _INI_H
+
+#include "bar.h"
+
+struct bar *ini_load(const char *);
+
+#endif /* _INI_H */
diff --git a/packages/i3blocks-gaps/include/io.h b/packages/i3blocks-gaps/include/io.h
new file mode 100644
index 0000000..9e4767b
--- /dev/null
+++ b/packages/i3blocks-gaps/include/io.h
@@ -0,0 +1,25 @@
+/*
+ * io.h - header for non-blocking I/O operations
+ * Copyright (C) 2015 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#ifndef _IO_H
+#define _IO_H
+
+int io_signal(int, int);
+int io_readline(int, char *, size_t);
+
+#endif /* _IO_H */
diff --git a/packages/i3blocks-gaps/include/json.h b/packages/i3blocks-gaps/include/json.h
new file mode 100644
index 0000000..1fb431f
--- /dev/null
+++ b/packages/i3blocks-gaps/include/json.h
@@ -0,0 +1,29 @@
+/*
+ * json.h - JSON manipulation header
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#ifndef _JSON_H
+#define _JSON_H
+
+#include "bar.h"
+#include "block.h"
+
+void json_parse(const char *json, const char *name, int *start, int *len);
+void json_print_bar(struct bar *);
+
+#endif /* _JSON_H */
+
diff --git a/packages/i3blocks-gaps/include/log.h b/packages/i3blocks-gaps/include/log.h
new file mode 100644
index 0000000..12b7bd7
--- /dev/null
+++ b/packages/i3blocks-gaps/include/log.h
@@ -0,0 +1,45 @@
+/*
+ * log.h - debug and error printing macros
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#ifndef _LOG_H
+#define _LOG_H
+
+#include
+#include
+#include
+
+extern unsigned log_level;
+
+enum log_level {
+ LOG_NORMAL,
+ LOG_WARN,
+ LOG_DEBUG,
+};
+
+#define debug(msg, ...) \
+ if (log_level >= LOG_DEBUG) { \
+ fprintf(stderr, "DEBUG %s:%d: " msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+ }
+
+#define error(msg, ...) \
+ fprintf(stderr, "ERROR %s:%d: " msg "\n", __func__, __LINE__, ##__VA_ARGS__)
+
+#define errorx(msg, ...) \
+ error(msg ": %s", ##__VA_ARGS__, strerror(errno))
+
+#endif /* _LOG_H */
diff --git a/packages/i3blocks-gaps/include/sched.h b/packages/i3blocks-gaps/include/sched.h
new file mode 100644
index 0000000..ea3c6f5
--- /dev/null
+++ b/packages/i3blocks-gaps/include/sched.h
@@ -0,0 +1,25 @@
+/*
+ * sched.h - scheduling header
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#ifndef _SCHED_H
+#define _SCHED_H
+
+int sched_init(struct bar *);
+void sched_start(struct bar *);
+
+#endif /* _SCHED_H */
diff --git a/packages/i3blocks-gaps/scripts/bandwidth b/packages/i3blocks-gaps/scripts/bandwidth
new file mode 100755
index 0000000..c69a22c
--- /dev/null
+++ b/packages/i3blocks-gaps/scripts/bandwidth
@@ -0,0 +1,107 @@
+#!/bin/bash
+# Copyright (C) 2012 Stefan Breunig
+# Copyright (C) 2014 kaueraal
+# Copyright (C) 2015 Thiago Perrotta
+
+# 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 .
+
+# Get custom IN and OUT labels if provided by command line arguments
+while [[ $# -gt 1 ]]; do
+ key="$1"
+ case "$key" in
+ -i|--inlabel)
+ INLABEL="$2"
+ shift;;
+ -o|--outlabel)
+ OUTLABEL="$2"
+ shift;;
+ esac
+ shift
+done
+
+[[ -z $INLABEL ]] && INLABEL="IN "
+[[ -z $OUTLABEL ]] && OUTLABEL="OUT "
+
+# Use the provided interface, otherwise the device used for the default route.
+if [[ -n $BLOCK_INSTANCE ]]; then
+ INTERFACE=$BLOCK_INSTANCE
+else
+ INTERFACE=$(ip route | awk '/^default/ { print $5 ; exit }')
+fi
+
+# Issue #36 compliant.
+if ! [ -e "/sys/class/net/${INTERFACE}/operstate" ] || ! [ "`cat /sys/class/net/${INTERFACE}/operstate`" = "up" ]
+then
+ echo "$INTERFACE down"
+ echo "$INTERFACE down"
+ echo "#FF0000"
+ exit 0
+fi
+
+# path to store the old results in
+path="/dev/shm/$(basename $0)-${INTERFACE}"
+
+# grabbing data for each adapter.
+read rx < "/sys/class/net/${INTERFACE}/statistics/rx_bytes"
+read tx < "/sys/class/net/${INTERFACE}/statistics/tx_bytes"
+
+# get time
+time=$(date +%s)
+
+# write current data if file does not exist. Do not exit, this will cause
+# problems if this file is sourced instead of executed as another process.
+if ! [[ -f "${path}" ]]; then
+ echo "${time} ${rx} ${tx}" > "${path}"
+ chmod 0666 "${path}"
+fi
+
+# read previous state and update data storage
+read old < "${path}"
+echo "${time} ${rx} ${tx}" > "${path}"
+
+# parse old data and calc time passed
+old=(${old//;/ })
+time_diff=$(( $time - ${old[0]} ))
+
+# sanity check: has a positive amount of time passed
+[[ "${time_diff}" -gt 0 ]] || exit
+
+# calc bytes transferred, and their rate in byte/s
+rx_diff=$(( $rx - ${old[1]} ))
+tx_diff=$(( $tx - ${old[2]} ))
+rx_rate=$(( $rx_diff / $time_diff ))
+tx_rate=$(( $tx_diff / $time_diff ))
+
+# shift by 10 bytes to get KiB/s. If the value is larger than
+# 1024^2 = 1048576, then display MiB/s instead
+
+# incoming
+echo -n "$INLABEL"
+rx_kib=$(( $rx_rate >> 10 ))
+if hash bc 2>/dev/null && [[ "$rx_rate" -gt 1048576 ]]; then
+ printf '%sM' "`echo "scale=1; $rx_kib / 1024" | bc`"
+else
+ echo -n "${rx_kib}K"
+fi
+
+echo -n " "
+
+# outgoing
+echo -n "$OUTLABEL"
+tx_kib=$(( $tx_rate >> 10 ))
+if hash bc 2>/dev/null && [[ "$tx_rate" -gt 1048576 ]]; then
+ printf '%sM' "`echo "scale=1; $tx_kib / 1024" | bc`"
+else
+ echo -n "${tx_kib}K"
+fi
diff --git a/packages/i3blocks-gaps/scripts/battery b/packages/i3blocks-gaps/scripts/battery
new file mode 100755
index 0000000..d36acae
--- /dev/null
+++ b/packages/i3blocks-gaps/scripts/battery
@@ -0,0 +1,89 @@
+#!/usr/bin/perl
+#
+# Copyright 2014 Pierre Mavro
+# Copyright 2014 Vivien Didelot
+#
+# Licensed under the terms of the GNU GPL v3, or any later version.
+#
+# This script is meant to use with i3blocks. It parses the output of the "acpi"
+# command (often provided by a package of the same name) to read the status of
+# the battery, and eventually its remaining time (to full charge or discharge).
+#
+# The color will gradually change for a percentage below 85%, and the urgency
+# (exit code 33) is set if there is less that 5% remaining.
+
+use strict;
+use warnings;
+use utf8;
+
+my $acpi;
+my $status;
+my $percent;
+my $ac_adapt;
+my $full_text;
+my $short_text;
+my $bat_number = $ENV{BLOCK_INSTANCE} || 0;
+
+# read the first line of the "acpi" command output
+open (ACPI, "acpi -b | grep 'Battery $bat_number' |") or die;
+$acpi = ;
+close(ACPI);
+
+# fail on unexpected output
+if ($acpi !~ /: (\w+), (\d+)%/) {
+ die "$acpi\n";
+}
+
+$status = $1;
+$percent = $2;
+$full_text = "$percent%";
+
+if ($status eq 'Discharging') {
+ $full_text .= ' DIS';
+} elsif ($status eq 'Charging') {
+ $full_text .= ' CHR';
+} elsif ($status eq 'Unknown') {
+ open (AC_ADAPTER, "acpi -a |") or die;
+ $ac_adapt = ;
+ close(AC_ADAPTER);
+
+ if ($ac_adapt =~ /: ([\w-]+)/) {
+ $ac_adapt = $1;
+
+ if ($ac_adapt eq 'on-line') {
+ $full_text .= ' CHR';
+ } elsif ($ac_adapt eq 'off-line') {
+ $full_text .= ' DIS';
+ }
+ }
+}
+
+$short_text = $full_text;
+
+if ($acpi =~ /(\d\d:\d\d):/) {
+ $full_text .= " ($1)";
+}
+
+# print text
+print "$full_text\n";
+print "$short_text\n";
+
+# consider color and urgent flag only on discharge
+if ($status eq 'Discharging') {
+
+ if ($percent < 20) {
+ print "#FF0000\n";
+ } elsif ($percent < 40) {
+ print "#FFAE00\n";
+ } elsif ($percent < 60) {
+ print "#FFF600\n";
+ } elsif ($percent < 85) {
+ print "#A8FF00\n";
+ }
+
+ if ($percent < 5) {
+ exit(33);
+ }
+}
+
+exit(0);
diff --git a/packages/i3blocks-gaps/scripts/cpu_usage b/packages/i3blocks-gaps/scripts/cpu_usage
new file mode 100755
index 0000000..ed5cd2f
--- /dev/null
+++ b/packages/i3blocks-gaps/scripts/cpu_usage
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+#
+# Copyright 2014 Pierre Mavro
+# Copyright 2014 Vivien Didelot
+# Copyright 2014 Andreas Guldstrand
+#
+# Licensed under the terms of the GNU GPL v3, or any later version.
+
+use strict;
+use warnings;
+use utf8;
+use Getopt::Long;
+
+# default values
+my $t_warn = 50;
+my $t_crit = 80;
+my $cpu_usage = -1;
+my $decimals = 2;
+
+sub help {
+ print "Usage: cpu_usage [-w ] [-c ] [-d ]\n";
+ print "-w : warning threshold to become yellow\n";
+ print "-c : critical threshold to become red\n";
+ print "-d : Use decimals for percentage (default is $decimals) \n";
+ exit 0;
+}
+
+GetOptions("help|h" => \&help,
+ "w=i" => \$t_warn,
+ "c=i" => \$t_crit,
+ "d=i" => \$decimals,
+);
+
+# Get CPU usage
+$ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is
+open (MPSTAT, 'mpstat 1 1 |') or die;
+while () {
+ if (/^.*\s+(\d+\.\d+)\s+$/) {
+ $cpu_usage = 100 - $1; # 100% - %idle
+ last;
+ }
+}
+close(MPSTAT);
+
+$cpu_usage eq -1 and die 'Can\'t find CPU information';
+
+# Print short_text, full_text
+printf "%.${decimals}f%%\n", $cpu_usage;
+printf "%.${decimals}f%%\n", $cpu_usage;
+
+# Print color, if needed
+if ($cpu_usage >= $t_crit) {
+ print "#FF0000\n";
+ exit 33;
+} elsif ($cpu_usage >= $t_warn) {
+ print "#FFFC00\n";
+}
+
+exit 0;
diff --git a/packages/i3blocks-gaps/scripts/disk b/packages/i3blocks-gaps/scripts/disk
new file mode 100755
index 0000000..5511eac
--- /dev/null
+++ b/packages/i3blocks-gaps/scripts/disk
@@ -0,0 +1,41 @@
+#!/bin/sh
+# Copyright (C) 2014 Julien Bonjean
+
+# 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 .
+
+DIR="${BLOCK_INSTANCE:-$HOME}"
+ALERT_LOW="${1:-10}" # color will turn red under this value (default: 10%)
+
+df -h -P -l "$DIR" | awk -v alert_low=$ALERT_LOW '
+/\/.*/ {
+ # full text
+ print $4
+
+ # short text
+ print $4
+
+ use=$5
+
+ # no need to continue parsing
+ exit 0
+}
+
+END {
+ gsub(/%$/,"",use)
+ if (100 - use < alert_low) {
+ # color
+ print "#FF0000"
+ }
+}
+'
diff --git a/packages/i3blocks-gaps/scripts/iface b/packages/i3blocks-gaps/scripts/iface
new file mode 100755
index 0000000..7014979
--- /dev/null
+++ b/packages/i3blocks-gaps/scripts/iface
@@ -0,0 +1,61 @@
+#!/bin/bash
+# Copyright (C) 2014 Julien Bonjean
+# Copyright (C) 2014 Alexander Keller
+
+# 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 .
+
+#------------------------------------------------------------------------
+
+# Use the provided interface, otherwise the device used for the default route.
+if [[ -n $BLOCK_INSTANCE ]]; then
+ IF=$BLOCK_INSTANCE
+else
+ IF=$(ip route | awk '/^default/ { print $5 ; exit }')
+fi
+
+#------------------------------------------------------------------------
+
+# As per #36 -- It is transparent: e.g. if the machine has no battery or wireless
+# connection (think desktop), the corresponding block should not be displayed.
+[[ ! -d /sys/class/net/${IF} ]] && exit
+
+#------------------------------------------------------------------------
+
+if [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then
+ echo down # full text
+ echo down # short text
+ echo \#FF0000 # color
+ exit
+fi
+
+case $1 in
+ -4)
+ AF=inet ;;
+ -6)
+ AF=inet6 ;;
+ *)
+ AF=inet6? ;;
+esac
+
+# if no interface is found, use the first device with a global scope
+IPADDR=$(ip addr show $IF | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit")
+
+case $BLOCK_BUTTON in
+ 3) echo -n "$IPADDR" | xclip -q -se c ;;
+esac
+
+#------------------------------------------------------------------------
+
+echo "$IPADDR" # full text
+echo "$IPADDR" # short text
diff --git a/packages/i3blocks-gaps/scripts/load_average b/packages/i3blocks-gaps/scripts/load_average
new file mode 100755
index 0000000..37a5c71
--- /dev/null
+++ b/packages/i3blocks-gaps/scripts/load_average
@@ -0,0 +1,34 @@
+#!/bin/sh
+# Copyright (C) 2014 Julien Bonjean
+
+# 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 .
+
+load="$(cut -d ' ' -f1 /proc/loadavg)"
+cpus="$(nproc)"
+
+# full text
+echo "$load"
+
+# short text
+echo "$load"
+
+# color if load is too high
+awk -v cpus=$cpus -v cpuload=$load '
+ BEGIN {
+ if (cpus <= cpuload) {
+ print "#FF0000";
+ exit 33;
+ }
+ }
+'
diff --git a/packages/i3blocks-gaps/scripts/memory b/packages/i3blocks-gaps/scripts/memory
new file mode 100755
index 0000000..bbbc369
--- /dev/null
+++ b/packages/i3blocks-gaps/scripts/memory
@@ -0,0 +1,65 @@
+#!/bin/sh
+# Copyright (C) 2014 Julien Bonjean
+
+# 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 .
+
+TYPE="${BLOCK_INSTANCE:-mem}"
+
+awk -v type=$TYPE '
+/^MemTotal:/ {
+ mem_total=$2
+}
+/^MemFree:/ {
+ mem_free=$2
+}
+/^Buffers:/ {
+ mem_free+=$2
+}
+/^Cached:/ {
+ mem_free+=$2
+}
+/^SwapTotal:/ {
+ swap_total=$2
+}
+/^SwapFree:/ {
+ swap_free=$2
+}
+END {
+ if (type == "swap") {
+ free=swap_free/1024/1024
+ used=(swap_total-swap_free)/1024/1024
+ total=swap_total/1024/1024
+ } else {
+ free=mem_free/1024/1024
+ used=(mem_total-mem_free)/1024/1024
+ total=mem_total/1024/1024
+ }
+ pct=used/total*100
+
+ # full text
+ printf("%.1fG/%.1fG (%.f%%)\n", used, total, pct)
+
+ # short text
+ printf("%.f%%\n", pct)
+
+ # color
+ if (pct > 90) {
+ print("#FF0000\n")
+ } else if (pct > 80) {
+ print("#FFAE00\n")
+ } else if (pct > 70) {
+ print("#FFF600\n")
+ }
+}
+' /proc/meminfo
diff --git a/packages/i3blocks-gaps/scripts/volume b/packages/i3blocks-gaps/scripts/volume
new file mode 100755
index 0000000..a55db88
--- /dev/null
+++ b/packages/i3blocks-gaps/scripts/volume
@@ -0,0 +1,70 @@
+#!/bin/bash
+# Copyright (C) 2014 Julien Bonjean
+# Copyright (C) 2014 Alexander Keller
+
+# 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 .
+
+#------------------------------------------------------------------------
+
+# The second parameter overrides the mixer selection
+# For PulseAudio users, use "pulse"
+# For Jack/Jack2 users, use "jackplug"
+# For ALSA users, you may use "default" for your primary card
+# or you may use hw:# where # is the number of the card desired
+MIXER="default"
+[ -n "$(lsmod | grep pulse)" ] && MIXER="pulse"
+[ -n "$(lsmod | grep jack)" ] && MIXER="jackplug"
+MIXER="${2:-$MIXER}"
+
+# The instance option sets the control to report and configure
+# This defaults to the first control of your selected mixer
+# For a list of the available, use `amixer -D $Your_Mixer scontrols`
+SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols |
+ sed -n "s/Simple mixer control '\([A-Za-z ]*\)',0/\1/p" |
+ head -n1
+ )}"
+
+# The first parameter sets the step to change the volume by (and units to display)
+# This may be in in % or dB (eg. 5% or 3dB)
+STEP="${1:-5%}"
+
+#------------------------------------------------------------------------
+
+capability() { # Return "Capture" if the device is a capture device
+ amixer -D $MIXER get $SCONTROL |
+ sed -n "s/ Capabilities:.*cvolume.*/Capture/p"
+}
+
+volume() {
+ amixer -D $MIXER get $SCONTROL $(capability)
+}
+
+format() {
+ perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)'
+ perl_filter+='{CORE::say $4 eq "off" ? "MUTE" : "'
+ # If dB was selected, print that instead
+ perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo '$1')
+ perl_filter+='"; exit}'
+ perl -ne "$perl_filter"
+}
+
+#------------------------------------------------------------------------
+
+case $BLOCK_BUTTON in
+ 3) amixer -q -D $MIXER sset $SCONTROL $(capability) toggle ;; # right click, mute/unmute
+ 4) amixer -q -D $MIXER sset $SCONTROL $(capability) ${STEP}+ unmute ;; # scroll up, increase
+ 5) amixer -q -D $MIXER sset $SCONTROL $(capability) ${STEP}- unmute ;; # scroll down, decrease
+esac
+
+volume | format
diff --git a/packages/i3blocks-gaps/scripts/wifi b/packages/i3blocks-gaps/scripts/wifi
new file mode 100755
index 0000000..6fe4d47
--- /dev/null
+++ b/packages/i3blocks-gaps/scripts/wifi
@@ -0,0 +1,46 @@
+#!/bin/bash
+# Copyright (C) 2014 Alexander Keller
+
+# 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 .
+
+#------------------------------------------------------------------------
+
+INTERFACE="${BLOCK_INSTANCE:-wlan0}"
+
+#------------------------------------------------------------------------
+
+# As per #36 -- It is transparent: e.g. if the machine has no battery or wireless
+# connection (think desktop), the corresponding block should not be displayed.
+[[ ! -d /sys/class/net/${INTERFACE}/wireless ]] ||
+ [[ "$(cat /sys/class/net/$INTERFACE/operstate)" = 'down' ]] && exit
+
+#------------------------------------------------------------------------
+
+QUALITY=$(grep $INTERFACE /proc/net/wireless | awk '{ print int($3 * 100 / 70) }')
+
+#------------------------------------------------------------------------
+
+echo $QUALITY% # full text
+echo $QUALITY% # short text
+
+# color
+if [[ $QUALITY -ge 80 ]]; then
+ echo "#00FF00"
+elif [[ $QUALITY -ge 60 ]]; then
+ echo "#FFF600"
+elif [[ $QUALITY -ge 40 ]]; then
+ echo "#FFAE00"
+else
+ echo "#FF0000"
+fi
diff --git a/packages/i3blocks-gaps/src/.gitignore b/packages/i3blocks-gaps/src/.gitignore
new file mode 100644
index 0000000..5761abc
--- /dev/null
+++ b/packages/i3blocks-gaps/src/.gitignore
@@ -0,0 +1 @@
+*.o
diff --git a/packages/i3blocks-gaps/src/bar.c b/packages/i3blocks-gaps/src/bar.c
new file mode 100644
index 0000000..e70e7ae
--- /dev/null
+++ b/packages/i3blocks-gaps/src/bar.c
@@ -0,0 +1,148 @@
+/*
+ * bar.c - status line handling functions
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "bar.h"
+#include "block.h"
+#include "click.h"
+#include "io.h"
+#include "log.h"
+
+void
+bar_poll_timed(struct bar *bar)
+{
+ for (int i = 0; i < bar->num; ++i) {
+ struct block *block = bar->blocks + i;
+
+ /* spawn unless it is only meant for click or signal */
+ if (block->interval != 0)
+ block_spawn(block, NULL);
+ }
+}
+
+void
+bar_poll_clicked(struct bar *bar)
+{
+ char json[1024] = { 0 };
+
+ while (io_readline(STDIN_FILENO, json, sizeof(json)) > 0) {
+ struct click click;
+
+ /* find the corresponding block */
+ click_parse(json, &click);
+ if (!*click.name && !*click.instance)
+ continue;
+
+ for (int i = 0; i < bar->num; ++i) {
+ struct block *block = bar->blocks + i;
+
+ if (strcmp(NAME(block), click.name) == 0 && strcmp(INSTANCE(block), click.instance) == 0) {
+ bdebug(block, "clicked");
+ block_spawn(block, &click);
+ break; /* Unlikely to click several blocks */
+ }
+ }
+ }
+}
+
+void
+bar_poll_outdated(struct bar *bar)
+{
+ for (int i = 0; i < bar->num; ++i) {
+ struct block *block = bar->blocks + i;
+
+ if (block->interval > 0) {
+ const unsigned long now = time(NULL);
+ const unsigned long next_update = block->timestamp + block->interval;
+
+ if (((long) (next_update - now)) <= 0) {
+ bdebug(block, "outdated");
+ block_spawn(block, NULL);
+ }
+ }
+ }
+}
+
+void
+bar_poll_signaled(struct bar *bar, int sig)
+{
+ for (int i = 0; i < bar->num; ++i) {
+ struct block *block = bar->blocks + i;
+
+ if (block->signal == sig) {
+ bdebug(block, "signaled");
+ block_spawn(block, NULL);
+ }
+ }
+}
+
+void
+bar_poll_exited(struct bar *bar)
+{
+ for (;;) {
+ siginfo_t infop = { 0 };
+
+ /* Non-blocking check for dead child(ren) */
+ if (waitid(P_ALL, 0, &infop, WEXITED | WNOHANG | WNOWAIT) == -1)
+ if (errno != ECHILD)
+ errorx("waitid");
+
+ /* Error or no (dead yet) child(ren) */
+ if (infop.si_pid == 0)
+ break;
+
+ /* Find the dead process */
+ for (int i = 0; i < bar->num; ++i) {
+ struct block *block = bar->blocks + i;
+
+ if (block->pid == infop.si_pid) {
+ bdebug(block, "exited");
+ block_reap(block);
+ if (block->interval == INTER_REPEAT) {
+ if (block->timestamp == time(NULL))
+ berror(block, "loop too fast");
+ block_spawn(block, NULL);
+ } else if (block->interval == INTER_PERSIST) {
+ bdebug(block, "unexpected exit?");
+ }
+ break;
+ }
+ }
+ }
+}
+
+void
+bar_poll_readable(struct bar *bar, const int fd)
+{
+ for (int i = 0; i < bar->num; ++i) {
+ struct block *block = bar->blocks + i;
+
+ if (block->out == fd) {
+ bdebug(block, "readable");
+ block_update(block);
+ break;
+ }
+ }
+}
diff --git a/packages/i3blocks-gaps/src/block.c b/packages/i3blocks-gaps/src/block.c
new file mode 100644
index 0000000..792a06e
--- /dev/null
+++ b/packages/i3blocks-gaps/src/block.c
@@ -0,0 +1,386 @@
+/*
+ * block.c - update of a single status line block
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "block.h"
+#include "click.h"
+#include "io.h"
+#include "json.h"
+#include "log.h"
+
+static void
+child_setenv(struct block *block, const char *name, const char *value)
+{
+ if (setenv(name, value, 1) == -1) {
+ berrorx(block, "setenv(%s=%s)", name, value);
+ _exit(EXIT_ERR_INTERNAL);
+ }
+}
+
+static void
+child_setup_env(struct block *block, struct click *click)
+{
+ child_setenv(block, "BLOCK_NAME", NAME(block));
+ child_setenv(block, "BLOCK_INSTANCE", INSTANCE(block));
+ child_setenv(block, "BLOCK_INTERVAL", INTERVAL(block));
+ child_setenv(block, "BLOCK_BUTTON", click ? click->button : "");
+ child_setenv(block, "BLOCK_X", click ? click->x : "");
+ child_setenv(block, "BLOCK_Y", click ? click->y : "");
+}
+
+static void
+child_reset_signals(struct block *block)
+{
+ sigset_t set;
+
+ if (sigfillset(&set) == -1) {
+ berrorx(block, "sigfillset");
+ _exit(EXIT_ERR_INTERNAL);
+ }
+
+ /* It should be safe to assume that all signals are unblocked by default */
+ if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) {
+ berrorx(block, "sigprocmask");
+ _exit(EXIT_ERR_INTERNAL);
+ }
+}
+
+static void
+child_redirect_write(struct block *block, int pipe[2], int fd)
+{
+ if (close(pipe[0]) == -1) {
+ berrorx(block, "close pipe read end");
+ _exit(EXIT_ERR_INTERNAL);
+ }
+
+ /* Defensive check */
+ if (pipe[1] == fd)
+ return;
+
+ if (dup2(pipe[1], fd) == -1) {
+ berrorx(block, "dup pipe write end");
+ _exit(EXIT_ERR_INTERNAL);
+ }
+
+ if (close(pipe[1]) == -1) {
+ berrorx(block, "close pipe write end");
+ _exit(EXIT_ERR_INTERNAL);
+ }
+}
+
+static void
+child_exec(struct block *block)
+{
+ static const char * const shell = "/bin/sh";
+
+ execl(shell, shell, "-c", COMMAND(block), (char *) NULL);
+ /* Unlikely to reach this point */
+ berrorx(block, "exec(%s -c %s)", shell, COMMAND(block));
+ _exit(EXIT_ERR_INTERNAL);
+}
+
+static void
+block_dump_stderr(struct block *block)
+{
+ char buf[2048] = { 0 };
+
+ /* Note read(2) returns 0 for end-of-pipe */
+ if (read(block->err, buf, sizeof(buf) - 1) == -1) {
+ berrorx(block, "read stderr");
+ return;
+ }
+
+ if (*buf)
+ bdebug(block, "stderr:\n{\n%s\n}", buf);
+}
+
+static void
+linecpy(char **lines, char *dest, size_t size)
+{
+ char *newline = strchr(*lines, '\n');
+
+ /* split if there's a newline */
+ if (newline)
+ *newline = '\0';
+
+ strncpy(dest, *lines, size);
+ *lines += strlen(dest);
+
+ /* increment if next char is non-null */
+ if (*(*lines + 1))
+ *lines += 1;
+}
+
+static void
+mark_as_failed(struct block *block, const char *reason)
+{
+ if (log_level < LOG_WARN)
+ return;
+
+ struct properties *props = &block->updated_props;
+
+ memset(props, 0, sizeof(struct properties));
+ strcpy(props->name, NAME(block));
+ strcpy(props->instance, INSTANCE(block));
+ snprintf(props->full_text, sizeof(props->full_text), "[%s] %s", NAME(block), reason);
+ snprintf(props->short_text, sizeof(props->short_text), "[%s] ERROR", NAME(block));
+ strcpy(props->color, "#FF0000");
+ strcpy(props->urgent, "true");
+}
+
+static void
+block_update_plain_text(struct block *block, char *buf)
+{
+ struct properties *props = &block->updated_props;
+ char *lines = buf;
+
+ linecpy(&lines, props->full_text, sizeof(props->full_text) - 1);
+ if (block->interval == INTER_PERSIST)
+ return;
+
+ linecpy(&lines, props->short_text, sizeof(props->short_text) - 1);
+ if (*lines)
+ linecpy(&lines, props->color, sizeof(props->color) - 1);
+}
+
+static void
+block_update_json(struct block *block, char *buf)
+{
+ struct properties *props = &block->updated_props;
+ int start, length, size;
+
+#define PARSE(_name, _size, _flags) \
+ if ((_flags) & PROP_I3BAR) { \
+ json_parse(buf, #_name, &start, &length); \
+ if (start > 0) { \
+ size = _size - 1 < length ? _size - 1 : length; \
+ strncpy(props->_name, buf + start, size); \
+ props->_name[size] = '\0'; \
+ } \
+ }
+
+ PROPERTIES(PARSE);
+
+#undef PARSE
+}
+
+void
+block_update(struct block *block)
+{
+ struct properties *props = &block->updated_props;
+ char buf[2048] = { 0 };
+ int nr;
+
+ /* Read a single line for persistent block, everything otherwise */
+ if (block->interval == INTER_PERSIST) {
+ nr = io_readline(block->out, buf, sizeof(buf));
+ if (nr < 0) {
+ berror(block, "failed to read a line");
+ return mark_as_failed(block, "failed to read");
+ } else if (nr == 0) {
+ berror(block, "pipe closed");
+ return mark_as_failed(block, "pipe closed");
+ }
+ } else {
+ /* Note: read(2) returns 0 for end-of-pipe */
+ if (read(block->out, buf, sizeof(buf) - 1) == -1) {
+ berrorx(block, "read stdout");
+ return mark_as_failed(block, strerror(errno));
+ }
+ }
+
+ /* Reset the defaults and merge the output */
+ memcpy(props, &block->default_props, sizeof(struct properties));
+
+ if (block->format == FORMAT_JSON)
+ block_update_json(block, buf);
+ else
+ block_update_plain_text(block, buf);
+
+ if (*FULL_TEXT(block) && *LABEL(block)) {
+ static const size_t size = sizeof(props->full_text);
+ char concat[size];
+ snprintf(concat, size, "%s %s", LABEL(block), FULL_TEXT(block));
+ strcpy(props->full_text, concat);
+ }
+
+ bdebug(block, "updated successfully");
+}
+
+void
+block_spawn(struct block *block, struct click *click)
+{
+ const unsigned long now = time(NULL);
+ int out[2], err[2];
+
+ if (!*COMMAND(block)) {
+ bdebug(block, "no command, skipping");
+ return;
+ }
+
+ if (block->pid > 0) {
+ bdebug(block, "process already spawned");
+ return;
+ }
+
+ if (pipe(out) == -1 || pipe(err) == -1) {
+ berrorx(block, "pipe");
+ return mark_as_failed(block, strerror(errno));
+ }
+
+ if (block->interval == INTER_PERSIST) {
+ if (io_signal(out[0], SIGRTMIN))
+ return mark_as_failed(block, "event I/O impossible");
+ }
+
+ block->pid = fork();
+ if (block->pid == -1) {
+ berrorx(block, "fork");
+ return mark_as_failed(block, strerror(errno));
+ }
+
+ /* Child? */
+ if (block->pid == 0) {
+ /* Error messages are merged into the parent's stderr... */
+ child_setup_env(block, click);
+ child_reset_signals(block);
+ child_redirect_write(block, out, STDOUT_FILENO);
+ child_redirect_write(block, err, STDERR_FILENO);
+ /* ... until here */
+ child_exec(block);
+ }
+
+ /*
+ * Note: for non-persistent blocks, no need to set the pipe read end as
+ * non-blocking, since it is meant to be read once the child has exited
+ * (and thus the write end is closed and read is available).
+ */
+
+ /* Parent */
+ if (close(out[1]) == -1)
+ berrorx(block, "close stdout");
+ if (close(err[1]) == -1)
+ berrorx(block, "close stderr");
+
+ block->out = out[0];
+ block->err = err[0];
+
+ if (!click)
+ block->timestamp = now;
+
+ bdebug(block, "forked child %d at %ld", block->pid, now);
+}
+
+void
+block_reap(struct block *block)
+{
+ int status, code;
+
+ if (block->pid <= 0) {
+ bdebug(block, "not spawned yet");
+ return;
+ }
+
+ if (waitpid(block->pid, &status, 0) == -1) {
+ berrorx(block, "waitpid(%d)", block->pid);
+ mark_as_failed(block, strerror(errno));
+ goto close;
+ }
+
+ code = WEXITSTATUS(status);
+ bdebug(block, "process %d exited with %d", block->pid, code);
+
+ /* Process successfully reaped, reset the block PID */
+ block->pid = 0;
+
+ block_dump_stderr(block);
+
+ if (code != 0 && code != EXIT_URGENT) {
+ char reason[32];
+
+ if (code == EXIT_ERR_INTERNAL)
+ sprintf(reason, "internal error");
+ else
+ sprintf(reason, "bad exit code %d", code);
+
+ berror(block, "%s", reason);
+ mark_as_failed(block, reason);
+ goto close;
+ }
+
+ /* Do not update unless it was meant to terminate */
+ if (block->interval == INTER_PERSIST)
+ goto close;
+
+ block_update(block);
+
+ /* Exit code takes precedence over the output */
+ if (code == EXIT_URGENT)
+ strcpy(block->updated_props.urgent, "true");
+close:
+ if (close(block->out) == -1)
+ berrorx(block, "close stdout");
+ if (close(block->err) == -1)
+ berrorx(block, "close stderr");
+
+ /* Invalidate descriptors to avoid misdetection after reassignment */
+ block->out = block->err = -1;
+}
+
+void block_setup(struct block *block)
+{
+ struct properties *defaults = &block->default_props;
+ struct properties *updated = &block->updated_props;
+
+ /* Convenient shortcuts */
+ if (strcmp(defaults->interval, "once") == 0)
+ block->interval = INTER_ONCE;
+ else if (strcmp(defaults->interval, "repeat") == 0)
+ block->interval = INTER_REPEAT;
+ else if (strcmp(defaults->interval, "persist") == 0)
+ block->interval = INTER_PERSIST;
+ else
+ block->interval = atoi(defaults->interval);
+
+ if (strcmp(defaults->format, "json") == 0)
+ block->format = FORMAT_JSON;
+ else
+ block->format = FORMAT_PLAIN;
+
+ block->signal = atoi(defaults->signal);
+
+ /* First update (for static blocks and loading labels) */
+ memcpy(updated, defaults, sizeof(struct properties));
+
+#define PLACEHOLDERS(_name, _size, _flags) " %s: \"%s\"\n"
+#define ARGS(_name, _size, _flags) #_name, updated->_name,
+
+ debug("\n{\n" PROPERTIES(PLACEHOLDERS) "%s", PROPERTIES(ARGS) "}");
+
+#undef ARGS
+#undef PLACEHOLDERS
+}
diff --git a/packages/i3blocks-gaps/src/click.c b/packages/i3blocks-gaps/src/click.c
new file mode 100644
index 0000000..e9ba6b1
--- /dev/null
+++ b/packages/i3blocks-gaps/src/click.c
@@ -0,0 +1,66 @@
+/*
+ * click.c - read and parse of a click
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#include "click.h"
+#include "json.h"
+#include "log.h"
+
+/*
+ * Parse a click, previous read from stdin.
+ *
+ * A click looks like this ("name" and "instance" can be absent):
+ *
+ * ',{"name":"foo","instance":"bar","button":1,"x":1186,"y":13}\n'
+ *
+ * Note that this function is non-idempotent. We need to parse from right to
+ * left. It's ok since the JSON layout is known and fixed.
+ */
+void
+click_parse(char *json, struct click *click)
+{
+ int nst, nlen;
+ int ist, ilen;
+ int bst, blen;
+ int xst, xlen;
+ int yst, ylen;
+
+ json_parse(json, "y", &yst, &ylen);
+ json_parse(json, "x", &xst, &xlen);
+ json_parse(json, "button", &bst, &blen);
+ json_parse(json, "instance", &ist, &ilen);
+ json_parse(json, "name", &nst, &nlen);
+
+ click->name = json + nst;
+ *(click->name + nlen) = '\0';
+
+ click->instance = json + ist;
+ *(click->instance + ilen) = '\0';
+
+ click->button = json + bst;
+ *(click->button + blen) = '\0';
+
+ click->y = json + yst;
+ *(click->y + ylen) = '\0';
+
+ click->x = json + xst;
+ *(click->x + xlen) = '\0';
+
+ debug("parsed click: name=%s instance=%s button=%s x=%s y=%s",
+ click->name, click->instance,
+ click->button, click->x, click->y);
+}
diff --git a/packages/i3blocks-gaps/src/ini.c b/packages/i3blocks-gaps/src/ini.c
new file mode 100644
index 0000000..62430cc
--- /dev/null
+++ b/packages/i3blocks-gaps/src/ini.c
@@ -0,0 +1,247 @@
+/*
+ * ini.c - parsing of the INI configuration file
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "bar.h"
+#include "block.h"
+#include "log.h"
+
+#ifndef SYSCONFDIR
+#define SYSCONFDIR "/etc"
+#endif
+
+static struct block *
+add_block(struct bar *bar)
+{
+ struct block *block = NULL;
+ void *reloc;
+
+ reloc = realloc(bar->blocks, sizeof(struct block) * (bar->num + 1));
+ if (reloc) {
+ bar->blocks = reloc;
+ block = bar->blocks + bar->num;
+ bar->num++;
+ }
+
+ return block;
+}
+
+static int
+parse_section(const char *line, char *name, unsigned int size)
+{
+ char *closing = strchr(line, ']');
+ const int len = strlen(line);
+
+ /* stop if the last char is not a closing bracket */
+ if (!closing || line + len - 1 != closing) {
+ error("malformated section \"%s\"", line);
+ return 1;
+ }
+
+ if (size - 1 < len - 2) {
+ error("section name too long \"%s\"", line);
+ return 1;
+ }
+
+ memcpy(name, line + 1, len - 2);
+ name[len - 2] = '\0';
+ return 0;
+}
+
+static int
+parse_property(const char *line, struct properties *props, bool strict)
+{
+ char *equal = strchr(line, '=');
+ const char *key, *value;
+
+ if (!equal) {
+ error("malformated property, should be a key=value pair");
+ return 1;
+ }
+
+ /* split key and value */
+ *equal = '\0';
+ key = line;
+ value = equal + 1;
+
+#define PARSE(_name, _size, _flags) \
+ if ((!strict || (_flags) & PROP_I3BAR) && strcmp(key, #_name) == 0) { \
+ strncpy(props->_name, value, _size - 1); \
+ return 0; \
+ }
+
+ PROPERTIES(PARSE);
+
+#undef PARSE
+
+ error("unknown key: \"%s\"", key);
+ return 1;
+}
+
+static struct bar *
+parse_bar(FILE *fp)
+{
+ char line[2048];
+ struct block *block = NULL;
+ struct block global = {};
+ struct bar *bar;
+
+ bar = calloc(1, sizeof(struct bar));
+ if (!bar)
+ return NULL;
+
+ while (fgets(line, sizeof(line), fp) != NULL) {
+ int len = strlen(line);
+
+ if (line[len - 1] != '\n') {
+ error("line \"%s\" is not terminated by a newline", line);
+ goto free;
+ }
+ line[len - 1] = '\0';
+
+ switch (*line) {
+ /* Comment or empty line? */
+ case '#':
+ case '\0':
+ break;
+
+ /* Section? */
+ case '[':
+ /* Finalize previous block */
+ if (block)
+ block_setup(block);
+
+ block = add_block(bar);
+ if (!block)
+ goto free;
+
+ /* Init the block with default settings (if any) */
+ memcpy(block, &global, sizeof(struct block));
+
+ if (parse_section(line, block->default_props.name, sizeof(block->default_props.name)))
+ goto free;
+
+ bdebug(block, "new block");
+ break;
+
+ /* Property? */
+ case 'a' ... 'z':
+ if (!block) {
+ debug("parsing global properties");
+ block = &global;
+ }
+
+ if (parse_property(line, &block->default_props, false))
+ goto free;
+
+ break;
+
+ /* Syntax error */
+ default:
+ error("malformated line: %s", line);
+ goto free;
+ }
+ }
+
+ /* Finalize the last block */
+ if (block)
+ block_setup(block);
+
+ return bar;
+
+free:
+ free(bar->blocks);
+ free(bar);
+ return NULL;
+}
+
+static struct bar *
+try_parse(const char *path, bool *found)
+{
+ struct bar *bar = NULL;
+ bool noent = false;
+ FILE *fp = fopen(path, "r");
+
+ debug("try file %s", path);
+
+ if (!fp) {
+ if (errno == ENOENT && found)
+ noent = true;
+ else
+ errorx("fopen");
+ } else {
+ bar = parse_bar(fp);
+
+ if (fclose(fp))
+ errorx("fclose");
+ }
+
+ if (found)
+ *found = !noent;
+
+ return bar;
+}
+
+struct bar *
+ini_load(const char *inifile)
+{
+ const char * const home = getenv("HOME");
+ const char * const xdg_home = getenv("XDG_CONFIG_HOME");
+ const char * const xdg_dirs = getenv("XDG_CONFIG_DIRS");
+ char buf[PATH_MAX];
+ struct bar *bar;
+ bool found;
+
+ /* command line config file? */
+ if (inifile)
+ return try_parse(inifile, NULL);
+
+ /* user config file? */
+ if (home) {
+ if (xdg_home)
+ snprintf(buf, PATH_MAX, "%s/i3blocks/config", xdg_home);
+ else
+ snprintf(buf, PATH_MAX, "%s/.config/i3blocks/config", home);
+ bar = try_parse(buf, &found);
+ if (found)
+ return bar;
+
+ snprintf(buf, PATH_MAX, "%s/.i3blocks.conf", home);
+ bar = try_parse(buf, &found);
+ if (found)
+ return bar;
+ }
+
+ /* system config file? */
+ if (xdg_dirs)
+ snprintf(buf, PATH_MAX, "%s/i3blocks/config", xdg_dirs);
+ else
+ snprintf(buf, PATH_MAX, "%s/xdg/i3blocks/config", SYSCONFDIR);
+ bar = try_parse(buf, &found);
+ if (found)
+ return bar;
+
+ snprintf(buf, PATH_MAX, "%s/i3blocks.conf", SYSCONFDIR);
+ return try_parse(buf, NULL);
+}
diff --git a/packages/i3blocks-gaps/src/io.c b/packages/i3blocks-gaps/src/io.c
new file mode 100644
index 0000000..f05dd40
--- /dev/null
+++ b/packages/i3blocks-gaps/src/io.c
@@ -0,0 +1,91 @@
+/*
+ * io.c - non-blocking I/O operations
+ * Copyright (C) 2015 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#define _GNU_SOURCE /* for F_SETSIG */
+
+#include
+#include
+
+#include "log.h"
+
+int
+io_signal(int fd, int sig)
+{
+ int flags;
+
+ /* Assign the signal for this file descriptor */
+ if (fcntl(fd, F_SETSIG, sig) == -1) {
+ errorx("failed to set signal %d on fd %d", sig, fd);
+ return 1;
+ }
+
+ /* Set owner process that is to receive "I/O possible" signal */
+ if (fcntl(fd, F_SETOWN, getpid()) == -1) {
+ errorx("failed to set process as owner of fd %d", fd);
+ return 1;
+ }
+
+ flags = fcntl(fd, F_GETFL);
+ if (flags == -1) {
+ errorx("failed to get flags of fd %d", fd);
+ return 1;
+ }
+
+ /* Enable "I/O possible" signaling and make I/O nonblocking */
+ if (fcntl(fd, F_SETFL, flags | O_ASYNC | O_NONBLOCK) == -1) {
+ errorx("failed to enable I/O signaling for fd %d", fd);
+ return 1;
+ }
+
+ return 0;
+}
+
+static ssize_t
+read_nonblock(int fd, char *buf, size_t size)
+{
+ ssize_t nr;
+
+ nr = read(fd, buf, size);
+ if (nr == -1) {
+ if (errno == EAGAIN) {
+ /* no more reading */
+ return 0;
+ }
+
+ errorx("read from %d", fd);
+ return -1;
+ }
+
+ /* Note read(2) returns 0 for end-of-pipe */
+ return nr;
+}
+
+int
+io_readline(int fd, char *buffer, size_t size)
+{
+ int nr = 0;
+ char c;
+
+ while (nr < size && read_nonblock(fd, &c, 1) > 0) {
+ buffer[nr++] = c;
+ if (c == '\n')
+ break;
+ }
+
+ return nr;
+}
diff --git a/packages/i3blocks-gaps/src/json.c b/packages/i3blocks-gaps/src/json.c
new file mode 100644
index 0000000..f64bdc0
--- /dev/null
+++ b/packages/i3blocks-gaps/src/json.c
@@ -0,0 +1,156 @@
+/*
+ * json.c - basic JSON parsing and printing
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "bar.h"
+#include "block.h"
+
+static inline bool
+is_number(const char *str)
+{
+ char *end;
+
+ strtoul(str, &end, 10);
+
+ /* not a valid number if end is not a null character */
+ return !(*str == 0 || *end != 0);
+}
+
+static inline void
+escape(const char *str)
+{
+ fprintf(stdout, "\"");
+
+ while (*str) {
+ switch (*str) {
+ case '"':
+ case '\\':
+ fprintf(stdout, "\\%c", *str);
+ break;
+ default:
+ fprintf(stdout, "%c", *str);
+ }
+
+ str++;
+ }
+
+ fprintf(stdout, "\"");
+}
+
+static void
+print_prop(const char *key, const char *value, int flags)
+{
+ /* Only print i3bar-specific properties */
+ if (!(flags & PROP_I3BAR))
+ return;
+
+ if (!*value)
+ return;
+
+ fprintf(stdout, ",\"%s\":", key);
+
+ /* Print as-is (except strings which must be escaped) */
+ if (flags & PROP_STRING && flags & PROP_NUMBER && is_number(value))
+ fprintf(stdout, "%s", value);
+ else if (flags & PROP_STRING)
+ escape(value);
+ else
+ fprintf(stdout, "%s", value);
+}
+
+static void
+print_block(struct block *block)
+{
+#define PRINT(_name, _size, _flags) \
+ print_prop(#_name, block->updated_props._name, _flags); \
+
+ fprintf(stdout, ",{\"\":\"\"");
+ PROPERTIES(PRINT);
+ fprintf(stdout, "}");
+
+#undef PRINT
+}
+
+/*
+ * Parse the input for the key and store the start of its value
+ * into and its size into .
+ *
+ * set to 0 means that the key was not present.
+ */
+void
+json_parse(const char *json, const char *name, int *start, int *len)
+{
+ const size_t keylen = strlen(name) + 2;
+ char key[keylen + 1];
+ snprintf(key, sizeof(key), "\"%s\"", name);
+
+ *start = *len = 0;
+
+ char *here = strstr(json, key);
+ if (here) {
+ here += keylen + 1;
+
+ /* skip pre-value whitespace */
+ while (isspace(*here))
+ here++;
+
+ if (*here == '"') {
+ /* string */
+ here++;
+ *start = here - json;
+ while (*here && *here != '"')
+ *len += 1, here++;
+
+ /* invalidate on incomplete string */
+ if (*here != '"')
+ *start = 0;
+ } else {
+ /* number */
+ *start = here - json;
+ while (isdigit(*here++))
+ *len += 1;
+ }
+ }
+}
+
+void
+json_print_bar(struct bar *bar)
+{
+ fprintf(stdout, ",[{\"full_text\":\"\"}");
+
+ for (int i = 0; i < bar->num; ++i) {
+ struct block *block = bar->blocks + i;
+
+ /* full_text is the only mandatory key, skip if empty */
+ if (!*FULL_TEXT(block)) {
+ bdebug(block, "no text to display, skipping");
+ continue;
+ }
+
+ print_block(block);
+ }
+
+ fprintf(stdout, "]\n");
+ fflush(stdout);
+}
diff --git a/packages/i3blocks-gaps/src/main.c b/packages/i3blocks-gaps/src/main.c
new file mode 100644
index 0000000..4f04fbb
--- /dev/null
+++ b/packages/i3blocks-gaps/src/main.c
@@ -0,0 +1,82 @@
+/*
+ * i3blocks.c - main entry point, load the config and start the scheduler
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#include
+#include
+
+#include "ini.h"
+#include "log.h"
+#include "sched.h"
+
+#ifndef VERSION
+#define VERSION "unknown"
+#endif
+
+unsigned log_level = LOG_NORMAL;
+
+static void
+start(void)
+{
+ fprintf(stdout, "{\"version\":1,\"click_events\":true}\n[[]\n");
+ fflush(stdout);
+}
+
+int
+main(int argc, char *argv[])
+{
+ char *inifile = NULL;
+ struct bar *bar;
+ int c;
+
+ while (c = getopt(argc, argv, "c:vhV"), c != -1) {
+ switch (c) {
+ case 'c':
+ inifile = optarg;
+ break;
+ case 'v':
+ log_level++;
+ break;
+ case 'h':
+ printf("Usage: %s [-c ] [-h] [-V]\n", argv[0]);
+ return 0;
+ case 'V':
+ printf("i3blocks " VERSION " © 2014 Vivien Didelot and contributors\n");
+ return 0;
+ default:
+ error("Try '%s -h' for more information.", argv[0]);
+ return 1;
+ }
+ }
+
+ debug("log level %u", log_level);
+
+ bar = ini_load(inifile);
+ if (!bar) {
+ error("Try '%s -h' for more information.", argv[0]);
+ return 1;
+ }
+
+ if (sched_init(bar))
+ return 1;
+
+ start();
+ sched_start(bar);
+
+ //stop();
+ return 0;
+}
diff --git a/packages/i3blocks-gaps/src/sched.c b/packages/i3blocks-gaps/src/sched.c
new file mode 100644
index 0000000..dabdeef
--- /dev/null
+++ b/packages/i3blocks-gaps/src/sched.c
@@ -0,0 +1,221 @@
+/*
+ * sched.c - scheduling of block updates (timeout, signal or click)
+ * Copyright (C) 2014 Vivien Didelot
+ *
+ * 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 .
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "bar.h"
+#include "block.h"
+#include "io.h"
+#include "json.h"
+#include "log.h"
+
+static sigset_t set;
+
+static int
+gcd(int a, int b)
+{
+ while (b != 0)
+ a %= b, a ^= b, b ^= a, a ^= b;
+
+ return a;
+}
+
+static unsigned int
+longest_sleep(struct bar *bar)
+{
+ unsigned int time = 0;
+
+ if (bar->num > 0 && bar->blocks->interval > 0)
+ time = bar->blocks->interval; /* first block's interval */
+
+ if (bar->num < 2)
+ return time;
+
+ /* The maximum sleep time is actually the GCD between all block intervals */
+ for (int i = 1; i < bar->num; ++i)
+ if ((bar->blocks + i)->interval > 0)
+ time = gcd(time, (bar->blocks + i)->interval);
+
+ return time;
+}
+
+static int
+setup_timer(struct bar *bar)
+{
+ const unsigned sleeptime = longest_sleep(bar);
+
+ if (!sleeptime) {
+ debug("no timer needed");
+ return 0;
+ }
+
+ struct itimerval itv = {
+ .it_value.tv_sec = sleeptime,
+ .it_interval.tv_sec = sleeptime,
+ };
+
+ if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
+ errorx("setitimer");
+ return 1;
+ }
+
+ debug("starting timer with interval of %d seconds", sleeptime);
+ return 0;
+}
+
+static int
+setup_signals(void)
+{
+ if (sigemptyset(&set) == -1) {
+ errorx("sigemptyset");
+ return 1;
+ }
+
+#define ADD_SIG(_sig) \
+ if (sigaddset(&set, _sig) == -1) { errorx("sigaddset(%d)", _sig); return 1; }
+
+ /* Control signals */
+ ADD_SIG(SIGTERM);
+ ADD_SIG(SIGINT);
+
+ /* Timer signal */
+ ADD_SIG(SIGALRM);
+
+ /* Block updates (forks) */
+ ADD_SIG(SIGCHLD);
+
+ /* Deprecated signals */
+ ADD_SIG(SIGUSR1);
+ ADD_SIG(SIGUSR2);
+
+ /* Click signal */
+ ADD_SIG(SIGIO);
+
+ /* I/O Possible signal for persistent blocks */
+ ADD_SIG(SIGRTMIN);
+
+ /* Real-time signals for blocks */
+ for (int sig = SIGRTMIN + 1; sig <= SIGRTMAX; ++sig) {
+ debug("provide signal %d (%s)", sig, strsignal(sig));
+ ADD_SIG(sig);
+ }
+
+#undef ADD_SIG
+
+ /* Block signals for which we are interested in waiting */
+ if (sigprocmask(SIG_SETMASK, &set, NULL) == -1) {
+ errorx("sigprocmask");
+ return 1;
+ }
+
+ return 0;
+}
+
+int
+sched_init(struct bar *bar)
+{
+ if (setup_signals())
+ return 1;
+
+ if (setup_timer(bar))
+ return 1;
+
+ /* Setup event I/O for stdin (clicks) */
+ if (!isatty(STDIN_FILENO))
+ if (io_signal(STDIN_FILENO, SIGIO))
+ return 1;
+
+ return 0;
+}
+
+void
+sched_start(struct bar *bar)
+{
+ siginfo_t siginfo;
+ int sig;
+
+ /*
+ * Initial display (for static blocks and loading labels),
+ * and first forks (for commands with an interval).
+ */
+ json_print_bar(bar);
+ bar_poll_timed(bar);
+
+ while (1) {
+ sig = sigwaitinfo(&set, &siginfo);
+ if (sig == -1) {
+ /* Hiding the bar may interrupt this system call */
+ if (errno == EINTR)
+ continue;
+
+ errorx("sigwaitinfo");
+ break;
+ }
+
+ debug("received signal %d (%s)", sig, strsignal(sig));
+
+ if (sig == SIGTERM || sig == SIGINT)
+ break;
+
+ /* Interval tick? */
+ if (sig == SIGALRM) {
+ bar_poll_outdated(bar);
+
+ /* Child(ren) dead? */
+ } else if (sig == SIGCHLD) {
+ bar_poll_exited(bar);
+ json_print_bar(bar);
+
+ /* Block clicked? */
+ } else if (sig == SIGIO) {
+ bar_poll_clicked(bar);
+
+ /* Persistent block ready to be read? */
+ } else if (sig == SIGRTMIN) {
+ bar_poll_readable(bar, siginfo.si_fd);
+ json_print_bar(bar);
+
+ /* Blocks signaled? */
+ } else if (sig > SIGRTMIN && sig <= SIGRTMAX) {
+ bar_poll_signaled(bar, sig - SIGRTMIN);
+
+ /* Deprecated signals? */
+ } else if (sig == SIGUSR1 || sig == SIGUSR2) {
+ error("SIGUSR{1,2} are deprecated, ignoring.");
+
+ } else debug("unhandled signal %d", sig);
+ }
+
+ /*
+ * Unblock signals (so subsequent syscall can be interrupted)
+ * and wait for child processes termination.
+ */
+ if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1)
+ errorx("sigprocmask");
+ while (waitpid(-1, NULL, 0) > 0)
+ continue;
+
+ debug("quit scheduling");
+}