├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── dwl-bar.1
├── protocols
└── wlr-layer-shell-unstable-v1.xml
└── src
├── bar.c
├── bar.h
├── config.def.h
├── event.c
├── event.h
├── input.c
├── input.h
├── log.c
├── log.h
├── main.c
├── main.h
├── render.c
├── render.h
├── shm.c
├── shm.h
├── user.c
├── user.h
├── util.c
└── util.h
/.gitignore:
--------------------------------------------------------------------------------
1 | .projectile
2 | dwl-bar
3 | compile_flags.txt
4 | bar.log
5 | config.h
6 | *-protocol.*
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | ##
2 | # dwl-bar
3 | #
4 | # @file
5 | # @version 0.0
6 | VERSION = 0.0
7 | PKG_CONFIG = pkg-config
8 |
9 | # paths
10 | PREFIX = /usr/local
11 | MANDIR = $(PREFIX)/share/man
12 | SRCDIR = src
13 |
14 | PKGS = wayland-client wayland-cursor pangocairo
15 | FILES = $(SRCDIR)/main.c $(SRCDIR)/main.h $(SRCDIR)/log.c $(SRCDIR)/log.h \
16 | $(SRCDIR)/render.c $(SRCDIR)/render.h $(SRCDIR)/event.c $(SRCDIR)/event.h \
17 | $(SRCDIR)/util.c $(SRCDIR)/util.h $(SRCDIR)/shm.c $(SRCDIR)/shm.h \
18 | $(SRCDIR)/input.c $(SRCDIR)/input.h $(SRCDIR)/user.c $(SRCDIR)/user.h \
19 | $(SRCDIR)/bar.c $(SRCDIR)/bar.h $(SRCDIR)/config.h
20 | OBJS = $(SRCDIR)/xdg-output-unstable-v1-protocol.o $(SRCDIR)/xdg-shell-protocol.o \
21 | $(SRCDIR)/wlr-layer-shell-unstable-v1-protocol.o
22 |
23 | ## Compile Flags
24 | CC = gcc
25 | BARCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(CFLAGS)
26 | BARLIBS = `$(PKG_CONFIG) --libs $(PKGS)` $(LIBS)
27 |
28 | WAYLAND_SCANNER = `$(PKG_CONFIG) --variable=wayland_scanner wayland-scanner`
29 | WAYLAND_PROTOCOLS = `$(PKG_CONFIG) --variable=pkgdatadir wayland-protocols`
30 |
31 |
32 | all: dwl-bar
33 | dwl-bar: $(FILES) $(OBJS)
34 | $(CC) $^ $(BARLIBS) $(BARCFLAGS) -o $@
35 | $(SRCDIR)/%.o: $(SRCDIR)/%.c $(SRCDIR)/%.h
36 | $(CC) -c $< $(BARLIBS) $(BARCFLAGS) -o $@
37 |
38 | $(SRCDIR)/xdg-shell-protocol.h:
39 | $(WAYLAND_SCANNER) client-header \
40 | $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
41 | $(SRCDIR)/xdg-shell-protocol.c:
42 | $(WAYLAND_SCANNER) private-code \
43 | $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
44 |
45 | $(SRCDIR)/xdg-output-unstable-v1-protocol.h:
46 | $(WAYLAND_SCANNER) client-header \
47 | $(WAYLAND_PROTOCOLS)/unstable/xdg-output/xdg-output-unstable-v1.xml $@
48 | $(SRCDIR)/xdg-output-unstable-v1-protocol.c:
49 | $(WAYLAND_SCANNER) private-code \
50 | $(WAYLAND_PROTOCOLS)/unstable/xdg-output/xdg-output-unstable-v1.xml $@
51 |
52 | $(SRCDIR)/wlr-layer-shell-unstable-v1-protocol.h:
53 | $(WAYLAND_SCANNER) client-header \
54 | protocols/wlr-layer-shell-unstable-v1.xml $@
55 | $(SRCDIR)/wlr-layer-shell-unstable-v1-protocol.c:
56 | $(WAYLAND_SCANNER) private-code \
57 | protocols/wlr-layer-shell-unstable-v1.xml $@
58 |
59 | $(SRCDIR)/config.h:
60 | cp src/config.def.h $@
61 |
62 | dev: clean $(SRCDIR)/config.h $(OBJS)
63 |
64 | clean:
65 | rm -f dwl-bar src/config.h src/*.o src/*-protocol.*
66 |
67 | dist: clean
68 | mkdir -p dwl-bar-$(VERSION)
69 | cp -R LICENSE Makefile README.md dwl-bar.1 src protocols \
70 | dwl-bar-$(VERSION)
71 | tar -caf dwl-bar-$(VERSION).tar.gz dwl-bar-$(VERSION)
72 | rm -rf dwl-bar-$(VERSION)
73 |
74 | install: dwl-bar
75 | mkdir -p $(PREFIX)/bin
76 | cp -f dwl-bar $(PREFIX)/bin
77 | chmod 755 $(PREFIX)/bin/dwl-bar
78 | mkdir -p $(MANDIR)/man1
79 | cp -f dwl-bar.1 $(MANDIR)/man1
80 | chmod 644 $(MANDIR)/man1/dwl-bar.1
81 |
82 | uninstall:
83 | rm -f $(PREFIX)/bin/dwl-bar $(MANDIR)/man1/dwl-bar.1
84 |
85 | # end
86 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # dwl-bar
2 | dwm-like bar for dwl
3 |
4 | I believe dwl-bar provides a more dwm-like experience out of the box than other bars like somebar.
5 |
6 | ## Dependencies
7 | I'm not sure what the package names will be for your distrobution, so just make sure these are generally what you have.
8 | + make
9 | + pango
10 | + cairo
11 | + wayland
12 | + wayland-protocols
13 |
14 | ## Compile
15 | Compile with `make`, install with `make install`, uninstall `make uninstall`.
16 |
17 | ## Configuration
18 | Like most suckless-like software, configuration is done through `src/config.def.h` modify it to your heart's content. dwl-bar is compatible with [someblocks](https://sr.ht/~raphi/someblocks/) for status.
19 |
20 | If you want dwl-bar to control dwl (via mouse gestures primarily) you may want to apply the [ipc](https://github.com/MadcowOG/dwl-bar/wiki/ipc) patch.
21 | **However, do note that you will also need to apply the [ipc](https://github.com/djpohly/dwl/wiki/ipc) patch for dwl.**
22 |
23 | For more information about patching see the [hacking](https://suckless.org/hacking/) article from suckless and the [wiki](https://github.com/MadcowOG/dwl-bar/wiki) for available patches.
24 |
25 | ## Thanks
26 | Thanks to [raphi](https://sr.ht/~raphi/) for [somebar](https://sr.ht/~raphi/somebar/) this project borrows from it.
27 | The ipc protocol is also just the ipc patch in [somebar's `contrib/`](https://git.sr.ht/~raphi/somebar/tree/master/item/contrib/ipc.patch).
28 | Thanks to the swaybar contriutors and [Drew DeVault](https://github.com/ddevault) for [swaybar](https://github.com/swaywm/sway/tree/master/swaybar), I basically did a lot of this project with it open in browser.
29 |
--------------------------------------------------------------------------------
/dwl-bar.1:
--------------------------------------------------------------------------------
1 | .TH dwl-bar 1
2 | .SH NAME
3 | dwl-bar \- dwm-like bar for dwl
4 | .SH SYNOPSIS
5 | .B dwl-bar
6 | .RB [\-v]
7 | .SH DESCRIPTION
8 | dwl-bar is a status bar for dwl.
9 | .SH OPTIONS
10 | .TP
11 | .B \-h
12 | prints help message and exits.
13 | .TP
14 | .B \-v
15 | prints version and exits.
16 | .TP
17 | .B \-l
18 | initiates logging
19 | .SH USAGE
20 | .SS Status
21 | .TP
22 | .B $XDG_RUNTIME_DIR/dwl-bar-x
23 | can be written into with the prefix 'status' to change the bar's status.
24 | .SS Mouse Commands
25 | .TP
26 | .B Middle Button
27 | Click the status label to spawn a terminal.
28 | .SH CUSTOMIZATION
29 | dwl-bar is customized through config.def.h and (re)compiling.
30 | .SH SEE ALSO
31 | .BR dwl (1)
32 | .SH BUGS
33 | Please open an issue at https://github.com/MacowOG/dwl-bar if you encounter any bugs.
34 |
--------------------------------------------------------------------------------
/protocols/wlr-layer-shell-unstable-v1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Copyright © 2017 Drew DeVault
5 |
6 | Permission to use, copy, modify, distribute, and sell this
7 | software and its documentation for any purpose is hereby granted
8 | without fee, provided that the above copyright notice appear in
9 | all copies and that both that copyright notice and this permission
10 | notice appear in supporting documentation, and that the name of
11 | the copyright holders not be used in advertising or publicity
12 | pertaining to distribution of the software without specific,
13 | written prior permission. The copyright holders make no
14 | representations about the suitability of this software for any
15 | purpose. It is provided "as is" without express or implied
16 | warranty.
17 |
18 | THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
19 | SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 | FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
23 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25 | THIS SOFTWARE.
26 |
27 |
28 |
29 |
30 | Clients can use this interface to assign the surface_layer role to
31 | wl_surfaces. Such surfaces are assigned to a "layer" of the output and
32 | rendered with a defined z-depth respective to each other. They may also be
33 | anchored to the edges and corners of a screen and specify input handling
34 | semantics. This interface should be suitable for the implementation of
35 | many desktop shell components, and a broad number of other applications
36 | that interact with the desktop.
37 |
38 |
39 |
40 |
41 | Create a layer surface for an existing surface. This assigns the role of
42 | layer_surface, or raises a protocol error if another role is already
43 | assigned.
44 |
45 | Creating a layer surface from a wl_surface which has a buffer attached
46 | or committed is a client error, and any attempts by a client to attach
47 | or manipulate a buffer prior to the first layer_surface.configure call
48 | must also be treated as errors.
49 |
50 | After creating a layer_surface object and setting it up, the client
51 | must perform an initial commit without any buffer attached.
52 | The compositor will reply with a layer_surface.configure event.
53 | The client must acknowledge it and is then allowed to attach a buffer
54 | to map the surface.
55 |
56 | You may pass NULL for output to allow the compositor to decide which
57 | output to use. Generally this will be the one that the user most
58 | recently interacted with.
59 |
60 | Clients can specify a namespace that defines the purpose of the layer
61 | surface.
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 | These values indicate which layers a surface can be rendered in. They
79 | are ordered by z depth, bottom-most first. Traditional shell surfaces
80 | will typically be rendered between the bottom and top layers.
81 | Fullscreen shell surfaces are typically rendered at the top layer.
82 | Multiple surfaces can share a single layer, and ordering within a
83 | single layer is undefined.
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 | This request indicates that the client will not use the layer_shell
97 | object any more. Objects that have been created through this instance
98 | are not affected.
99 |
100 |
101 |
102 |
103 |
104 |
105 | An interface that may be implemented by a wl_surface, for surfaces that
106 | are designed to be rendered as a layer of a stacked desktop-like
107 | environment.
108 |
109 | Layer surface state (layer, size, anchor, exclusive zone,
110 | margin, interactivity) is double-buffered, and will be applied at the
111 | time wl_surface.commit of the corresponding wl_surface is called.
112 |
113 | Attaching a null buffer to a layer surface unmaps it.
114 |
115 | Unmapping a layer_surface means that the surface cannot be shown by the
116 | compositor until it is explicitly mapped again. The layer_surface
117 | returns to the state it had right after layer_shell.get_layer_surface.
118 | The client can re-map the surface by performing a commit without any
119 | buffer attached, waiting for a configure event and handling it as usual.
120 |
121 |
122 |
123 |
124 | Sets the size of the surface in surface-local coordinates. The
125 | compositor will display the surface centered with respect to its
126 | anchors.
127 |
128 | If you pass 0 for either value, the compositor will assign it and
129 | inform you of the assignment in the configure event. You must set your
130 | anchor to opposite edges in the dimensions you omit; not doing so is a
131 | protocol error. Both values are 0 by default.
132 |
133 | Size is double-buffered, see wl_surface.commit.
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 | Requests that the compositor anchor the surface to the specified edges
142 | and corners. If two orthogonal edges are specified (e.g. 'top' and
143 | 'left'), then the anchor point will be the intersection of the edges
144 | (e.g. the top left corner of the output); otherwise the anchor point
145 | will be centered on that edge, or in the center if none is specified.
146 |
147 | Anchor is double-buffered, see wl_surface.commit.
148 |
149 |
150 |
151 |
152 |
153 |
154 | Requests that the compositor avoids occluding an area with other
155 | surfaces. The compositor's use of this information is
156 | implementation-dependent - do not assume that this region will not
157 | actually be occluded.
158 |
159 | A positive value is only meaningful if the surface is anchored to one
160 | edge or an edge and both perpendicular edges. If the surface is not
161 | anchored, anchored to only two perpendicular edges (a corner), anchored
162 | to only two parallel edges or anchored to all edges, a positive value
163 | will be treated the same as zero.
164 |
165 | A positive zone is the distance from the edge in surface-local
166 | coordinates to consider exclusive.
167 |
168 | Surfaces that do not wish to have an exclusive zone may instead specify
169 | how they should interact with surfaces that do. If set to zero, the
170 | surface indicates that it would like to be moved to avoid occluding
171 | surfaces with a positive exclusive zone. If set to -1, the surface
172 | indicates that it would not like to be moved to accommodate for other
173 | surfaces, and the compositor should extend it all the way to the edges
174 | it is anchored to.
175 |
176 | For example, a panel might set its exclusive zone to 10, so that
177 | maximized shell surfaces are not shown on top of it. A notification
178 | might set its exclusive zone to 0, so that it is moved to avoid
179 | occluding the panel, but shell surfaces are shown underneath it. A
180 | wallpaper or lock screen might set their exclusive zone to -1, so that
181 | they stretch below or over the panel.
182 |
183 | The default value is 0.
184 |
185 | Exclusive zone is double-buffered, see wl_surface.commit.
186 |
187 |
188 |
189 |
190 |
191 |
192 | Requests that the surface be placed some distance away from the anchor
193 | point on the output, in surface-local coordinates. Setting this value
194 | for edges you are not anchored to has no effect.
195 |
196 | The exclusive zone includes the margin.
197 |
198 | Margin is double-buffered, see wl_surface.commit.
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 | Types of keyboard interaction possible for layer shell surfaces. The
209 | rationale for this is twofold: (1) some applications are not interested
210 | in keyboard events and not allowing them to be focused can improve the
211 | desktop experience; (2) some applications will want to take exclusive
212 | keyboard focus.
213 |
214 |
215 |
216 |
217 | This value indicates that this surface is not interested in keyboard
218 | events and the compositor should never assign it the keyboard focus.
219 |
220 | This is the default value, set for newly created layer shell surfaces.
221 |
222 | This is useful for e.g. desktop widgets that display information or
223 | only have interaction with non-keyboard input devices.
224 |
225 |
226 |
227 |
228 | Request exclusive keyboard focus if this surface is above the shell surface layer.
229 |
230 | For the top and overlay layers, the seat will always give
231 | exclusive keyboard focus to the top-most layer which has keyboard
232 | interactivity set to exclusive. If this layer contains multiple
233 | surfaces with keyboard interactivity set to exclusive, the compositor
234 | determines the one receiving keyboard events in an implementation-
235 | defined manner. In this case, no guarantee is made when this surface
236 | will receive keyboard focus (if ever).
237 |
238 | For the bottom and background layers, the compositor is allowed to use
239 | normal focus semantics.
240 |
241 | This setting is mainly intended for applications that need to ensure
242 | they receive all keyboard events, such as a lock screen or a password
243 | prompt.
244 |
245 |
246 |
247 |
248 | This requests the compositor to allow this surface to be focused and
249 | unfocused by the user in an implementation-defined manner. The user
250 | should be able to unfocus this surface even regardless of the layer
251 | it is on.
252 |
253 | Typically, the compositor will want to use its normal mechanism to
254 | manage keyboard focus between layer shell surfaces with this setting
255 | and regular toplevels on the desktop layer (e.g. click to focus).
256 | Nevertheless, it is possible for a compositor to require a special
257 | interaction to focus or unfocus layer shell surfaces (e.g. requiring
258 | a click even if focus follows the mouse normally, or providing a
259 | keybinding to switch focus between layers).
260 |
261 | This setting is mainly intended for desktop shell components (e.g.
262 | panels) that allow keyboard interaction. Using this option can allow
263 | implementing a desktop shell that can be fully usable without the
264 | mouse.
265 |
266 |
267 |
268 |
269 |
270 |
271 | Set how keyboard events are delivered to this surface. By default,
272 | layer shell surfaces do not receive keyboard events; this request can
273 | be used to change this.
274 |
275 | This setting is inherited by child surfaces set by the get_popup
276 | request.
277 |
278 | Layer surfaces receive pointer, touch, and tablet events normally. If
279 | you do not want to receive them, set the input region on your surface
280 | to an empty region.
281 |
282 | Keyboard interactivity is double-buffered, see wl_surface.commit.
283 |
284 |
285 |
286 |
287 |
288 |
289 | This assigns an xdg_popup's parent to this layer_surface. This popup
290 | should have been created via xdg_surface::get_popup with the parent set
291 | to NULL, and this request must be invoked before committing the popup's
292 | initial state.
293 |
294 | See the documentation of xdg_popup for more details about what an
295 | xdg_popup is and how it is used.
296 |
297 |
298 |
299 |
300 |
301 |
302 | When a configure event is received, if a client commits the
303 | surface in response to the configure event, then the client
304 | must make an ack_configure request sometime before the commit
305 | request, passing along the serial of the configure event.
306 |
307 | If the client receives multiple configure events before it
308 | can respond to one, it only has to ack the last configure event.
309 |
310 | A client is not required to commit immediately after sending
311 | an ack_configure request - it may even ack_configure several times
312 | before its next surface commit.
313 |
314 | A client may send multiple ack_configure requests before committing, but
315 | only the last request sent before a commit indicates which configure
316 | event the client really is responding to.
317 |
318 |
319 |
320 |
321 |
322 |
323 | This request destroys the layer surface.
324 |
325 |
326 |
327 |
328 |
329 | The configure event asks the client to resize its surface.
330 |
331 | Clients should arrange their surface for the new states, and then send
332 | an ack_configure request with the serial sent in this configure event at
333 | some point before committing the new surface.
334 |
335 | The client is free to dismiss all but the last configure event it
336 | received.
337 |
338 | The width and height arguments specify the size of the window in
339 | surface-local coordinates.
340 |
341 | The size is a hint, in the sense that the client is free to ignore it if
342 | it doesn't resize, pick a smaller size (to satisfy aspect ratio or
343 | resize in steps of NxM pixels). If the client picks a smaller size and
344 | is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the
345 | surface will be centered on this axis.
346 |
347 | If the width or height arguments are zero, it means the client should
348 | decide its own window dimension.
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 | The closed event is sent by the compositor when the surface will no
358 | longer be shown. The output may have been destroyed or the user may
359 | have asked for it to be removed. Further changes to the surface will be
360 | ignored. The client should destroy the resource after receiving this
361 | event, and create a new surface if they so choose.
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 | Change the layer that the surface is rendered on.
384 |
385 | Layer is double-buffered, see wl_surface.commit.
386 |
387 |
388 |
389 |
390 |
391 |
--------------------------------------------------------------------------------
/src/bar.c:
--------------------------------------------------------------------------------
1 | #include "bar.h"
2 | #include "cairo.h"
3 | #include "config.h"
4 | #include "input.h"
5 | #include "main.h"
6 | #include "pango/pango-item.h"
7 | #include "pango/pango-layout.h"
8 | #include "render.h"
9 | #include "user.h"
10 | #include "util.h"
11 | #include "log.h"
12 | #include "pango/pango.h"
13 | #include
14 |
15 | static void bar_click(struct Monitor *monitor, void *data, uint32_t button, double x, double y);
16 | static int bar_component_add_elipses(struct BasicComponent *component, struct Pipeline *pipeline, int limit);
17 | static struct BasicComponent *bar_component_create(struct Pipeline *pipeline);
18 | static int bar_component_width(struct BasicComponent *component, struct Pipeline *pipeline);
19 | static void bar_bounds(void *data, double *x, double *y, double *width, double *height);
20 | static enum Clicked bar_get_location(struct Bar *bar, double x, double y, int *tag_index);
21 | static void bar_layout_render(struct Pipeline *pipeline, struct Bar *bar, cairo_t *painter, int *x, int *y);
22 | static void bar_render(struct Pipeline *pipeline, void *data, cairo_t *painter, int *x, int *y);
23 | static void bar_tags_render(struct Pipeline *pipeline, struct Bar *bar, cairo_t *painter, int *x, int *y);
24 | static void bar_title_render(struct Pipeline *pipeline, struct Bar *bar, cairo_t *painter, int *x, int *y);
25 | static void bar_status_render(struct Pipeline *pipeline, struct Bar *bar, cairo_t *painter, int *x, int *y);
26 | static int bar_width(struct Pipeline *pipeline, void *data, unsigned int future_widths);
27 |
28 | const struct PipelineListener bar_pipeline_listener = { .render = bar_render, .width = bar_width, };
29 | const struct HotspotListener bar_hotspot_listener = { .click = bar_click, .bounds = bar_bounds };
30 |
31 | void bar_click(struct Monitor *monitor, void *data, uint32_t button, double x, double y) {
32 | if (!monitor || !data)
33 | return;
34 |
35 | struct Bar *bar = data;
36 | const struct Binding *binding;
37 | union Arg *argp = NULL, arg;
38 | int tag_index = -1;
39 | enum Clicked clicked = bar_get_location(bar, x, y, &tag_index);
40 |
41 | if (clicked == Click_Tag) {
42 | arg.ui = tag_index;
43 | argp = &arg;
44 | }
45 |
46 | for (int i = 0; i < LENGTH(bindings); i++) {
47 | binding = &bindings[i];
48 | if (clicked != binding->clicked || button != binding->button)
49 | continue;
50 |
51 | binding->callback(monitor, (argp && !binding->bypass) ? argp : &binding->arg);
52 | }
53 | }
54 |
55 | int bar_component_add_elipses(struct BasicComponent *component, struct Pipeline *pipeline, int limit) {
56 | const char *current_string = pango_layout_get_text(component->layout);
57 | char *new_string;
58 | const int elipses_amnt = 3;
59 | int i;
60 |
61 | for (i = strlen(current_string);
62 | (((i+elipses_amnt)*pipeline->font->approx_width)+pipeline->font->height > limit && i >= 0);
63 | i--);
64 |
65 | if (i <= 0)
66 | return 0;
67 |
68 | new_string = strncpy(ecalloc(i+elipses_amnt+1, sizeof(*new_string)),
69 | current_string, i);
70 | new_string[i+1] = '\0';
71 | new_string = strcat(new_string, "...");
72 |
73 | pango_layout_set_text(component->layout, new_string, -1);
74 | free(new_string);
75 | return bar_component_width(component, pipeline);
76 | }
77 |
78 | struct BasicComponent *bar_component_create(struct Pipeline *pipeline) {
79 | if (!pipeline)
80 | return NULL;
81 |
82 | struct BasicComponent *component = basic_component_create(pipeline->context, pipeline->font->description);
83 | component->tx = pipeline->font->height/2.0;
84 | component->ty = 1;
85 | return component;
86 | }
87 |
88 | int bar_component_width(struct BasicComponent *component, struct Pipeline *pipeline) {
89 | return basic_component_text_width(component) + pipeline->font->height;
90 | }
91 |
92 | void bar_bounds(void *data, double *x, double *y, double *width, double *height) {
93 | struct Bar *bar = data;
94 | int bar_width = 0;
95 | struct Tag *tag;
96 | for (int i = 0; i < LENGTH(bar->tags); i++) {
97 | tag = &bar->tags[i];
98 | bar_width += tag->component->width;
99 | }
100 | bar_width += bar->layout->width;
101 | bar_width += bar->title->width;
102 | bar_width += bar->status->width;
103 |
104 | *x = bar->x;
105 | *y = bar->y;
106 | *width = bar_width;
107 | *height = bar->pipeline->shm->height;
108 | }
109 |
110 | enum Clicked bar_get_location(struct Bar *bar, double x, double y, int *tag_index) {
111 | enum Clicked clicked = Click_None;
112 | struct Tag *tag;
113 |
114 | for (int i = 0; i < LENGTH(bar->tags); i++) {
115 | tag = &bar->tags[i];
116 | if (basic_component_is_clicked(tag->component, x, y)) {
117 | clicked = Click_Tag;
118 | *tag_index = i;
119 | return clicked;
120 | }
121 | }
122 |
123 | if (basic_component_is_clicked(bar->layout, x, y))
124 | clicked = Click_Layout;
125 | else if (basic_component_is_clicked(bar->title, x, y))
126 | clicked = Click_Title;
127 | else if (basic_component_is_clicked(bar->status, x, y))
128 | clicked = Click_Status;
129 |
130 | return clicked;
131 | }
132 |
133 | struct Bar *bar_create(struct List *hotspots, struct Pipeline *pipeline) {
134 | if (!pipeline)
135 | return NULL;
136 |
137 | struct Bar *bar = ecalloc(1, sizeof(*bar));
138 | bar->pipeline = pipeline;
139 | bar->title = bar_component_create(pipeline);
140 | bar->layout = bar_component_create(pipeline);
141 | bar->status = bar_component_create(pipeline);
142 |
143 | char *status = string_create("dwl %.1f", VERSION);
144 | pango_layout_set_text(bar->status->layout, status, strlen(status));
145 | free(status);
146 |
147 | struct Tag *tag;
148 | for (int i = 0; i < LENGTH(tags); i++) {
149 | tag = &bar->tags[i];
150 | *tag = (struct Tag){ 0, 0, 0,
151 | bar_component_create(pipeline) };
152 | pango_layout_set_text(tag->component->layout, tags[i], strlen(tags[i]));
153 | tag->component->width = basic_component_text_width(tag->component) + pipeline->font->height;
154 | }
155 |
156 | pipeline_add(pipeline, &bar_pipeline_listener, bar);
157 | struct Hotspot *hotspot = list_add(hotspots, ecalloc(1, sizeof(*hotspot)));
158 | hotspot->listener = &bar_hotspot_listener;
159 | hotspot->data = bar;
160 |
161 | bar->x = 0;
162 | bar->y = 0;
163 |
164 | return bar;
165 | }
166 |
167 | void bar_destroy(struct Bar *bar) {
168 | if (!bar) return;
169 |
170 | basic_component_destroy(bar->title);
171 | basic_component_destroy(bar->layout);
172 | basic_component_destroy(bar->status);
173 | struct Tag *tag;
174 | for (int i = 0; i < LENGTH(bar->tags); i++) {
175 | tag = &bar->tags[i];
176 | basic_component_destroy(tag->component);
177 | }
178 | free(bar);
179 | }
180 |
181 | void bar_layout_render(struct Pipeline *pipeline, struct Bar *bar, cairo_t *painter, int *x, int *y) {
182 | if (!bar || !pipeline)
183 | return;
184 |
185 | bar->layout->width = bar_component_width(bar->layout, pipeline);
186 | bar->layout->height = pipeline->shm->height;
187 | pipeline_set_colorscheme(pipeline, schemes[InActive_Scheme]);
188 | basic_component_render(bar->layout, pipeline, painter, x, y);
189 |
190 | *x += bar->layout->width;
191 | }
192 |
193 | void bar_render(struct Pipeline *pipeline, void *data, cairo_t *painter, int *x, int *y) {
194 | if (!pipeline || !data)
195 | return;
196 |
197 | struct Bar *bar = data;
198 | bar->x = *x;
199 | bar->y = *y;
200 | bar_tags_render(pipeline, bar, painter, x, y);
201 | bar_layout_render(pipeline, bar, painter, x, y);
202 | bar_title_render(pipeline, bar, painter, x, y);
203 | bar_status_render(pipeline, bar, painter, x, y);
204 | }
205 |
206 | void bar_tags_render(struct Pipeline *pipeline, struct Bar *bar, cairo_t *painter, int *x, int *y) {
207 | if (!bar || !pipeline)
208 | return;
209 |
210 | struct Tag *tag;
211 | for (int i = 0; i < LENGTH(bar->tags); i++) {
212 | tag = &bar->tags[i];
213 |
214 | if (tag->state & Tag_Active)
215 | pipeline_set_colorscheme(pipeline, schemes[Active_Scheme]);
216 | else if (tag->state & Tag_Urgent)
217 | pipeline_set_colorscheme(pipeline, schemes[Urgent_Scheme]);
218 | else
219 | pipeline_set_colorscheme(pipeline, schemes[InActive_Scheme]);
220 |
221 | tag->component->height = pipeline->shm->height;
222 | basic_component_render(tag->component, pipeline, painter, x, y);
223 |
224 | if (!tag->occupied)
225 | goto done;
226 |
227 | /* Creating the occupied tag box */
228 | int boxHeight = pipeline->font->height / 9,
229 | boxWidth = pipeline->font->height / 6 + 1;
230 |
231 | if (tag->has_focused) {
232 | cairo_rectangle(painter, *x + boxHeight, boxHeight, boxWidth, boxWidth);
233 | cairo_fill(painter);
234 | } else {
235 | cairo_rectangle(painter, *x + boxHeight + 0.5, boxHeight + 0.5, boxWidth, boxWidth);
236 | cairo_set_line_width(painter, 1);
237 | cairo_stroke(painter);
238 | }
239 |
240 | done:
241 | *x += tag->component->width;
242 | }
243 | }
244 |
245 | void bar_title_render(struct Pipeline *pipeline, struct Bar *bar, cairo_t *painter, int *x, int *y) {
246 | if (!bar || !pipeline)
247 | return;
248 |
249 | if (bar->active)
250 | pipeline_set_colorscheme(pipeline, schemes[Active_Scheme]);
251 | else
252 | pipeline_set_colorscheme(pipeline, schemes[InActive_Scheme]);
253 |
254 | bar->title->width = pipeline->shm->width - *x - bar_component_width(bar->status, pipeline) - pipeline_get_future_widths(pipeline);
255 | bar->title->height = pipeline->shm->height;
256 |
257 | if (bar_component_width(bar->title, pipeline) > bar->title->width)
258 | bar->title->width = bar_component_width(bar->title, pipeline);
259 |
260 | basic_component_render(bar->title, pipeline, painter, x, y);
261 |
262 | if (!bar->floating)
263 | goto done;
264 |
265 | int boxHeight = pipeline->font->height / 9,
266 | boxWidth = pipeline->font->height / 6 + 1;
267 |
268 | set_color(painter, grey3);
269 | cairo_rectangle(painter, *x + boxHeight + 0.5, boxHeight + 0.5, boxWidth, boxWidth);
270 | cairo_set_line_width(painter, 1);
271 | cairo_stroke(painter);
272 |
273 | done:
274 | *x += bar->title->width;
275 | }
276 |
277 | void bar_status_render(struct Pipeline *pipeline, struct Bar *bar, cairo_t *painter, int *x, int *y) {
278 | if (!bar || !pipeline)
279 | return;
280 |
281 | char *previous_status = NULL;
282 |
283 | pipeline_set_colorscheme(pipeline, schemes[InActive_Scheme]);
284 | if (!bar->active && status_on_active)
285 | pipeline_set_colorscheme(pipeline, (const int *[4]){ grey1, grey1 });
286 |
287 | bar->status->width = bar_component_width(bar->status, pipeline);
288 | bar->status->height = pipeline->shm->height;
289 |
290 | if (bar->status->width > (pipeline->shm->width - *x - pipeline_get_future_widths(pipeline))) {
291 | previous_status = strdup(pango_layout_get_text(bar->status->layout));
292 | bar->status->width = bar_component_add_elipses(bar->status, pipeline,
293 | (pipeline->shm->width - *x - pipeline_get_future_widths(pipeline)));
294 | if (bar->status->width == 0) {
295 | free(previous_status);
296 | return;
297 | }
298 | }
299 |
300 | basic_component_render(bar->status, pipeline, painter, x, y);
301 |
302 | if (previous_status) {
303 | pango_layout_set_text(bar->status->layout, previous_status, -1);
304 | free(previous_status);
305 | }
306 |
307 | *x += bar->status->width;
308 | }
309 |
310 | void bar_set_active(struct Bar *bar, unsigned int is_active) {
311 | if (!bar) return;
312 |
313 | bar->active = is_active;
314 | }
315 |
316 | void bar_set_floating(struct Bar *bar, unsigned int is_floating) {
317 | if (!bar) return;
318 |
319 | bar->floating = is_floating;
320 | }
321 |
322 | void bar_set_layout(struct Bar *bar, const char *text) {
323 | if (!bar) return;
324 |
325 | pango_layout_set_text(bar->layout->layout, text, -1);
326 | }
327 |
328 | void bar_set_status(struct Bar *bar, const char *text) {
329 | if (!bar) return;
330 |
331 | pango_layout_set_text(bar->status->layout, text, -1);
332 | }
333 |
334 | void bar_set_tag(struct Bar *bar, unsigned int index,
335 | unsigned int state, unsigned int occupied, unsigned int has_focused) {
336 | if (!bar) return;
337 |
338 | if (!bar || index >= LENGTH(bar->tags) ) return;
339 |
340 | struct Tag *tag = &bar->tags[index];
341 | tag->has_focused = has_focused;
342 | tag->occupied = occupied;
343 | tag->state = state;
344 | }
345 |
346 | void bar_set_title(struct Bar *bar, const char *text) {
347 | if (!bar) return;
348 |
349 | pango_layout_set_text(bar->title->layout, text, -1);
350 | }
351 |
352 | int bar_width(struct Pipeline *pipeline, void *data, unsigned int future_widths) {
353 | if (!data || !pipeline) return 0;
354 |
355 | struct Bar *bar = data;
356 | int width = 0, title_width, status_width;
357 |
358 | for (int i = 0; i < LENGTH(bar->tags); i++)
359 | width += bar_component_width(bar->tags[i].component, pipeline);
360 | width += bar_component_width(bar->layout, pipeline);
361 |
362 | title_width = pipeline->shm->width - width - bar_component_width(bar->status, pipeline) - future_widths;
363 | if (bar_component_width(bar->title, pipeline) > bar->title->width)
364 | title_width = bar_component_width(bar->title, pipeline);
365 | width += title_width;
366 |
367 | status_width = bar_component_width(bar->status, pipeline);
368 | if (status_width > (pipeline->shm->width - width - future_widths)) {
369 | char *previous_status = strdup(pango_layout_get_text(bar->status->layout));
370 | bar->status->width = bar_component_add_elipses(bar->status, pipeline,
371 | (pipeline->shm->width - width - pipeline_get_future_widths(pipeline)));
372 | pango_layout_set_text(bar->status->layout, previous_status, -1);
373 | free(previous_status);
374 | }
375 | width += status_width;
376 |
377 | return width;
378 | }
379 |
--------------------------------------------------------------------------------
/src/bar.h:
--------------------------------------------------------------------------------
1 | #ifndef BAR_H_
2 | #define BAR_H_
3 |
4 | #include "config.h"
5 | #include "render.h"
6 |
7 | enum TagState {
8 | Tag_None = 0,
9 | Tag_Active = 1,
10 | Tag_Urgent = 2,
11 | };
12 |
13 | struct Tag {
14 | unsigned int occupied, has_focused, state;
15 | struct BasicComponent *component;
16 | };
17 |
18 | struct Bar {
19 | struct Pipeline *pipeline;
20 | struct BasicComponent *layout, *title, *status;
21 | struct Tag tags[LENGTH(tags)];
22 |
23 | unsigned int active, floating;
24 | unsigned int x, y;
25 | };
26 |
27 | struct Bar *bar_create(struct List *hotspots, struct Pipeline *pipeline);
28 | void bar_destroy(struct Bar *bar);
29 | void bar_set_active(struct Bar *bar, unsigned int is_active);
30 | void bar_set_floating(struct Bar *bar, unsigned int is_floating);
31 | void bar_set_layout(struct Bar *bar, const char *text);
32 | void bar_set_status(struct Bar *bar, const char *text);
33 | void bar_set_tag(struct Bar *bar, unsigned int index,
34 | unsigned int state, unsigned int occupied, unsigned int focusedClient);
35 | void bar_set_title(struct Bar *bar, const char *text);
36 |
37 | extern const struct PipelineListener bar_pipeline_listener;
38 |
39 | #endif // BAR_H_
40 |
--------------------------------------------------------------------------------
/src/config.def.h:
--------------------------------------------------------------------------------
1 | #ifndef CONFIG_H_
2 | #define CONFIG_H_
3 |
4 | #include "user.h"
5 | #include
6 | #include
7 |
8 | static const int bar_top = 1; /* Boolean value, non-zero is true. If not top then bottom */
9 | static const int status_on_active = 1; /* Display the status on active monitor only. If not then on all. */
10 | static const char *font = "Monospace 10";
11 | static const char *terminal[] = { "alacritty", NULL };
12 |
13 | /*
14 | * Colors:
15 | * Colors are in rgba format.
16 | * The color scheming format is the same as dwm.
17 | * We use an enum as a index for our scheme types.
18 | *
19 | * cyan - used in an active background
20 | * grey3 - used in active text and urgent background
21 | * grey1 - used in an inactive background
22 | * grey2 - used in inactive text
23 | */
24 | static const int cyan[4] = { 0, 85, 119, 255 };
25 | static const int grey1[4] = { 34, 34, 34, 255 };
26 | static const int grey2[4] = { 187, 187, 187, 255 };
27 | static const int grey3[4] = { 238, 238, 238, 255 };
28 |
29 | static const int *schemes[3][2] = {
30 | /* Scheme Type fg, bg */
31 | [InActive_Scheme] = {grey2, grey1},
32 | [Active_Scheme] = {grey3, cyan},
33 | [Urgent_Scheme] = {grey1, grey3},
34 | };
35 |
36 | /*
37 | * Tags
38 | * Must not exceed 31 tags and amount must match dwl's tagcount.
39 | */
40 | static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
41 |
42 | /*
43 | * Buttons
44 | * See user.h for details on relevant structures.
45 | */
46 | static const Binding bindings[] = {
47 | /* Click Location, button, callback, bypass, arguments */
48 | { Click_Status, BTN_MIDDLE, spawn, 0, {.v = terminal } },
49 | };
50 |
51 | #endif // CONFIG_H_
52 |
--------------------------------------------------------------------------------
/src/event.c:
--------------------------------------------------------------------------------
1 | #include "event.h"
2 | #include "util.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | void events_add(struct Events *events, int fd, short mask, void *data,
9 | void (*callback)(int, short, void *)) {
10 | if (!events)
11 | return;
12 |
13 | if (events->pollfds_length == events->pollfds_capacity) {
14 | events->pollfds = realloc(events->pollfds, sizeof(struct pollfd) * (events->pollfds_capacity+1));
15 | events->pollfds_capacity++;
16 | }
17 | events->pollfds[events->pollfds_length++] = (struct pollfd){fd, mask, 0};
18 |
19 | struct EventCallback *backcall = list_add(events->callbacks, ecalloc(1, sizeof(*backcall)));
20 | backcall->callback = callback;
21 | backcall->data = data;
22 | }
23 |
24 | struct Events *events_create(void) {
25 | struct Events *events = ecalloc(1, sizeof(*events));
26 |
27 | events->callbacks = list_create(0);
28 | events->pollfds = NULL;
29 | events->pollfds_length = 0;
30 | events->pollfds_capacity = 0;
31 |
32 | return events;
33 | }
34 |
35 | void events_destroy(struct Events *events) {
36 | if (!events)
37 | return;
38 |
39 | list_elements_destroy(events->callbacks, free);
40 | free(events->pollfds);
41 | free(events);
42 | }
43 |
44 | void events_poll(struct Events *events) {
45 | if (!events)
46 | return;
47 |
48 | if (poll(events->pollfds, events->pollfds_length, -1) <= 0)
49 | return;
50 |
51 | for (int i = 0; i < events->pollfds_length; i++) {
52 | struct pollfd *pollfd = &events->pollfds[i];
53 | struct EventCallback *callback = events->callbacks->data[i];
54 |
55 |
56 | if (pollfd->revents & (pollfd->events | POLLHUP | POLLERR))
57 | callback->callback(pollfd->fd, pollfd->revents, callback->data);
58 | }
59 | }
60 |
61 | void events_remove(struct Events *events, int fd) {
62 | if (!events)
63 | return;
64 |
65 | for (int i = 0; i < events->pollfds_length; i++) {
66 | if (events->pollfds[i].fd != fd)
67 | continue;
68 |
69 | free(list_remove(events->callbacks, i));
70 |
71 | events->pollfds_length--;
72 | memmove(&events->pollfds[i], &events->pollfds[i+1],
73 | sizeof(struct pollfd) * (events->pollfds_length - i));
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/event.h:
--------------------------------------------------------------------------------
1 | #ifndef EVENT_H_
2 | #define EVENT_H_
3 | #include "util.h"
4 |
5 | struct EventCallback {
6 | void (*callback)(int fd, short mask, void *data);
7 | void *data;
8 | };
9 |
10 | struct Events {
11 | struct List *callbacks; // struct EventCallback*
12 | struct pollfd *pollfds;
13 | int pollfds_length, pollfds_capacity;
14 | };
15 |
16 | void events_add(struct Events *events, int fd, short mask, void *data, void (*callback)(int fd, short mask, void *data));
17 | struct Events *events_create(void);
18 | void events_destroy(struct Events *events);
19 | void events_poll(struct Events *events);
20 | void events_remove(struct Events *events, int fd);
21 |
22 | #endif // EVENT_H_
23 |
--------------------------------------------------------------------------------
/src/input.c:
--------------------------------------------------------------------------------
1 | #include "input.h"
2 | #include "log.h"
3 | #include "main.h"
4 | #include "user.h"
5 | #include "util.h"
6 | #include "render.h"
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | static int button_cmp(const void *left, const void *right);
18 | static void hotspots_process(struct Monitor* monitor, double x, double y, uint32_t button);
19 | static void pointer_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value);
20 | static void pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete);
21 | static void pointer_axis_source(void *data, struct wl_pointer *wl_pointer, uint32_t axis_source);
22 | static void pointer_axis_stop(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis);
23 | static void pointer_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state);
24 | static struct Pointer *pointer_create(struct wl_seat *seat);
25 | static void pointer_destroy(struct Pointer *pointer);
26 | static void pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y);
27 | static void pointer_frame(void *data, struct wl_pointer *wl_pointer);
28 | static void pointer_process_scroll(struct Pointer *pointer, unsigned int axis_index);
29 | static void pointer_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface);
30 | static void pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y);
31 | static void pointer_update_cursor(struct Pointer *pointer);
32 | static void seat_capabilities(void *data, struct wl_seat *wl_seat, uint32_t capabilities);
33 | static void seat_name(void *data, struct wl_seat *wl_seat, const char *name);
34 | static void touch_cancel(void *data, struct wl_touch *wl_touch);
35 | static struct Touch *touch_create(struct wl_seat *seat);
36 | static void touch_destroy(struct Touch *touch);
37 | static void touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial, uint32_t time, struct wl_surface *surface, int32_t id, wl_fixed_t x, wl_fixed_t y);
38 | static void touch_frame(void *data, struct wl_touch *wl_touch);
39 | static struct TouchPoint *touch_get_point(struct Touch *touch, int32_t id);
40 | static void touch_motion(void *data, struct wl_touch *wl_touch, uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y);
41 | static void touch_orientation(void *data, struct wl_touch *wl_touch, int32_t id, wl_fixed_t orientation);
42 | static uint32_t touch_point_to_button(struct TouchPoint *point, uint32_t time);
43 | static void touch_shape(void *data, struct wl_touch *wl_touch, int32_t id, wl_fixed_t major, wl_fixed_t minor);
44 | static void touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial, uint32_t time, int32_t id);
45 | static uint32_t wl_axis_to_button(int axis, wl_fixed_t value);
46 |
47 | static const struct wl_pointer_listener pointer_listener = {
48 | .axis = pointer_axis,
49 | .axis_discrete = pointer_axis_discrete,
50 | .axis_source = pointer_axis_source,
51 | .axis_stop = pointer_axis_stop,
52 | .button = pointer_button,
53 | .enter = pointer_enter,
54 | .frame = pointer_frame,
55 | .leave = pointer_leave,
56 | .motion = pointer_motion,
57 | };
58 |
59 | const struct wl_seat_listener seat_listener = {
60 | .capabilities = seat_capabilities,
61 | .name = seat_name,
62 | };
63 |
64 | static const struct wl_touch_listener touch_listener = {
65 | .cancel = touch_cancel,
66 | .down = touch_down,
67 | .frame = touch_frame,
68 | .motion = touch_motion,
69 | .orientation = touch_orientation,
70 | .shape = touch_shape,
71 | .up = touch_up,
72 | };
73 |
74 | int button_cmp(const void *left, const void *right) {
75 | return (*(uint32_t*)left) == (*(uint32_t*)right);
76 | }
77 |
78 | void pointer_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis_index, wl_fixed_t value) {
79 | struct Pointer *pointer = data;
80 | struct Axis *axis = &pointer->axis[axis_index];
81 |
82 | if (axis->discrete_steps == 0
83 | && time - axis->update_time - SCROLL_TIMEOUT)
84 | axis->value = 0;
85 |
86 | axis->value += value;
87 | axis->update_time = time;
88 | pointer->scrolled = 1;
89 | }
90 |
91 | void pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete) {
92 | struct Pointer *pointer = data;
93 |
94 | pointer->axis[axis].discrete_steps += abs(discrete);
95 | pointer->scrolled = 1;
96 | }
97 |
98 | void pointer_axis_source(void *data, struct wl_pointer *wl_pointer, uint32_t axis_source) {
99 | /* Nop */
100 | }
101 |
102 | void pointer_axis_stop(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis) {
103 | /* Nop */
104 | }
105 |
106 | void pointer_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
107 | struct Pointer *pointer = data;
108 | int index;
109 |
110 | if (state == WL_POINTER_BUTTON_STATE_PRESSED && list_cmp_find(pointer->buttons, &button, button_cmp) == -1) {
111 | uint32_t *btn = list_add(pointer->buttons, ecalloc(1, sizeof(*btn)));
112 | *btn = button;
113 | }
114 | else if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
115 | (index = list_cmp_find(pointer->buttons, &button, button_cmp)) != -1) {
116 | free(list_remove(pointer->buttons, index));
117 | }
118 | }
119 |
120 | struct Pointer *pointer_create(struct wl_seat *seat) {
121 | if (!seat) return NULL;
122 |
123 | struct Pointer *pointer = ecalloc(1, sizeof(*pointer));
124 | pointer->pointer = wl_seat_get_pointer(seat);
125 | pointer->scrolled = 0;
126 | pointer->buttons = list_create(0);
127 | pointer->focused_monitor = NULL;
128 | pointer->cursor_surface = NULL;
129 | pointer->cursor_image = NULL;
130 | pointer->cursor_theme = NULL;
131 |
132 | return pointer;
133 | }
134 |
135 | void pointer_destroy(struct Pointer *pointer) {
136 | if (!pointer) return;
137 |
138 | wl_pointer_release(pointer->pointer);
139 | wl_surface_destroy(pointer->cursor_surface);
140 | wl_cursor_theme_destroy(pointer->cursor_theme);
141 | list_elements_destroy(pointer->buttons, free);
142 | free(pointer);
143 | }
144 |
145 | void pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
146 | struct Pointer *pointer = data;
147 | pointer->focused_monitor = monitor_from_surface(surface);
148 | if (!pointer->focused_monitor)
149 | return;
150 |
151 | pointer_update_cursor(pointer);
152 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface,
153 | pointer->cursor_image->hotspot_x, pointer->cursor_image->hotspot_y);
154 | }
155 |
156 | void pointer_frame(void *data, struct wl_pointer *wl_pointer) {
157 | struct Pointer *pointer = data;
158 | struct Monitor *monitor = pointer->focused_monitor;
159 | if (!monitor) return;
160 |
161 | for (int i = 0; i < pointer->buttons->length; i++)
162 | hotspots_process(pointer->focused_monitor, pointer->x, pointer->y,
163 | *(uint32_t*)pointer->buttons->data[i]);
164 | list_elements_destroy(pointer->buttons, free);
165 | pointer->buttons = list_create(0);
166 |
167 | if (pointer->scrolled) {
168 | for (int i = 0; i < 2; i++)
169 | pointer_process_scroll(pointer, i);
170 | }
171 | }
172 |
173 | void pointer_process_scroll(struct Pointer *pointer, unsigned int axis_index) {
174 | struct Axis *axis = &pointer->axis[axis_index];
175 | if (axis->discrete_steps) {
176 | for (int i = 0; i < axis->discrete_steps; i++)
177 | hotspots_process(pointer->focused_monitor, pointer->x, pointer->y, wl_axis_to_button(axis_index, axis->value));
178 | axis->value = 0;
179 | axis->discrete_steps = 0;
180 | } else {
181 | while (abs(axis->value) > SCROLL_THRESHOLD) {
182 | if (axis->value > 0){
183 | hotspots_process(pointer->focused_monitor, pointer->x, pointer->y, wl_axis_to_button(axis_index, SCROLL_THRESHOLD));
184 | axis->value -= SCROLL_THRESHOLD;
185 | } else {
186 | hotspots_process(pointer->focused_monitor, pointer->x, pointer->y, wl_axis_to_button(axis_index, -SCROLL_THRESHOLD));
187 | axis->value += SCROLL_THRESHOLD;
188 | }
189 | }
190 | }
191 | }
192 |
193 | void pointer_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface) {
194 | struct Pointer *pointer = data;
195 | pointer->focused_monitor = NULL;
196 | }
197 |
198 | void pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
199 | struct Pointer *pointer = data;
200 | pointer->x = wl_fixed_to_double(surface_x);
201 | pointer->y = wl_fixed_to_double(surface_y);
202 | }
203 |
204 | void pointer_update_cursor(struct Pointer *pointer) {
205 | if (!pointer)
206 | return;
207 |
208 | if (!pointer->cursor_surface)
209 | pointer->cursor_surface = wl_compositor_create_surface(compositor);
210 |
211 | if (pointer->cursor_theme)
212 | wl_cursor_theme_destroy(pointer->cursor_theme);
213 |
214 | unsigned int cursor_size = 24;
215 | const char *cursor_theme = getenv("XCURSOR_THEME");
216 | const char *env_cursor_size = getenv("XCURSOR_SIZE");
217 | if (env_cursor_size && strlen(env_cursor_size) > 0) {
218 | errno = 0;
219 | char *end;
220 | unsigned int size = strtoul(env_cursor_size, &end, 10);
221 | if (!*end && errno == 0)
222 | cursor_size = size;
223 | }
224 | pointer->cursor_theme = wl_cursor_theme_load(cursor_theme, cursor_size, shm);
225 | pointer->cursor_image = wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr")->images[0];
226 | wl_surface_attach(pointer->cursor_surface, wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0);
227 | wl_surface_commit(pointer->cursor_surface);
228 | }
229 |
230 | void hotspots_process(struct Monitor* monitor, double x, double y, uint32_t button) {
231 | struct Hotspot *hotspot;
232 | for (int i = 0; i < monitor->hotspots->length; i++) {
233 | hotspot = monitor->hotspots->data[i];
234 |
235 | double hotspot_x = 0, hotspot_y = 0, hotspot_width = 0, hotspot_height = 0;
236 | hotspot->listener->bounds(hotspot->data, &hotspot_x, &hotspot_y, &hotspot_width, &hotspot_height);
237 |
238 | if (!( x > hotspot_x && y > hotspot_y &&
239 | x < (hotspot_x+hotspot_width) && y < (hotspot_y+hotspot_height)))
240 | continue;
241 |
242 | hotspot->listener->click(monitor, hotspot->data, button, x, y);
243 | return;
244 | }
245 | }
246 |
247 | void seat_capabilities(void *data, struct wl_seat *wl_seat, uint32_t capabilities) {
248 | struct Seat *seat = data;
249 | int has_pointer = capabilities & WL_SEAT_CAPABILITY_POINTER,
250 | has_touch = capabilities & WL_SEAT_CAPABILITY_TOUCH;
251 |
252 | if (!seat->pointer && has_pointer) {
253 | seat->pointer = pointer_create(seat->seat);
254 | wl_pointer_add_listener(seat->pointer->pointer, &pointer_listener, seat->pointer);
255 | }
256 | else if (seat->pointer && !has_pointer) {
257 | pointer_destroy(seat->pointer);
258 | }
259 |
260 | if (!seat->touch && has_touch) {
261 | seat->touch = touch_create(seat->seat);
262 | wl_touch_add_listener(seat->touch->touch, &touch_listener, seat->touch);
263 | }
264 | else if (seat->touch && !has_touch) {
265 | touch_destroy(seat->touch);
266 | }
267 | }
268 |
269 | void seat_destroy(struct Seat *seat) {
270 | if (!seat) return;
271 |
272 | pointer_destroy(seat->pointer);
273 | touch_destroy(seat->touch);
274 | wl_seat_release(seat->seat);
275 | free(seat);
276 | }
277 |
278 | void seat_name(void *data, struct wl_seat *wl_seat, const char *name) {
279 | /* Nop */
280 | }
281 |
282 | void touch_cancel(void *data, struct wl_touch *wl_touch) {
283 | struct Touch *touch = data;
284 | struct TouchPoint *point;
285 | for (int i = 0; i < LENGTH(touch->points); i++) {
286 | point = &touch->points[i];
287 | point->id = -1;
288 | point->focused_monitor = NULL;
289 | }
290 | }
291 |
292 | struct Touch *touch_create(struct wl_seat *seat) {
293 | if (!seat) return NULL;
294 |
295 | struct Touch *touch = ecalloc(1, sizeof(*touch));
296 | touch->touch = wl_seat_get_touch(seat);
297 | struct TouchPoint *point;
298 | for (int i = 0; i < LENGTH(touch->points); i++) {
299 | point = &touch->points[i];
300 | point->id = -1;
301 | point->focused_monitor = NULL;
302 | }
303 |
304 | return touch;
305 | }
306 |
307 | void touch_destroy(struct Touch *touch) {
308 | if (!touch) return;
309 |
310 | wl_touch_release(touch->touch);
311 | free(touch);
312 | }
313 |
314 | void touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial, uint32_t time,
315 | struct wl_surface *surface, int32_t id, wl_fixed_t x, wl_fixed_t y) {
316 | struct Touch *touch = data;
317 | struct TouchPoint *point = touch_get_point(touch, id);
318 | if (!point)
319 | return;
320 |
321 | point->focused_monitor = monitor_from_surface(surface);
322 | if (!point->focused_monitor)
323 | return;
324 |
325 | point->id = id;
326 | point->time = time;
327 | point->start_x = wl_fixed_to_double(x);
328 | point->start_y = wl_fixed_to_double(y);
329 | }
330 |
331 | void touch_frame(void *data, struct wl_touch *wl_touch) {
332 | /* Nop */
333 | }
334 |
335 | struct TouchPoint *touch_get_point(struct Touch *touch, int32_t id) {
336 | struct TouchPoint *point;
337 | int empty_index = -1;
338 | for (int i = 0; i < LENGTH(touch->points); i++) {
339 | point = &touch->points[i];
340 | if (point->id == id) {
341 | return point;
342 | }
343 | if (!point->focused_monitor && point->id == -1)
344 | empty_index = i;
345 | }
346 |
347 | if (empty_index == -1)
348 | return NULL;
349 |
350 | return &touch->points[empty_index];
351 | }
352 |
353 | void touch_motion(void *data, struct wl_touch *wl_touch, uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y) {
354 | struct Touch *touch = data;
355 | struct TouchPoint *point = touch_get_point(touch, id);
356 | if (!point)
357 | return;
358 |
359 | point->time = time;
360 | point->x = wl_fixed_to_double(x);
361 | point->y = wl_fixed_to_double(y);
362 | }
363 |
364 | void touch_orientation(void *data, struct wl_touch *wl_touch, int32_t id, wl_fixed_t orientation) {
365 | /* Nop */
366 | }
367 |
368 | uint32_t touch_point_to_button(struct TouchPoint *point, uint32_t time) {
369 | /* "progress" is a measure from 0..100 representing the fraction of the
370 | * output the touch gesture has travelled, positive when moving to the right
371 | * and negative when moving to the left. */
372 | int progress = (int)((point->x - point->start_x) / point->focused_monitor->pipeline->shm->width * 100);
373 | if (abs(progress) > 20)
374 | return (progress > 0 ? Gesture_Right : Gesture_Left);
375 |
376 | if (time - point->time < 500)
377 | return BTN_LEFT;
378 | if (time - point->time < 1000)
379 | return BTN_RIGHT;
380 |
381 | /* If hold time is longer than 1 second then it is a middle click. */
382 | return BTN_MIDDLE;
383 | }
384 |
385 | void touch_shape(void *data, struct wl_touch *wl_touch, int32_t id, wl_fixed_t major, wl_fixed_t minor) {
386 | /* Nop */
387 | }
388 |
389 | void touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial, uint32_t time, int32_t id) {
390 | struct Touch *touch = data;
391 | struct TouchPoint *point = touch_get_point(touch, id);
392 | if (!point) return;
393 |
394 | uint32_t button = touch_point_to_button(point, time);
395 | hotspots_process(point->focused_monitor, point->x, point->y, button);
396 | }
397 |
398 | uint32_t wl_axis_to_button(int axis, wl_fixed_t value) {
399 | int negative = wl_fixed_to_double(value) < 0;
400 | switch (axis) {
401 | case WL_POINTER_AXIS_VERTICAL_SCROLL:
402 | return negative ? Scroll_Up : Scroll_Down;
403 | case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
404 | return negative ? Scroll_Left : Scroll_Right;
405 | default:
406 | return 0;
407 | }
408 | }
409 |
--------------------------------------------------------------------------------
/src/input.h:
--------------------------------------------------------------------------------
1 | #ifndef INPUT_H_
2 | #define INPUT_H_
3 |
4 | #include "main.h"
5 | #include "util.h"
6 | #include "user.h"
7 | #include
8 | #include
9 |
10 | #define SCROLL_TIMEOUT 1000
11 | #define SCROLL_THRESHOLD 10000
12 |
13 | struct TouchPoint {
14 | int32_t id;
15 | uint32_t time;
16 | struct Monitor *focused_monitor;
17 | double start_x, start_y,
18 | x, y;
19 | };
20 |
21 | struct Touch {
22 | struct wl_touch *touch;
23 | struct TouchPoint points[16];
24 | };
25 |
26 | struct Axis {
27 | wl_fixed_t value;
28 | uint32_t discrete_steps, update_time;
29 | };
30 |
31 | struct Pointer {
32 | struct wl_pointer *pointer;
33 | struct Monitor *focused_monitor;
34 |
35 | struct wl_cursor_theme *cursor_theme;
36 | struct wl_cursor_image *cursor_image;
37 | struct wl_surface *cursor_surface;
38 |
39 | double x, y;
40 | struct List *buttons; /* uint32_t* */
41 | struct Axis axis[2];
42 | int scrolled;
43 | };
44 |
45 | struct Seat {
46 | uint32_t wl_name;
47 | struct wl_seat *seat;
48 | struct Pointer *pointer;
49 | struct Touch *touch;
50 |
51 | struct wl_list link;
52 | };
53 |
54 | struct HotspotListener {
55 | void (*click)(struct Monitor *monitor, void *data, uint32_t button, double x, double y);
56 | void (*bounds)(void *data, double *x, double *y, double *width, double *height);
57 | };
58 |
59 | struct Hotspot {
60 | const struct HotspotListener *listener;
61 | void *data;
62 | };
63 |
64 | extern const struct wl_seat_listener seat_listener;
65 |
66 | void seat_destroy(struct Seat *seat);
67 |
68 | #endif // INPUT_H_
69 |
--------------------------------------------------------------------------------
/src/log.c:
--------------------------------------------------------------------------------
1 | #include "log.h"
2 | #include
3 | #include
4 | #include
5 |
6 | FILE *log_file = NULL;
7 |
8 | void bar_log(enum LogLevel level, const char *fmt, ...) {
9 | if (!log_file)
10 | return;
11 |
12 | va_list ap;
13 | va_start(ap, fmt);
14 | switch (level) {
15 | case LOG_INFO:
16 | fprintf(log_file, "[dwl-bar] info: ");
17 | break;
18 | case LOG_ERROR:
19 | fprintf(log_file, "[dwl-bar] error: ");
20 | break;
21 | }
22 | vfprintf(log_file, fmt, ap);
23 | va_end(ap);
24 | fputc('\n', log_file);
25 |
26 | fflush(log_file);
27 | }
28 |
29 | void log_destroy(void) {
30 | if (!log_file)
31 | return;
32 |
33 | fclose(log_file);
34 | }
35 |
36 | int setup_log(void) {
37 | log_file = fopen("bar.log", "w");
38 | if (!log_file)
39 | return 0;
40 |
41 | bar_log(LOG_INFO, "Setup Logging");
42 |
43 | return 1;
44 | }
45 |
--------------------------------------------------------------------------------
/src/log.h:
--------------------------------------------------------------------------------
1 | #ifndef LOG_H_
2 | #define LOG_H_
3 |
4 | enum LogLevel { LOG_INFO, LOG_ERROR };
5 |
6 | void bar_log(enum LogLevel level, const char *fmt, ...);
7 | void log_destroy(void);
8 | int setup_log(void);
9 |
10 | #endif // LOG_H_
11 |
--------------------------------------------------------------------------------
/src/main.c:
--------------------------------------------------------------------------------
1 | #include "bar.h"
2 | #include "event.h"
3 | #include "log.h"
4 | #include "render.h"
5 | #include "util.h"
6 | #include "main.h"
7 | #include "input.h"
8 | #include "xdg-output-unstable-v1-protocol.h"
9 | #include "xdg-shell-protocol.h"
10 | #include "wlr-layer-shell-unstable-v1-protocol.h"
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | static void check_global(void *global, const char *name);
29 | static void check_globals(void);
30 | static void cleanup(void);
31 | static void display_in(int fd, short mask, void *data);
32 | static void fifo_handle(const char *line);
33 | static void fifo_in(int fd, short mask, void *data);
34 | static void fifo_setup(void);
35 | static void monitor_destroy(struct Monitor *monitor);
36 | static struct Monitor *monitor_from_name(const char *name);
37 | struct Monitor *monitor_from_surface(const struct wl_surface *surface);
38 | static void monitor_initialize(struct Monitor *monitor);
39 | static void monitor_update(struct Monitor *monitor);
40 | static void pipe_in(int fd, short mask, void *data);
41 | static void registry_global_add(void *data, struct wl_registry *registry, uint32_t name,
42 | const char *interface, uint32_t version);
43 | static void registry_global_remove(void *data, struct wl_registry *registry, uint32_t name);
44 | static void run(void);
45 | static void set_cloexec(int fd);
46 | static void setup(void);
47 | static void stdin_handle(const char *line);
48 | static void stdin_in(int fd, short mask, void *data);
49 | static void sigaction_handler(int _);
50 | static void xdg_output_name(void *data, struct zxdg_output_v1 *output, const char *name);
51 | static void xdg_wm_base_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial);
52 |
53 | static struct xdg_wm_base *base;
54 | struct wl_compositor *compositor;
55 | static struct wl_display *display;
56 | static int display_fd;
57 | static struct Events *events;
58 | static int fifo_fd;
59 | static char *fifo_path;
60 | static struct wl_list monitors; // struct Monitor*
61 | static struct zxdg_output_manager_v1 *output_manager;
62 | static const struct wl_registry_listener registry_listener = {
63 | .global = registry_global_add,
64 | .global_remove = registry_global_remove,
65 | };
66 | static int running = 0;
67 | static struct wl_list seats; // struct Seat*
68 | static int self_pipe[2];
69 | struct zwlr_layer_shell_v1 *shell;
70 | struct wl_shm *shm;
71 | static const struct zxdg_output_v1_listener xdg_output_listener = {
72 | .name = xdg_output_name,
73 | };
74 | static const struct xdg_wm_base_listener xdg_wm_base_listener = {
75 | .ping = xdg_wm_base_ping,
76 | };
77 |
78 | void check_global(void *global, const char *name) {
79 | if (global)
80 | return;
81 | panic("Wayland compositor did not export: %s", name);
82 | }
83 |
84 | void check_globals(void) {
85 | check_global(base, "xdg_wm_base");
86 | check_global(compositor, "wl_compositor");
87 | check_global(output_manager, "zxdg_output_manager_v1");
88 | check_global(shell, "zwlr_layer_shell_v1");
89 | check_global(shm, "wl_shm");
90 | }
91 |
92 | void cleanup(void) {
93 | xdg_wm_base_destroy(base);
94 | wl_compositor_destroy(compositor);
95 | close(fifo_fd);
96 | unlink(fifo_path);
97 | free(fifo_path);
98 | zxdg_output_manager_v1_destroy(output_manager);
99 | zwlr_layer_shell_v1_destroy(shell);
100 | wl_shm_destroy(shm);
101 | events_destroy(events);
102 | log_destroy();
103 |
104 | struct Monitor *monitor, *tmp_monitor;
105 | wl_list_for_each_safe(monitor, tmp_monitor, &monitors, link)
106 | monitor_destroy(monitor);
107 |
108 | struct Seat *seat, *tmp_seat;
109 | wl_list_for_each_safe(seat, tmp_seat, &seats, link)
110 | seat_destroy(seat);
111 |
112 | wl_display_disconnect(display);
113 | }
114 |
115 | void display_in(int fd, short mask, void *data) {
116 | if (mask & (POLLHUP | POLLERR) ||
117 | wl_display_dispatch(display) == -1) {
118 | running = 0;
119 | return;
120 | }
121 | }
122 |
123 | void fifo_handle(const char *line) {
124 | char *command;
125 | unsigned long loc = 0;
126 |
127 | command = to_delimiter(line, &loc, ' ');
128 |
129 | if (STRING_EQUAL(command, "status")) {
130 | char *status = to_delimiter(line, &loc, '\n');
131 | struct Monitor *pos;
132 | wl_list_for_each(pos, &monitors, link) {
133 | bar_set_status(pos->bar, status);
134 | pipeline_invalidate(pos->pipeline);
135 | }
136 | free(status);
137 | }
138 |
139 | free(command);
140 | }
141 |
142 | void fifo_in(int fd, short mask, void *data) {
143 | if (mask & POLLERR) {
144 | events_remove(events, fd);
145 | char *default_status = string_create("dwl %.1f", VERSION);
146 | struct Monitor *pos;
147 | wl_list_for_each(pos, &monitors, link) {
148 | bar_set_status(pos->bar, default_status);
149 | pipeline_invalidate(pos->pipeline);
150 | }
151 | free(default_status);
152 | return;
153 | }
154 |
155 | int new_fd = dup(fd);
156 | FILE *fifo_file = fdopen(new_fd, "r");
157 | char *buffer = NULL;
158 | size_t size = 0;
159 | while (1) {
160 | if (getline(&buffer, &size, fifo_file) == -1)
161 | break;
162 |
163 | fifo_handle(buffer);
164 | }
165 | free(buffer);
166 | fclose(fifo_file);
167 | close(new_fd);
168 |
169 | }
170 |
171 | void fifo_setup(void) {
172 | int result, i;
173 | char *runtime_path = getenv("XDG_RUNTIME_DIR");
174 |
175 | for (i = 0; i < 100; i++) {
176 | fifo_path = string_create("%s/dwl-bar-%d", runtime_path, i);
177 |
178 | result = mkfifo(fifo_path, 0666);
179 | if (result < 0) {
180 | if (errno != EEXIST)
181 | panic("mkfifo");
182 |
183 | continue;
184 | }
185 |
186 | if ((fifo_fd = open(fifo_path, O_CLOEXEC | O_RDWR | O_NONBLOCK)) < 0)
187 | panic("open fifo");
188 |
189 | return;
190 | }
191 |
192 | panic("setup fifo"); /* If we get here then we couldn't setup the fifo */
193 | }
194 |
195 | void monitor_destroy(struct Monitor *monitor) {
196 | if (!monitor)
197 | return;
198 |
199 | free(monitor->xdg_name);
200 | if (wl_output_get_version(monitor->wl_output) >= WL_OUTPUT_RELEASE_SINCE_VERSION)
201 | wl_output_release(monitor->wl_output);
202 | list_elements_destroy(monitor->hotspots, free);
203 | pipeline_destroy(monitor->pipeline);
204 | bar_destroy(monitor->bar);
205 | free(monitor);
206 | }
207 |
208 | struct Monitor *monitor_from_name(const char *name) {
209 | struct Monitor *pos;
210 | wl_list_for_each(pos, &monitors, link) {
211 | if (STRING_EQUAL(name, pos->xdg_name))
212 | return pos;
213 | }
214 |
215 | return NULL;
216 | }
217 |
218 | struct Monitor *monitor_from_surface(const struct wl_surface *surface) {
219 | struct Monitor *pos;
220 | wl_list_for_each(pos, &monitors, link) {
221 | if (pos->pipeline->surface == surface)
222 | return pos;
223 | }
224 |
225 | return NULL;
226 | }
227 |
228 | void monitor_initialize(struct Monitor *monitor) {
229 | if (!monitor) return;
230 |
231 | monitor->hotspots = list_create(1);
232 | monitor->pipeline = pipeline_create();
233 | monitor->bar = bar_create(monitor->hotspots, monitor->pipeline);
234 | if (!monitor->pipeline || !monitor->bar)
235 | panic("Failed to create a pipline or bar for monitor: %s", monitor->xdg_name);
236 | monitor_update(monitor);
237 | }
238 |
239 | void monitor_update(struct Monitor *monitor) {
240 | if (!monitor)
241 | return;
242 |
243 | if (!pipeline_is_visible(monitor->pipeline)) {
244 | pipeline_show(monitor->pipeline, monitor->wl_output);
245 | return;
246 | }
247 |
248 | pipeline_invalidate(monitor->pipeline);
249 | }
250 |
251 | void monitors_update(void) {
252 | struct Monitor *monitor;
253 | wl_list_for_each(monitor, &monitors, link) {
254 | monitor_update(monitor);
255 | }
256 | }
257 |
258 | void pipe_in(int fd, short mask, void *data) {
259 | running = 0;
260 | }
261 |
262 | void registry_global_add(void *data, struct wl_registry *registry, uint32_t name,
263 | const char *interface, uint32_t version) {
264 | if (STRING_EQUAL(interface, wl_compositor_interface.name))
265 | compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 4);
266 | else if (STRING_EQUAL(interface, wl_output_interface.name)) {
267 | struct Monitor *monitor = ecalloc(1, sizeof(*monitor));
268 | monitor->wl_output = wl_registry_bind(registry, name, &wl_output_interface, 1);
269 | monitor->wl_name = name;
270 | monitor->xdg_name = NULL;
271 | monitor->xdg_output = NULL;
272 |
273 | wl_list_insert(&monitors, &monitor->link);
274 |
275 | if (!output_manager)
276 | return;
277 |
278 | monitor->xdg_output = zxdg_output_manager_v1_get_xdg_output(output_manager, monitor->wl_output);
279 | zxdg_output_v1_add_listener(monitor->xdg_output, &xdg_output_listener, monitor);
280 |
281 | if (!running) return;
282 | monitor_initialize(monitor);
283 | }
284 | else if (STRING_EQUAL(interface, wl_seat_interface.name)) {
285 | struct Seat *seat = ecalloc(1, sizeof(*seat));
286 | seat->seat = wl_registry_bind(registry, name, &wl_seat_interface, 5);
287 | seat->wl_name = name;
288 | seat->pointer = NULL;
289 | seat->touch = NULL;
290 | wl_list_insert(&seats, &seat->link);
291 | wl_seat_add_listener(seat->seat, &seat_listener, seat);
292 | }
293 | else if (STRING_EQUAL(interface, wl_shm_interface.name))
294 | shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
295 | else if (STRING_EQUAL(interface, xdg_wm_base_interface.name)) {
296 | base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 2);
297 | xdg_wm_base_add_listener(base, &xdg_wm_base_listener, NULL);
298 | }
299 | else if (STRING_EQUAL(interface, zxdg_output_manager_v1_interface.name)) {
300 | output_manager = wl_registry_bind(registry, name, &zxdg_output_manager_v1_interface, 3);
301 |
302 | struct Monitor *pos;
303 | wl_list_for_each(pos, &monitors, link) {
304 | // If the monitor is getting or has the xdg_name.
305 | if (pos->xdg_output || pos->xdg_name)
306 | continue;
307 |
308 | pos->xdg_output = zxdg_output_manager_v1_get_xdg_output(output_manager, pos->wl_output);
309 | zxdg_output_v1_add_listener(pos->xdg_output, &xdg_output_listener, pos);
310 | }
311 | }
312 | else if (STRING_EQUAL(interface, zwlr_layer_shell_v1_interface.name))
313 | shell = wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 4);
314 | }
315 |
316 | void registry_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
317 | struct Monitor *monitor, *tmp_monitor;
318 | wl_list_for_each_safe(monitor, tmp_monitor, &monitors, link) {
319 | if (monitor->wl_name != name) continue;
320 | wl_list_remove(&monitor->link);
321 | monitor_destroy(monitor);
322 | }
323 |
324 | struct Seat *seat, *tmp_seat;
325 | wl_list_for_each_safe(seat, tmp_seat, &seats, link) {
326 | if (seat->wl_name != name) continue;
327 | wl_list_remove(&seat->link);
328 | seat_destroy(seat);
329 | }
330 | }
331 |
332 | void run(void) {
333 | running = 1;
334 |
335 | while (running) {
336 | wl_display_dispatch_pending(display);
337 | if (wl_display_flush(display) == -1 && errno != EAGAIN)
338 | break;
339 |
340 | events_poll(events);
341 | }
342 | }
343 |
344 | void set_cloexec(int fd) {
345 | int flags = fcntl(fd, F_GETFD);
346 | if (flags == -1)
347 | panic("F_GETFD");
348 | if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0)
349 | panic("FD_SETFD");
350 | }
351 |
352 | void setup(void) {
353 | if (pipe(self_pipe) == -1)
354 | panic("pipe");
355 |
356 | set_cloexec(self_pipe[0]);
357 | set_cloexec(self_pipe[1]);
358 |
359 | static struct sigaction sighandle;
360 | static struct sigaction child_sigaction;
361 |
362 | sighandle.sa_handler = &sigaction_handler;
363 | child_sigaction.sa_handler = SIG_IGN;
364 |
365 | if (sigaction(SIGTERM, &sighandle, NULL) < 0)
366 | panic("sigaction SIGTERM");
367 | if (sigaction(SIGINT, &sighandle, NULL) < 0)
368 | panic("sigaction SIGINT");
369 | if (sigaction(SIGCHLD, &child_sigaction, NULL) < 0)
370 | panic("sigaction SIGCHLD");
371 |
372 | display = wl_display_connect(NULL);
373 | if (!display)
374 | panic("Failed to connect to Wayland compositor.");
375 | display_fd = wl_display_get_fd(display);
376 |
377 | wl_list_init(&seats);
378 | wl_list_init(&monitors);
379 |
380 | struct wl_registry *registry = wl_display_get_registry(display);
381 | wl_registry_add_listener(registry, ®istry_listener, NULL);
382 | wl_display_roundtrip(display);
383 |
384 | fifo_setup();
385 |
386 | check_globals();
387 |
388 | wl_display_roundtrip(display);
389 |
390 | struct Monitor *monitor;
391 | wl_list_for_each(monitor, &monitors, link) {
392 | monitor_initialize(monitor);
393 | }
394 |
395 | if (fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK) < 0)
396 | panic("STDIN_FILENO O_NONBLOCK");
397 |
398 | events = events_create();
399 | events_add(events, display_fd, POLLIN, NULL, display_in);
400 | events_add(events, self_pipe[0], POLLIN, NULL, pipe_in);
401 | events_add(events, STDIN_FILENO, POLLIN, NULL, stdin_in);
402 | events_add(events, fifo_fd, POLLIN, NULL, fifo_in);
403 | }
404 |
405 | void stdin_handle(const char *line) {
406 | if (!line)
407 | return;
408 |
409 | char *name, *command;
410 | struct Monitor *monitor;
411 | unsigned long loc = 0; /* Keep track of where we are in the string `line` */
412 |
413 | name = to_delimiter(line, &loc, ' ');
414 | command = to_delimiter(line, &loc, ' ');
415 | monitor = monitor_from_name(name);
416 | if (!monitor) {
417 | free(name);
418 | free(command);
419 | return;
420 | }
421 | free(name);
422 |
423 | if (STRING_EQUAL(command, "title")) {
424 | char *title = to_delimiter(line, &loc, '\n');
425 | if (*title == '\0') {
426 | bar_set_title(monitor->bar, "");
427 | } else
428 | bar_set_title(monitor->bar, title);
429 | free(title);
430 | } else if (STRING_EQUAL(command, "appid")) {
431 | /* Do nothing */
432 | } else if (STRING_EQUAL(command, "floating")) {
433 | char *is_floating = to_delimiter(line, &loc, '\n');
434 | if (*is_floating == '1')
435 | bar_set_floating(monitor->bar, 1);
436 | else
437 | bar_set_floating(monitor->bar, 0);
438 | free(is_floating);
439 | } else if (STRING_EQUAL(command, "fullscreen")) {
440 | /* Do nothing */
441 | } else if (STRING_EQUAL(command, "selmon")) {
442 | char *selmon = to_delimiter(line, &loc, '\n');
443 | if (*selmon == '1')
444 | bar_set_active(monitor->bar, 1);
445 | else
446 | bar_set_active(monitor->bar, 0);
447 | free(selmon);
448 | } else if (STRING_EQUAL(command, "tags")) {
449 | char *occupied_str, *tags_str, *clients_str, *urgent_str;
450 | int occupied, _tags, clients, urgent, i, tag_mask, state;
451 |
452 | occupied_str = to_delimiter(line, &loc, ' ');
453 | tags_str = to_delimiter(line, &loc, ' ');
454 | clients_str = to_delimiter(line, &loc, ' ');
455 | urgent_str = to_delimiter(line, &loc, ' ');
456 |
457 | occupied = atoi(occupied_str);
458 | _tags = atoi(tags_str);
459 | clients = atoi(clients_str);
460 | urgent = atoi(urgent_str);
461 |
462 | for (i = 0; i < LENGTH(tags); i++) {
463 | state = Tag_None;
464 | tag_mask = 1 << i;
465 |
466 | if (_tags & tag_mask)
467 | state |= Tag_Active;
468 | if (urgent & tag_mask)
469 | state |= Tag_Urgent;
470 |
471 | bar_set_tag(monitor->bar, i, state, occupied & tag_mask ? 1 : 0, clients & tag_mask ? 1 : 0);
472 | }
473 |
474 | free(occupied_str);
475 | free(tags_str);
476 | free(clients_str);
477 | free(urgent_str);
478 | } else if (STRING_EQUAL(command, "layout")) {
479 | char *layout = to_delimiter(line, &loc, '\n');
480 | bar_set_layout(monitor->bar, layout);
481 | free(layout);
482 | }
483 |
484 | free(command);
485 | monitor_update(monitor);
486 | }
487 |
488 | void stdin_in(int fd, short mask, void *data) {
489 | if (mask & (POLLHUP | POLLERR)) {
490 | running = 0;
491 | return;
492 | }
493 |
494 | int new_fd = dup(fd);
495 | FILE *stdin_file = fdopen(new_fd, "r");
496 | char *buffer = NULL;
497 | size_t size = 0;
498 | while(1) {
499 | if (getline(&buffer, &size, stdin_file) == -1)
500 | break;
501 |
502 | stdin_handle(buffer);
503 | }
504 | free(buffer);
505 | fclose(stdin_file);
506 | close(new_fd);
507 | }
508 |
509 | void sigaction_handler(int _) {
510 | if (write(self_pipe[1], "0", 1) < 0)
511 | panic("sigaction_handler");
512 | }
513 |
514 | void xdg_output_name(void *data, struct zxdg_output_v1 *output, const char *name) {
515 | struct Monitor *monitor = data;
516 | monitor->xdg_name = strdup(name);
517 | zxdg_output_v1_destroy(output);
518 | monitor->xdg_output = NULL;
519 | }
520 |
521 | void xdg_wm_base_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial) {
522 | xdg_wm_base_pong(xdg_wm_base, serial);
523 | }
524 |
525 | int main(int argc, char *argv[]) {
526 | int opt;
527 | while((opt = getopt(argc, argv, "hlv")) != -1) {
528 | switch (opt) {
529 | case 'l':
530 | if (!setup_log())
531 | panic("Failed to setup logging");
532 | break;
533 | case 'h':
534 | printf("Usage: %s [-h] [-v]\n", argv[0]);
535 | exit(EXIT_SUCCESS);
536 | case 'v':
537 | printf("%s %.1f\n", argv[0], VERSION);
538 | exit(EXIT_SUCCESS);
539 | case '?':
540 | printf("Invalid Argument\n");
541 | printf("Usage: %s [-h] [-v] [-l]\n", argv[0]);
542 | exit(EXIT_FAILURE);
543 | }
544 | }
545 |
546 | setup();
547 | run();
548 | cleanup();
549 | }
550 |
551 | void panic(const char *fmt, ...) {
552 | va_list ap;
553 | va_start(ap, fmt);
554 | fprintf(stderr, "[dwl-bar] panic: ");
555 | vfprintf(stderr, fmt, ap);
556 | va_end(ap);
557 | if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
558 | fputc(' ', stderr);
559 | perror(NULL);
560 |
561 | } else {
562 | fputc('\n', stderr);
563 | }
564 |
565 | cleanup();
566 | exit(EXIT_FAILURE);
567 | }
568 |
--------------------------------------------------------------------------------
/src/main.h:
--------------------------------------------------------------------------------
1 | #ifndef MAIN_H_
2 | #define MAIN_H_
3 |
4 | #include "xdg-output-unstable-v1-protocol.h"
5 | #include
6 | #include
7 | #include
8 |
9 | #define VERSION 0.0
10 |
11 | struct Monitor {
12 | char *xdg_name;
13 | uint32_t wl_name;
14 |
15 | struct wl_output *wl_output;
16 | struct zxdg_output_v1 *xdg_output;
17 | struct Pipeline *pipeline;
18 | struct List *hotspots; /* struct Hotspot* */
19 | struct Bar *bar;
20 |
21 | struct wl_list link;
22 | };
23 |
24 | void panic(const char *fmt, ...);
25 | void monitors_update(void);
26 | struct Monitor *monitor_from_surface(const struct wl_surface *surface);
27 |
28 | extern struct wl_compositor *compositor;
29 | extern struct zwlr_layer_shell_v1 *shell;
30 | extern struct wl_shm *shm;
31 |
32 | #endif // MAIN_H_
33 |
--------------------------------------------------------------------------------
/src/render.c:
--------------------------------------------------------------------------------
1 | #include "render.h"
2 | #include "log.h"
3 | #include "main.h"
4 | #include "shm.h"
5 | #include "util.h"
6 | #include "config.h"
7 | #include "wlr-layer-shell-unstable-v1-protocol.h"
8 | #include "pango/pango-layout.h"
9 | #include "pango/pangocairo.h"
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | static struct Font *get_font(void);
16 | static void pipeline_frame(void* data, struct wl_callback* callback, uint32_t callback_data);
17 | static void pipeline_layer_surface(void* data, struct zwlr_layer_surface_v1* _, uint32_t serial, uint32_t width, uint32_t height);
18 | static void pipeline_render(struct Pipeline *pipeline);
19 |
20 | const struct wl_callback_listener frame_listener = {.done = pipeline_frame};
21 | const struct zwlr_layer_surface_v1_listener layer_surface_listener = {.configure = pipeline_layer_surface};
22 |
23 | struct BasicComponent *basic_component_create(PangoContext *context, PangoFontDescription *description) {
24 | struct BasicComponent *component = ecalloc(1, sizeof(*component));
25 | component->layout = pango_layout_new(context);
26 | pango_layout_set_font_description(component->layout, description);
27 | component->x = 0;
28 | component->y = 0;
29 | component->width = 0;
30 | component->height = 0;
31 | component->tx = 0;
32 | component->ty = 0;
33 |
34 | return component;
35 | }
36 |
37 | void basic_component_destroy(struct BasicComponent *component) {
38 | if (!component)
39 | return;
40 |
41 | g_object_unref(component->layout);
42 | free(component);
43 | }
44 |
45 | int basic_component_is_clicked(struct BasicComponent *component, double x, double y) {
46 | return (x > component->x && y > component->y &&
47 | x < (component->x + component->width) && y < (component->y + component->height));
48 | }
49 |
50 | void basic_component_render(struct BasicComponent *component, struct Pipeline *pipeline,
51 | cairo_t *painter, int *x, int *y) {
52 | if (!component)
53 | return;
54 |
55 | pango_cairo_update_layout(painter, component->layout);
56 | component->x = *x;
57 | component->y = *y;
58 |
59 | pipeline_color_background(pipeline, painter);
60 | cairo_rectangle(painter, *x, *y, component->width, component->height);
61 | cairo_fill(painter);
62 |
63 | pipeline_color_foreground(pipeline, painter);
64 | cairo_move_to(painter, *x+component->tx, *y+component->ty);
65 | pango_cairo_show_layout(painter, component->layout);
66 | }
67 |
68 | int basic_component_text_width(struct BasicComponent *component) {
69 | if (!component)
70 | return 0;
71 |
72 | int w;
73 | pango_layout_get_size(component->layout, &w, NULL);
74 | return PANGO_PIXELS(w);
75 | }
76 |
77 | struct Font *get_font(void) {
78 | PangoFontMap* map = pango_cairo_font_map_get_default();
79 | if (!map)
80 | panic("font map");
81 |
82 | PangoFontDescription* desc = pango_font_description_from_string(font);
83 | if (!desc)
84 | panic("font description");
85 |
86 | PangoContext* context = pango_font_map_create_context(map);
87 | if (!context)
88 | panic("temp context");
89 |
90 | PangoFont* fnt = pango_font_map_load_font(map, context, desc);
91 | if (!fnt)
92 | panic("font load");
93 |
94 | PangoFontMetrics* metrics = pango_font_get_metrics(fnt, pango_language_get_default());
95 | if (!metrics)
96 | panic("font metrics");
97 |
98 | struct Font *font = ecalloc(1, sizeof(*font));
99 | font->description = desc;
100 | font->height = PANGO_PIXELS(pango_font_metrics_get_height(metrics));
101 | font->approx_width = PANGO_PIXELS(pango_font_metrics_get_approximate_char_width(metrics));
102 |
103 | pango_font_metrics_unref(metrics);
104 | g_object_unref(fnt);
105 | g_object_unref(context);
106 |
107 | return font;
108 | }
109 |
110 | void pipeline_add(struct Pipeline *pipeline, const struct PipelineListener *listener, void *data) {
111 | if (!pipeline)
112 | return;
113 |
114 | struct PipelineCallback *callback = list_add(pipeline->callbacks, ecalloc(1, sizeof(*callback)));
115 | callback->listener = listener;
116 | callback->data = data;
117 | }
118 |
119 | struct Pipeline *pipeline_create(void) {
120 | struct Pipeline *pipeline = ecalloc(1, sizeof(*pipeline));
121 | pipeline->callbacks = list_create(0);
122 | pipeline->current = 0;
123 | pipeline->invalid = 0;
124 | pipeline->context = pango_font_map_create_context(pango_cairo_font_map_get_default());
125 | pipeline->font = get_font();
126 | pipeline->shm = NULL;
127 |
128 | return pipeline;
129 | }
130 |
131 | void pipeline_destroy(struct Pipeline *pipeline) {
132 | if (!pipeline)
133 | return;
134 |
135 | list_elements_destroy(pipeline->callbacks, free);
136 | g_object_unref(pipeline->context);
137 | pango_font_description_free(pipeline->font->description);
138 | free(pipeline->font);
139 | shm_destroy(pipeline->shm);
140 | wl_surface_destroy(pipeline->surface);
141 | zwlr_layer_surface_v1_destroy(pipeline->layer_surface);
142 | free(pipeline);
143 | }
144 |
145 | void pipeline_frame(void* data, struct wl_callback* callback, uint32_t callback_data) {
146 | pipeline_render((struct Pipeline *)data);
147 | wl_callback_destroy(callback);
148 | }
149 |
150 | int pipeline_get_future_widths(struct Pipeline *pipeline) {
151 | if (!pipeline)
152 | return 0;
153 |
154 | int width = 0;
155 | struct PipelineCallback *callback;
156 | for (int i = pipeline->callbacks->length-1; i > pipeline->current; i--) {
157 | callback = pipeline->callbacks->data[i];
158 | width += callback->listener->width(pipeline, callback->data, width);
159 | }
160 |
161 | return width;
162 | }
163 |
164 | void pipeline_hide(struct Pipeline *pipeline) {
165 | if (!pipeline || !pipeline_is_visible(pipeline))
166 | return;
167 |
168 |
169 | zwlr_layer_surface_v1_destroy(pipeline->layer_surface);
170 | wl_surface_destroy(pipeline->surface);
171 | shm_destroy(pipeline->shm);
172 |
173 | pipeline->layer_surface = NULL;
174 | pipeline->surface = NULL;
175 | pipeline->shm = NULL;
176 | }
177 |
178 | void pipeline_invalidate(struct Pipeline *pipeline) {
179 | if (!pipeline || pipeline->invalid || !pipeline_is_visible(pipeline))
180 | return;
181 |
182 | struct wl_callback *callback = wl_surface_frame(pipeline->surface);
183 | wl_callback_add_listener(callback, &frame_listener, pipeline);
184 | wl_surface_commit(pipeline->surface);
185 | pipeline->invalid = 1;
186 | }
187 |
188 | int pipeline_is_visible(struct Pipeline *pipeline) {
189 | if (!pipeline) return 0;
190 | return !(!pipeline->surface);
191 | }
192 |
193 | void pipeline_layer_surface(void* data, struct zwlr_layer_surface_v1* _,
194 | uint32_t serial, uint32_t width, uint32_t height) {
195 | struct Pipeline *pipeline = data;
196 | zwlr_layer_surface_v1_ack_configure(pipeline->layer_surface, serial);
197 |
198 | if (pipeline->shm) {
199 | if (pipeline->shm->width == width && pipeline->shm->height == height)
200 | return;
201 | shm_destroy(pipeline->shm);
202 | }
203 |
204 | pipeline->shm = shm_create(width, height, WL_SHM_FORMAT_XRGB8888);
205 | pipeline_render(pipeline);
206 | }
207 |
208 | void pipeline_render(struct Pipeline *pipeline) {
209 | if (!pipeline || !pipeline->shm)
210 | return;
211 |
212 | int x = 0, y = 0;
213 | cairo_surface_t *image = cairo_image_surface_create_for_data(shm_data(pipeline->shm),
214 | CAIRO_FORMAT_ARGB32, pipeline->shm->width, pipeline->shm->height, pipeline->shm->stride);
215 | cairo_t *painter = cairo_create(image);
216 | pango_cairo_update_context(painter, pipeline->context);
217 |
218 | struct PipelineCallback *callback;
219 | for (int i = 0; i < pipeline->callbacks->length; i++) {
220 | pipeline->current = i;
221 | callback = pipeline->callbacks->data[i];
222 | callback->listener->render(pipeline, callback->data, painter, &x, &y);
223 | }
224 |
225 | wl_surface_attach(pipeline->surface, shm_buffer(pipeline->shm), 0, 0);
226 | wl_surface_damage(pipeline->surface, 0, 0, pipeline->shm->width, pipeline->shm->height);
227 | wl_surface_commit(pipeline->surface);
228 |
229 | cairo_destroy(painter);
230 | cairo_surface_destroy(image);
231 |
232 | shm_flip(pipeline->shm);
233 | pipeline->invalid = 0;
234 | }
235 |
236 | void pipeline_show(struct Pipeline *pipeline, struct wl_output *output) {
237 | if (!pipeline || !output || pipeline_is_visible(pipeline))
238 | return;
239 |
240 | pipeline->surface = wl_compositor_create_surface(compositor);
241 | pipeline->layer_surface = zwlr_layer_shell_v1_get_layer_surface(shell, pipeline->surface, output,
242 | ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "doom.dwl-bar");
243 | zwlr_layer_surface_v1_add_listener(pipeline->layer_surface, &layer_surface_listener, pipeline);
244 |
245 | int anchor = bar_top ? ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP : ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
246 | zwlr_layer_surface_v1_set_anchor(pipeline->layer_surface,
247 | anchor | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
248 |
249 | int height = pipeline->font->height + 2;
250 | zwlr_layer_surface_v1_set_size(pipeline->layer_surface, 0, height);
251 | zwlr_layer_surface_v1_set_exclusive_zone(pipeline->layer_surface, height);
252 | wl_surface_commit(pipeline->surface);
253 | }
254 |
255 | void pipeline_set_colorscheme(struct Pipeline* pipeline, const int **scheme) {
256 | for (int i = 0; i < 4; i++) {
257 | pipeline->foreground[i] = scheme[0][i];
258 | pipeline->background[i] = scheme[1][i];
259 | }
260 | }
261 |
262 | void pipeline_color_foreground(struct Pipeline* pipeline, cairo_t *painter) {
263 | set_color(painter, pipeline->foreground);
264 | }
265 |
266 | void pipeline_color_background(struct Pipeline* pipeline, cairo_t *painter) {
267 | set_color(painter, pipeline->background);
268 | }
269 |
270 | void set_color(cairo_t *painter, const int rgba[4]) {
271 | cairo_set_source_rgba(painter, rgba[0]/255.0, rgba[1]/255.0, rgba[2]/255.0, rgba[3]/255.0);
272 | }
273 |
--------------------------------------------------------------------------------
/src/render.h:
--------------------------------------------------------------------------------
1 | #ifndef RENDER_H_
2 | #define RENDER_H_
3 |
4 | #include "util.h"
5 | #include "shm.h"
6 | #include "user.h"
7 | #include "wlr-layer-shell-unstable-v1-protocol.h"
8 | #include "pango/pango-types.h"
9 | #include
10 | #include
11 |
12 | struct Font {
13 | PangoFontDescription *description;
14 | unsigned int height, approx_width;
15 | };
16 |
17 | /* The render pipeline, also handles click events by keeping track of each components bounds'. */
18 | struct Pipeline {
19 | struct List *callbacks; /* struct PipelineCallbacks* */
20 | int current /* The current callback we are on */,
21 | invalid;
22 |
23 | /* Colors */
24 | int background[4], foreground[4];
25 |
26 | PangoContext *context;
27 | struct Font *font;
28 |
29 | struct Shm *shm;
30 | struct wl_surface *surface;
31 | struct zwlr_layer_surface_v1 *layer_surface;
32 | };
33 |
34 | struct PipelineListener {
35 | void (*render)(struct Pipeline *pipeline, void *data, cairo_t *painter, int *x, int *y);
36 | int (*width)(struct Pipeline *pipeline, void *data, unsigned int future_widths);
37 | };
38 |
39 | struct PipelineCallback {
40 | const struct PipelineListener *listener;
41 | void *data;
42 | };
43 |
44 | /* Basic helper component, can be used if the only thing to be displayed is text. */
45 | struct BasicComponent {
46 | PangoLayout *layout;
47 | int width, height,
48 | x, y /* box start coordinates */,
49 | tx, ty /* text starts coordinates, tx is added to starting x coordinates. */;
50 | };
51 |
52 | struct BasicComponent *basic_component_create(PangoContext *context, PangoFontDescription *description);
53 | void basic_component_destroy(struct BasicComponent *component);
54 | int basic_component_is_clicked(struct BasicComponent *component, double x, double y);
55 | void basic_component_render(struct BasicComponent *component, struct Pipeline *pipeline,
56 | cairo_t *painter, int *x, int *y);
57 | int basic_component_text_width(struct BasicComponent *component);
58 | void pipeline_add(struct Pipeline *pipeline, const struct PipelineListener *listener, void *data);
59 | struct Pipeline *pipeline_create(void);
60 | void pipeline_destroy(struct Pipeline *pipeline);
61 | int pipeline_get_future_widths(struct Pipeline *pipeline);
62 | void pipeline_hide(struct Pipeline *pipeline);
63 | void pipeline_invalidate(struct Pipeline *pipeline);
64 | int pipeline_is_visible(struct Pipeline *pipeline);
65 | void pipeline_show(struct Pipeline *pipeline, struct wl_output *output);
66 | void pipeline_set_colorscheme(struct Pipeline* pipeline, const int **scheme);
67 | void pipeline_color_foreground(struct Pipeline* pipeline, cairo_t *painter);
68 | void pipeline_color_background(struct Pipeline* pipeline, cairo_t *painter);
69 | void set_color(cairo_t *painter, const int rgba[4]);
70 |
71 | #endif // RENDER_H_
72 |
--------------------------------------------------------------------------------
/src/shm.c:
--------------------------------------------------------------------------------
1 | #include "shm.h"
2 | #include "main.h"
3 | #include
4 |
5 | #define BUFFERS 2
6 |
7 | static int allocate_shm(int size);
8 | static struct Buffer buffer_create(struct MemoryMapping *memmap, struct wl_shm_pool *shm,
9 | int fd, int width, int height, int offset, enum wl_shm_format format);
10 | static void buffer_destroy(struct Buffer *buf);
11 | static struct MemoryMapping memory_mapping_create(int fd, int pool_size);
12 | static void memory_mapping_destroy(struct MemoryMapping *map);
13 |
14 |
15 | int allocate_shm(int size) {
16 | char name[] = "wl_shm";
17 | int fd;
18 |
19 | if ((fd = shm_open(name, O_CREAT | O_RDWR | O_EXCL, 0600)) < 0)
20 | panic("shm_open when allocating shm");
21 |
22 | shm_unlink(name);
23 |
24 | if (ftruncate(fd, size) < 0)
25 | panic("ftruncate when allocating shm");
26 |
27 | return fd;
28 | }
29 |
30 | static struct Buffer buffer_create(struct MemoryMapping *map, struct wl_shm_pool *shm,
31 | int fd, int width, int height, int offset, enum wl_shm_format format) {
32 | if (!map)
33 | panic("map is null");
34 |
35 | int stride = width * 4,
36 | pool_size = height * stride;
37 | struct Buffer buffer;
38 |
39 | struct wl_buffer *wl_buffer = wl_shm_pool_create_buffer(shm, offset, width, height, stride, format);
40 | buffer.buffer = wl_buffer;
41 | buffer.buffer_ptr = map->ptr+offset;
42 |
43 | return buffer;
44 | }
45 |
46 | void buffer_destroy(struct Buffer *buffer) {
47 | if (!buffer) return;
48 | wl_buffer_destroy(buffer->buffer);
49 | }
50 |
51 | struct MemoryMapping memory_mapping_create(int fd, int pool_size) {
52 | struct MemoryMapping map;
53 | void* ptr = mmap(NULL, pool_size, PROT_READ | PROT_WRITE,
54 | MAP_SHARED, fd, 0);
55 | if (ptr == MAP_FAILED || !ptr) {
56 | close(fd);
57 | panic("MAP_FAILED");
58 | }
59 |
60 | map.ptr = ptr;
61 | map.size = pool_size;
62 |
63 | return map;
64 | }
65 |
66 | void memory_mapping_destroy(struct MemoryMapping *map) {
67 | if (!map) return;
68 | munmap(map->ptr, map->size);
69 | }
70 |
71 | struct Shm *shm_create(int width, int height, enum wl_shm_format format) {
72 | struct Shm *shared_mem = calloc(1, sizeof(*shared_mem));
73 | int i, offset,
74 | stride = width * 4,
75 | size = stride * height,
76 | total = size * BUFFERS;
77 | int fd = allocate_shm(total);
78 |
79 | struct MemoryMapping memory = memory_mapping_create(fd, total);
80 | struct wl_shm_pool* pool = wl_shm_create_pool(shm, fd, total);
81 | for (i = 0; i < BUFFERS; i++) {
82 | offset = size*i;
83 | shared_mem->buffers[i] = buffer_create(&memory, pool, fd, width, height, offset, format);
84 | }
85 | close(fd);
86 | wl_shm_pool_destroy(pool);
87 |
88 | shared_mem->map = memory;
89 | shared_mem->current = 0;
90 |
91 | shared_mem->height = height;
92 | shared_mem->width = width;
93 | shared_mem->stride = stride;
94 |
95 | return shared_mem;
96 | }
97 |
98 | void shm_destroy(struct Shm *shm) {
99 | if (!shm) return;
100 |
101 | memory_mapping_destroy(&shm->map);
102 | for (int i = 0; i < BUFFERS; i++)
103 | buffer_destroy(&shm->buffers[i]);
104 | free(shm);
105 | }
106 |
107 | uint8_t *shm_data(struct Shm *shm) {
108 | return shm->buffers[shm->current].buffer_ptr;
109 | }
110 |
111 | struct wl_buffer *shm_buffer(struct Shm *shm) {
112 | return shm->buffers[shm->current].buffer;
113 | }
114 |
115 | void shm_flip(struct Shm *shm) {
116 | shm->current = 1-shm->current;
117 | }
118 |
--------------------------------------------------------------------------------
/src/shm.h:
--------------------------------------------------------------------------------
1 | #ifndef SHM_H_
2 | #define SHM_H_
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | struct MemoryMapping {
13 | void *ptr;
14 | int size;
15 | };
16 |
17 | struct Buffer {
18 | struct wl_buffer *buffer;
19 | uint8_t *buffer_ptr;
20 | };
21 |
22 | struct Shm {
23 | int width, height, stride, current;
24 | struct MemoryMapping map;
25 | struct Buffer buffers[2];
26 | };
27 |
28 | struct Shm *shm_create(int width, int height, enum wl_shm_format format);
29 | void shm_destroy(struct Shm *shm);
30 | uint8_t *shm_data(struct Shm *shm);
31 | struct wl_buffer *shm_buffer(struct Shm *shm);
32 | void shm_flip(struct Shm *shm);
33 |
34 |
35 | #endif // SHM_H_
36 |
--------------------------------------------------------------------------------
/src/user.c:
--------------------------------------------------------------------------------
1 | #include "user.h"
2 | #include "util.h"
3 | #include
4 | #include
5 | #include
6 |
7 | void spawn(struct Monitor *monitor, const union Arg *arg) {
8 | if (fork() != 0)
9 | return;
10 |
11 | char* const* argv = arg->v;
12 | setsid();
13 | execvp(argv[0], argv);
14 | fprintf(stderr, "dwl-bar: execvp %s", argv[0]);
15 | perror(" failed\n");
16 | exit(1);
17 | }
18 |
--------------------------------------------------------------------------------
/src/user.h:
--------------------------------------------------------------------------------
1 | #ifndef USER_H_
2 | #define USER_H_
3 |
4 | #include "main.h"
5 |
6 | typedef struct Binding Binding;
7 |
8 | enum Clicked {
9 | Click_None,
10 | Click_Tag,
11 | Click_Layout,
12 | Click_Title,
13 | Click_Status,
14 | };
15 |
16 | enum ColorScheme {
17 | InActive_Scheme = 0,
18 | Active_Scheme = 1,
19 | Urgent_Scheme = 2,
20 | };
21 |
22 | enum TouchGesture {
23 | Gesture_Left,
24 | Gesture_Right,
25 | };
26 |
27 | enum PointerScroll {
28 | Scroll_Up,
29 | Scroll_Down,
30 | Scroll_Left,
31 | Scroll_Right,
32 | };
33 |
34 | union Arg {
35 | unsigned int ui;
36 | int i;
37 | const void *v;
38 | };
39 |
40 | struct Binding {
41 | enum Clicked clicked;
42 | int button;
43 | void (*callback)(struct Monitor *monitor, const union Arg *arg);
44 | /* Informs the click function that they should only pass the defined arg in this binding */
45 | unsigned int bypass;
46 | const union Arg arg;
47 | };
48 |
49 | void spawn(struct Monitor *monitor, const union Arg *arg);
50 |
51 | #endif // USER_H_
52 |
--------------------------------------------------------------------------------
/src/util.c:
--------------------------------------------------------------------------------
1 | #include "util.h"
2 | #include "log.h"
3 | #include "main.h"
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | static void list_resize(struct List *list);
11 |
12 | void *ecalloc(size_t amnt, size_t size) {
13 | void *p = calloc(amnt, size);
14 |
15 | if (!p)
16 | panic("Out of memory");
17 |
18 | return p;
19 | }
20 |
21 | void *list_add(struct List *list, void *data) {
22 | if (!list)
23 | return NULL;
24 |
25 | list_resize(list);
26 | list->data[list->length++] = data;
27 | return list->data[list->length-1];
28 | }
29 |
30 | void list_copy(struct List *dest, struct List *src) {
31 | if (!dest || !src)
32 | return;
33 |
34 | for (int i = 0; i < src->length; i++)
35 | list_add(dest, src->data[i]);
36 | }
37 |
38 | struct List *list_create(size_t initial_size) {
39 | struct List *list = ecalloc(1, sizeof(*list));
40 |
41 | list->allocated = initial_size > 10 ? initial_size : 10;
42 | list->length = 0;
43 | list->data = ecalloc(list->allocated, sizeof(void*));
44 |
45 | return list;
46 | }
47 |
48 | int list_cmp_find(struct List* list, const void *data, int compare(const void *left, const void *right)) {
49 | if (!list)
50 | return -1;
51 |
52 | for (int i = 0; i < list->length; i++)
53 | if (compare(data, list->data[i]) == 0)
54 | return i;
55 |
56 | return -1;
57 | }
58 |
59 | void list_destroy(struct List *list) {
60 | if (!list)
61 | return;
62 |
63 | free(list->data);
64 | free(list);
65 | }
66 |
67 | void list_elements_destroy(struct List *list, void (*destroy)(void *data)) {
68 | if (!list)
69 | return;
70 |
71 | for (int i = 0; i < list->length; i++)
72 | destroy(list->data[i]);
73 | free(list->data);
74 | free(list);
75 | }
76 |
77 | int list_find(struct List* list, const void *data) {
78 | if (!list)
79 | return -1;
80 |
81 | for (int i = 0; i < list->length; i++)
82 | if (data == list->data[i])
83 | return i;
84 |
85 | return -1;
86 | }
87 |
88 | void *list_remove(struct List *list, unsigned int index) {
89 | if (!list || index > list->length-1)
90 | return NULL;
91 |
92 | void *tmp = list->data[index];
93 |
94 | list->length--;
95 | memmove(&list->data[index], &list->data[index + 1], sizeof(void*) * (list->length - index));
96 |
97 | return tmp;
98 | }
99 |
100 | void list_resize(struct List *list) {
101 | if (list->length < list->allocated)
102 | return;
103 |
104 | list->allocated *= 2;
105 | list->data = realloc(list->data, sizeof(void*) * list->allocated);
106 | }
107 |
108 | char *string_create(const char *fmt, ...) {
109 | va_list ap, aq;
110 | va_start(ap, fmt);
111 | va_copy(aq, ap);
112 |
113 | char *str;
114 | size_t len = vsnprintf(NULL, 0, fmt, ap) + 1;
115 | str = ecalloc(1, len);
116 | vsnprintf(str, len, fmt, aq);
117 |
118 | va_end(ap);
119 | va_end(aq);
120 |
121 | return str;
122 | }
123 |
124 | char *to_delimiter(const char *string, unsigned long *start_end, char delimiter) {
125 | if (!string || !start_end)
126 | return NULL;
127 |
128 | char *output;
129 | const char *read;
130 | unsigned long i = 0;
131 |
132 | for (read = string + *start_end; *read != '\0' && *read != delimiter; read++)
133 | i++;
134 |
135 | output = strncpy(ecalloc(i+1, sizeof(*output)),
136 | string + *start_end, i);
137 | output[i++] = '\0';
138 | *start_end += i;
139 |
140 | return output;
141 | }
142 |
--------------------------------------------------------------------------------
/src/util.h:
--------------------------------------------------------------------------------
1 | #ifndef UTIL_H_
2 | #define UTIL_H_
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #define STRING_EQUAL(string1, string2) strcmp(string1, string2) == 0
9 | #define STRINGN_EQUAL(string1, string2, n) strncmp(string1, string2, n) == 0
10 | #define LENGTH(X) (sizeof X / sizeof X[0] )
11 |
12 | struct List {
13 | void **data;
14 | size_t allocated, length;
15 | };
16 |
17 | void *ecalloc(size_t amnt, size_t size);
18 | void *list_add(struct List *list, void *data);
19 | void list_copy(struct List *dest, struct List *src);
20 | struct List *list_create(size_t initial_size);
21 | int list_cmp_find(struct List *list, const void *data, int compare(const void *left, const void *right));
22 | void list_destroy(struct List *list);
23 | void list_elements_destroy(struct List *list, void (*destroy)(void *data));
24 | int list_find(struct List* list, const void *data);
25 | void *list_remove(struct List *list, unsigned int index);
26 | char *string_create(const char* fmt, ...);
27 | char *to_delimiter(const char* string, ulong *start_end, char delimiter);
28 |
29 | #endif // UTIL_H_
30 |
--------------------------------------------------------------------------------