├── .gitignore
├── LICENSE
├── README.md
├── devmgr.c
├── devmgr.h
├── main.c
├── meson.build
├── meson_options.txt
├── pango.c
├── pango.h
├── protocols
├── meson.build
└── wlr-layer-shell-unstable-v1.xml
├── shm.c
└── shm.h
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # wshowkeys
2 |
3 | Displays keypresses on screen on supported Wayland compositors (requires
4 | `wlr_layer_shell_v1` support).
5 |
6 | 
7 |
8 | Forked from https://git.sr.ht/~sircmpwn/wshowkeys as Drew has moved onto other thigns.
9 |
10 | ## Installation
11 |
12 | Dependencies:
13 |
14 | - cairo
15 | - libinput
16 | - pango
17 | - udev
18 | - wayland
19 | - xkbcommon
20 |
21 | ```
22 | $ meson build
23 | $ ninja -C build
24 | # ninja -C build install
25 | # chmod a+s /usr/bin/wshowkeys
26 | ```
27 |
28 | wshowkeys must be configured as setuid during installation. It requires root
29 | permissions to read input events. These permissions are dropped after startup.
30 |
31 | ## Usage
32 |
33 | ```
34 | wshowkeys [-b|-f|-s #RRGGBB[AA]] [-F font] [-t timeout]
35 | [-a top|left|right|bottom] [-m margin] [-o output]
36 | ```
37 |
38 | - *-b #RRGGBB[AA]*: set background color
39 | - *-f #RRGGBB[AA]*: set foreground color
40 | - *-s #RRGGBB[AA]*: set color for special keys
41 | - *-F font*: set font (Pango format, e.g. 'monospace 24')
42 | - *-t timeout*: set timeout before clearing old keystrokes
43 | - *-a top|left|right|bottom*: anchor the keystrokes to an edge. May be specified
44 | twice.
45 | - *-m margin*: set a margin (in pixels) from the nearest edge
46 | - *-o output*: request wshowkeys is shown on the specified output
47 | (unimplemented)
48 |
--------------------------------------------------------------------------------
/devmgr.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Portions of this file taken from wlroots; MIT licensed. Its purpose is to
3 | * run a child process as root for opening evdev devices.
4 | *
5 | * NOTICE: Most of this code runs as root.
6 | */
7 | #ifdef __FreeBSD__
8 | #define __BSD_VISIBLE 1
9 | #endif
10 | #include
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 "devmgr.h"
24 |
25 | enum msg_type {
26 | MSG_OPEN,
27 | MSG_END,
28 | };
29 |
30 | struct msg {
31 | enum msg_type msg_type;
32 | char path[PATH_MAX];
33 | };
34 |
35 | static ssize_t recv_msg(int sock, int *fd_out, void *buf, size_t buf_len) {
36 | char control[CMSG_SPACE(sizeof(*fd_out))] = {0};
37 | struct iovec iovec = { .iov_base = buf, .iov_len = buf_len };
38 | struct msghdr msghdr = {0};
39 |
40 | if (buf) {
41 | msghdr.msg_iov = &iovec;
42 | msghdr.msg_iovlen = 1;
43 | }
44 |
45 | if (fd_out) {
46 | msghdr.msg_control = &control;
47 | msghdr.msg_controllen = sizeof(control);
48 | }
49 |
50 | ssize_t ret;
51 | do {
52 | ret = recvmsg(sock, &msghdr, MSG_CMSG_CLOEXEC);
53 | } while (ret < 0 && errno == EINTR);
54 |
55 | if (fd_out) {
56 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msghdr);
57 | if (cmsg) {
58 | memcpy(fd_out, CMSG_DATA(cmsg), sizeof(*fd_out));
59 | } else {
60 | *fd_out = -1;
61 | }
62 | }
63 |
64 | return ret;
65 | }
66 |
67 | static void send_msg(int sock, int fd, void *buf, size_t buf_len) {
68 | char control[CMSG_SPACE(sizeof(fd))] = {0};
69 | struct iovec iovec = { .iov_base = buf, .iov_len = buf_len };
70 | struct msghdr msghdr = {0};
71 |
72 | if (buf) {
73 | msghdr.msg_iov = &iovec;
74 | msghdr.msg_iovlen = 1;
75 | }
76 |
77 | if (fd >= 0) {
78 | msghdr.msg_control = &control;
79 | msghdr.msg_controllen = sizeof(control);
80 |
81 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msghdr);
82 | *cmsg = (struct cmsghdr) {
83 | .cmsg_level = SOL_SOCKET,
84 | .cmsg_type = SCM_RIGHTS,
85 | .cmsg_len = CMSG_LEN(sizeof(fd)),
86 | };
87 | memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd));
88 | }
89 |
90 | ssize_t ret;
91 | do {
92 | ret = sendmsg(sock, &msghdr, 0);
93 | } while (ret < 0 && errno == EINTR);
94 | }
95 |
96 | static void devmgr_run(int sockfd, const char *devpath) {
97 | struct msg msg;
98 | int fdin = -1;
99 | bool running = true;
100 |
101 | while (running && recv_msg(sockfd, &fdin, &msg, sizeof(msg)) > 0) {
102 | switch (msg.msg_type) {
103 | case MSG_OPEN:
104 | errno = 0;
105 | if (strstr(msg.path, devpath) != msg.path) {
106 | /* Hackerman detected */
107 | exit(1);
108 | }
109 | int fd = open(msg.path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
110 | int ret = errno;
111 | send_msg(sockfd, ret ? -1 : fd, &ret, sizeof(ret));
112 | if (fd >= 0) {
113 | close(fd);
114 | }
115 | break;
116 | case MSG_END:
117 | running = false;
118 | send_msg(sockfd, -1, NULL, 0);
119 | break;
120 | }
121 | }
122 |
123 | exit(0);
124 | }
125 |
126 | int devmgr_start(int *fd, pid_t *pid, const char *devpath) {
127 | if (geteuid() != 0) {
128 | fprintf(stderr, "wshowkeys needs to be setuid to read input events\n");
129 | return 1;
130 | }
131 |
132 | int sock[2];
133 | if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sock) < 0) {
134 | fprintf(stderr, "devmgr: socketpair: %s", strerror(errno));
135 | return -1;
136 | }
137 |
138 | pid_t child = fork();
139 | if (child < 0) {
140 | fprintf(stderr, "devmgr: fork: %s", strerror(errno));
141 | close(sock[0]);
142 | close(sock[1]);
143 | return 1;
144 | } else if (child == 0) {
145 | close(sock[0]);
146 | devmgr_run(sock[1], devpath); /* Does not return */
147 | }
148 | close(sock[1]);
149 | *fd = sock[0];
150 | *pid = child;
151 |
152 | if (setgid(getgid()) != 0) {
153 | fprintf(stderr, "devmgr: setgid: %s\n", strerror(errno));
154 | return 1;
155 | }
156 | if (setuid(getuid()) != 0) {
157 | fprintf(stderr, "devmgr: setuid: %s\n", strerror(errno));
158 | return 1;
159 | }
160 | if (setuid(0) != -1) {
161 | fprintf(stderr, "devmgr: failed to drop root\n");
162 | return 1;
163 | }
164 |
165 | return 0;
166 | }
167 |
168 | int devmgr_open(int sockfd, const char *path) {
169 | struct msg msg = { .msg_type = MSG_OPEN };
170 | snprintf(msg.path, sizeof(msg.path), "%s", path);
171 |
172 | send_msg(sockfd, -1, &msg, sizeof(msg));
173 |
174 | int fd, err, ret;
175 | int retry = 0;
176 | do {
177 | ret = recv_msg(sockfd, &fd, &err, sizeof(err));
178 | } while (ret == 0 && retry++ < 3);
179 |
180 | return err ? -err : fd;
181 | }
182 |
183 | void devmgr_finish(int sock, pid_t pid) {
184 | struct msg msg = { .msg_type = MSG_END };
185 |
186 | send_msg(sock, -1, &msg, sizeof(msg));
187 | recv_msg(sock, NULL, NULL, 0);
188 |
189 | waitpid(pid, NULL, 0);
190 |
191 | close(sock);
192 | }
193 |
--------------------------------------------------------------------------------
/devmgr.h:
--------------------------------------------------------------------------------
1 | #ifndef _DEVMGR_H
2 | #define _DEVMGR_H
3 |
4 | int devmgr_start(int *fd, pid_t *pid, const char *devpath);
5 | int devmgr_open(int sockfd, const char *path);
6 | void devmgr_finish(int sock, pid_t pid);
7 |
8 | #endif
9 |
--------------------------------------------------------------------------------
/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include "devmgr.h"
18 | #include "shm.h"
19 | #include "pango.h"
20 | #include "wlr-layer-shell-unstable-v1-client-protocol.h"
21 | #include "xdg-output-unstable-v1-client-protocol.h"
22 |
23 | struct wsk_keypress {
24 | xkb_keysym_t sym;
25 | char name[128];
26 | char utf8[128];
27 | struct wsk_keypress *next;
28 | };
29 |
30 | struct wsk_output {
31 | struct wl_output *output;
32 | int scale;
33 | enum wl_output_subpixel subpixel;
34 | struct wsk_output *next;
35 | };
36 |
37 | struct wsk_state {
38 | int devmgr;
39 | pid_t devmgr_pid;
40 | struct udev *udev;
41 | struct libinput *libinput;
42 |
43 | uint32_t foreground, background, specialfg;
44 | const char *font;
45 | int timeout;
46 |
47 | struct wl_display *display;
48 | struct wl_registry *registry;
49 | struct wl_compositor *compositor;
50 | struct wl_shm *shm;
51 | struct wl_seat *seat;
52 | struct wl_keyboard *keyboard;
53 | struct zxdg_output_manager_v1 *output_mgr;
54 | struct zwlr_layer_shell_v1 *layer_shell;
55 |
56 | struct wl_surface *surface;
57 | struct zwlr_layer_surface_v1 *layer_surface;
58 | uint32_t width, height;
59 | bool frame_scheduled, dirty;
60 | struct pool_buffer buffers[2];
61 | struct pool_buffer *current_buffer;
62 | struct wsk_output *output, *outputs;
63 |
64 | struct xkb_state *xkb_state;
65 | struct xkb_context *xkb_context;
66 | struct xkb_keymap *xkb_keymap;
67 |
68 | struct wsk_keypress *keys;
69 | struct timespec last_key;
70 |
71 | bool run;
72 | };
73 |
74 | static void cairo_set_source_u32(cairo_t *cairo, uint32_t color) {
75 | cairo_set_source_rgba(cairo,
76 | (color >> (3*8) & 0xFF) / 255.0,
77 | (color >> (2*8) & 0xFF) / 255.0,
78 | (color >> (1*8) & 0xFF) / 255.0,
79 | (color >> (0*8) & 0xFF) / 255.0);
80 | }
81 |
82 | static cairo_subpixel_order_t to_cairo_subpixel_order(
83 | enum wl_output_subpixel subpixel) {
84 | switch (subpixel) {
85 | case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB:
86 | return CAIRO_SUBPIXEL_ORDER_RGB;
87 | case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR:
88 | return CAIRO_SUBPIXEL_ORDER_BGR;
89 | case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB:
90 | return CAIRO_SUBPIXEL_ORDER_VRGB;
91 | case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR:
92 | return CAIRO_SUBPIXEL_ORDER_VBGR;
93 | default:
94 | return CAIRO_SUBPIXEL_ORDER_DEFAULT;
95 | }
96 | return CAIRO_SUBPIXEL_ORDER_DEFAULT;
97 | }
98 |
99 | static void render_to_cairo(cairo_t *cairo, struct wsk_state *state,
100 | int scale, uint32_t *width, uint32_t *height) {
101 | cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
102 | cairo_set_source_u32(cairo, state->background);
103 | cairo_paint(cairo);
104 |
105 | struct wsk_keypress *key = state->keys;
106 | while (key) {
107 | bool special = false;
108 | const char *name = key->utf8;
109 | if (!name[0]) {
110 | special = true;
111 | cairo_set_source_u32(cairo, state->specialfg);
112 | name = key->name;
113 | } else {
114 | cairo_set_source_u32(cairo, state->foreground);
115 | }
116 |
117 | cairo_move_to(cairo, *width, 0);
118 |
119 | int w, h;
120 | if (special) {
121 | get_text_size(cairo, state->font, &w, &h, NULL, scale, "%s+", name);
122 | pango_printf(cairo, state->font, scale, "%s+", name);
123 | } else {
124 | get_text_size(cairo, state->font, &w, &h, NULL, scale, "%s", name);
125 | pango_printf(cairo, state->font, scale, "%s", name);
126 | }
127 |
128 | *width = *width + w;
129 | if ((int)*height < h) {
130 | *height = h;
131 | }
132 | key = key->next;
133 | }
134 | }
135 |
136 | static void render_frame(struct wsk_state *state) {
137 | cairo_surface_t *recorder = cairo_recording_surface_create(
138 | CAIRO_CONTENT_COLOR_ALPHA, NULL);
139 | cairo_t *cairo = cairo_create(recorder);
140 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST);
141 | cairo_font_options_t *fo = cairo_font_options_create();
142 | cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL);
143 | cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_SUBPIXEL);
144 | if (state->output) {
145 | cairo_font_options_set_subpixel_order(
146 | fo, to_cairo_subpixel_order(state->output->subpixel));
147 | }
148 | cairo_set_font_options(cairo, fo);
149 | cairo_font_options_destroy(fo);
150 | cairo_save(cairo);
151 | cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
152 | cairo_paint(cairo);
153 | cairo_restore(cairo);
154 |
155 | int scale = state->output ? state->output->scale : 1;
156 | uint32_t width = 0, height = 0;
157 | render_to_cairo(cairo, state, scale, &width, &height);
158 | if (height / scale != state->height
159 | || width / scale != state->width
160 | || state->width == 0) {
161 | // Reconfigure surface
162 | if (width == 0 || height == 0) {
163 | wl_surface_attach(state->surface, NULL, 0, 0);
164 | } else {
165 | zwlr_layer_surface_v1_set_size(
166 | state->layer_surface, width / scale, height / scale);
167 | }
168 |
169 | // TODO: this could infinite loop if the compositor assigns us a
170 | // different height than what we asked for
171 | wl_surface_commit(state->surface);
172 | } else if (height > 0) {
173 | // Replay recording into shm and send it off
174 | state->current_buffer = get_next_buffer(state->shm,
175 | state->buffers, state->width * scale, state->height * scale);
176 | if (!state->current_buffer) {
177 | cairo_surface_destroy(recorder);
178 | cairo_destroy(cairo);
179 | return;
180 | }
181 | cairo_t *shm = state->current_buffer->cairo;
182 |
183 | cairo_save(shm);
184 | cairo_set_operator(shm, CAIRO_OPERATOR_CLEAR);
185 | cairo_paint(shm);
186 | cairo_restore(shm);
187 |
188 | cairo_set_source_surface(shm, recorder, 0.0, 0.0);
189 | cairo_paint(shm);
190 |
191 | wl_surface_set_buffer_scale(state->surface, scale);
192 | wl_surface_attach(state->surface,
193 | state->current_buffer->buffer, 0, 0);
194 | wl_surface_damage_buffer(state->surface, 0, 0,
195 | state->width, state->height);
196 | wl_surface_commit(state->surface);
197 | }
198 | }
199 |
200 | static void set_dirty(struct wsk_state *state) {
201 | if (state->frame_scheduled) {
202 | state->dirty = true;
203 | } else if (state->surface) {
204 | render_frame(state);
205 | }
206 | }
207 |
208 | static void layer_surface_configure(void *data,
209 | struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1,
210 | uint32_t serial, uint32_t width, uint32_t height) {
211 | struct wsk_state *state = data;
212 | state->width = width;
213 | state->height = height;
214 | zwlr_layer_surface_v1_ack_configure(zwlr_layer_surface_v1, serial);
215 | set_dirty(state);
216 | }
217 |
218 | static void layer_surface_closed(void *data,
219 | struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1) {
220 | struct wsk_state *state = data;
221 | state->run = false;
222 | }
223 |
224 | static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
225 | .configure = layer_surface_configure,
226 | .closed = layer_surface_closed,
227 | };
228 |
229 | static void surface_enter(void *data,
230 | struct wl_surface *wl_surface, struct wl_output *output) {
231 | struct wsk_state *state = data;
232 | struct wsk_output *wsk_output = state->outputs;
233 | while (wsk_output->output != output) {
234 | wsk_output = wsk_output->next;
235 | }
236 | state->output = wsk_output;
237 | }
238 |
239 | static void surface_leave(void *data,
240 | struct wl_surface *wl_surface, struct wl_output *output) {
241 | // Who cares (not really possible with layer shell)
242 | }
243 |
244 | static const struct wl_surface_listener wl_surface_listener = {
245 | .enter = surface_enter,
246 | .leave = surface_leave,
247 | };
248 |
249 | static void keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
250 | uint32_t format, int32_t fd, uint32_t size) {
251 | struct wsk_state *state = data;
252 | char *map_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
253 | if (map_shm == MAP_FAILED) {
254 | close(fd);
255 | fprintf(stderr, "Unable to mmap keymap: %s", strerror(errno));
256 | return;
257 | }
258 | if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
259 | munmap(map_shm, size);
260 | close(fd);
261 | return;
262 | }
263 |
264 | struct xkb_keymap *keymap = xkb_keymap_new_from_string(
265 | state->xkb_context, map_shm, XKB_KEYMAP_FORMAT_TEXT_V1,
266 | XKB_KEYMAP_COMPILE_NO_FLAGS);
267 | munmap(map_shm, size);
268 | close(fd);
269 |
270 | struct xkb_state *xkb_state = xkb_state_new(keymap);
271 | xkb_keymap_unref(state->xkb_keymap);
272 | xkb_state_unref(state->xkb_state);
273 | state->xkb_keymap = keymap;
274 | state->xkb_state = xkb_state;
275 | }
276 |
277 | static void keyboard_enter(void *data, struct wl_keyboard *wl_keyboard,
278 | uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
279 | // Who cares
280 | }
281 |
282 | static void keyboard_leave(void *data, struct wl_keyboard *wl_keyboard,
283 | uint32_t serial, struct wl_surface *surface) {
284 | // Who cares
285 | }
286 |
287 | static void keyboard_key(void *data, struct wl_keyboard *wl_keyboard,
288 | uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
289 | // Who cares
290 | }
291 |
292 | static void keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard,
293 | uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
294 | uint32_t mods_locked, uint32_t group) {
295 | // Who cares
296 | }
297 |
298 | static void keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
299 | int32_t rate, int32_t delay) {
300 | // TODO
301 | }
302 |
303 | static const struct wl_keyboard_listener wl_keyboard_listener = {
304 | .keymap = keyboard_keymap,
305 | .enter = keyboard_enter,
306 | .leave = keyboard_leave,
307 | .key = keyboard_key,
308 | .modifiers = keyboard_modifiers,
309 | .repeat_info = keyboard_repeat_info,
310 | };
311 |
312 | static void seat_capabilities(
313 | void *data, struct wl_seat *wl_seat, uint32_t capabilities) {
314 | struct wsk_state *state = data;
315 | if (state->keyboard) {
316 | // TODO: support multiple seats
317 | return;
318 | }
319 |
320 | if (!(capabilities & WL_SEAT_CAPABILITY_KEYBOARD)) {
321 | fprintf(stderr, "wl_seat does not support keyboard");
322 | state->run = false;
323 | return;
324 | }
325 |
326 | state->keyboard = wl_seat_get_keyboard(wl_seat);
327 | wl_keyboard_add_listener(state->keyboard, &wl_keyboard_listener, state);
328 | }
329 |
330 | static void seat_name(void *data, struct wl_seat *wl_seat, const char *name) {
331 | struct wsk_state *state = data;
332 | /* TODO: support multiple seats */
333 | if (libinput_udev_assign_seat(state->libinput, "seat0") != 0) {
334 | fprintf(stderr, "Failed to assign libinput seat\n");
335 | state->run = false;
336 | return;
337 | }
338 | }
339 |
340 | static const struct wl_seat_listener wl_seat_listener = {
341 | .capabilities = seat_capabilities,
342 | .name = seat_name,
343 | };
344 |
345 | static void output_geometry(void *data, struct wl_output *wl_output,
346 | int32_t x, int32_t y, int32_t physical_width, int32_t physical_height,
347 | int32_t subpixel, const char *make, const char *model,
348 | int32_t transform) {
349 | struct wsk_output *output = data;
350 | output->subpixel = subpixel;
351 | }
352 |
353 | static void output_mode(void *data, struct wl_output *wl_output,
354 | uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
355 | // Who cares
356 | }
357 |
358 | static void output_done(void *data, struct wl_output *wl_output) {
359 | // Who cares
360 | }
361 |
362 | static void output_scale(void *data,
363 | struct wl_output *wl_output, int32_t factor) {
364 | struct wsk_output *output = data;
365 | output->scale = factor;
366 | }
367 |
368 | static const struct wl_output_listener wl_output_listener = {
369 | .geometry = output_geometry,
370 | .mode = output_mode,
371 | .done = output_done,
372 | .scale = output_scale,
373 | };
374 |
375 | static void registry_global(void *data, struct wl_registry *wl_registry,
376 | uint32_t name, const char *interface, uint32_t version) {
377 | struct wsk_state *state = data;
378 | if (strcmp(interface, wl_compositor_interface.name) == 0) {
379 | state->compositor = wl_registry_bind(wl_registry,
380 | name, &wl_compositor_interface, 4);
381 | } else if (strcmp(interface, wl_shm_interface.name) == 0) {
382 | state->shm = wl_registry_bind(wl_registry, name, &wl_shm_interface, 1);
383 | } else if (strcmp(interface, wl_seat_interface.name) == 0) {
384 | state->seat = wl_registry_bind(wl_registry,
385 | name, &wl_seat_interface, 5);
386 | } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) {
387 | state->output_mgr = wl_registry_bind(wl_registry,
388 | name, &zxdg_output_manager_v1_interface, 1);
389 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
390 | state->layer_shell = wl_registry_bind(wl_registry,
391 | name, &zwlr_layer_shell_v1_interface, 1);
392 | } else if (strcmp(interface, wl_output_interface.name) == 0) {
393 | struct wsk_output *output = calloc(1, sizeof(struct wsk_output));
394 | output->output = wl_registry_bind(wl_registry,
395 | name, &wl_output_interface, 3);
396 | output->scale = 1;
397 | struct wsk_output **link = &state->outputs;
398 | while (*link) {
399 | link = &(*link)->next;
400 | }
401 | *link = output;
402 | wl_output_add_listener(output->output, &wl_output_listener, output);
403 | }
404 | }
405 |
406 | static void registry_global_remove(void *data,
407 | struct wl_registry *wl_registry, uint32_t name) {
408 | /* This space deliberately left blank */
409 | }
410 |
411 | static const struct wl_registry_listener registry_listener = {
412 | .global = registry_global,
413 | .global_remove = registry_global_remove,
414 | };
415 |
416 | static void handle_libinput_event(struct wsk_state *state,
417 | struct libinput_event *event) {
418 | if (!state->xkb_state) {
419 | return;
420 | }
421 |
422 | enum libinput_event_type event_type = libinput_event_get_type(event);
423 | if (event_type != LIBINPUT_EVENT_KEYBOARD_KEY) {
424 | return;
425 | }
426 |
427 | struct libinput_event_keyboard *kbevent =
428 | libinput_event_get_keyboard_event(event);
429 |
430 | uint32_t keycode = libinput_event_keyboard_get_key(kbevent) + 8;
431 | enum libinput_key_state key_state =
432 | libinput_event_keyboard_get_key_state(kbevent);
433 | xkb_state_update_key(state->xkb_state, keycode,
434 | key_state == LIBINPUT_KEY_STATE_RELEASED ?
435 | XKB_KEY_UP : XKB_KEY_DOWN);
436 |
437 | xkb_keysym_t keysym = xkb_state_key_get_one_sym(state->xkb_state, keycode);
438 |
439 | struct wsk_keypress *keypress;
440 | switch (key_state) {
441 | case LIBINPUT_KEY_STATE_RELEASED:
442 | /* Who cares */
443 | break;
444 | case LIBINPUT_KEY_STATE_PRESSED:
445 | keypress = calloc(1, sizeof(struct wsk_keypress));
446 | assert(keypress);
447 | keypress->sym = keysym;
448 | xkb_keysym_get_name(keypress->sym, keypress->name,
449 | sizeof(keypress->name));
450 | if (xkb_state_key_get_utf8(state->xkb_state, keycode,
451 | keypress->utf8, sizeof(keypress->utf8)) <= 0 ||
452 | keypress->utf8[0] <= ' ') {
453 | keypress->utf8[0] = '\0';
454 | }
455 |
456 | struct wsk_keypress **link = &state->keys;
457 | while (*link) {
458 | link = &(*link)->next;
459 | }
460 | *link = keypress;
461 | break;
462 | }
463 |
464 | clock_gettime(CLOCK_MONOTONIC, &state->last_key);
465 | set_dirty(state);
466 | }
467 |
468 | static int libinput_open_restricted(const char *path,
469 | int flags, void *data) {
470 | int *fd = data;
471 | return devmgr_open(*fd, path);
472 | }
473 |
474 | static void libinput_close_restricted(int fd, void *data) {
475 | close(fd);
476 | }
477 |
478 | static const struct libinput_interface libinput_impl = {
479 | .open_restricted = libinput_open_restricted,
480 | .close_restricted = libinput_close_restricted,
481 | };
482 |
483 | static uint32_t parse_color(const char *color) {
484 | if (color[0] == '#') {
485 | ++color;
486 | }
487 |
488 | int len = strlen(color);
489 | if (len != 6 && len != 8) {
490 | fprintf(stderr, "Invalid color %s, defaulting to color "
491 | "0xFFFFFFFF\n", color);
492 | return 0xFFFFFFFF;
493 | }
494 | uint32_t res = (uint32_t)strtoul(color, NULL, 16);
495 | if (strlen(color) == 6) {
496 | res = (res << 8) | 0xFF;
497 | }
498 | return res;
499 | }
500 |
501 | int main(int argc, char *argv[]) {
502 | /* NOTICE: This code runs as root */
503 | struct wsk_state state = { 0 };
504 | if (devmgr_start(&state.devmgr, &state.devmgr_pid, INPUTDEVPATH) > 0) {
505 | return 1;
506 | }
507 |
508 | /* Begin normal user code: */
509 | int ret = 0;
510 |
511 | unsigned int anchor = 0;
512 | int margin = 32;
513 | state.background = 0x000000CC;
514 | state.specialfg = 0xAAAAAAFF;
515 | state.foreground = 0xFFFFFFFF;
516 | state.font = "monospace 24";
517 | state.timeout = 1;
518 |
519 | int c;
520 | while ((c = getopt(argc, argv, "hb:f:s:F:t:a:m:o:")) != -1) {
521 | switch (c) {
522 | case 'b':
523 | state.background = parse_color(optarg);
524 | break;
525 | case 'f':
526 | state.foreground = parse_color(optarg);
527 | break;
528 | case 's':
529 | state.specialfg = parse_color(optarg);
530 | break;
531 | case 'F':
532 | state.font = optarg;
533 | break;
534 | case 't':
535 | state.timeout = atoi(optarg);
536 | break;
537 | case 'a':
538 | if (strcmp(optarg, "top") == 0) {
539 | anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
540 | } else if (strcmp(optarg, "left") == 0) {
541 | anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
542 | } else if (strcmp(optarg, "right") == 0) {
543 | anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
544 | } else if (strcmp(optarg, "bottom") == 0) {
545 | anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
546 | }
547 | break;
548 | case 'm':
549 | margin = atoi(optarg);
550 | break;
551 | case 'o':
552 | fprintf(stderr, "-o is unimplemented\n");
553 | return 0;
554 | default:
555 | fprintf(stderr, "usage: wshowkeys [-b|-f|-s #RRGGBB[AA]] [-F font] "
556 | "[-t timeout]\n\t[-a top|left|right|bottom] [-m margin] "
557 | "[-o output]\n");
558 | return 1;
559 | }
560 | }
561 |
562 | state.udev = udev_new();
563 | if (!state.udev) {
564 | fprintf(stderr, "udev_create: %s\n", strerror(errno));
565 | ret = 1;
566 | goto exit;
567 | }
568 |
569 | state.libinput = libinput_udev_create_context(
570 | &libinput_impl, &state.devmgr, state.udev);
571 | udev_unref(state.udev);
572 | if (!state.libinput) {
573 | fprintf(stderr, "libinput_udev_create_context: %s\n", strerror(errno));
574 | ret = 1;
575 | goto exit;
576 | }
577 |
578 | state.xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
579 | if (!state.xkb_context) {
580 | fprintf(stderr, "xkb_context_new: %s\n", strerror(errno));
581 | ret = 1;
582 | goto exit;
583 | }
584 |
585 | state.display = wl_display_connect(NULL);
586 | if (!state.display) {
587 | fprintf(stderr, "wl_display_connect: %s\n", strerror(errno));
588 | ret = 1;
589 | goto exit;
590 | }
591 |
592 | state.registry = wl_display_get_registry(state.display);
593 | assert(state.registry);
594 | wl_registry_add_listener(state.registry, ®istry_listener, &state);
595 | wl_display_roundtrip(state.display);
596 |
597 | struct {
598 | const char *name;
599 | void *ptr;
600 | } need_globals[] = {
601 | "wl_compositor", &state.compositor,
602 | "wl_shm", &state.shm,
603 | "wl_seat", &state.seat,
604 | "wlr_layer_shell", &state.layer_shell,
605 | };
606 | for (size_t i = 0; i < sizeof(need_globals) / sizeof(need_globals[0]); ++i) {
607 | if (!need_globals[i].ptr) {
608 | fprintf(stderr, "Error: required Wayland interface '%s' "
609 | "is not present\n", need_globals[i].name);
610 | ret = 1;
611 | goto exit;
612 | }
613 | }
614 |
615 | // TODO: Listener for xdg output
616 |
617 | wl_seat_add_listener(state.seat, &wl_seat_listener, &state);
618 | wl_display_roundtrip(state.display);
619 |
620 | state.surface = wl_compositor_create_surface(state.compositor);
621 | assert(state.surface);
622 | wl_surface_add_listener(state.surface, &wl_surface_listener, &state);
623 |
624 | state.layer_surface = zwlr_layer_shell_v1_get_layer_surface(
625 | state.layer_shell, state.surface, NULL,
626 | ZWLR_LAYER_SHELL_V1_LAYER_TOP, "showkeys");
627 | assert(state.layer_surface);
628 | zwlr_layer_surface_v1_add_listener(
629 | state.layer_surface, &layer_surface_listener, &state);
630 | zwlr_layer_surface_v1_set_size(state.layer_surface, 1, 1);
631 | zwlr_layer_surface_v1_set_anchor(state.layer_surface, anchor);
632 | zwlr_layer_surface_v1_set_margin(state.layer_surface,
633 | margin, margin, margin, margin);
634 | zwlr_layer_surface_v1_set_exclusive_zone(state.layer_surface, -1);
635 | wl_surface_commit(state.surface);
636 |
637 | struct pollfd pollfds[] = {
638 | { .fd = libinput_get_fd(state.libinput), .events = POLLIN, },
639 | { .fd = wl_display_get_fd(state.display), .events = POLLIN, },
640 | };
641 |
642 | state.run = true;
643 | while (state.run) {
644 | errno = 0;
645 | do {
646 | if (wl_display_flush(state.display) == -1 && errno != EAGAIN) {
647 | fprintf(stderr, "wl_display_flush: %s\n", strerror(errno));
648 | break;
649 | }
650 | } while (errno == EAGAIN);
651 |
652 | int timeout = -1;
653 | if (state.keys) {
654 | timeout = 100;
655 | }
656 |
657 | if (poll(pollfds, sizeof(pollfds) / sizeof(pollfds[0]), timeout) < 0) {
658 | fprintf(stderr, "poll: %s\n", strerror(errno));
659 | break;
660 | }
661 |
662 | /* Clear out old keys */
663 | struct timespec now;
664 | clock_gettime(CLOCK_MONOTONIC, &now);
665 | if (now.tv_sec >= state.last_key.tv_sec + state.timeout &&
666 | now.tv_nsec >= state.last_key.tv_nsec) {
667 | struct wsk_keypress *key = state.keys;
668 | while (key) {
669 | struct wsk_keypress *next = key->next;
670 | free(key);
671 | key = next;
672 | }
673 | state.keys = NULL;
674 | set_dirty(&state);
675 | }
676 |
677 | if ((pollfds[0].revents & POLLIN)) {
678 | if (libinput_dispatch(state.libinput) != 0) {
679 | fprintf(stderr, "libinput_dispatch: %s\n", strerror(errno));
680 | break;
681 | }
682 | struct libinput_event *event;
683 | while ((event = libinput_get_event(state.libinput))) {
684 | handle_libinput_event(&state, event);
685 | libinput_event_destroy(event);
686 | }
687 | }
688 |
689 | if ((pollfds[1].revents & POLLIN)
690 | && wl_display_dispatch(state.display) == -1) {
691 | fprintf(stderr, "wl_display_dispatch: %s\n", strerror(errno));
692 | break;
693 | }
694 | }
695 |
696 | exit:
697 | wl_display_disconnect(state.display);
698 | libinput_unref(state.libinput);
699 | devmgr_finish(state.devmgr, state.devmgr_pid);
700 | return ret;
701 | }
702 |
--------------------------------------------------------------------------------
/meson.build:
--------------------------------------------------------------------------------
1 | project(
2 | 'wshowkeys',
3 | 'c',
4 | version: '0.1.0',
5 | license: 'GPL',
6 | meson_version: '>=0.48.0',
7 | default_options: [
8 | 'c_std=c11',
9 | 'warning_level=2',
10 | 'werror=true',
11 | ],
12 | )
13 |
14 | cc = meson.get_compiler('c')
15 |
16 | add_project_arguments(cc.get_supported_arguments([
17 | '-D_POSIX_C_SOURCE=200809L',
18 |
19 | '-Wundef',
20 | '-Wlogical-op',
21 | '-Wmissing-include-dirs',
22 | '-Wold-style-definition',
23 | '-Wpointer-arith',
24 | '-Winit-self',
25 | '-Wstrict-prototypes',
26 | '-Wimplicit-fallthrough=2',
27 | '-Wendif-labels',
28 | '-Wstrict-aliasing=2',
29 | '-Woverflow',
30 |
31 | '-Wno-missing-braces',
32 | '-Wno-missing-field-initializers',
33 | '-Wno-unused-parameter',
34 | ]), language: 'c')
35 |
36 | add_project_arguments([
37 | '-DINPUTDEVPATH="@0@"'.format(get_option('devpath')),
38 | ], language: 'c')
39 |
40 | cairo = dependency('cairo')
41 | libinput = dependency('libinput')
42 | pango = dependency('pango')
43 | pangocairo = dependency('pangocairo')
44 | udev = dependency('libudev')
45 | wayland_client = dependency('wayland-client')
46 | wayland_protos = dependency('wayland-protocols')
47 | xkbcommon = dependency('xkbcommon')
48 |
49 | rt = cc.find_library('rt')
50 |
51 | subdir('protocols')
52 |
53 | executable(
54 | 'wshowkeys',
55 | files(
56 | 'devmgr.c',
57 | 'main.c',
58 | 'pango.c',
59 | 'shm.c',
60 | ),
61 | dependencies: [
62 | cairo,
63 | client_protos,
64 | libinput,
65 | pango,
66 | pangocairo,
67 | rt,
68 | udev,
69 | wayland_client,
70 | wayland_protos,
71 | xkbcommon,
72 | ],
73 | install: true,
74 | )
75 |
--------------------------------------------------------------------------------
/meson_options.txt:
--------------------------------------------------------------------------------
1 | option('devpath',
2 | type: 'string',
3 | value: '/dev/input/',
4 | description: 'Platform-specific path to input device files. This must be as specific as possible for security reasons.')
5 |
--------------------------------------------------------------------------------
/pango.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include "cairo.h"
10 |
11 | PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
12 | const char *text, double scale) {
13 | PangoLayout *layout = pango_cairo_create_layout(cairo);
14 | PangoAttrList *attrs = pango_attr_list_new();
15 | pango_layout_set_text(layout, text, -1);
16 | pango_attr_list_insert(attrs, pango_attr_scale_new(scale));
17 | PangoFontDescription *desc = pango_font_description_from_string(font);
18 | pango_layout_set_font_description(layout, desc);
19 | pango_layout_set_single_paragraph_mode(layout, 1);
20 | pango_layout_set_attributes(layout, attrs);
21 | pango_attr_list_unref(attrs);
22 | pango_font_description_free(desc);
23 | return layout;
24 | }
25 |
26 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
27 | int *baseline, double scale, const char *fmt, ...) {
28 | va_list args;
29 | va_start(args, fmt);
30 | // Add one since vsnprintf excludes null terminator.
31 | int length = vsnprintf(NULL, 0, fmt, args) + 1;
32 | va_end(args);
33 |
34 | char *buf = malloc(length);
35 | if (buf == NULL) {
36 | return;
37 | }
38 | va_start(args, fmt);
39 | vsnprintf(buf, length, fmt, args);
40 | va_end(args);
41 |
42 | PangoLayout *layout = get_pango_layout(cairo, font, buf, scale);
43 | pango_cairo_update_layout(cairo, layout);
44 | pango_layout_get_pixel_size(layout, width, height);
45 | if (baseline) {
46 | *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE;
47 | }
48 | g_object_unref(layout);
49 | free(buf);
50 | }
51 |
52 | void pango_printf(cairo_t *cairo, const char *font, double scale,
53 | const char *fmt, ...) {
54 | va_list args;
55 | va_start(args, fmt);
56 | // Add one since vsnprintf excludes null terminator.
57 | int length = vsnprintf(NULL, 0, fmt, args) + 1;
58 | va_end(args);
59 |
60 | char *buf = malloc(length);
61 | if (buf == NULL) {
62 | return;
63 | }
64 | va_start(args, fmt);
65 | vsnprintf(buf, length, fmt, args);
66 | va_end(args);
67 |
68 | PangoLayout *layout = get_pango_layout(cairo, font, buf, scale);
69 | cairo_font_options_t *fo = cairo_font_options_create();
70 | cairo_get_font_options(cairo, fo);
71 | pango_cairo_context_set_font_options(pango_layout_get_context(layout), fo);
72 | cairo_font_options_destroy(fo);
73 | pango_cairo_update_layout(cairo, layout);
74 | pango_cairo_show_layout(cairo, layout);
75 | g_object_unref(layout);
76 | free(buf);
77 | }
78 |
--------------------------------------------------------------------------------
/pango.h:
--------------------------------------------------------------------------------
1 | #ifndef _WSK_PANGO_H
2 | #define _WSK_PANGO_H
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
10 | const char *text, double scale);
11 | void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
12 | int *baseline, double scale, const char *fmt, ...);
13 | void pango_printf(cairo_t *cairo, const char *font,
14 | double scale, const char *fmt, ...);
15 |
16 | #endif
17 |
--------------------------------------------------------------------------------
/protocols/meson.build:
--------------------------------------------------------------------------------
1 | wl_protocol_dir = wayland_protos.get_pkgconfig_variable('pkgdatadir')
2 |
3 | wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)
4 | if wayland_scanner_dep.found()
5 | wayland_scanner = find_program(
6 | wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'),
7 | native: true,
8 | )
9 | else
10 | wayland_scanner = find_program('wayland-scanner', native: true)
11 | endif
12 |
13 | protocols = [
14 | [wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'],
15 | [wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
16 | ['wlr-layer-shell-unstable-v1.xml'],
17 | ]
18 |
19 | wl_protos_src = []
20 | wl_protos_headers = []
21 |
22 | foreach p : protocols
23 | xml = join_paths(p)
24 | wl_protos_src += custom_target(
25 | xml.underscorify() + '_protocol_c',
26 | input: xml,
27 | output: '@BASENAME@-protocol.c',
28 | command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'],
29 | )
30 | wl_protos_headers += custom_target(
31 | xml.underscorify() + '_client_h',
32 | input: xml,
33 | output: '@BASENAME@-client-protocol.h',
34 | command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'],
35 | )
36 | endforeach
37 |
38 | lib_client_protos = static_library(
39 | 'client_protos',
40 | wl_protos_src + wl_protos_headers,
41 | dependencies: wayland_client.partial_dependency(compile_args: true),
42 | )
43 |
44 | client_protos = declare_dependency(
45 | link_with: lib_client_protos,
46 | sources: wl_protos_headers,
47 | )
48 |
--------------------------------------------------------------------------------
/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 | You may pass NULL for output to allow the compositor to decide which
51 | output to use. Generally this will be the one that the user most
52 | recently interacted with.
53 |
54 | Clients can specify a namespace that defines the purpose of the layer
55 | surface.
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | These values indicate which layers a surface can be rendered in. They
73 | are ordered by z depth, bottom-most first. Traditional shell surfaces
74 | will typically be rendered between the bottom and top layers.
75 | Fullscreen shell surfaces are typically rendered at the top layer.
76 | Multiple surfaces can share a single layer, and ordering within a
77 | single layer is undefined.
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | An interface that may be implemented by a wl_surface, for surfaces that
90 | are designed to be rendered as a layer of a stacked desktop-like
91 | environment.
92 |
93 | Layer surface state (size, anchor, exclusive zone, margin, interactivity)
94 | is double-buffered, and will be applied at the time wl_surface.commit of
95 | the corresponding wl_surface is called.
96 |
97 |
98 |
99 |
100 | Sets the size of the surface in surface-local coordinates. The
101 | compositor will display the surface centered with respect to its
102 | anchors.
103 |
104 | If you pass 0 for either value, the compositor will assign it and
105 | inform you of the assignment in the configure event. You must set your
106 | anchor to opposite edges in the dimensions you omit; not doing so is a
107 | protocol error. Both values are 0 by default.
108 |
109 | Size is double-buffered, see wl_surface.commit.
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 | Requests that the compositor anchor the surface to the specified edges
118 | and corners. If two orthogonal edges are specified (e.g. 'top' and
119 | 'left'), then the anchor point will be the intersection of the edges
120 | (e.g. the top left corner of the output); otherwise the anchor point
121 | will be centered on that edge, or in the center if none is specified.
122 |
123 | Anchor is double-buffered, see wl_surface.commit.
124 |
125 |
126 |
127 |
128 |
129 |
130 | Requests that the compositor avoids occluding an area of the surface
131 | with other surfaces. The compositor's use of this information is
132 | implementation-dependent - do not assume that this region will not
133 | actually be occluded.
134 |
135 | A positive value is only meaningful if the surface is anchored to an
136 | edge, rather than a corner. The zone is the number of surface-local
137 | coordinates from the edge that is considered exclusive.
138 |
139 | Surfaces that do not wish to have an exclusive zone may instead specify
140 | how they should interact with surfaces that do. If set to zero, the
141 | surface indicates that it would like to be moved to avoid occluding
142 | surfaces with a positive exclusive zone. If set to -1, the surface
143 | indicates that it would not like to be moved to accommodate for other
144 | surfaces, and the compositor should extend it all the way to the edges
145 | it is anchored to.
146 |
147 | For example, a panel might set its exclusive zone to 10, so that
148 | maximized shell surfaces are not shown on top of it. A notification
149 | might set its exclusive zone to 0, so that it is moved to avoid
150 | occluding the panel, but shell surfaces are shown underneath it. A
151 | wallpaper or lock screen might set their exclusive zone to -1, so that
152 | they stretch below or over the panel.
153 |
154 | The default value is 0.
155 |
156 | Exclusive zone is double-buffered, see wl_surface.commit.
157 |
158 |
159 |
160 |
161 |
162 |
163 | Requests that the surface be placed some distance away from the anchor
164 | point on the output, in surface-local coordinates. Setting this value
165 | for edges you are not anchored to has no effect.
166 |
167 | The exclusive zone includes the margin.
168 |
169 | Margin is double-buffered, see wl_surface.commit.
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 | Set to 1 to request that the seat send keyboard events to this layer
180 | surface. For layers below the shell surface layer, the seat will use
181 | normal focus semantics. For layers above the shell surface layers, the
182 | seat will always give exclusive keyboard focus to the top-most layer
183 | which has keyboard interactivity set to true.
184 |
185 | Layer surfaces receive pointer, touch, and tablet events normally. If
186 | you do not want to receive them, set the input region on your surface
187 | to an empty region.
188 |
189 | Events is double-buffered, see wl_surface.commit.
190 |
191 |
192 |
193 |
194 |
195 |
196 | This assigns an xdg_popup's parent to this layer_surface. This popup
197 | should have been created via xdg_surface::get_popup with the parent set
198 | to NULL, and this request must be invoked before committing the popup's
199 | initial state.
200 |
201 | See the documentation of xdg_popup for more details about what an
202 | xdg_popup is and how it is used.
203 |
204 |
205 |
206 |
207 |
208 |
209 | When a configure event is received, if a client commits the
210 | surface in response to the configure event, then the client
211 | must make an ack_configure request sometime before the commit
212 | request, passing along the serial of the configure event.
213 |
214 | If the client receives multiple configure events before it
215 | can respond to one, it only has to ack the last configure event.
216 |
217 | A client is not required to commit immediately after sending
218 | an ack_configure request - it may even ack_configure several times
219 | before its next surface commit.
220 |
221 | A client may send multiple ack_configure requests before committing, but
222 | only the last request sent before a commit indicates which configure
223 | event the client really is responding to.
224 |
225 |
226 |
227 |
228 |
229 |
230 | This request destroys the layer surface.
231 |
232 |
233 |
234 |
235 |
236 | The configure event asks the client to resize its surface.
237 |
238 | Clients should arrange their surface for the new states, and then send
239 | an ack_configure request with the serial sent in this configure event at
240 | some point before committing the new surface.
241 |
242 | The client is free to dismiss all but the last configure event it
243 | received.
244 |
245 | The width and height arguments specify the size of the window in
246 | surface-local coordinates.
247 |
248 | The size is a hint, in the sense that the client is free to ignore it if
249 | it doesn't resize, pick a smaller size (to satisfy aspect ratio or
250 | resize in steps of NxM pixels). If the client picks a smaller size and
251 | is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the
252 | surface will be centered on this axis.
253 |
254 | If the width or height arguments are zero, it means the client should
255 | decide its own window dimension.
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 | The closed event is sent by the compositor when the surface will no
265 | longer be shown. The output may have been destroyed or the user may
266 | have asked for it to be removed. Further changes to the surface will be
267 | ignored. The client should destroy the resource after receiving this
268 | event, and create a new surface if they so choose.
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
--------------------------------------------------------------------------------
/shm.c:
--------------------------------------------------------------------------------
1 | /* Portions of this file taken from sway, MIT licensed */
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include "shm.h"
14 |
15 | static void randname(char *buf) {
16 | struct timespec ts;
17 | clock_gettime(CLOCK_REALTIME, &ts);
18 | long r = ts.tv_nsec;
19 | for (int i = 0; i < 6; ++i) {
20 | buf[i] = 'A'+(r&15)+(r&16)*2;
21 | r >>= 5;
22 | }
23 | }
24 |
25 | int create_shm_file(void) {
26 | int retries = 100;
27 | do {
28 | char name[] = "/wl_shm-XXXXXX";
29 | randname(name + strlen(name) - 6);
30 |
31 | --retries;
32 | // CLOEXEC is guaranteed to be set by shm_open
33 | int fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
34 | if (fd >= 0) {
35 | shm_unlink(name);
36 | return fd;
37 | }
38 | } while (retries > 0 && errno == EEXIST);
39 |
40 | return -1;
41 | }
42 |
43 | int allocate_shm_file(size_t size) {
44 | int fd = create_shm_file();
45 | if (fd < 0) {
46 | return -1;
47 | }
48 |
49 | int ret;
50 | do {
51 | ret = ftruncate(fd, size);
52 | } while (ret < 0 && errno == EINTR);
53 | if (ret < 0) {
54 | close(fd);
55 | return -1;
56 | }
57 |
58 | return fd;
59 | }
60 |
61 | static void buffer_release(void *data, struct wl_buffer *wl_buffer) {
62 | struct pool_buffer *buffer = data;
63 | buffer->busy = false;
64 | }
65 |
66 | static const struct wl_buffer_listener buffer_listener = {
67 | .release = buffer_release
68 | };
69 |
70 | static struct pool_buffer *create_buffer(struct wl_shm *shm,
71 | struct pool_buffer *buf, int32_t width, int32_t height,
72 | uint32_t format) {
73 | uint32_t stride = width * 4;
74 | size_t size = stride * height;
75 |
76 | int fd = allocate_shm_file(size);
77 | assert(fd != -1);
78 | void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
79 | struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, size);
80 | buf->buffer = wl_shm_pool_create_buffer(pool, 0,
81 | width, height, stride, format);
82 | wl_shm_pool_destroy(pool);
83 | close(fd);
84 |
85 | buf->size = size;
86 | buf->width = width;
87 | buf->height = height;
88 | buf->data = data;
89 | buf->surface = cairo_image_surface_create_for_data(data,
90 | CAIRO_FORMAT_ARGB32, width, height, stride);
91 | buf->cairo = cairo_create(buf->surface);
92 | buf->pango = pango_cairo_create_context(buf->cairo);
93 |
94 | wl_buffer_add_listener(buf->buffer, &buffer_listener, buf);
95 | return buf;
96 | }
97 |
98 | void destroy_buffer(struct pool_buffer *buffer) {
99 | if (buffer->buffer) {
100 | wl_buffer_destroy(buffer->buffer);
101 | }
102 | if (buffer->cairo) {
103 | cairo_destroy(buffer->cairo);
104 | }
105 | if (buffer->surface) {
106 | cairo_surface_destroy(buffer->surface);
107 | }
108 | if (buffer->pango) {
109 | g_object_unref(buffer->pango);
110 | }
111 | if (buffer->data) {
112 | munmap(buffer->data, buffer->size);
113 | }
114 | memset(buffer, 0, sizeof(struct pool_buffer));
115 | }
116 |
117 | struct pool_buffer *get_next_buffer(struct wl_shm *shm,
118 | struct pool_buffer pool[static 2], uint32_t width, uint32_t height) {
119 | struct pool_buffer *buffer = NULL;
120 |
121 | for (size_t i = 0; i < 2; ++i) {
122 | if (pool[i].busy) {
123 | continue;
124 | }
125 | buffer = &pool[i];
126 | }
127 |
128 | if (!buffer) {
129 | return NULL;
130 | }
131 |
132 | if (buffer->width != width || buffer->height != height) {
133 | destroy_buffer(buffer);
134 | }
135 |
136 | if (!buffer->buffer) {
137 | if (!create_buffer(shm, buffer, width, height,
138 | WL_SHM_FORMAT_ARGB8888)) {
139 | return NULL;
140 | }
141 | }
142 | buffer->busy = true;
143 | return buffer;
144 | }
145 |
--------------------------------------------------------------------------------
/shm.h:
--------------------------------------------------------------------------------
1 | #ifndef SHM_H
2 | #define SHM_H
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | int create_shm_file(void);
10 | int allocate_shm_file(size_t size);
11 |
12 | struct pool_buffer {
13 | struct wl_buffer *buffer;
14 | cairo_surface_t *surface;
15 | cairo_t *cairo;
16 | PangoContext *pango;
17 | uint32_t width, height;
18 | void *data;
19 | size_t size;
20 | bool busy;
21 | };
22 |
23 | struct pool_buffer *get_next_buffer(struct wl_shm *shm,
24 | struct pool_buffer pool[static 2], uint32_t width, uint32_t height);
25 | void destroy_buffer(struct pool_buffer *buffer);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------