├── .gitignore ├── .gitmodules ├── .mailmap ├── COPYING ├── README.md ├── autogen.sh ├── compositor ├── meson.build └── src │ ├── commands.c │ ├── commands.h │ ├── config.c │ ├── config_.h │ ├── containers.c │ ├── containers.h │ ├── outputs.c │ ├── outputs.h │ ├── seats.c │ ├── seats.h │ ├── types.h │ ├── wayhouse.c │ ├── wayhouse.h │ ├── xwayland.c │ └── xwayland.h ├── dock ├── meson.build └── src │ └── dock.c ├── libwhclient ├── include │ └── client.h ├── meson.build └── src │ └── client.c ├── meson.build └── meson_options.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /src/config.h.in 2 | /src/config.h 3 | 4 | /wayhouse 5 | /wh-dock 6 | 7 | *-server-protocol.h 8 | *-client-protocol.h 9 | *-protocol.c 10 | 11 | /local-rules.mk 12 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libgwater"] 2 | path = subprojects/libgwater 3 | url = git://github.com/sardemff7/libgwater 4 | [submodule "libnkutils"] 5 | path = subprojects/libnkutils 6 | url = git://github.com/sardemff7/libnkutils 7 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Morgane Glidic 2 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 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 | WayHouse 2 | ======== 3 | 4 | WayHouse is a small Wayland tiling compositor based on libweston. 5 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | mkdir -p m4 4 | autoreconf --install --force 5 | -------------------------------------------------------------------------------- /compositor/meson.build: -------------------------------------------------------------------------------- 1 | executable('wayhouse', files( 2 | 'src/wayhouse.c', 3 | 'src/types.h', 4 | 'src/config_.h', 5 | 'src/config.c', 6 | 'src/commands.h', 7 | 'src/commands.c', 8 | 'src/seats.h', 9 | 'src/seats.c', 10 | 'src/outputs.h', 11 | 'src/outputs.c', 12 | 'src/containers.h', 13 | 'src/containers.c', 14 | 'src/xwayland.h', 15 | 'src/xwayland.c', 16 | ), 17 | c_args: [ 18 | '-DG_LOG_DOMAIN="wayhouse"' 19 | ], 20 | dependencies: [ libweston_desktop, libweston, xkbcommon, libinput, libgwater_wayland_server, wayland_server, libnkutils, gmodule, gobject, glib ], 21 | install: true, 22 | ) 23 | -------------------------------------------------------------------------------- /compositor/src/commands.c: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #include "config.h" 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "types.h" 40 | #include "wayhouse.h" 41 | #include "outputs.h" 42 | #include "containers.h" 43 | #include "commands.h" 44 | 45 | struct _WhCommands { 46 | WhCore *core; 47 | GScanner *scanner; 48 | }; 49 | 50 | typedef enum { 51 | WH_COMMAND_SCOPE_ROOT = 0, 52 | WH_COMMAND_SCOPE_DIRECTION, 53 | WH_COMMAND_SCOPE_DIRECTION_CROSS, 54 | WH_COMMAND_SCOPE_TARGET, 55 | WH_COMMAND_SCOPE_LAYOUT, 56 | WH_COMMAND_SCOPE_ORIENTATION, 57 | WH_COMMAND_SCOPE_STATE_CHANGE, 58 | } WhCommandScope; 59 | 60 | typedef enum { 61 | WH_COMMAND_QUIT, 62 | WH_COMMAND_CLOSE, 63 | WH_COMMAND_FOCUS, 64 | WH_COMMAND_MOVE, 65 | WH_COMMAND_FULLSCREEN, 66 | WH_COMMAND_LAYOUT, 67 | WH_COMMAND_OUTPUT, 68 | } WhCommandCommandSymbol; 69 | 70 | 71 | static const gchar * const _wh_commands_symbols[] = { 72 | [WH_COMMAND_QUIT] = "quit", 73 | [WH_COMMAND_CLOSE] = "close", 74 | [WH_COMMAND_FOCUS] = "focus", 75 | [WH_COMMAND_MOVE] = "move", 76 | [WH_COMMAND_FULLSCREEN] = "fullscreen", 77 | [WH_COMMAND_LAYOUT] = "layout", 78 | [WH_COMMAND_OUTPUT] = "output", 79 | }; 80 | 81 | #define WH_DIRECTION_WORKSPACE (WH_DIRECTION_CHILD+1) 82 | #define WH_DIRECTION_OUTPUT (WH_DIRECTION_CHILD+2) 83 | static const gchar * const _wh_commands_directions[] = { 84 | [WH_DIRECTION_LEFT] = "left", 85 | [WH_DIRECTION_RIGHT] = "right", 86 | [WH_DIRECTION_TOP] = "top", 87 | [WH_DIRECTION_BOTTOM] = "bottom", 88 | [WH_DIRECTION_PARENT] = "parent", 89 | [WH_DIRECTION_CHILD] = "child", 90 | [WH_DIRECTION_WORKSPACE] = "workspace", 91 | [WH_DIRECTION_OUTPUT] = "output", 92 | }; 93 | 94 | static const gchar * const _wh_commands_cross_directions[] = { 95 | [WH_DIRECTION_LEFT] = "left", 96 | [WH_DIRECTION_RIGHT] = "right", 97 | [WH_DIRECTION_TOP] = "top", 98 | [WH_DIRECTION_BOTTOM] = "bottom", 99 | }; 100 | 101 | static const gchar * const _wh_commands_targets[] = { 102 | [WH_TARGET_NEXT] = "next", 103 | [WH_TARGET_PREVIOUS] = "previous", 104 | [WH_TARGET_BACK_AND_FORTH] = "back-and-forth", 105 | }; 106 | 107 | static const gchar * const _wh_commands_layout_types[] = { 108 | [WH_CONTAINER_LAYOUT_TABBED] = "tabbed", 109 | [WH_CONTAINER_LAYOUT_SPLIT] = "split", 110 | }; 111 | static const gchar * const _wh_commands_layout_orientations[] = { 112 | [WH_ORIENTATION_HORIZONTAL] = "horizontal", 113 | [WH_ORIENTATION_VERTICAL] = "vertical", 114 | [WH_ORIENTATION_TOGGLE] = "toggle", 115 | }; 116 | 117 | static const gchar * const _wh_commands_state_changes[] = { 118 | [WH_STATE_ENABLE] = "enable", 119 | [WH_STATE_DISABLE] = "disable", 120 | [WH_STATE_TOGGLE] = "toggle", 121 | }; 122 | 123 | typedef enum { 124 | WH_COMMAND_TARGET_TYPE_ERROR, 125 | WH_COMMAND_TARGET_TYPE_DIRECTION, 126 | WH_COMMAND_TARGET_TYPE_WORKSPACE_DIRECTION, 127 | WH_COMMAND_TARGET_TYPE_WORKSPACE_NAME, 128 | WH_COMMAND_TARGET_TYPE_WORKSPACE_NUMBER, 129 | WH_COMMAND_TARGET_TYPE_OUTPUT_DIRECTION, 130 | WH_COMMAND_TARGET_TYPE_OUTPUT_NAME, 131 | } WhCommandTargetType; 132 | 133 | typedef gpointer (*WhCoreGetter)(WhCore *core); 134 | #define WH_CORE_GETTER(func) ((WhCoreGetter) (func)) 135 | 136 | struct _WhCommand { 137 | WhCommands *commands; 138 | gchar *string; 139 | WhCoreGetter getter; 140 | GClosure *closure; 141 | guint n_params; 142 | GValue params[4]; 143 | }; 144 | 145 | static WhCommandTargetType 146 | _wh_command_parse_target(GScanner *scanner, WhCommand *self) 147 | { 148 | g_scanner_set_scope(scanner, WH_COMMAND_SCOPE_DIRECTION); 149 | if ( g_scanner_get_next_token(scanner) != G_TOKEN_SYMBOL ) 150 | return WH_COMMAND_TARGET_TYPE_ERROR; 151 | 152 | switch ( scanner->value.v_int64 ) 153 | { 154 | case WH_DIRECTION_WORKSPACE: 155 | g_scanner_set_scope(scanner, WH_COMMAND_SCOPE_TARGET); 156 | switch ( g_scanner_get_next_token(scanner) ) 157 | { 158 | case G_TOKEN_SYMBOL: 159 | return WH_COMMAND_TARGET_TYPE_WORKSPACE_DIRECTION; 160 | break; 161 | case G_TOKEN_STRING: 162 | return WH_COMMAND_TARGET_TYPE_WORKSPACE_NAME; 163 | case G_TOKEN_INT: 164 | return WH_COMMAND_TARGET_TYPE_WORKSPACE_NUMBER; 165 | default: 166 | break; 167 | } 168 | break; 169 | case WH_DIRECTION_OUTPUT: 170 | g_scanner_set_scope(scanner, WH_COMMAND_SCOPE_DIRECTION_CROSS); 171 | switch ( g_scanner_get_next_token(scanner) ) 172 | { 173 | case G_TOKEN_SYMBOL: 174 | return WH_COMMAND_TARGET_TYPE_OUTPUT_DIRECTION; 175 | break; 176 | case G_TOKEN_STRING: 177 | return WH_COMMAND_TARGET_TYPE_OUTPUT_NAME; 178 | default: 179 | break; 180 | } 181 | break; 182 | default: 183 | return WH_COMMAND_TARGET_TYPE_DIRECTION; 184 | } 185 | return WH_COMMAND_TARGET_TYPE_ERROR; 186 | } 187 | 188 | static gboolean 189 | _wh_command_parse_layout(GScanner *scanner, WhCommand *self) 190 | { 191 | g_scanner_set_scope(scanner, WH_COMMAND_SCOPE_LAYOUT); 192 | if ( g_scanner_get_next_token(scanner) != G_TOKEN_SYMBOL ) 193 | return FALSE; 194 | 195 | g_value_init(&self->params[self->n_params], G_TYPE_UINT64); 196 | g_value_set_uint64(&self->params[self->n_params], scanner->value.v_int64); 197 | ++self->n_params; 198 | 199 | switch ( g_scanner_peek_next_token(scanner) ) 200 | { 201 | case G_TOKEN_EOF: 202 | scanner->value.v_int64 = WH_ORIENTATION_TOGGLE; 203 | break; 204 | case G_TOKEN_SYMBOL: 205 | g_scanner_get_next_token(scanner); 206 | break; 207 | default: 208 | return FALSE; 209 | } 210 | 211 | return TRUE; 212 | } 213 | 214 | static gboolean 215 | _wh_command_parse_state_change(GScanner *scanner, WhCommand *self) 216 | { 217 | g_scanner_set_scope(scanner, WH_COMMAND_SCOPE_STATE_CHANGE); 218 | return ( g_scanner_get_next_token(scanner) == G_TOKEN_SYMBOL ); 219 | } 220 | 221 | static gboolean 222 | _wh_command_parse_command(GScanner *scanner, WhCommand *self) 223 | { 224 | g_scanner_set_scope(scanner, WH_COMMAND_SCOPE_ROOT); 225 | if ( g_scanner_get_next_token(scanner) != G_TOKEN_SYMBOL ) 226 | return FALSE; 227 | 228 | /* We use int64 here since we pass enum values as symbol values */ 229 | switch ( scanner->value.v_int64 ) 230 | { 231 | case WH_COMMAND_QUIT: 232 | self->closure = g_cclosure_new(G_CALLBACK(wh_stop), NULL, NULL); 233 | return TRUE; 234 | case WH_COMMAND_CLOSE: 235 | self->closure = g_cclosure_new(G_CALLBACK(wh_surface_close), NULL, NULL); 236 | self->getter = WH_CORE_GETTER(wh_core_get_focus); 237 | return TRUE; 238 | case WH_COMMAND_FOCUS: 239 | switch ( _wh_command_parse_target(scanner, self) ) 240 | { 241 | case WH_COMMAND_TARGET_TYPE_ERROR: 242 | return FALSE; 243 | case WH_COMMAND_TARGET_TYPE_DIRECTION: 244 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_focus_container), NULL, NULL); 245 | break; 246 | case WH_COMMAND_TARGET_TYPE_WORKSPACE_DIRECTION: 247 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_focus_workspace), NULL, NULL); 248 | break; 249 | case WH_COMMAND_TARGET_TYPE_WORKSPACE_NAME: 250 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_focus_workspace_name), NULL, NULL); 251 | break; 252 | case WH_COMMAND_TARGET_TYPE_WORKSPACE_NUMBER: 253 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_focus_workspace_number), NULL, NULL); 254 | break; 255 | case WH_COMMAND_TARGET_TYPE_OUTPUT_DIRECTION: 256 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_focus_output), NULL, NULL); 257 | break; 258 | case WH_COMMAND_TARGET_TYPE_OUTPUT_NAME: 259 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_focus_output_name), NULL, NULL); 260 | break; 261 | } 262 | self->getter = WH_CORE_GETTER(wh_core_get_workspaces); 263 | return TRUE; 264 | case WH_COMMAND_MOVE: 265 | switch ( _wh_command_parse_target(scanner, self) ) 266 | { 267 | case WH_COMMAND_TARGET_TYPE_ERROR: 268 | return FALSE; 269 | case WH_COMMAND_TARGET_TYPE_DIRECTION: 270 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_move_container), NULL, NULL); 271 | break; 272 | case WH_COMMAND_TARGET_TYPE_WORKSPACE_DIRECTION: 273 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_move_container_to_workspace), NULL, NULL); 274 | break; 275 | case WH_COMMAND_TARGET_TYPE_WORKSPACE_NAME: 276 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_move_container_to_workspace_name), NULL, NULL); 277 | break; 278 | case WH_COMMAND_TARGET_TYPE_WORKSPACE_NUMBER: 279 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_move_container_to_workspace_number), NULL, NULL); 280 | break; 281 | case WH_COMMAND_TARGET_TYPE_OUTPUT_DIRECTION: 282 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_move_workspace_to_output), NULL, NULL); 283 | break; 284 | case WH_COMMAND_TARGET_TYPE_OUTPUT_NAME: 285 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_move_workspace_to_output_name), NULL, NULL); 286 | break; 287 | } 288 | self->getter = WH_CORE_GETTER(wh_core_get_workspaces); 289 | return TRUE; 290 | case WH_COMMAND_FULLSCREEN: 291 | if ( ! _wh_command_parse_state_change(scanner, self) ) 292 | return FALSE; 293 | self->closure = g_cclosure_new(G_CALLBACK(wh_surface_fullscreen), NULL, NULL); 294 | self->getter = WH_CORE_GETTER(wh_core_get_focus); 295 | return TRUE; 296 | case WH_COMMAND_LAYOUT: 297 | if ( ! _wh_command_parse_layout(scanner, self) ) 298 | return FALSE; 299 | self->getter = WH_CORE_GETTER(wh_core_get_workspaces); 300 | self->closure = g_cclosure_new(G_CALLBACK(wh_workspaces_layout_switch), NULL, NULL); 301 | return TRUE; 302 | case WH_COMMAND_OUTPUT: 303 | if ( ! _wh_command_parse_state_change(scanner, self) ) 304 | return FALSE; 305 | g_value_init(&self->params[self->n_params], G_TYPE_UINT64); 306 | g_value_set_uint64(&self->params[self->n_params], scanner->value.v_int64); 307 | ++self->n_params; 308 | if ( g_scanner_get_next_token(scanner) != G_TOKEN_STRING ) 309 | return FALSE; 310 | self->closure = g_cclosure_new(G_CALLBACK(wh_outputs_control), NULL, NULL); 311 | self->getter = WH_CORE_GETTER(wh_core_get_outputs); 312 | return TRUE; 313 | } 314 | 315 | return FALSE; 316 | } 317 | 318 | WhCommand * 319 | wh_command_parse(WhCommands *commands, gchar *string) 320 | { 321 | GScanner *scanner = commands->scanner; 322 | WhCommand *self; 323 | 324 | self = g_slice_new0(WhCommand); 325 | self->commands = commands; 326 | self->string = string; 327 | 328 | g_scanner_input_text(scanner, string, strlen(string)); 329 | self->n_params = 2; 330 | g_value_init(&self->params[0], G_TYPE_POINTER); 331 | g_value_init(&self->params[1], G_TYPE_POINTER); 332 | 333 | if ( ! _wh_command_parse_command(scanner, self) ) 334 | { 335 | wh_command_free(self); 336 | return NULL; 337 | } 338 | 339 | switch ( scanner->token ) 340 | { 341 | case G_TOKEN_SYMBOL: 342 | case G_TOKEN_INT: 343 | g_value_init(&self->params[self->n_params], G_TYPE_UINT64); 344 | g_value_set_uint64(&self->params[self->n_params], scanner->value.v_int64); 345 | ++self->n_params; 346 | break; 347 | case G_TOKEN_STRING: 348 | g_value_init(&self->params[self->n_params], G_TYPE_STRING); 349 | g_value_set_string(&self->params[self->n_params], scanner->value.v_string); 350 | ++self->n_params; 351 | break; 352 | default: 353 | break; 354 | } 355 | 356 | if ( ( scanner->token != G_TOKEN_EOF ) && ( g_scanner_get_next_token(scanner) != G_TOKEN_EOF ) ) 357 | { 358 | g_warning("Garbage at the end of the command: %s", string + g_scanner_cur_position(scanner)); 359 | wh_command_free(self); 360 | return NULL; 361 | } 362 | 363 | g_closure_set_marshal(self->closure, g_cclosure_marshal_generic); 364 | 365 | return self; 366 | } 367 | 368 | void 369 | wh_command_free(WhCommand *self) 370 | { 371 | guint i; 372 | for ( i = 0 ; i < self->n_params ; ++i ) 373 | g_value_unset(&self->params[i]); 374 | if ( self->closure != NULL ) 375 | g_closure_unref(self->closure); 376 | g_free(self->string); 377 | 378 | g_slice_free(WhCommand, self); 379 | } 380 | 381 | void 382 | wh_command_call(WhCommand *self, WhSeat *seat) 383 | { 384 | gpointer target; 385 | 386 | if ( self->getter != NULL ) 387 | target = self->getter(self->commands->core); 388 | else 389 | target = self->commands->core; 390 | g_value_set_pointer(&self->params[0], target); 391 | g_value_set_pointer(&self->params[1], seat); 392 | g_closure_invoke(self->closure, NULL, self->n_params, self->params, NULL); 393 | } 394 | 395 | const gchar * 396 | wh_command_get_string(WhCommand *self) 397 | { 398 | return self->string; 399 | } 400 | 401 | #define _wh_commands_add_symbols(scanner, scope, list) G_STMT_START { \ 402 | for ( i = 0 ; i < G_N_ELEMENTS(list) ; ++i ) \ 403 | { \ 404 | if ( list[i] != NULL ) \ 405 | g_scanner_scope_add_symbol(scanner, scope, list[i], GUINT_TO_POINTER(i)); \ 406 | } \ 407 | } G_STMT_END 408 | 409 | WhCommands * 410 | wh_commands_new(WhCore *core) 411 | { 412 | WhCommands *self; 413 | 414 | self = g_new0(WhCommands, 1); 415 | self->core = core; 416 | 417 | self->scanner = g_scanner_new(NULL); 418 | self->scanner->config->store_int64 = TRUE; 419 | 420 | guint i; 421 | _wh_commands_add_symbols(self->scanner, WH_COMMAND_SCOPE_ROOT, _wh_commands_symbols); 422 | _wh_commands_add_symbols(self->scanner, WH_COMMAND_SCOPE_DIRECTION, _wh_commands_directions); 423 | _wh_commands_add_symbols(self->scanner, WH_COMMAND_SCOPE_DIRECTION_CROSS, _wh_commands_cross_directions); 424 | _wh_commands_add_symbols(self->scanner, WH_COMMAND_SCOPE_TARGET, _wh_commands_targets); 425 | _wh_commands_add_symbols(self->scanner, WH_COMMAND_SCOPE_LAYOUT, _wh_commands_layout_types); 426 | _wh_commands_add_symbols(self->scanner, WH_COMMAND_SCOPE_ORIENTATION, _wh_commands_layout_orientations); 427 | _wh_commands_add_symbols(self->scanner, WH_COMMAND_SCOPE_STATE_CHANGE, _wh_commands_state_changes); 428 | 429 | return self; 430 | } 431 | 432 | void 433 | wh_commands_free(WhCommands *self) 434 | { 435 | if ( self == NULL ) 436 | return; 437 | 438 | g_scanner_destroy(self->scanner); 439 | 440 | g_free(self); 441 | } 442 | -------------------------------------------------------------------------------- /compositor/src/commands.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #ifndef __WAYHOUSE_COMMANDS_H__ 24 | #define __WAYHOUSE_COMMANDS_H__ 25 | 26 | #include "types.h" 27 | 28 | WhCommands *wh_commands_new(WhCore *core); 29 | void wh_commands_free(WhCommands *self); 30 | 31 | WhCommand *wh_command_parse(WhCommands *commands, gchar *string); 32 | void wh_command_free(WhCommand *command); 33 | 34 | void wh_command_call(WhCommand *command, WhSeat *seat); 35 | const gchar *wh_command_get_string(WhCommand *command); 36 | 37 | #endif /* __WAYHOUSE_COMMANDS_H__ */ 38 | -------------------------------------------------------------------------------- /compositor/src/config.c: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #include "config.h" 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "types.h" 42 | #include "wayhouse.h" 43 | #include "commands.h" 44 | #include "seats.h" 45 | #include "config_.h" 46 | 47 | struct _WhConfig { 48 | WhCore *core; 49 | struct xkb_rule_names xkb_names; 50 | struct wl_listener output_pending_listener; 51 | enum weston_compositor_backend backend; 52 | union { 53 | struct weston_drm_backend_config drm; 54 | struct weston_wayland_backend_config wayland; 55 | struct weston_x11_backend_config x11; 56 | } backend_config; 57 | union { 58 | const struct weston_windowed_output_api *windowed; 59 | const struct weston_drm_output_api *drm; 60 | } api; 61 | struct { 62 | gboolean enable_tap_set; 63 | gboolean enable_tap; 64 | } input; 65 | GHashTable *outputs; 66 | GHashTable *output_aliases; 67 | gboolean xwayland; 68 | gchar **common_plugins; 69 | GHashTable *assigns; 70 | }; 71 | 72 | typedef struct { 73 | gchar *name; 74 | gchar *modeline; 75 | gint scale; 76 | } WhConfigOutputDrm; 77 | 78 | typedef struct { 79 | gchar *name; 80 | gint width; 81 | gint height; 82 | gint scale; 83 | } WhConfigOutputVirtual; 84 | 85 | typedef struct { 86 | WhConfig *config; 87 | enum { 88 | WH_ACTION_COMMAND, 89 | WH_ACTION_EXEC, 90 | } type; 91 | union { 92 | WhCommand *command; 93 | gchar **argv; 94 | }; 95 | } WhAction; 96 | 97 | typedef enum { 98 | WH_MODIFIER_CTRL, 99 | WH_MODIFIER_ALT, 100 | WH_MODIFIER_SUPER, 101 | WH_MODIFIER_SHIFT, 102 | } WhModifier; 103 | 104 | static const gchar * const _wh_config_modifiers[] = { 105 | [WH_MODIFIER_CTRL] = "ctrl", 106 | [WH_MODIFIER_ALT] = "alt", 107 | [WH_MODIFIER_SUPER] = "super", 108 | [WH_MODIFIER_SHIFT] = "shift", 109 | }; 110 | 111 | static void 112 | _wh_config_workspace_config_free(gpointer data) 113 | { 114 | WhWorkspaceConfig *self = data; 115 | g_free(self->name); 116 | g_slice_free(WhWorkspaceConfig, self); 117 | } 118 | 119 | static void 120 | _wh_config_output_drm_free(gpointer data) 121 | { 122 | g_slice_free(WhConfigOutputDrm, data); 123 | } 124 | 125 | static void 126 | _wh_config_output_virtual_free(gpointer data) 127 | { 128 | g_slice_free(WhConfigOutputVirtual, data); 129 | } 130 | 131 | static void 132 | _wh_config_output_pending_drm(struct wl_listener *listener, void *data) 133 | { 134 | WhConfig *self = wl_container_of(listener, self, output_pending_listener); 135 | struct weston_output *woutput = data; 136 | const gchar *name = woutput->name; 137 | const gchar *alias; 138 | WhConfigOutputDrm *output; 139 | 140 | alias = g_hash_table_lookup(self->output_aliases, name); 141 | if ( alias != NULL ) 142 | name = alias; 143 | 144 | output = g_hash_table_lookup(self->outputs, name); 145 | if ( output == NULL ) 146 | output = g_hash_table_lookup(self->outputs, "default"); 147 | if ( output == NULL ) 148 | return; 149 | 150 | self->api.drm->set_mode(woutput, WESTON_DRM_BACKEND_OUTPUT_PREFERRED, output->modeline); 151 | self->api.drm->set_gbm_format(woutput, NULL); 152 | self->api.drm->set_seat(woutput, NULL); 153 | weston_output_set_scale(woutput, output->scale); 154 | weston_output_set_transform(woutput, WL_OUTPUT_TRANSFORM_NORMAL); 155 | weston_output_enable(woutput); 156 | } 157 | 158 | static void 159 | _wh_config_output_pending_virtual(struct wl_listener *listener, void *data) 160 | { 161 | WhConfig *self = wl_container_of(listener, self, output_pending_listener); 162 | struct weston_output *woutput = data; 163 | const gchar *name = woutput->name; 164 | const gchar *alias; 165 | WhConfigOutputVirtual *output; 166 | 167 | alias = g_hash_table_lookup(self->output_aliases, name); 168 | if ( alias != NULL ) 169 | name = alias; 170 | 171 | output = g_hash_table_lookup(self->outputs, name); 172 | g_return_if_fail(output != NULL); 173 | 174 | weston_output_set_scale(woutput, output->scale); 175 | weston_output_set_transform(woutput, WL_OUTPUT_TRANSFORM_NORMAL); 176 | self->api.windowed->output_set_size(woutput, output->width, output->height); 177 | weston_output_enable(woutput); 178 | } 179 | 180 | static void 181 | _wh_config_drm_input_configure(struct weston_compositor *compositor, struct libinput_device *device) 182 | { 183 | WhConfig *self = wh_core_get_config(weston_compositor_get_user_data(compositor)); 184 | gboolean enable_tap; 185 | 186 | if ( libinput_device_config_tap_get_finger_count(device) > 0 ) 187 | { 188 | enable_tap = libinput_device_config_tap_get_default_enabled(device); 189 | if ( self->input.enable_tap_set ) 190 | enable_tap = self->input.enable_tap; 191 | libinput_device_config_tap_set_enabled(device, enable_tap); 192 | } 193 | } 194 | 195 | static void 196 | _wh_config_init(WhConfig *self, gboolean use_pixman) 197 | { 198 | self->assigns = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, _wh_config_workspace_config_free); 199 | 200 | self->backend = WESTON_BACKEND_DRM; 201 | if ( g_getenv("WAYLAND_DISPLAY") != NULL ) 202 | self->backend = WESTON_BACKEND_WAYLAND; 203 | else if ( g_getenv("DISPLAY") != NULL ) 204 | self->backend = WESTON_BACKEND_X11; 205 | 206 | struct weston_backend_config *base = &self->backend_config.drm.base; 207 | GDestroyNotify output_free = NULL; 208 | switch ( self->backend ) 209 | { 210 | case WESTON_BACKEND_DRM: 211 | base->struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION; 212 | base->struct_size = sizeof(struct weston_drm_backend_config); 213 | self->backend_config.drm.configure_device = _wh_config_drm_input_configure; 214 | self->backend_config.drm.use_pixman = use_pixman; 215 | output_free = _wh_config_output_drm_free; 216 | break; 217 | case WESTON_BACKEND_WAYLAND: 218 | base->struct_version = WESTON_WAYLAND_BACKEND_CONFIG_VERSION; 219 | base->struct_size = sizeof(struct weston_wayland_backend_config); 220 | self->backend_config.wayland.use_pixman = use_pixman; 221 | output_free = _wh_config_output_virtual_free; 222 | break; 223 | case WESTON_BACKEND_X11: 224 | base->struct_version = WESTON_X11_BACKEND_CONFIG_VERSION; 225 | base->struct_size = sizeof(struct weston_x11_backend_config); 226 | self->backend_config.x11.use_pixman = use_pixman; 227 | output_free = _wh_config_output_virtual_free; 228 | break; 229 | default: 230 | /* Not supported */ 231 | g_return_if_reached(); 232 | } 233 | 234 | self->output_aliases = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); 235 | self->outputs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, output_free); 236 | } 237 | 238 | #define _wh_config_define_getter(name, type, ...) static gint \ 239 | _wh_config_get_##name(GKeyFile *file, const gchar *section, const gchar *key, type *value) \ 240 | { \ 241 | gint ret = 1; \ 242 | GError *error = NULL; \ 243 | \ 244 | if ( g_key_file_has_key(file, section, key, &error) ) \ 245 | { \ 246 | *value = g_key_file_get_##name(file, section, key, ##__VA_ARGS__, &error); \ 247 | if ( error != NULL ) \ 248 | g_warning("Could not get [%s] %s: %s", section, key, error->message); \ 249 | else \ 250 | ret = 0; \ 251 | } \ 252 | else if ( error != NULL ) \ 253 | g_warning("Could not check [%s] %s: %s", section, key, error->message); \ 254 | \ 255 | if ( error != NULL ) \ 256 | g_error_free(error); \ 257 | return ( error == NULL ) ? ret : -1; \ 258 | } 259 | 260 | _wh_config_define_getter(boolean, gboolean) 261 | _wh_config_define_getter(integer, gint) 262 | _wh_config_define_getter(uint64, guint64) 263 | _wh_config_define_getter(string, gchar *) 264 | _wh_config_define_getter(string_list, gchar **, NULL) 265 | 266 | static gint 267 | _wh_config_get_enum(GKeyFile *file, const gchar *section, const gchar *key, const gchar * const *values, guint64 size, guint64 *value) 268 | { 269 | gint ret; 270 | gchar *string; 271 | 272 | ret = _wh_config_get_string(file, section, key, &string); 273 | if ( ret != 0 ) 274 | return ret; 275 | 276 | if ( ! nk_enum_parse(string, values, size, TRUE, FALSE, value) ) 277 | ret = -1; 278 | g_free(string); 279 | 280 | return ret; 281 | } 282 | 283 | static gint 284 | _wh_config_get_command(WhConfig *self, GKeyFile *file, const gchar *section, const gchar *key, WhCommand **value) 285 | { 286 | gint ret; 287 | gchar *string; 288 | 289 | ret = _wh_config_get_string(file, section, key, &string); 290 | if ( ret != 0 ) 291 | return ret; 292 | 293 | *value = wh_command_parse(wh_core_get_commands(self->core), string); 294 | if ( *value == NULL ) 295 | ret = -1; 296 | 297 | return ret; 298 | } 299 | 300 | static gint 301 | _wh_config_get_argv(GKeyFile *file, const gchar *section, const gchar *key, gchar ***value) 302 | { 303 | gint ret; 304 | gchar *string; 305 | 306 | ret = _wh_config_get_string(file, section, key, &string); 307 | if ( ret != 0 ) 308 | return ret; 309 | 310 | gint argc; 311 | GError *error = NULL; 312 | if ( ! g_shell_parse_argv(string, &argc, value, &error) ) 313 | { 314 | g_warning("Could not parse [%s)] %s: %s", section, key, error->message); 315 | g_error_free(error); 316 | ret = -1; 317 | } 318 | else if ( argc < 1 ) 319 | { 320 | g_warning("Could not parse [%s)] %s: empty", section, key); 321 | g_strfreev(*value); 322 | *value = NULL; 323 | ret = -1; 324 | } 325 | 326 | return ret; 327 | } 328 | 329 | static WhAction * 330 | _wh_config_binding_parse_common(WhConfig *config, GKeyFile *file, const gchar *section) 331 | { 332 | WhCommand *command = NULL; 333 | gchar **argv = NULL; 334 | 335 | if ( ( _wh_config_get_command(config, file, section, "command", &command) != 0 ) 336 | && ( _wh_config_get_argv(file, section, "exec", &argv) != 0 ) ) 337 | goto error; 338 | 339 | WhAction *self; 340 | self = g_new0(WhAction, 1); 341 | self->config = config; 342 | 343 | self->type = ( command != NULL ) ? WH_ACTION_COMMAND : WH_ACTION_EXEC; 344 | switch ( self->type ) 345 | { 346 | case WH_ACTION_COMMAND: 347 | self->command = command; 348 | g_debug("%s -> command %s", section, wh_command_get_string(command)); 349 | break; 350 | case WH_ACTION_EXEC: 351 | self->argv = argv; 352 | g_debug("%s -> exec %s", section, argv[0]); 353 | argv = NULL; 354 | break; 355 | } 356 | 357 | return self; 358 | 359 | error: 360 | g_strfreev(argv); 361 | return NULL; 362 | } 363 | 364 | static void 365 | _wh_config_action_free(WhAction *self) 366 | { 367 | switch ( self->type ) 368 | { 369 | case WH_ACTION_COMMAND: 370 | wh_command_free(self->command); 371 | break; 372 | case WH_ACTION_EXEC: 373 | g_strfreev(self->argv); 374 | break; 375 | } 376 | 377 | g_free(self); 378 | } 379 | 380 | static void 381 | _wh_config_action_trigger(WhAction *self, WhSeat *seat) 382 | { 383 | switch ( self->type ) 384 | { 385 | case WH_ACTION_COMMAND: 386 | g_debug("command %s", wh_command_get_string(self->command)); 387 | wh_command_call(self->command, seat); 388 | break; 389 | case WH_ACTION_EXEC: 390 | g_debug("exec %s", self->argv[0]); 391 | g_spawn_async(NULL, self->argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); 392 | break; 393 | } 394 | } 395 | 396 | static void 397 | _wh_config_keybind_callback(struct weston_keyboard *keyboard, uint32_t time, uint32_t key, void *user_data) 398 | { 399 | WhAction *self = user_data; 400 | WhSeat *seat = wh_seats_get_from_weston_seat(wh_core_get_seats(self->config->core), keyboard->seat); 401 | _wh_config_action_trigger(self, seat); 402 | } 403 | 404 | static const gchar * 405 | _wh_config_binding_parse_key(const gchar *binding, enum weston_keyboard_modifier *modifiers) 406 | { 407 | guint64 value; 408 | *modifiers = 0; 409 | if ( g_utf8_strchr(binding, -1, '+') == NULL ) 410 | { 411 | if ( ! nk_enum_parse(binding, _wh_config_modifiers, G_N_ELEMENTS(_wh_config_modifiers), TRUE, FALSE, &value) ) 412 | return binding; 413 | *modifiers = (1 << value); 414 | return NULL; 415 | } 416 | 417 | const gchar *s, *c; 418 | for ( s = binding ; ( c = g_utf8_strchr(s, -1, '+') ) != NULL ; s = c + 1 ) 419 | { 420 | gsize l = c - s + 1; 421 | gchar *b; 422 | 423 | b = g_alloca(l ); 424 | g_snprintf(b, l, "%s", s); 425 | if ( nk_enum_parse(b, _wh_config_modifiers, G_N_ELEMENTS(_wh_config_modifiers), TRUE, FALSE, &value) ) 426 | *modifiers |= (1 << value); 427 | } 428 | return s; 429 | } 430 | 431 | static void 432 | _wh_config_binding_parse_keycode(WhConfig *self, GKeyFile *file, const gchar *section) 433 | { 434 | const gchar *binding = section + strlen("keycode "); 435 | 436 | enum weston_keyboard_modifier modifiers; 437 | binding = _wh_config_binding_parse_key(binding, &modifiers); 438 | 439 | if ( binding == NULL ) 440 | return; 441 | 442 | gchar *e; 443 | guint64 key; 444 | 445 | errno = 0; 446 | key = g_ascii_strtoull(binding, &e, 10); 447 | if ( ( errno != 0 ) || ( e == binding ) || ( *e != '\0' ) || ( key > G_MAXUINT32 ) ) 448 | return; 449 | 450 | WhAction *action; 451 | 452 | action = _wh_config_binding_parse_common(self, file, section); 453 | if ( action == NULL ) 454 | return; 455 | 456 | weston_compositor_add_key_binding(wh_core_get_compositor(self->core), key, modifiers, _wh_config_keybind_callback, action); 457 | } 458 | 459 | static void 460 | _wh_config_binding_parse_keysym(WhConfig *self, GKeyFile *file, const gchar *section) 461 | { 462 | const gchar *binding = section + strlen("keysym "); 463 | WhAction *action; 464 | 465 | action = _wh_config_binding_parse_common(self, file, section); 466 | if ( action == NULL ) 467 | return; 468 | 469 | (void)binding; 470 | _wh_config_action_free(action); 471 | } 472 | 473 | static void 474 | _wh_config_binding_mouse_callback(struct weston_pointer *pointer, uint32_t time, uint32_t key, void *user_data) 475 | { 476 | WhAction *self = user_data; 477 | WhSeat *seat = wh_seats_get_from_weston_seat(wh_core_get_seats(self->config->core), pointer->seat); 478 | _wh_config_action_trigger(self, seat); 479 | } 480 | 481 | static void 482 | _wh_config_binding_parse_mouse(WhConfig *self, GKeyFile *file, const gchar *section) 483 | { 484 | const gchar *binding = section + strlen("mouse "); 485 | 486 | enum weston_keyboard_modifier modifiers; 487 | binding = _wh_config_binding_parse_key(binding, &modifiers); 488 | 489 | if ( binding == NULL ) 490 | return; 491 | 492 | gchar *e; 493 | guint64 button; 494 | 495 | errno = 0; 496 | button = g_ascii_strtoull(binding, &e, 10); 497 | if ( ( errno != 0 ) || ( e == binding ) || ( *e != '\0' ) || ( button > G_MAXUINT32 ) ) 498 | return; 499 | 500 | WhAction *action; 501 | 502 | action = _wh_config_binding_parse_common(self, file, section); 503 | if ( action == NULL ) 504 | return; 505 | 506 | weston_compositor_add_button_binding(wh_core_get_compositor(self->core), button, modifiers, _wh_config_binding_mouse_callback, action); 507 | } 508 | 509 | static void 510 | _wh_config_workspace_parse(WhConfig *self, GKeyFile *file, const gchar *section) 511 | { 512 | const gchar *name = section + strlen("workspace "); 513 | gchar **outputs = NULL; 514 | GList *workspaces; 515 | 516 | if ( _wh_config_get_string_list(file, section, "outputs", &outputs) < 0 ) 517 | return; 518 | 519 | gchar **output; 520 | for ( output = outputs ; *output != NULL ; ++output ) 521 | { 522 | 523 | } 524 | } 525 | 526 | static void 527 | _wh_config_assign_parse(WhConfig *self, GKeyFile *file, const gchar *section) 528 | { 529 | const gchar *app_id = section + strlen("assign "); 530 | 531 | guint64 number = WH_WORKSPACE_NO_NUMBER; 532 | gchar *name = NULL; 533 | 534 | if ( _wh_config_get_uint64(file, section, "number", &number) < 0 ) 535 | return; 536 | if ( _wh_config_get_string(file, section, "name", &name) < 0 ) 537 | return; 538 | 539 | if ( ( number == WH_WORKSPACE_NO_NUMBER ) && ( name == NULL ) ) 540 | return; 541 | 542 | WhWorkspaceConfig *config; 543 | 544 | config = g_slice_new(WhWorkspaceConfig); 545 | config->number = number; 546 | config->name = name; 547 | 548 | g_hash_table_insert(self->assigns, g_strdup(app_id), config); 549 | } 550 | 551 | static void 552 | _wh_config_global_parse(WhConfig *self, GKeyFile *file) 553 | { 554 | if ( g_key_file_has_group(file, "wayhouse") ) 555 | { 556 | _wh_config_get_boolean(file, "wayhouse", "xwayland", &self->xwayland); 557 | _wh_config_get_string_list(file, "wayhouse", "common-plugins", &self->common_plugins); 558 | } 559 | if ( g_key_file_has_group(file, "keymap") ) 560 | { 561 | _wh_config_get_string(file, "keymap", "layout", (gchar **) &self->xkb_names.layout); 562 | _wh_config_get_string(file, "keymap", "variant", (gchar **) &self->xkb_names.variant); 563 | } 564 | 565 | gchar **groups; 566 | groups = g_key_file_get_groups(file, NULL); 567 | if ( groups == NULL ) 568 | return; 569 | 570 | gchar **group; 571 | for ( group = groups ; *group != NULL ; ++group ) 572 | { 573 | gsize l = strlen(*group); 574 | if ( g_str_has_prefix(*group, "keycode ") && ( l > strlen("keycode ") ) ) 575 | _wh_config_binding_parse_keycode(self, file, *group); 576 | else if ( g_str_has_prefix(*group, "keysym ") && ( l > strlen("keysym ") ) ) 577 | _wh_config_binding_parse_keysym(self, file, *group); 578 | else if ( g_str_has_prefix(*group, "mouse ") && ( l > strlen("mouse ") ) ) 579 | _wh_config_binding_parse_mouse(self, file, *group); 580 | else if ( g_str_has_prefix(*group, "workspace ") && ( l > strlen("workspace ") ) ) 581 | _wh_config_workspace_parse(self, file, *group); 582 | else if ( g_str_has_prefix(*group, "assign ") && ( l > strlen("assign ") ) ) 583 | _wh_config_assign_parse(self, file, *group); 584 | g_free(*group); 585 | } 586 | g_free(groups); 587 | } 588 | 589 | static void 590 | _wh_config_output_parse_drm(WhConfig *self, GKeyFile *file, const gchar *section) 591 | { 592 | const gchar *name = section + strlen("drm "); 593 | gint ret; 594 | gchar *alias = NULL; 595 | gchar *modeline = NULL; 596 | gint scale = 1; 597 | 598 | ret = _wh_config_get_string(file, section, "alias", &alias); 599 | if ( ret < 0 ) 600 | return; 601 | if ( ret == 0 ) 602 | { 603 | g_hash_table_insert(self->output_aliases, g_strdup(name), alias); 604 | return; 605 | } 606 | 607 | if ( _wh_config_get_integer(file, section, "scale", &scale) < 0 ) 608 | return; 609 | 610 | if ( _wh_config_get_string(file, section, "modeline", &modeline) < 0 ) 611 | return; 612 | 613 | WhConfigOutputDrm *output; 614 | output = g_slice_new(WhConfigOutputDrm); 615 | output->name = g_strdup(name); 616 | output->scale = scale; 617 | output->modeline = modeline; 618 | 619 | g_hash_table_insert(self->outputs, output->name, output); 620 | } 621 | 622 | static void 623 | _wh_config_output_parse_virtual(WhConfig *self, GKeyFile *file, const gchar *section) 624 | { 625 | const gchar *name = section + strlen("virtual "); 626 | gint ret; 627 | gint width, height, scale = 1; 628 | 629 | ret = _wh_config_get_integer(file, section, "width", &width); 630 | if ( ret != 0 ) 631 | { 632 | if ( ret > 0 ) 633 | g_warning("You must provide a width for virtual output %s", name); 634 | return; 635 | } 636 | ret = _wh_config_get_integer(file, section, "height", &height); 637 | if ( ret != 0 ) 638 | { 639 | if ( ret > 0 ) 640 | g_warning("You must provide an height for virtual output %s", name); 641 | return; 642 | } 643 | if ( _wh_config_get_integer(file, section, "scale", &scale) < 0 ) 644 | return; 645 | 646 | if ( ( width < 1 ) || ( height < 1 ) || ( scale < 1 ) ) 647 | { 648 | g_warning("Wrong size or scale for virtual output %s", name); 649 | return; 650 | } 651 | 652 | WhConfigOutputVirtual *output; 653 | 654 | output = g_slice_new(WhConfigOutputVirtual); 655 | output->name = g_strdup(name); 656 | output->width = width; 657 | output->height = height; 658 | output->scale = scale; 659 | 660 | g_hash_table_insert(self->outputs, output->name, output); 661 | } 662 | 663 | static void 664 | _wh_config_output_parse_all(WhConfig *self, GKeyFile *file) 665 | { 666 | gchar **groups; 667 | groups = g_key_file_get_groups(file, NULL); 668 | if ( groups == NULL ) 669 | return; 670 | 671 | const gchar *prefix; 672 | gsize l; 673 | void (*parse)(WhConfig *self, GKeyFile *file, const gchar *section); 674 | switch ( self->backend ) 675 | { 676 | case WESTON_BACKEND_DRM: 677 | prefix = "drm "; 678 | l = strlen("drm "); 679 | parse = _wh_config_output_parse_drm; 680 | break; 681 | case WESTON_BACKEND_WAYLAND: 682 | case WESTON_BACKEND_X11: 683 | prefix = "virtual "; 684 | l = strlen("virtual "); 685 | parse = _wh_config_output_parse_virtual; 686 | break; 687 | default: 688 | g_return_if_reached(); 689 | } 690 | 691 | gchar **group; 692 | for ( group = groups ; *group != NULL ; ++group ) 693 | { 694 | if ( g_str_has_prefix(*group, prefix) && ( strlen(*group) > l ) ) 695 | parse(self, file, *group); 696 | g_free(*group); 697 | } 698 | g_free(groups); 699 | } 700 | 701 | static void 702 | _wh_config_load_file(WhConfig *self, const gchar *dir, const gchar *filename, void (*parse)(WhConfig *self, GKeyFile *file)) 703 | { 704 | gchar *path; 705 | GError *error = NULL; 706 | 707 | path = g_build_filename(dir, filename, NULL); 708 | if ( ! g_file_test(path, G_FILE_TEST_IS_REGULAR) ) 709 | goto end; 710 | 711 | GKeyFile *file; 712 | 713 | file = g_key_file_new(); 714 | if ( g_key_file_load_from_file(file, path, G_KEY_FILE_NONE, &error) ) 715 | parse(self, file); 716 | else 717 | g_warning("Could not load '%s': %s", path, error->message); 718 | g_key_file_unref(file); 719 | 720 | end: 721 | g_clear_error(&error); 722 | g_free(path); 723 | } 724 | 725 | static gboolean 726 | _wh_config_load_dir(WhConfig *self, const gchar *dirbase) 727 | { 728 | gboolean found = FALSE; 729 | gchar *dir; 730 | 731 | dir = g_build_filename(dirbase, PACKAGE_NAME, NULL); 732 | if ( ! g_file_test(dir, G_FILE_TEST_IS_DIR) ) 733 | goto end; 734 | 735 | _wh_config_load_file(self, dir, PACKAGE_NAME ".conf", _wh_config_global_parse); 736 | _wh_config_load_file(self, dir, "outputs.conf", _wh_config_output_parse_all); 737 | 738 | found = TRUE; 739 | 740 | end: 741 | g_free(dir); 742 | return found; 743 | } 744 | 745 | static void 746 | _wh_config_load(WhConfig *self) 747 | { 748 | if ( _wh_config_load_dir(self, g_get_user_config_dir()) ) 749 | return; 750 | 751 | const gchar * const *system_dir; 752 | for ( system_dir = g_get_system_config_dirs() ; *system_dir != NULL ; ++system_dir ) 753 | { 754 | if ( _wh_config_load_dir(self, *system_dir) ) 755 | return; 756 | } 757 | } 758 | 759 | WhConfig * 760 | wh_config_new(WhCore *core, gboolean use_pixman) 761 | { 762 | WhConfig *self; 763 | 764 | self = g_new0(WhConfig, 1); 765 | self->core = core; 766 | 767 | _wh_config_init(self, use_pixman); 768 | _wh_config_load(self); 769 | 770 | return self; 771 | } 772 | 773 | void 774 | wh_config_free(WhConfig *self) 775 | { 776 | g_hash_table_unref(self->assigns); 777 | 778 | g_hash_table_unref(self->outputs); 779 | g_hash_table_unref(self->output_aliases); 780 | 781 | g_free(self); 782 | } 783 | 784 | gboolean 785 | wh_config_load_backend(WhConfig *self) 786 | { 787 | struct weston_compositor *compositor = wh_core_get_compositor(self->core); 788 | 789 | weston_compositor_load_backend(compositor, self->backend, &self->backend_config.drm.base); 790 | 791 | switch ( self->backend ) 792 | { 793 | case WESTON_BACKEND_DRM: 794 | self->api.drm = weston_drm_output_get_api(compositor); 795 | if ( self->api.drm == NULL ) 796 | return FALSE; 797 | 798 | self->output_pending_listener.notify = _wh_config_output_pending_drm; 799 | break; 800 | case WESTON_BACKEND_X11: 801 | case WESTON_BACKEND_WAYLAND: 802 | { 803 | self->api.windowed = weston_windowed_output_get_api(compositor); 804 | if ( self->api.windowed == NULL ) 805 | return FALSE; 806 | 807 | GHashTableIter iter; 808 | gchar *name; 809 | g_hash_table_iter_init(&iter, self->outputs); 810 | while ( g_hash_table_iter_next(&iter, (gpointer *) &name, NULL) ) 811 | self->api.windowed->output_create(compositor, name); 812 | 813 | self->output_pending_listener.notify = _wh_config_output_pending_virtual; 814 | } 815 | break; 816 | default: 817 | g_return_val_if_reached(FALSE); 818 | } 819 | 820 | wl_signal_add(&compositor->output_pending_signal, &self->output_pending_listener); 821 | weston_pending_output_coldplug(compositor); 822 | 823 | return TRUE; 824 | } 825 | 826 | struct xkb_rule_names * 827 | wh_config_get_xkb_names(WhConfig *self) 828 | { 829 | return &self->xkb_names; 830 | } 831 | 832 | gboolean 833 | wh_config_get_xwayland(WhConfig *self) 834 | { 835 | return self->xwayland; 836 | } 837 | 838 | const gchar * const * 839 | wh_config_get_common_plugins(WhConfig *self) 840 | { 841 | return (const gchar * const *) self->common_plugins; 842 | } 843 | 844 | const WhWorkspaceConfig * 845 | wh_config_get_assign(WhConfig *self, const gchar *app_id) 846 | { 847 | return g_hash_table_lookup(self->assigns, app_id); 848 | } 849 | -------------------------------------------------------------------------------- /compositor/src/config_.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #ifndef __WAYHOUSE_CONFIG_H__ 24 | #define __WAYHOUSE_CONFIG_H__ 25 | 26 | #include "types.h" 27 | 28 | WhConfig *wh_config_new(WhCore *core, gboolean use_pixman); 29 | void wh_config_free(WhConfig *config); 30 | gboolean wh_config_load_backend(WhConfig *config); 31 | 32 | struct xkb_rule_names *wh_config_get_xkb_names(WhConfig *config); 33 | struct weston_backend_config *wh_config_get_drm_config(WhConfig *config); 34 | struct weston_backend_config *wh_config_get_wayland_config(WhConfig *config); 35 | struct weston_backend_config *wh_config_get_x11_config(WhConfig *config); 36 | gboolean wh_config_get_xwayland(WhConfig *config); 37 | const gchar * const *wh_config_get_common_plugins(WhConfig *config); 38 | 39 | const WhWorkspaceConfig *wh_config_get_first_workspace(void); 40 | const WhWorkspaceConfig *wh_config_get_assign(WhConfig *config, const gchar *app_id); 41 | 42 | #endif /* __WAYHOUSE_CONFIG_H__ */ 43 | -------------------------------------------------------------------------------- /compositor/src/containers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #include "config.h" 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | 32 | #include "types.h" 33 | #include "wayhouse.h" 34 | #include "config_.h" 35 | #include "seats.h" 36 | #include "outputs.h" 37 | #include "containers.h" 38 | 39 | struct _WhWorkspaces { 40 | WhCore *core; 41 | GHashTable *workspaces; 42 | GHashTable *workspaces_by_number; 43 | GList *workspaces_sorted; 44 | guint64 workspace_biggest; 45 | struct weston_layer layer; 46 | struct weston_layer fullscreen_layer; 47 | GQueue *history; 48 | }; 49 | 50 | typedef enum { 51 | WH_CONTAINER_TYPE_CONTAINER = 0, 52 | WH_CONTAINER_TYPE_WORKSPACE, 53 | WH_CONTAINER_TYPE_SURFACE, 54 | } WhContainerType; 55 | 56 | #define WH_CONTAINER_IS_SURFACE(c) ((c)->type == WH_CONTAINER_TYPE_SURFACE) 57 | #define WH_CONTAINER_SURFACE(c) ((WhSurface *) (c)) 58 | #define WH_CONTAINER_IS_WORKSPACE(c) ((c)->type == WH_CONTAINER_TYPE_WORKSPACE) 59 | #define WH_CONTAINER_WORKSPACE(c) ((WhWorkspace *) (c)) 60 | 61 | typedef enum { 62 | WH_CONTAINER_LAYOUT_TABBED_HORIZONTAL = ( WH_CONTAINER_LAYOUT_TABBED | ( WH_ORIENTATION_HORIZONTAL << 1 ) ), 63 | WH_CONTAINER_LAYOUT_TABBED_VERTICAL = ( WH_CONTAINER_LAYOUT_TABBED | ( WH_ORIENTATION_VERTICAL << 1 ) ), 64 | WH_CONTAINER_LAYOUT_SPLIT_HORIZONTAL = ( WH_CONTAINER_LAYOUT_SPLIT | ( WH_ORIENTATION_HORIZONTAL << 1 ) ), 65 | WH_CONTAINER_LAYOUT_SPLIT_VERTICAL = ( WH_CONTAINER_LAYOUT_SPLIT | ( WH_ORIENTATION_VERTICAL << 1 ) ), 66 | } WhContainerLayout; 67 | 68 | #define WH_CONTAINER_LAYOUT_GET_ORIENTATION(l) ((l >> 1) & 1) 69 | #define WH_CONTAINER_LAYOUT_IS_HORIZONTAL(l) (WH_CONTAINER_LAYOUT_GET_ORIENTATION(l) == WH_ORIENTATION_HORIZONTAL) 70 | #define WH_CONTAINER_LAYOUT_IS_VERTICAL(l) (WH_CONTAINER_LAYOUT_GET_ORIENTATION(l) == WH_ORIENTATION_VERTICAL) 71 | 72 | #define WH_DIRECTION_GET_TARGET(d) ((d >> 1) & 1) 73 | #define WH_DIRECTION_GET_ORIENTATION(d) ((d) & 1) 74 | 75 | struct _WhContainer { 76 | WhWorkspaces *workspaces; 77 | WhContainerType type; 78 | 79 | gboolean current; 80 | GQueue *children; 81 | GList *link; 82 | GQueue *history; 83 | GList *history_link; 84 | 85 | gboolean visible; 86 | WhContainer *parent; 87 | WhContainerLayout layout; 88 | struct weston_geometry geometry; 89 | }; 90 | 91 | struct _WhWorkspace { 92 | WhContainer container; 93 | WhOutput *output; 94 | gchar *name; 95 | guint64 number; 96 | }; 97 | 98 | 99 | struct _WhSurface { 100 | WhContainer container; 101 | struct weston_desktop_surface *desktop_surface; 102 | struct weston_surface *surface; 103 | struct weston_view *view; 104 | }; 105 | 106 | static void 107 | _wh_container_resize(WhContainer *self) 108 | { 109 | gint32 x, y; 110 | gint32 width, height; 111 | 112 | x = self->geometry.x; 113 | y = self->geometry.y; 114 | width = self->geometry.width; 115 | height = self->geometry.height; 116 | 117 | if ( WH_CONTAINER_IS_SURFACE(self) ) 118 | { 119 | WhSurface *surface = WH_CONTAINER_SURFACE(self); 120 | struct weston_geometry geometry = weston_desktop_surface_get_geometry(surface->desktop_surface); 121 | if ( ( geometry.width != width ) || ( geometry.height != height ) ) 122 | wh_surface_set_size(surface, width, height); 123 | return; 124 | } 125 | 126 | if ( g_queue_is_empty(self->children) ) 127 | return; 128 | 129 | guint length; 130 | length = g_queue_get_length(self->children); 131 | 132 | switch ( self->layout ) 133 | { 134 | case WH_CONTAINER_LAYOUT_TABBED_HORIZONTAL: 135 | case WH_CONTAINER_LAYOUT_TABBED_VERTICAL: 136 | break; 137 | case WH_CONTAINER_LAYOUT_SPLIT_HORIZONTAL: 138 | width /= length; 139 | break; 140 | case WH_CONTAINER_LAYOUT_SPLIT_VERTICAL: 141 | height /= length; 142 | break; 143 | } 144 | 145 | 146 | GList *child_; 147 | for ( child_ = g_queue_peek_head_link(self->children) ; child_ != NULL ; child_ = g_list_next(child_) ) 148 | { 149 | WhContainer *child = child_->data; 150 | 151 | child->geometry.x = x; 152 | child->geometry.y = y; 153 | child->geometry.width = width; 154 | child->geometry.height = height; 155 | _wh_container_resize(child); 156 | 157 | switch ( self->layout ) 158 | { 159 | case WH_CONTAINER_LAYOUT_TABBED_HORIZONTAL: 160 | case WH_CONTAINER_LAYOUT_TABBED_VERTICAL: 161 | break; 162 | case WH_CONTAINER_LAYOUT_SPLIT_HORIZONTAL: 163 | x += width; 164 | break; 165 | case WH_CONTAINER_LAYOUT_SPLIT_VERTICAL: 166 | y += height; 167 | break; 168 | } 169 | } 170 | } 171 | 172 | static void _wh_container_free(WhContainer *self); 173 | static void _wh_container_show(WhContainer *self); 174 | static void _wh_container_hide(WhContainer *self); 175 | static void 176 | _wh_container_reparent(WhContainer *self, WhContainer *parent) 177 | { 178 | WhContainer *old_parent = self->parent; 179 | guint length; 180 | 181 | if ( old_parent == NULL ) 182 | goto set; 183 | 184 | g_queue_unlink(old_parent->history, self->history_link); 185 | g_queue_unlink(old_parent->children, self->link); 186 | length = g_queue_get_length(old_parent->children); 187 | if ( length > 0 ) 188 | _wh_container_resize(old_parent); 189 | else if ( ! WH_CONTAINER_IS_WORKSPACE(old_parent) ) 190 | _wh_container_free(old_parent); 191 | else if ( ! old_parent->visible ) 192 | { 193 | WhWorkspace *workspace = WH_CONTAINER_WORKSPACE(old_parent); 194 | g_hash_table_remove(self->workspaces->workspaces, workspace->name); 195 | } 196 | 197 | _wh_container_hide(self); 198 | 199 | set: 200 | self->parent = parent; 201 | if ( self->parent == NULL ) 202 | return; 203 | 204 | length = g_queue_get_length(parent->children); 205 | 206 | g_queue_push_tail_link(parent->children, self->link); 207 | g_queue_push_tail_link(parent->history, self->history_link); 208 | 209 | _wh_container_resize(parent); 210 | if ( parent->visible ) 211 | _wh_container_show(parent); 212 | } 213 | 214 | static void 215 | _wh_container_init(WhContainer *self, WhWorkspaces *workspaces, WhContainerType type) 216 | { 217 | self->workspaces = workspaces; 218 | self->type = type; 219 | 220 | self->children = g_queue_new(); 221 | self->link = g_list_alloc(); 222 | self->link->data = self; 223 | self->history = g_queue_new(); 224 | self->history_link = g_list_alloc(); 225 | self->history_link->data = self; 226 | } 227 | 228 | static void 229 | _wh_container_uninit(WhContainer *self) 230 | { 231 | if ( ! WH_CONTAINER_IS_WORKSPACE(self) ) 232 | _wh_container_reparent(self, NULL); 233 | else 234 | { 235 | g_queue_unlink(self->workspaces->history, self->history_link); 236 | self->workspaces->workspaces_sorted = g_list_remove_link(self->workspaces->workspaces_sorted, self->link); 237 | } 238 | 239 | g_queue_free(self->history); 240 | g_queue_free(self->children); 241 | 242 | g_list_free_1(self->history_link); 243 | g_list_free_1(self->link); 244 | } 245 | 246 | static WhContainer * 247 | _wh_container_new(WhWorkspaces *workspaces) 248 | { 249 | WhContainer *self; 250 | 251 | self = g_new0(WhContainer, 1); 252 | _wh_container_init(self, workspaces, WH_CONTAINER_TYPE_CONTAINER); 253 | 254 | return self; 255 | } 256 | 257 | static void 258 | _wh_container_free(WhContainer *self) 259 | { 260 | g_return_if_fail(! WH_CONTAINER_IS_WORKSPACE(self)); 261 | g_return_if_fail(! WH_CONTAINER_IS_SURFACE(self)); 262 | 263 | _wh_container_uninit(self); 264 | g_free(self); 265 | } 266 | 267 | static void 268 | _wh_workspace_set_output(WhWorkspace *self, WhOutput *output) 269 | { 270 | if ( output == NULL ) 271 | { 272 | WhWorkspace *last; 273 | last = g_queue_peek_head(self->container.workspaces->history); 274 | output = last->output; 275 | } 276 | self->output = output; 277 | self->container.geometry = wh_output_get_geometry(self->output); 278 | _wh_container_resize(&self->container); 279 | } 280 | 281 | static guint64 282 | _wh_workspaces_get_next_number(WhWorkspaces *self) 283 | { 284 | guint64 number = 0; 285 | GList *workspace_; 286 | for ( workspace_ = self->workspaces_sorted ; workspace_ != NULL ; workspace_ = g_list_next(workspace_) ) 287 | { 288 | WhWorkspace *workspace = workspace_->data; 289 | if ( workspace->number == WH_WORKSPACE_NO_NUMBER ) 290 | break; 291 | if ( workspace->number > number ) 292 | break; 293 | ++number; 294 | } 295 | return number; 296 | } 297 | 298 | static gint 299 | _wh_workspace_compare(gconstpointer a_, gconstpointer b_) 300 | { 301 | const WhWorkspace *a = a_, *b = b_; 302 | 303 | if ( ( a->number == WH_WORKSPACE_NO_NUMBER ) && ( b->number == WH_WORKSPACE_NO_NUMBER ) ) 304 | return g_strcmp0(a->name, b->name); 305 | 306 | if ( a->number == WH_WORKSPACE_NO_NUMBER ) 307 | return 1; 308 | if ( b->number == WH_WORKSPACE_NO_NUMBER ) 309 | return -1; 310 | 311 | return a->number - b->number; 312 | } 313 | 314 | static WhWorkspace * 315 | _wh_workspace_new(WhWorkspaces *workspaces, guint64 number, const gchar *name) 316 | { 317 | WhWorkspace *self; 318 | self = g_new0(WhWorkspace, 1); 319 | _wh_container_init(&self->container, workspaces, WH_CONTAINER_TYPE_WORKSPACE); 320 | if ( name != NULL ) 321 | { 322 | gchar *e; 323 | 324 | errno = 0; 325 | number = g_ascii_strtoull(name, &e, 10); 326 | if ( ( errno != 0 ) || ( e == name ) ) 327 | number = WH_WORKSPACE_NO_NUMBER; 328 | self->number = number; 329 | self->name = g_strdup(name); 330 | } 331 | else 332 | { 333 | if ( number == WH_WORKSPACE_NO_NUMBER ) 334 | number = _wh_workspaces_get_next_number(workspaces); 335 | self->number = number; 336 | self->name = g_strdup_printf("%" G_GUINT64_FORMAT, self->number); 337 | } 338 | 339 | if ( workspaces->workspaces == NULL ) 340 | self->container.current = TRUE; 341 | 342 | g_hash_table_insert(workspaces->workspaces, self->name, self); 343 | workspaces->workspaces_sorted = g_list_concat(self->container.link, workspaces->workspaces_sorted); 344 | workspaces->workspaces_sorted = g_list_sort(workspaces->workspaces_sorted, _wh_workspace_compare); 345 | g_queue_push_tail_link(workspaces->history, self->container.history_link); 346 | 347 | return self; 348 | } 349 | 350 | static void 351 | _wh_workspace_free(gpointer data) 352 | { 353 | WhWorkspace *self = data; 354 | _wh_container_hide(&self->container); 355 | _wh_container_uninit(&self->container); 356 | 357 | WhWorkspaces *workspaces = self->container.workspaces; 358 | 359 | if ( ( self->number != WH_WORKSPACE_NO_NUMBER ) && ( self->number == workspaces->workspace_biggest ) ) 360 | { 361 | workspaces->workspace_biggest = 0; 362 | GList *workspace_; 363 | for ( workspace_ = workspaces->workspaces_sorted ; workspace_ != NULL ; workspace_ = g_list_next(workspace_) ) 364 | { 365 | WhWorkspace *workspace = workspace_->data; 366 | 367 | if ( ( workspace->number != WH_WORKSPACE_NO_NUMBER ) && ( workspace->number > workspaces->workspace_biggest ) ) 368 | workspaces->workspace_biggest = workspace->number; 369 | } 370 | } 371 | 372 | g_free(self->name); 373 | 374 | g_free(self); 375 | } 376 | 377 | static void 378 | _wh_container_hide(WhContainer *self) 379 | { 380 | self->visible = FALSE; 381 | 382 | if ( WH_CONTAINER_IS_SURFACE(self) ) 383 | { 384 | WhSurface *surface = WH_CONTAINER_SURFACE(self); 385 | 386 | weston_view_damage_below(surface->view); 387 | weston_layer_entry_remove(&surface->view->layer_link); 388 | } 389 | else 390 | { 391 | GList *child; 392 | for ( child = g_queue_peek_head_link(self->children) ; child != NULL ; child = g_list_next(child) ) 393 | _wh_container_hide(child->data); 394 | } 395 | 396 | /* FIXME ? 397 | if ( self->workspaces->current == self ) 398 | { 399 | if ( ! WH_CONTAINER_IS_WORKSPACE(self) ) 400 | self->workspaces->current = self->parent; 401 | else 402 | { 403 | GList *workspace_; 404 | for ( workspace_ = self->workspaces->workspaces ; workspace_ != NULL ; workspace_ = g_list_next(workspace_) ) 405 | { 406 | WhWorkspace *workspace = workspace_->data; 407 | if ( workspace->container.visible ) 408 | { 409 | self->workspaces->current = &workspace->container; 410 | break; 411 | } 412 | } 413 | } 414 | } 415 | * */ 416 | } 417 | 418 | static void 419 | _wh_container_show(WhContainer *self) 420 | { 421 | self->visible = TRUE; 422 | if ( WH_CONTAINER_IS_SURFACE(self) ) 423 | { 424 | WhSurface *surface = WH_CONTAINER_SURFACE(self); 425 | 426 | weston_view_geometry_dirty(surface->view); 427 | weston_layer_entry_remove(&surface->view->layer_link); 428 | if ( weston_desktop_surface_get_fullscreen(surface->desktop_surface) ) 429 | weston_layer_entry_insert(&self->workspaces->fullscreen_layer.view_list, &surface->view->layer_link); 430 | else 431 | weston_layer_entry_insert(&self->workspaces->layer.view_list, &surface->view->layer_link); 432 | weston_desktop_surface_propagate_layer(surface->desktop_surface); 433 | weston_view_geometry_dirty(surface->view); 434 | weston_surface_damage(surface->surface); 435 | } 436 | else 437 | { 438 | gboolean first = TRUE; 439 | GList *child; 440 | for ( child = g_queue_peek_head_link(self->children) ; child != NULL ; child = g_list_next(child) ) 441 | { 442 | switch ( self->layout ) 443 | { 444 | case WH_CONTAINER_LAYOUT_TABBED_HORIZONTAL: 445 | case WH_CONTAINER_LAYOUT_TABBED_VERTICAL: 446 | if ( ! first ) 447 | _wh_container_hide(child->data); 448 | else 449 | case WH_CONTAINER_LAYOUT_SPLIT_HORIZONTAL: 450 | case WH_CONTAINER_LAYOUT_SPLIT_VERTICAL: 451 | _wh_container_show(child->data); 452 | first = FALSE; 453 | break; 454 | } 455 | } 456 | } 457 | } 458 | 459 | void 460 | wh_workspace_show(WhWorkspace *workspace) 461 | { 462 | WhContainer *self = &workspace->container; 463 | g_debug("Show workspaces %s", workspace->name); 464 | 465 | g_queue_unlink(self->workspaces->history, self->history_link); 466 | g_queue_push_head_link(self->workspaces->history, self->history_link); 467 | 468 | _wh_container_show(self); 469 | } 470 | 471 | void 472 | wh_workspace_hide(WhWorkspace *workspace) 473 | { 474 | WhContainer *self = &workspace->container; 475 | g_debug("Hide workspaces %s", workspace->name); 476 | 477 | _wh_container_hide(self); 478 | 479 | if ( g_queue_is_empty(self->children) ) 480 | g_hash_table_remove(self->workspaces->workspaces, workspace->name); 481 | } 482 | 483 | WhWorkspaces * 484 | wh_workspaces_new(WhCore *core) 485 | { 486 | struct weston_compositor *compositor = wh_core_get_compositor(core); 487 | WhWorkspaces *self; 488 | 489 | self = g_new0(WhWorkspaces, 1); 490 | self->core = core; 491 | 492 | self->workspaces = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, _wh_workspace_free); 493 | self->workspaces_by_number = g_hash_table_new(NULL, NULL); 494 | 495 | self->history = g_queue_new(); 496 | weston_layer_init(&self->fullscreen_layer, compositor); 497 | weston_layer_set_position(&self->fullscreen_layer, WESTON_LAYER_POSITION_FULLSCREEN); 498 | weston_layer_init(&self->layer, compositor); 499 | weston_layer_set_position(&self->layer, WESTON_LAYER_POSITION_NORMAL); 500 | 501 | return self; 502 | } 503 | 504 | void 505 | wh_workspaces_free(WhWorkspaces *self) 506 | { 507 | if ( self == NULL ) 508 | return; 509 | 510 | g_hash_table_unref(self->workspaces_by_number); 511 | g_hash_table_unref(self->workspaces); 512 | 513 | g_queue_free(self->history); 514 | 515 | g_free(self); 516 | } 517 | 518 | void 519 | wh_workspaces_add_output(WhWorkspaces *self, WhOutput *output) 520 | { 521 | WhWorkspace *workspace; 522 | 523 | /* 524 | * TODO: assign workspaces, check config 525 | */ 526 | workspace = _wh_workspace_new(self, WH_WORKSPACE_NO_NUMBER, NULL); 527 | _wh_workspace_set_output(workspace, output); 528 | wh_output_set_current_workspace(output, workspace); 529 | wh_workspace_show(workspace); 530 | } 531 | 532 | void 533 | wh_workspaces_remove_output(WhWorkspaces *self, WhOutput *output) 534 | { 535 | WhWorkspace *last, *workspace; 536 | last = g_queue_peek_head(self->history); 537 | gboolean current = ( last->output == output ); 538 | 539 | while ( last->output == output ) 540 | last = g_list_next(last->container.history_link)->data; 541 | 542 | GHashTableIter iter; 543 | g_hash_table_iter_init(&iter, self->workspaces); 544 | while ( g_hash_table_iter_next(&iter, NULL, (gpointer *) &workspace) ) 545 | { 546 | if ( workspace->output != output ) 547 | continue; 548 | 549 | _wh_workspace_set_output(workspace, last->output); 550 | } 551 | if ( ! current ) 552 | return; 553 | last = g_queue_peek_head(self->history); 554 | wh_output_set_current_workspace(last->output, last); 555 | } 556 | 557 | static WhContainer * 558 | _wh_workspace_get_last(WhContainer *self) 559 | { 560 | WhContainer *con = self; 561 | while ( ! g_queue_is_empty(con->history) ) 562 | con = g_queue_peek_head(con->history); 563 | return con; 564 | } 565 | 566 | static WhContainer * 567 | _wh_workspace_get_current(WhWorkspace *self) 568 | { 569 | WhContainer *con, *next; 570 | for ( con = &self->container ; ! g_queue_is_empty(con->history) ; con = next ) 571 | { 572 | next = g_queue_peek_head(con->history); 573 | if ( ! next->current ) 574 | return con; 575 | } 576 | return con; 577 | } 578 | 579 | static WhContainer * 580 | _wh_workspaces_get_current(WhWorkspaces *self) 581 | { 582 | return _wh_workspace_get_current(g_queue_peek_head(self->history)); 583 | } 584 | 585 | static void 586 | _wh_workspaces_set_current_recurse(WhContainer *self, gboolean current) 587 | { 588 | self->current = current; 589 | 590 | GQueue *history; 591 | if ( WH_CONTAINER_IS_WORKSPACE(self) ) 592 | history = self->workspaces->history; 593 | else 594 | { 595 | history = self->parent->history; 596 | _wh_workspaces_set_current_recurse(self->parent, current); 597 | } 598 | g_queue_unlink(history, self->history_link); 599 | g_queue_push_head_link(history, self->history_link); 600 | } 601 | 602 | static void 603 | _wh_workspaces_set_current(WhWorkspaces *self, WhContainer *next) 604 | { 605 | WhContainer *current; 606 | 607 | current = _wh_workspaces_get_current(self); 608 | 609 | if ( current == next ) 610 | return; 611 | 612 | _wh_workspaces_set_current_recurse(current, FALSE); 613 | _wh_workspaces_set_current_recurse(next, TRUE); 614 | 615 | if ( WH_CONTAINER_IS_SURFACE(next) ) 616 | wh_core_set_focus(self->core, WH_CONTAINER_SURFACE(next)); 617 | else if ( WH_CONTAINER_IS_SURFACE(current) ) 618 | wh_core_set_focus(self->core, NULL); 619 | } 620 | 621 | static WhWorkspace * 622 | _wh_container_get_workspace(WhContainer *self) 623 | { 624 | WhContainer *con = self; 625 | while ( ! WH_CONTAINER_IS_WORKSPACE(con) ) 626 | con = con->parent; 627 | return WH_CONTAINER_WORKSPACE(con); 628 | } 629 | 630 | static WhContainer * 631 | _wh_container_get(WhContainer *self, WhDirection direction) 632 | { 633 | if ( direction & WH_DIRECTION_TREE_MASK ) 634 | { 635 | switch ( WH_DIRECTION_GET_TARGET(direction) ) 636 | { 637 | case WH_TARGET_PREVIOUS: 638 | if ( ! WH_CONTAINER_IS_WORKSPACE(self) ) 639 | return self->parent; 640 | break; 641 | case WH_TARGET_NEXT: 642 | if ( ! WH_CONTAINER_IS_SURFACE(self) ) 643 | return g_queue_peek_head(self->history); 644 | break; 645 | default: 646 | g_return_val_if_reached(NULL); 647 | } 648 | return self; 649 | } 650 | 651 | WhWorkspace *workspace; 652 | WhOutput *output = NULL; 653 | workspace = _wh_container_get_workspace(self); 654 | output = wh_outputs_get(wh_core_get_outputs(self->workspaces->core), workspace->output, direction); 655 | 656 | if ( ! WH_CONTAINER_IS_WORKSPACE(self) ) 657 | { 658 | if ( WH_CONTAINER_LAYOUT_GET_ORIENTATION(self->parent->layout) == WH_DIRECTION_GET_ORIENTATION(direction) ) 659 | { 660 | gpointer (*getter)(GQueue *queue); 661 | switch ( WH_DIRECTION_GET_TARGET(direction) ) 662 | { 663 | case WH_TARGET_PREVIOUS: 664 | if ( self->link->prev != NULL ) 665 | return self->link->prev->data; 666 | getter = g_queue_peek_tail; 667 | break; 668 | case WH_TARGET_NEXT: 669 | if ( self->link->next != NULL ) 670 | return self->link->next->data; 671 | getter = g_queue_peek_head; 672 | break; 673 | default: 674 | g_return_val_if_reached(NULL); 675 | } 676 | WhContainer *target; 677 | target = _wh_container_get(self->parent, direction); 678 | if ( target != self->parent ) 679 | return _wh_workspace_get_last(target); 680 | if ( output == NULL ) 681 | return getter(self->parent->children); 682 | } 683 | } 684 | 685 | if ( output != NULL ) 686 | { 687 | workspace = wh_output_get_current_workspace(output); 688 | return _wh_workspace_get_last(&workspace->container); 689 | } 690 | 691 | return self; 692 | } 693 | 694 | void 695 | wh_workspaces_focus_container(WhWorkspaces *self, WhSeat *seat, WhDirection direction) 696 | { 697 | WhContainer *current, *next; 698 | 699 | current = _wh_workspaces_get_current(self); 700 | next = _wh_container_get(current, direction); 701 | 702 | if ( next == current ) 703 | return; 704 | 705 | _wh_workspaces_set_current(self, next); 706 | } 707 | 708 | void 709 | wh_workspaces_focus_workspace(WhWorkspaces *self, WhSeat *seat, WhTarget target) 710 | { 711 | WhWorkspace *current = g_queue_peek_head(self->history), *workspace = NULL; 712 | switch ( target ) 713 | { 714 | case WH_TARGET_NEXT: 715 | if ( current->container.link->next != NULL ) 716 | workspace = current->container.link->next->data; 717 | /* TODO: prev output if any */ 718 | break; 719 | case WH_TARGET_PREVIOUS: 720 | if ( current->container.link->prev != NULL ) 721 | workspace = current->container.link->prev->data; 722 | /* TODO: prev output if any */ 723 | break; 724 | case WH_TARGET_BACK_AND_FORTH: 725 | workspace = g_queue_peek_nth(self->history, 1); 726 | break; 727 | } 728 | if ( workspace == NULL ) 729 | return; 730 | 731 | wh_output_set_current_workspace(workspace->output, workspace); 732 | } 733 | 734 | void 735 | wh_workspaces_focus_workspace_name(WhWorkspaces *self, WhSeat *seat, const gchar *target) 736 | { 737 | WhWorkspace *workspace; 738 | workspace = g_hash_table_lookup(self->workspaces, target); 739 | if ( workspace != NULL ) 740 | { 741 | if ( ! wh_output_set_current_workspace(workspace->output, workspace) ) 742 | wh_workspaces_focus_workspace(self, seat, WH_TARGET_BACK_AND_FORTH); 743 | return; 744 | } 745 | workspace = _wh_workspace_new(self, WH_WORKSPACE_NO_NUMBER, target); 746 | _wh_workspace_set_output(workspace, NULL); 747 | wh_output_set_current_workspace(workspace->output, workspace); 748 | } 749 | 750 | void 751 | wh_workspaces_focus_workspace_number(WhWorkspaces *self, WhSeat *seat, guint64 target) 752 | { 753 | WhWorkspace *workspace; 754 | workspace = g_hash_table_lookup(self->workspaces_by_number, GUINT_TO_POINTER(target)); 755 | if ( workspace != NULL ) 756 | { 757 | if ( ! wh_output_set_current_workspace(workspace->output, workspace) ) 758 | wh_workspaces_focus_workspace(self, seat, WH_TARGET_BACK_AND_FORTH); 759 | return; 760 | } 761 | workspace = _wh_workspace_new(self, target, NULL); 762 | _wh_workspace_set_output(workspace, NULL); 763 | wh_output_set_current_workspace(workspace->output, workspace); 764 | } 765 | 766 | void 767 | wh_workspaces_focus_output(WhWorkspaces *self, WhSeat *seat, WhDirection direction) 768 | { 769 | if ( direction & WH_DIRECTION_TREE_MASK ) 770 | g_return_if_reached(); 771 | 772 | WhWorkspace *workspace; 773 | WhOutput *output; 774 | 775 | workspace = _wh_container_get_workspace(g_queue_peek_head(self->history)); 776 | output = wh_outputs_get(wh_core_get_outputs(self->core), workspace->output, direction); 777 | if ( output == NULL ) 778 | return; 779 | 780 | WhContainer *con; 781 | workspace = wh_output_get_current_workspace(output); 782 | con = _wh_workspace_get_last(&workspace->container); 783 | _wh_workspaces_set_current(self, con); 784 | } 785 | 786 | void 787 | wh_workspaces_focus_output_name(WhWorkspaces *self, WhSeat *seat, const gchar *target) 788 | { 789 | } 790 | 791 | void 792 | wh_workspaces_move_container(WhWorkspaces *self, WhSeat *seat, WhDirection direction) 793 | { 794 | } 795 | 796 | void 797 | wh_workspaces_move_container_to_workspace(WhWorkspaces *self, WhSeat *seat, WhTarget target) 798 | { 799 | } 800 | 801 | void 802 | wh_workspaces_move_container_to_workspace_name(WhWorkspaces *self, WhSeat *seat, const gchar *target) 803 | { 804 | } 805 | 806 | void 807 | wh_workspaces_move_container_to_workspace_number(WhWorkspaces *self, WhSeat *seat, guint64 target) 808 | { 809 | } 810 | 811 | void 812 | wh_workspaces_move_workspace_to_output(WhWorkspaces *self, WhSeat *seat, WhDirection target) 813 | { 814 | } 815 | 816 | void 817 | wh_workspaces_move_workspace_to_output_name(WhWorkspaces *self, WhSeat *seat, const gchar *target) 818 | { 819 | } 820 | 821 | 822 | void 823 | wh_workspaces_layout_switch(WhWorkspaces *self, WhSeat *seat, WhContainerLayoutType type, WhOrientation orientation) 824 | { 825 | WhContainer *con; 826 | 827 | con = _wh_workspaces_get_current(self); 828 | 829 | if ( WH_CONTAINER_IS_SURFACE(con) ) 830 | con = con->parent; 831 | 832 | if ( orientation == WH_ORIENTATION_TOGGLE ) 833 | { 834 | if ( ( con->layout & 1 ) != type ) 835 | orientation = WH_ORIENTATION_HORIZONTAL; 836 | else 837 | orientation = ( ( ~con->layout >> 1 ) & 1 ); 838 | } 839 | 840 | guint layout = type | ( orientation << 1 ); 841 | 842 | if ( con->layout == layout ) 843 | return; 844 | 845 | con->layout = layout; 846 | _wh_container_resize(con); 847 | if ( con->visible ) 848 | _wh_container_show(con); 849 | } 850 | 851 | static void 852 | _wh_workspaces_refocus(WhWorkspaces *self) 853 | { 854 | WhContainer *con; 855 | 856 | con = g_queue_peek_head(self->history); 857 | while ( ! g_queue_is_empty(con->history) ) 858 | con = g_queue_peek_head(con->history); 859 | _wh_workspaces_set_current(self, con); 860 | } 861 | 862 | 863 | struct weston_view * 864 | wh_surface_get_view(WhSurface *self) 865 | { 866 | return self->view; 867 | } 868 | 869 | struct weston_surface * 870 | wh_surface_get_surface(WhSurface *self) 871 | { 872 | return self->surface; 873 | } 874 | 875 | void 876 | wh_surface_set_size(WhSurface *self, gint32 width, gint32 height) 877 | { 878 | weston_desktop_surface_set_size(self->desktop_surface, width, height); 879 | weston_view_set_mask(self->view, 0, 0, width, height); 880 | weston_view_update_transform(self->view); 881 | } 882 | 883 | void 884 | wh_surface_set_activated(WhSurface *self, gboolean activated) 885 | { 886 | if ( self == NULL ) 887 | return; 888 | 889 | if ( activated ) 890 | _wh_container_show(&self->container); 891 | weston_desktop_surface_set_activated(self->desktop_surface, activated); 892 | } 893 | 894 | void 895 | wh_surface_fullscreen(WhSurface *self, WhStateChange change) 896 | { 897 | gboolean fullscreen = FALSE; 898 | switch ( change ) 899 | { 900 | case WH_STATE_ENABLE: 901 | fullscreen = TRUE; 902 | break; 903 | case WH_STATE_DISABLE: 904 | fullscreen = FALSE; 905 | break; 906 | case WH_STATE_TOGGLE: 907 | fullscreen = ! weston_desktop_surface_get_fullscreen(self->desktop_surface); 908 | break; 909 | } 910 | 911 | if ( fullscreen ) 912 | { 913 | WhWorkspace *workspace; 914 | workspace = _wh_container_get_workspace(&self->container); 915 | wh_surface_set_size(self, workspace->container.geometry.width, workspace->container.geometry.height); 916 | } 917 | weston_desktop_surface_set_fullscreen(self->desktop_surface, fullscreen); 918 | } 919 | 920 | void 921 | wh_surface_close(WhSurface *self) 922 | { 923 | if ( self == NULL ) 924 | return; 925 | weston_desktop_surface_close(self->desktop_surface); 926 | } 927 | 928 | static void 929 | _wh_desktop_ping_timeout(struct weston_desktop_client *client, void *user_data) 930 | { 931 | } 932 | 933 | static void 934 | _wh_desktop_pong(struct weston_desktop_client *client, void *user_data) 935 | { 936 | } 937 | 938 | static void 939 | _wh_desktop_surface_added(struct weston_desktop_surface *surface, void *user_data) 940 | { 941 | WhWorkspaces *workspaces = user_data; 942 | WhSurface *self; 943 | 944 | self = g_new0(WhSurface, 1); 945 | _wh_container_init(&self->container, workspaces, WH_CONTAINER_TYPE_SURFACE); 946 | self->desktop_surface = surface; 947 | 948 | weston_desktop_surface_set_user_data(self->desktop_surface, self); 949 | 950 | self->surface = weston_desktop_surface_get_surface(self->desktop_surface); 951 | self->view = weston_desktop_surface_create_view(self->desktop_surface); 952 | weston_desktop_surface_set_maximized(self->desktop_surface, true); 953 | 954 | const gchar *app_id; 955 | const WhWorkspaceConfig *config = NULL; 956 | WhContainer *parent = NULL; 957 | 958 | app_id = weston_desktop_surface_get_app_id(surface); 959 | if ( app_id != NULL ) 960 | config = wh_config_get_assign(wh_core_get_config(workspaces->core), app_id); 961 | if ( config != NULL ) 962 | { 963 | if ( config->name != NULL ) 964 | parent = g_hash_table_lookup(workspaces->workspaces, config->name); 965 | else 966 | parent = g_hash_table_lookup(workspaces->workspaces_by_number, GUINT_TO_POINTER(config->number)); 967 | if ( parent == NULL ) 968 | { 969 | WhWorkspace *workspace; 970 | workspace = _wh_workspace_new(workspaces, config->number, config->name); 971 | _wh_workspace_set_output(workspace, NULL); 972 | parent = &workspace->container; 973 | } 974 | } 975 | 976 | if ( parent == NULL ) 977 | parent = _wh_workspaces_get_current(workspaces); 978 | if ( parent == NULL ) 979 | /* TODO: keep them around for when we have an output */ 980 | return; 981 | if ( WH_CONTAINER_IS_SURFACE(parent) ) 982 | parent = parent->parent; 983 | 984 | _wh_container_reparent(&self->container, parent); 985 | if ( parent->visible ) 986 | { 987 | g_debug("Parent visible, showing us"); 988 | _wh_container_show(parent); 989 | } 990 | 991 | /* TODO: some focus stealing prevention */ 992 | if ( wh_core_get_focus(workspaces->core) == NULL ) 993 | { 994 | g_debug("No focus, focusing ourselves"); 995 | _wh_workspaces_set_current(workspaces, &self->container); 996 | } 997 | } 998 | 999 | static void 1000 | _wh_desktop_surface_removed(struct weston_desktop_surface *surface, void *user_data) 1001 | { 1002 | WhWorkspaces *workspaces = user_data; 1003 | WhSurface *self = weston_desktop_surface_get_user_data(surface); 1004 | 1005 | if ( self == NULL ) 1006 | return; 1007 | 1008 | gboolean refocus = ( wh_core_get_focus(workspaces->core) == self ); 1009 | 1010 | if ( refocus ) 1011 | wh_core_set_focus(workspaces->core, NULL); 1012 | 1013 | _wh_container_uninit(&self->container); 1014 | weston_desktop_surface_set_user_data(surface, NULL); 1015 | g_free(self); 1016 | 1017 | if ( refocus ) 1018 | _wh_workspaces_refocus(workspaces); 1019 | } 1020 | 1021 | static void 1022 | _wh_desktop_committed(struct weston_desktop_surface *surface, int32_t sx, int32_t sy, void *user_data) 1023 | { 1024 | WhSurface *self = weston_desktop_surface_get_user_data(surface); 1025 | struct weston_geometry geometry = weston_desktop_surface_get_geometry(self->desktop_surface); 1026 | 1027 | int32_t x, y; 1028 | if ( weston_desktop_surface_get_fullscreen(self->desktop_surface) ) 1029 | { 1030 | WhWorkspace *workspace; 1031 | workspace = _wh_container_get_workspace(&self->container); 1032 | x = workspace->container.geometry.x; 1033 | y = workspace->container.geometry.y; 1034 | } 1035 | else 1036 | { 1037 | _wh_container_resize(self->container.parent); 1038 | x = self->container.geometry.x; 1039 | y = self->container.geometry.y; 1040 | } 1041 | x -= geometry.x; 1042 | y -= geometry.y; 1043 | weston_view_set_position(self->view, x, y); 1044 | weston_view_set_mask_infinite(self->view); 1045 | weston_view_update_transform(self->view); 1046 | } 1047 | 1048 | static void 1049 | _wh_desktop_show_window_menu(struct weston_desktop_surface *surface, struct weston_seat *seat, int32_t x, int32_t y, void *user_data) 1050 | { 1051 | /* TODO: make sure a surface is always in a non-tabbed/stacked container with its parent */ 1052 | g_warning("Client requesting window menu: not yet implemented"); 1053 | } 1054 | 1055 | static void 1056 | _wh_desktop_set_parent(struct weston_desktop_surface *surface, struct weston_desktop_surface *parent, void *user_data) 1057 | { 1058 | /* TODO: make sure a surface is always in a non-tabbed/stacked container with its parent */ 1059 | g_warning("Client requesting parent relation: not yet implemented"); 1060 | } 1061 | 1062 | static void 1063 | _wh_desktop_move(struct weston_desktop_surface *surface, struct weston_seat *seat, uint32_t serial, void *user_data) 1064 | { 1065 | g_warning("Client requesting move: unsupported"); 1066 | } 1067 | 1068 | static void 1069 | _wh_desktop_resize(struct weston_desktop_surface *surface, struct weston_seat *seat, uint32_t serial, enum weston_desktop_surface_edge edges, void *user_data) 1070 | { 1071 | g_warning("Client requesting resize: unsupported"); 1072 | } 1073 | 1074 | static void 1075 | _wh_desktop_fullscreen_requested(struct weston_desktop_surface *surface, bool fullscreen, struct weston_output *output, void *user_data) 1076 | { 1077 | WhSurface *self = weston_desktop_surface_get_user_data(surface); 1078 | wh_surface_fullscreen(self, fullscreen ? WH_STATE_ENABLE : WH_STATE_DISABLE); 1079 | } 1080 | 1081 | static void 1082 | _wh_desktop_maximized_requested(struct weston_desktop_surface *surface, bool maximized, void *user_data) 1083 | { 1084 | weston_desktop_surface_set_maximized(surface, FALSE); 1085 | g_warning("Client requesting maximized state: unsupported"); 1086 | } 1087 | 1088 | static void 1089 | _wh_desktop_minimized_requested(struct weston_desktop_surface *surface, void *user_data) 1090 | { 1091 | g_warning("Client requesting minimized state: unsupported"); 1092 | } 1093 | 1094 | const struct weston_desktop_api wh_workspaces_desktop_api = { 1095 | .struct_size = sizeof(struct weston_desktop_api), 1096 | .ping_timeout = _wh_desktop_ping_timeout, 1097 | .pong = _wh_desktop_pong, 1098 | .surface_added = _wh_desktop_surface_added, 1099 | .surface_removed = _wh_desktop_surface_removed, 1100 | .committed = _wh_desktop_committed, 1101 | .show_window_menu = _wh_desktop_show_window_menu, 1102 | .set_parent = _wh_desktop_set_parent, 1103 | .move = _wh_desktop_move, 1104 | .resize = _wh_desktop_resize, 1105 | .fullscreen_requested = _wh_desktop_fullscreen_requested, 1106 | .maximized_requested = _wh_desktop_maximized_requested, 1107 | .minimized_requested = _wh_desktop_minimized_requested, 1108 | }; 1109 | -------------------------------------------------------------------------------- /compositor/src/containers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #ifndef __WAYHOUSE_CONTAINERS_H__ 24 | #define __WAYHOUSE_CONTAINERS_H__ 25 | 26 | #include "types.h" 27 | #include 28 | 29 | WhWorkspaces *wh_workspaces_new(WhCore *core); 30 | void wh_workspaces_free(WhWorkspaces *workspaces); 31 | 32 | void wh_workspaces_add_surface(WhWorkspaces *workspaces, WhSurface *surface); 33 | void wh_workspaces_add_output(WhWorkspaces *workspaces, WhOutput *output); 34 | void wh_workspaces_remove_output(WhWorkspaces *workspaces, WhOutput *output); 35 | void wh_workspaces_focus_container(WhWorkspaces *workspaces, WhSeat *seat, WhDirection direction); 36 | void wh_workspaces_focus_workspace(WhWorkspaces *workspaces, WhSeat *seat, WhTarget target); 37 | void wh_workspaces_focus_workspace_name(WhWorkspaces *workspaces, WhSeat *seat, const gchar *target); 38 | void wh_workspaces_focus_workspace_number(WhWorkspaces *workspaces, WhSeat *seat, guint64 target); 39 | void wh_workspaces_focus_output(WhWorkspaces *workspaces, WhSeat *seat, WhDirection direction); 40 | void wh_workspaces_focus_output_name(WhWorkspaces *workspaces, WhSeat *seat, const gchar *target); 41 | void wh_workspaces_move_container(WhWorkspaces *workspaces, WhSeat *seat, WhDirection direction); 42 | void wh_workspaces_move_container_to_workspace(WhWorkspaces *workspaces, WhSeat *seat, WhTarget target); 43 | void wh_workspaces_move_container_to_workspace_name(WhWorkspaces *workspaces, WhSeat *seat, const gchar *target); 44 | void wh_workspaces_move_container_to_workspace_number(WhWorkspaces *workspaces, WhSeat *seat, guint64 target); 45 | void wh_workspaces_move_workspace_to_output(WhWorkspaces *workspaces, WhSeat *seat, WhDirection direction); 46 | void wh_workspaces_move_workspace_to_output_name(WhWorkspaces *workspaces, WhSeat *seat, const gchar *target); 47 | void wh_workspaces_layout_switch(WhWorkspaces *workspaces, WhSeat *seat, WhContainerLayoutType type, WhOrientation orientation); 48 | 49 | void wh_workspace_show(WhWorkspace *workspace); 50 | void wh_workspace_hide(WhWorkspace *workspace); 51 | 52 | extern const struct weston_desktop_api wh_workspaces_desktop_api; 53 | 54 | struct weston_view *wh_surface_get_view(WhSurface *surface); 55 | struct weston_surface *wh_surface_get_surface(WhSurface *surface); 56 | 57 | void wh_surface_set_container(WhSurface *surface, WhContainer *container); 58 | void wh_surface_set_size(WhSurface *surface, gint32 width, gint32 height); 59 | void wh_surface_set_activated(WhSurface *surface, gboolean activated); 60 | 61 | void wh_surface_fullscreen(WhSurface *surface, WhStateChange change); 62 | void wh_surface_close(WhSurface *surface); 63 | 64 | #endif /* __WAYHOUSE_CONTAINERS_H__ */ 65 | -------------------------------------------------------------------------------- /compositor/src/outputs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #include "config.h" 24 | 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | 31 | #include "types.h" 32 | #include "wayhouse.h" 33 | #include "containers.h" 34 | #include "outputs.h" 35 | 36 | struct _WhOutputs { 37 | WhCore *core; 38 | struct wl_listener output_create_listener; 39 | struct wl_listener output_destroy_listener; 40 | GHashTable *outputs; 41 | GHashTable *outputs_by_name; 42 | }; 43 | 44 | struct _WhOutput { 45 | WhOutputs *outputs; 46 | struct weston_output *output; 47 | WhWorkspace *current; 48 | }; 49 | 50 | struct _WhContainer { 51 | WhWorkspaces *workspaces; 52 | enum { A, B} type; 53 | 54 | gboolean current; 55 | GQueue *children; 56 | GList *link; 57 | GQueue *history; 58 | GList *history_link; 59 | 60 | gboolean visible; 61 | WhContainer *parent; 62 | guint layout; 63 | struct weston_geometry geometry; 64 | }; 65 | 66 | struct _WhWorkspace { 67 | WhContainer container; 68 | WhOutput *output; 69 | gchar *name; 70 | guint64 number; 71 | }; 72 | 73 | void 74 | wh_outputs_control(WhOutputs *self, WhSeat *seat, WhStateChange state, const gchar *name) 75 | { 76 | WhOutput *output; 77 | 78 | output = g_hash_table_lookup(self->outputs_by_name, name); 79 | if ( output == NULL ) 80 | return; 81 | 82 | switch ( state ) 83 | { 84 | case WH_STATE_ENABLE: 85 | if ( ! output->output->enabled ) 86 | { 87 | weston_output_enable(output->output); 88 | wh_workspaces_add_output(wh_core_get_workspaces(self->core), output); 89 | } 90 | break; 91 | case WH_STATE_DISABLE: 92 | if ( output->output->enabled ) 93 | { 94 | weston_output_disable(output->output); 95 | wh_workspaces_remove_output(wh_core_get_workspaces(self->core), output); 96 | output->current = NULL; 97 | } 98 | break; 99 | case WH_STATE_TOGGLE: 100 | if ( output->output->enabled ) 101 | { 102 | weston_output_disable(output->output); 103 | wh_workspaces_remove_output(wh_core_get_workspaces(self->core), output); 104 | output->current = NULL; 105 | } 106 | else 107 | { 108 | weston_output_enable(output->output); 109 | wh_workspaces_add_output(wh_core_get_workspaces(self->core), output); 110 | } 111 | break; 112 | } 113 | } 114 | 115 | gboolean 116 | wh_output_set_current_workspace(WhOutput *self, WhWorkspace *workspace) 117 | { 118 | g_debug("Output %s got workspace %s (previous %s)", self->output->name, workspace->name, self->current ? self->current->name : "none"); 119 | if ( self->current == workspace ) 120 | return FALSE; 121 | 122 | if ( self->current != NULL ) 123 | wh_workspace_hide(self->current); 124 | self->current = workspace; 125 | wh_workspace_show(self->current); 126 | return TRUE; 127 | } 128 | 129 | WhWorkspace * 130 | wh_output_get_current_workspace(WhOutput *self) 131 | { 132 | g_debug("Output %s has current workspace workspace %s", self->output->name, self->current ? self->current->name : "none"); 133 | return self->current; 134 | } 135 | 136 | static void 137 | _wh_output_new(WhOutputs *outputs, struct weston_output *output) 138 | { 139 | WhOutput *self; 140 | 141 | self = g_new0(WhOutput, 1); 142 | self->outputs = outputs; 143 | self->output = output; 144 | 145 | g_hash_table_insert(self->outputs->outputs, self->output, self); 146 | g_hash_table_insert(self->outputs->outputs_by_name, self->output->name, self); 147 | 148 | wh_workspaces_add_output(wh_core_get_workspaces(self->outputs->core), self); 149 | } 150 | 151 | static void 152 | _wh_output_free(gpointer data) 153 | { 154 | WhOutput *self = data; 155 | 156 | wh_workspaces_remove_output(wh_core_get_workspaces(self->outputs->core), self); 157 | 158 | g_free(self); 159 | } 160 | 161 | struct weston_geometry 162 | wh_output_get_geometry(WhOutput *self) 163 | { 164 | struct weston_geometry geometry = { 165 | .x = self->output->x, 166 | .y = self->output->y, 167 | .width = self->output->width, 168 | .height = self->output->height, 169 | }; 170 | return geometry; 171 | } 172 | 173 | static void 174 | _wh_outputs_output_created(struct wl_listener *listener, void *data) 175 | { 176 | WhOutputs *self = wl_container_of(listener, self, output_create_listener); 177 | struct weston_output *output = data; 178 | 179 | _wh_output_new(self, output); 180 | } 181 | 182 | static void 183 | _wh_outputs_output_destroyed(struct wl_listener *listener, void *data) 184 | { 185 | /* FIXME: we need a way to check that the output is gone for good or just disabled 186 | WhOutputs *self = wl_container_of(listener, self, output_destroy_listener); 187 | struct weston_output *output = data; 188 | 189 | g_hash_table_remove(self->outputs_by_name, output->name); 190 | g_hash_table_remove(self->outputs, output); 191 | */ 192 | } 193 | 194 | WhOutputs * 195 | wh_outputs_new(WhCore *core) 196 | { 197 | WhOutputs *self; 198 | 199 | self = g_new0(WhOutputs, 1); 200 | self->core = core; 201 | 202 | self->outputs = g_hash_table_new_full(NULL, NULL, NULL, _wh_output_free); 203 | self->outputs_by_name = g_hash_table_new(g_str_hash, g_str_equal); 204 | 205 | struct weston_compositor *compositor = wh_core_get_compositor(self->core); 206 | struct weston_output *output; 207 | 208 | wl_list_for_each(output, &compositor->output_list, link) 209 | _wh_output_new(self, output); 210 | 211 | self->output_create_listener.notify = _wh_outputs_output_created; 212 | wl_signal_add(&compositor->output_created_signal, &self->output_create_listener); 213 | 214 | self->output_destroy_listener.notify = _wh_outputs_output_destroyed; 215 | wl_signal_add(&compositor->output_destroyed_signal, &self->output_destroy_listener); 216 | 217 | return self; 218 | } 219 | 220 | void 221 | wh_outputs_free(WhOutputs *self) 222 | { 223 | if ( self == NULL ) 224 | return; 225 | 226 | g_hash_table_unref(self->outputs_by_name); 227 | g_hash_table_unref(self->outputs); 228 | 229 | g_free(self); 230 | } 231 | 232 | WhOutput * 233 | wh_outputs_get(WhOutputs *self, WhOutput *current, WhDirection direction) 234 | { 235 | gint32 cx, cy, dx, dy, tx, ty, x, y, min, max, val; 236 | gboolean vertical; 237 | 238 | dx = current->output->width / 2; 239 | dy = current->output->height / 2; 240 | cx = current->output->x + dx; 241 | cy = current->output->y + dy; 242 | tx = G_MAXINT32; 243 | ty = G_MAXINT32; 244 | 245 | const gchar * const directions[] = { 246 | [WH_DIRECTION_TOP] = "top", 247 | [WH_DIRECTION_BOTTOM] = "bottom", 248 | [WH_DIRECTION_LEFT] = "left", 249 | [WH_DIRECTION_RIGHT] = "right", 250 | }; 251 | 252 | g_debug("Get output on %s of %s (%dx%d+%dx%d): %dx%d (%dx%d)", directions[direction], current->output->name, current->output->width, current->output->height, current->output->x, current->output->y, cx, cy, dx, dy); 253 | GHashTableIter iter; 254 | g_hash_table_iter_init(&iter, self->outputs); 255 | switch ( direction ) 256 | { 257 | case WH_DIRECTION_TOP: 258 | min = G_MININT32; 259 | max = current->output->y; 260 | vertical = TRUE; 261 | break; 262 | case WH_DIRECTION_BOTTOM: 263 | min = current->output->y + current->output->height; 264 | max = G_MAXINT32; 265 | vertical = TRUE; 266 | break; 267 | case WH_DIRECTION_LEFT: 268 | min = G_MININT32; 269 | max = current->output->x; 270 | vertical = FALSE; 271 | break; 272 | case WH_DIRECTION_RIGHT: 273 | min = current->output->x + current->output->width; 274 | max = G_MAXINT32; 275 | vertical = FALSE; 276 | break; 277 | case WH_DIRECTION_PARENT: 278 | case WH_DIRECTION_CHILD: 279 | default: 280 | g_return_val_if_reached(NULL); 281 | } 282 | 283 | WhOutput *output, *target = NULL; 284 | while ( g_hash_table_iter_next(&iter, NULL, (gpointer *) &output) ) 285 | { 286 | if ( current == output ) 287 | continue; 288 | 289 | x = cx - ( output->output->x + output->output->width / 2 ); 290 | x = ABS(x); 291 | y = cy - ( output->output->y + output->output->height / 2 ); 292 | y = ABS(y); 293 | g_debug(" Try %s (%dx%d+%dx%d): %dx%d", output->output->name, output->output->width, output->output->height, output->output->x, output->output->y, x, y); 294 | if ( vertical ) 295 | { 296 | g_debug(" Vertical move, deviation: %d / %d|%d", x, dx, tx); 297 | if ( ( x > dx ) || ( x > tx ) ) 298 | continue; 299 | val = output->output->y; 300 | } 301 | else 302 | { 303 | g_debug(" Horizontal move, deviation: %d / %d|%d", y, dy, ty); 304 | if ( ( y > dy ) || ( y > ty ) ) 305 | continue; 306 | val = output->output->x; 307 | } 308 | g_debug("Check min < val < max: %d < %d < %d", min, val, max); 309 | if ( ( val < min ) || ( val > max ) ) 310 | continue; 311 | 312 | tx = x; 313 | ty = y; 314 | target = output; 315 | } 316 | 317 | if ( target != NULL ) 318 | g_debug(" Found %s", target->output->name); 319 | return target; 320 | } 321 | -------------------------------------------------------------------------------- /compositor/src/outputs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #ifndef __WAYHOUSE_OUTPUTS_H__ 24 | #define __WAYHOUSE_OUTPUTS_H__ 25 | 26 | #include "types.h" 27 | 28 | WhOutputs *wh_outputs_new(WhCore *core); 29 | void wh_outputs_free(WhOutputs *outputs); 30 | 31 | WhOutput *wh_outputs_get(WhOutputs *outputs, WhOutput *output, WhDirection direction); 32 | 33 | void wh_outputs_control(WhOutputs *outputs, WhSeat *seat, WhStateChange state, const gchar *name); 34 | 35 | gboolean wh_output_set_current_workspace(WhOutput *output, WhWorkspace *workspace); 36 | WhWorkspace *wh_output_get_current_workspace(WhOutput *output); 37 | 38 | struct weston_geometry wh_output_get_geometry(WhOutput *self); 39 | 40 | #endif /* __WAYHOUSE_OUTPUTS_H__ */ 41 | -------------------------------------------------------------------------------- /compositor/src/seats.c: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #include "config.h" 24 | 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | 31 | #include "types.h" 32 | #include "wayhouse.h" 33 | #include "containers.h" 34 | #include "seats.h" 35 | 36 | struct _WhSeats { 37 | WhCore *core; 38 | struct wl_listener seat_create_listener; 39 | GHashTable *seats; 40 | }; 41 | 42 | struct _WhSeat { 43 | WhSeats *seats; 44 | struct weston_seat *seat; 45 | struct wl_listener destroy_listener; 46 | }; 47 | 48 | static void 49 | _wh_seat_destroyed(struct wl_listener *listener, void *data) 50 | { 51 | WhSeat *self = wl_container_of(listener, self, destroy_listener); 52 | 53 | g_hash_table_remove(self->seats->seats, self->seat); 54 | } 55 | 56 | static void 57 | _wh_seat_new(WhSeats *seats, struct weston_seat *seat) 58 | { 59 | WhSeat *self; 60 | 61 | self = g_new0(WhSeat, 1); 62 | self->seats = seats; 63 | self->seat = seat; 64 | 65 | g_hash_table_insert(self->seats->seats, seat, self); 66 | self->destroy_listener.notify = _wh_seat_destroyed; 67 | wl_signal_add(&self->seat->destroy_signal, &self->destroy_listener); 68 | } 69 | 70 | static void 71 | _wh_seat_free(gpointer data) 72 | { 73 | WhSeat *self = data; 74 | 75 | wl_list_remove(&self->destroy_listener.link); 76 | 77 | g_free(self); 78 | } 79 | 80 | void 81 | wh_seats_set_focus(WhSeats *self, WhSurface *surface) 82 | { 83 | GHashTableIter iter; 84 | WhSeat *seat; 85 | struct weston_surface *focus = ( surface == NULL ) ? NULL : wh_surface_get_surface(surface); 86 | 87 | g_hash_table_iter_init(&iter, self->seats); 88 | while ( g_hash_table_iter_next(&iter, NULL, (gpointer *) &seat) ) 89 | weston_seat_set_keyboard_focus(seat->seat, focus); 90 | } 91 | 92 | static void 93 | _wh_seats_seat_created(struct wl_listener *listener, void *data) 94 | { 95 | WhSeats *self = wl_container_of(listener, self, seat_create_listener); 96 | struct weston_seat *seat = data; 97 | 98 | _wh_seat_new(self, seat); 99 | } 100 | 101 | WhSeats * 102 | wh_seats_new(WhCore *core) 103 | { 104 | WhSeats *self; 105 | 106 | self = g_new0(WhSeats, 1); 107 | self->core = core; 108 | 109 | self->seats = g_hash_table_new_full(NULL, NULL, NULL, _wh_seat_free); 110 | 111 | struct weston_compositor *compositor = wh_core_get_compositor(self->core); 112 | struct weston_seat *seat; 113 | 114 | wl_list_for_each(seat, &compositor->seat_list, link) 115 | _wh_seat_new(self, seat); 116 | 117 | self->seat_create_listener.notify = _wh_seats_seat_created; 118 | wl_signal_add(&compositor->seat_created_signal, &self->seat_create_listener); 119 | 120 | return self; 121 | } 122 | 123 | void 124 | wh_seats_free(WhSeats *self) 125 | { 126 | if ( self == NULL ) 127 | return; 128 | 129 | g_hash_table_unref(self->seats); 130 | 131 | g_free(self); 132 | } 133 | 134 | WhSeat * 135 | wh_seats_get_from_weston_seat(WhSeats *seats, struct weston_seat *seat) 136 | { 137 | return NULL; 138 | } 139 | -------------------------------------------------------------------------------- /compositor/src/seats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #ifndef __WAYHOUSE_SEATS_H__ 24 | #define __WAYHOUSE_SEATS_H__ 25 | 26 | #include "types.h" 27 | 28 | WhSeats *wh_seats_new(WhCore *core); 29 | void wh_seats_free(WhSeats *seats); 30 | 31 | WhSeat *wh_seats_get_from_weston_seat(WhSeats *seats, struct weston_seat *seat); 32 | 33 | void wh_seats_set_focus(WhSeats *seats, WhSurface *surface); 34 | 35 | #endif /* __WAYHOUSE_SEATS_H__ */ 36 | -------------------------------------------------------------------------------- /compositor/src/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #ifndef __WAYHOUSE_TYPES_H__ 24 | #define __WAYHOUSE_TYPES_H__ 25 | 26 | typedef enum { 27 | WH_ORIENTATION_HORIZONTAL = (0 << 0), 28 | WH_ORIENTATION_VERTICAL = (1 << 0), 29 | WH_ORIENTATION_TOGGLE = (1 << 1), 30 | } WhOrientation; 31 | 32 | typedef enum { 33 | WH_TARGET_PREVIOUS = (0 << 0), 34 | WH_TARGET_NEXT = (1 << 0), 35 | WH_TARGET_BACK_AND_FORTH = (1 << 1), 36 | } WhTarget; 37 | 38 | #define WH_DIRECTION_TREE_MASK (1 << 2) 39 | typedef enum { 40 | WH_DIRECTION_LEFT = ( WH_ORIENTATION_HORIZONTAL | (WH_TARGET_PREVIOUS << 1) ), 41 | WH_DIRECTION_RIGHT = ( WH_ORIENTATION_HORIZONTAL | (WH_TARGET_NEXT << 1) ), 42 | WH_DIRECTION_TOP = ( WH_ORIENTATION_VERTICAL | (WH_TARGET_PREVIOUS << 1) ), 43 | WH_DIRECTION_BOTTOM = ( WH_ORIENTATION_VERTICAL | (WH_TARGET_NEXT << 1) ), 44 | WH_DIRECTION_PARENT = ( WH_ORIENTATION_VERTICAL | (WH_TARGET_PREVIOUS << 1) | WH_DIRECTION_TREE_MASK ), 45 | WH_DIRECTION_CHILD = ( WH_ORIENTATION_VERTICAL | (WH_TARGET_NEXT << 1) | WH_DIRECTION_TREE_MASK ), 46 | } WhDirection; 47 | 48 | typedef enum { 49 | WH_CONTAINER_LAYOUT_TABBED = (0 << 0), 50 | WH_CONTAINER_LAYOUT_SPLIT = (1 << 0), 51 | } WhContainerLayoutType; 52 | 53 | typedef enum { 54 | WH_STATE_ENABLE, 55 | WH_STATE_DISABLE, 56 | WH_STATE_TOGGLE, 57 | } WhStateChange; 58 | 59 | #define WH_WORKSPACE_NO_NUMBER ((guint64) -1) 60 | 61 | typedef struct { 62 | guint64 number; 63 | gchar *name; 64 | } WhWorkspaceConfig; 65 | 66 | typedef struct _WhCore WhCore; 67 | 68 | typedef struct _WhCommands WhCommands; 69 | typedef struct _WhCommand WhCommand; 70 | typedef struct _WhConfig WhConfig; 71 | 72 | typedef struct _WhSeats WhSeats; 73 | typedef struct _WhSeat WhSeat; 74 | 75 | typedef struct _WhWorkspaces WhWorkspaces; 76 | typedef struct _WhSurface WhSurface; 77 | typedef struct _WhWorkspace WhWorkspace; 78 | typedef struct _WhContainer WhContainer; 79 | 80 | typedef struct _WhOutputs WhOutputs; 81 | typedef struct _WhOutput WhOutput; 82 | 83 | typedef struct _WhXwayland WhXwayland; 84 | 85 | 86 | #endif /* __WAYHOUSE_TYPES_H__ */ 87 | -------------------------------------------------------------------------------- /compositor/src/wayhouse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #include "config.h" 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #ifdef G_OS_UNIX 32 | #include 33 | #endif /* G_OS_UNIX */ 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include "types.h" 46 | #include "seats.h" 47 | #include "outputs.h" 48 | #include "containers.h" 49 | #include "commands.h" 50 | #include "config_.h" 51 | #include "xwayland.h" 52 | #include "wayhouse.h" 53 | 54 | struct _WhCore { 55 | GWaterWaylandServerSource *source; 56 | struct wl_display *display; 57 | struct weston_compositor *compositor; 58 | struct weston_desktop *desktop; 59 | struct weston_desktop_api *desktop_api; 60 | struct weston_layer base; 61 | WhCommands *commands; 62 | WhConfig *config; 63 | WhSeats *seats; 64 | WhOutputs *outputs; 65 | WhWorkspaces *workspaces; 66 | WhXwayland *xwayland; 67 | WhSurface *focus; 68 | GMainLoop *loop; 69 | }; 70 | 71 | struct weston_compositor * 72 | wh_core_get_compositor(WhCore *context) 73 | { 74 | return context->compositor; 75 | } 76 | 77 | WhCommands * 78 | wh_core_get_commands(WhCore *context) 79 | { 80 | return context->commands; 81 | } 82 | 83 | WhConfig * 84 | wh_core_get_config(WhCore *context) 85 | { 86 | return context->config; 87 | } 88 | 89 | WhSeats * 90 | wh_core_get_seats(WhCore *context) 91 | { 92 | return context->seats; 93 | } 94 | 95 | WhOutputs * 96 | wh_core_get_outputs(WhCore *context) 97 | { 98 | return context->outputs; 99 | } 100 | 101 | WhWorkspaces * 102 | wh_core_get_workspaces(WhCore *context) 103 | { 104 | return context->workspaces; 105 | } 106 | 107 | WhSurface * 108 | wh_core_get_focus(WhCore *context) 109 | { 110 | return context->focus; 111 | } 112 | 113 | void 114 | wh_core_set_focus(WhCore *context, WhSurface *surface) 115 | { 116 | wh_surface_set_activated(context->focus, FALSE); 117 | context->focus = surface; 118 | wh_seats_set_focus(context->seats, context->focus); 119 | wh_surface_set_activated(context->focus, TRUE); 120 | } 121 | 122 | static int 123 | _wh_log(const char *format, va_list args) 124 | { 125 | gsize l; 126 | gchar *format_; 127 | l = strlen(format); 128 | if ( format[l-1] == '\n' ) 129 | { 130 | format_ = g_alloca(l); 131 | g_snprintf(format_, l, "%s", format); 132 | format = format_; 133 | } 134 | g_logv("libweston", G_LOG_LEVEL_DEBUG, format, args); 135 | return 0; 136 | } 137 | 138 | static gboolean 139 | _wh_listen(WhCore *context, const gchar *socket_name) 140 | { 141 | errno = 0; 142 | if ( socket_name != NULL ) 143 | { 144 | if ( wl_display_add_socket(context->display, socket_name) < 0) 145 | { 146 | g_warning("Couldn’t add socket: %s\n", g_strerror(errno)); 147 | return FALSE; 148 | } 149 | } 150 | else 151 | { 152 | socket_name = wl_display_add_socket_auto(context->display); 153 | if ( socket_name == NULL ) 154 | { 155 | g_warning("Couldn’t add socket: %s\n", g_strerror(errno)); 156 | return FALSE; 157 | } 158 | } 159 | 160 | g_setenv("WAYLAND_DISPLAY", socket_name, TRUE); 161 | g_unsetenv("DISPLAY"); 162 | 163 | return TRUE; 164 | } 165 | 166 | static void 167 | _wh_load_common_plugins(WhCore *context, const gchar * const *plugin) 168 | { 169 | if ( plugin == NULL ) 170 | return; 171 | 172 | for ( ; *plugin != NULL ; ++plugin ) 173 | { 174 | #ifdef LIBWESTON_HAS_COMMON_PLUGINS 175 | if ( weston_compositor_load_plugin(context->compositor, *plugin) < 0 ) 176 | g_warning("Couldn’t load common plugin %s", *plugin); 177 | #else /* ! LIBWESTON_HAS_COMMON_PLUGINS */ 178 | gchar *path; 179 | GModule *mod; 180 | int (*init)(struct weston_compositor *compositor); 181 | 182 | if ( g_path_is_absolute(*plugin) ) 183 | path = g_strdup(*plugin); 184 | else 185 | path = g_build_filename(LIBWESTON_PLUGINS_DIR, *plugin, NULL); 186 | g_debug("Try libweston plugin %s", path); 187 | mod = g_module_open(path, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY); 188 | if ( mod != NULL ) 189 | { 190 | if ( ! g_module_symbol(mod, "weston_plugin_init", (gpointer *) &init) ) 191 | g_debug("Couldn’t find init function for plugin %s", *plugin); 192 | else if ( init(context->compositor) < 0 ) 193 | g_debug("Plugin init failed %s", *plugin); 194 | else 195 | mod = NULL; 196 | if ( mod != NULL ) 197 | g_module_close(mod); 198 | } 199 | else 200 | g_debug("Couldn’t load plugin %s: %s", *plugin, g_module_error()); 201 | g_free(path); 202 | #endif /* ! LIBWESTON_HAS_COMMON_PLUGINS */ 203 | } 204 | } 205 | 206 | static void 207 | _wh_load_weston_plugins(WhCore *context, const gchar * const *plugin) 208 | { 209 | if ( plugin == NULL ) 210 | return; 211 | 212 | for ( ; *plugin != NULL ; ++plugin ) 213 | { 214 | gchar *path; 215 | GModule *mod; 216 | int argc = 0; 217 | int (*init)(struct weston_compositor *compositor, int *argc, char *argv[]); 218 | 219 | if ( g_path_is_absolute(*plugin) ) 220 | path = g_strdup(*plugin); 221 | else 222 | path = g_build_filename(WESTON_PLUGINS_DIR, *plugin, NULL); 223 | g_debug("Try weston plugin %s", path); 224 | mod = g_module_open(path, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY); 225 | if ( mod != NULL ) 226 | { 227 | if ( ! g_module_symbol(mod, "wet_module_init", (gpointer *) &init) ) 228 | { 229 | if ( ! g_module_symbol(mod, "module_init", (gpointer *) &init) ) 230 | g_debug("Couldn’t find init function for plugin %s", *plugin); 231 | else if ( init(context->compositor, &argc, NULL) < 0 ) 232 | g_debug("Plugin init failed %s", *plugin); 233 | else 234 | mod = NULL; 235 | 236 | } 237 | else if ( init(context->compositor, &argc, NULL) < 0 ) 238 | g_debug("Plugin init failed %s", *plugin); 239 | else 240 | mod = NULL; 241 | if ( mod != NULL ) 242 | g_module_close(mod); 243 | } 244 | else 245 | g_debug("Couldn’t load plugin %s: %s", *plugin, g_module_error()); 246 | g_free(path); 247 | } 248 | } 249 | 250 | void 251 | wh_stop(WhCore *context, WhSeat *seat) 252 | { 253 | if ( context->loop != NULL ) 254 | g_main_loop_quit(context->loop); 255 | } 256 | 257 | static void 258 | _wh_exit(struct weston_compositor *compositor) 259 | { 260 | WhCore *context = weston_compositor_get_user_data(compositor); 261 | wh_stop(context, NULL); 262 | } 263 | 264 | #ifdef G_OS_UNIX 265 | static gboolean 266 | _wh_stop(gpointer user_data) 267 | { 268 | wh_stop(user_data, NULL); 269 | return FALSE; 270 | } 271 | #endif /* G_OS_UNIX */ 272 | 273 | int 274 | main(int argc, char *argv[]) 275 | { 276 | #ifdef WAYHOUSE_DEBUG 277 | g_setenv("G_MESSAGES_DEBUG", "all", FALSE); 278 | #endif /* WAYHOUSE_DEBUG */ 279 | 280 | setlocale(LC_ALL, ""); 281 | bindtextdomain(GETTEXT_PACKAGE, WAYHOUSE_LOCALEDIR); 282 | bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); 283 | 284 | if ( ! g_get_filename_charsets(NULL) ) 285 | { 286 | g_warning(PACKAGE_NAME " does not support non-UTF-8 filename encoding"); 287 | return 1; 288 | } 289 | 290 | 291 | if ( ! g_module_supported() ) 292 | { 293 | g_warning("No module support"); 294 | return 2; 295 | } 296 | 297 | WhCore *context; 298 | context = g_new0(WhCore, 1); 299 | 300 | int retval = 0; 301 | GError *error = NULL; 302 | gboolean use_pixman = FALSE; 303 | gchar *runtime_dir = NULL; 304 | gchar *socket_name = NULL; 305 | gchar **common_plugins = NULL; 306 | gchar **weston_plugins = NULL; 307 | gboolean print_version = FALSE; 308 | 309 | GOptionContext *option_context = NULL; 310 | GOptionEntry entries[] = 311 | { 312 | { "use-pixman", 'p', 0, G_OPTION_ARG_NONE, &use_pixman, "Use Pixman rendering", NULL }, 313 | { "socket", 's', 0, G_OPTION_ARG_STRING, &socket_name, "Socket name to use", "" }, 314 | { "common-plugins", 'm', 0, G_OPTION_ARG_STRING_ARRAY, &common_plugins, "Common libweston plugins to load", "" }, 315 | { "weston-plugins", 'w', 0, G_OPTION_ARG_STRING_ARRAY, &weston_plugins, "weston plugins to load", "" }, 316 | { "version", 'V', 0, G_OPTION_ARG_NONE, &print_version, "Print version", NULL }, 317 | { .long_name = NULL } 318 | }; 319 | 320 | option_context = g_option_context_new("- tiling Wayland compositor"); 321 | g_option_context_add_main_entries(option_context, entries, GETTEXT_PACKAGE); 322 | if ( ! g_option_context_parse(option_context, &argc, &argv, &error) ) 323 | { 324 | g_warning("Option parsing failed: %s\n", error->message); 325 | retval = 2; 326 | goto end; 327 | } 328 | g_option_context_free(option_context); 329 | 330 | if ( print_version ) 331 | { 332 | g_printf(PACKAGE_NAME " " WAYHOUSE_VERSION "\n"); 333 | goto end; 334 | } 335 | 336 | runtime_dir = g_build_filename(g_get_user_runtime_dir(), PACKAGE_NAME, NULL); 337 | if ( ( ! g_file_test(runtime_dir, G_FILE_TEST_IS_DIR) ) && ( g_mkdir_with_parents(runtime_dir, 0755) < 0 ) ) 338 | { 339 | g_warning("Couldn't create the run dir '%s': %s", runtime_dir, g_strerror(errno)); 340 | retval = 3; 341 | goto end; 342 | } 343 | 344 | weston_log_set_handler(_wh_log, _wh_log); 345 | 346 | #ifdef G_OS_UNIX 347 | g_unix_signal_add(SIGTERM, _wh_stop, context); 348 | g_unix_signal_add(SIGINT, _wh_stop, context); 349 | 350 | /* Ignore SIGPIPE as it is useless */ 351 | signal(SIGPIPE, SIG_IGN); 352 | #endif /* G_OS_UNIX */ 353 | 354 | context->source = g_water_wayland_server_source_new(NULL); 355 | context->display = g_water_wayland_server_source_get_display(context->source); 356 | context->compositor = weston_compositor_create(context->display, context); 357 | if ( context->compositor == NULL ) 358 | { 359 | g_warning("Couldn’t create compositor"); 360 | goto end; 361 | } 362 | 363 | context->compositor->vt_switching = 1; 364 | context->compositor->exit = _wh_exit; 365 | 366 | weston_layer_init(&context->base, context->compositor); 367 | weston_layer_set_position(&context->base, WESTON_LAYER_POSITION_BACKGROUND); 368 | 369 | context->seats = wh_seats_new(context); 370 | context->workspaces = wh_workspaces_new(context); 371 | context->outputs = wh_outputs_new(context); 372 | 373 | context->commands = wh_commands_new(context); 374 | context->config = wh_config_new(context, use_pixman); 375 | weston_compositor_set_xkb_rule_names(context->compositor, wh_config_get_xkb_names(context->config)); 376 | if ( ! wh_config_load_backend(context->config) ) 377 | goto error; 378 | 379 | context->desktop = weston_desktop_create(context->compositor, &wh_workspaces_desktop_api, context->workspaces); 380 | if ( context->desktop == NULL ) 381 | { 382 | g_warning("Couldn’t create desktop"); 383 | goto error; 384 | } 385 | 386 | if ( ! _wh_listen(context, socket_name) ) 387 | goto error; 388 | 389 | if ( wh_config_get_xwayland(context->config) ) 390 | context->xwayland = wh_xwayland_new(context); 391 | 392 | _wh_load_common_plugins(context, (const gchar * const *) common_plugins); 393 | _wh_load_common_plugins(context, wh_config_get_common_plugins(context->config)); 394 | _wh_load_weston_plugins(context, (const gchar * const *) weston_plugins); 395 | 396 | gchar back_colour[8]; 397 | gchar *back_argv[] = { 398 | "ww-background", 399 | "-c", 400 | back_colour, 401 | NULL 402 | }; 403 | g_snprintf(back_colour, sizeof(back_colour), "#%06x", getpid()); 404 | g_debug("Spawn %s %s %s", back_argv[0], back_argv[1], back_argv[2]); 405 | g_spawn_async(NULL, back_argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); 406 | 407 | weston_compositor_wake(context->compositor); 408 | 409 | context->loop = g_main_loop_new(NULL, FALSE); 410 | g_main_loop_run(context->loop); 411 | g_main_loop_unref(context->loop); 412 | 413 | if ( wh_config_get_xwayland(context->config) ) 414 | wh_xwayland_free(context->xwayland); 415 | 416 | error: 417 | weston_desktop_destroy(context->desktop); 418 | weston_compositor_destroy(context->compositor); 419 | 420 | wh_config_free(context->config); 421 | wh_commands_free(context->commands); 422 | wh_outputs_free(context->outputs); 423 | wh_workspaces_free(context->workspaces); 424 | wh_seats_free(context->seats); 425 | 426 | g_water_wayland_server_source_free(context->source); 427 | 428 | end: 429 | g_strfreev(weston_plugins); 430 | g_strfreev(common_plugins); 431 | g_free(runtime_dir); 432 | g_free(context); 433 | 434 | return retval; 435 | } 436 | -------------------------------------------------------------------------------- /compositor/src/wayhouse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #ifndef __WAYHOUSE_WAYHOUSE_H__ 24 | #define __WAYHOUSE_WAYHOUSE_H__ 25 | 26 | #include "types.h" 27 | 28 | struct weston_compositor *wh_core_get_compositor(WhCore *context); 29 | WhConfig *wh_core_get_config(WhCore *core); 30 | WhCommands *wh_core_get_commands(WhCore *core); 31 | WhSeats *wh_core_get_seats(WhCore *core); 32 | WhOutputs *wh_core_get_outputs(WhCore *core); 33 | WhWorkspaces *wh_core_get_workspaces(WhCore *core); 34 | WhSurface *wh_core_get_focus(WhCore *core); 35 | 36 | void wh_core_set_focus(WhCore *core, WhSurface *surface); 37 | 38 | void wh_stop(WhCore *core, WhSeat *seat); 39 | 40 | #endif /* __WAYHOUSE_WAYHOUSE_H__ */ 41 | -------------------------------------------------------------------------------- /compositor/src/xwayland.c: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #include "config.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #include "types.h" 35 | #include "wayhouse.h" 36 | #include "xwayland.h" 37 | 38 | struct _WhXwayland { 39 | WhCore *core; 40 | const struct weston_xwayland_api *api; 41 | struct weston_xwayland *xwayland; 42 | GPid pid; 43 | struct wl_client *client; 44 | int wm_fd; 45 | }; 46 | 47 | static void 48 | _wh_xwayland_spawn_child(gpointer user_data) 49 | { 50 | signal(SIGUSR1, SIG_IGN); 51 | } 52 | 53 | static gboolean 54 | _wh_xwayland_sigusr1(gpointer user_data) 55 | { 56 | WhXwayland *self = user_data; 57 | self->api->xserver_loaded(self->xwayland, self->client, self->wm_fd); 58 | return G_SOURCE_REMOVE; 59 | } 60 | 61 | static void 62 | _wh_xwayland_child_watch(GPid pid, gint status, gpointer user_data) 63 | { 64 | WhXwayland *self = user_data; 65 | 66 | self->api->xserver_exited(self->xwayland, status); 67 | 68 | self->client = NULL; 69 | 70 | g_spawn_close_pid(self->pid); 71 | self->pid = -1; 72 | } 73 | 74 | static pid_t 75 | _wh_xwayland_spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd) 76 | { 77 | WhXwayland *self = user_data; 78 | int wayland_pair[2], x_pair[2]; 79 | int wayland_fd, x_fd; 80 | gchar wayland_fd_str[8], abstract_fd_str[8], unix_fd_str[8], x_fd_str[8]; 81 | 82 | if ( socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, wayland_pair) < 0 ) 83 | { 84 | weston_log("wl connection socketpair failed\n"); 85 | g_warning("Couldn't create Wayland socket pair: %s", g_strerror(errno)); 86 | return -1; 87 | } 88 | 89 | if ( socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, x_pair) < 0 ) 90 | { 91 | g_warning("Couldn't create X WM socket pair: %s", g_strerror(errno)); 92 | return -1; 93 | } 94 | 95 | #define check_dup(a, b) G_STMT_START { \ 96 | a = dup(b); \ 97 | if ( a < 0 ) \ 98 | { \ 99 | g_warning("Couldn't duplicate fd: %s", g_strerror(errno)); \ 100 | return -1; \ 101 | } \ 102 | } G_STMT_END 103 | 104 | /* Remove CLOEXEC */ 105 | check_dup(wayland_fd, wayland_pair[1]); 106 | check_dup(abstract_fd, abstract_fd); 107 | check_dup(unix_fd, unix_fd); 108 | check_dup(x_fd, x_pair[1]); 109 | 110 | #undef check_dup 111 | 112 | close(wayland_pair[1]); 113 | close(x_pair[1]); 114 | 115 | #define fd_to_str(name) g_snprintf(name##_fd_str, sizeof(name##_fd_str), "%d", name##_fd); 116 | fd_to_str(wayland); 117 | fd_to_str(abstract); 118 | fd_to_str(unix); 119 | fd_to_str(x); 120 | #undef fd_to_str 121 | 122 | gchar *argv[] = { 123 | "Xwayland", 124 | (gchar *) display, 125 | "-rootless", 126 | "-listen", abstract_fd_str, 127 | "-listen", unix_fd_str, 128 | "-wm", x_fd_str, 129 | "-terminate", 130 | NULL 131 | }; 132 | 133 | gchar **envp = g_get_environ(); 134 | envp = g_environ_setenv(envp, "WAYLAND_SOCKET", wayland_fd_str, TRUE); 135 | 136 | GError *error = NULL; 137 | 138 | if ( g_spawn_async(NULL, argv, envp, G_SPAWN_SEARCH_PATH | G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_DO_NOT_REAP_CHILD, _wh_xwayland_spawn_child, self, &self->pid, &error) ) 139 | { 140 | g_child_watch_add(self->pid, _wh_xwayland_child_watch, self); 141 | g_unix_signal_add(SIGUSR1, _wh_xwayland_sigusr1, self); 142 | self->client = wl_client_create(wh_core_get_compositor(self->core)->wl_display, wayland_pair[0]); 143 | self->wm_fd = x_pair[0]; 144 | } 145 | else 146 | { 147 | g_warning("Couldn't spawn Xwayland: %s", error->message); 148 | g_clear_error(&error); 149 | 150 | self->pid = -1; 151 | close(wayland_pair[0]); 152 | close(x_pair[0]); 153 | } 154 | 155 | /* Close child-side fds */ 156 | close(wayland_fd); 157 | close(x_fd); 158 | close(abstract_fd); 159 | close(unix_fd); 160 | 161 | return self->pid; 162 | } 163 | 164 | WhXwayland * 165 | wh_xwayland_new(WhCore *core) 166 | { 167 | WhXwayland *self; 168 | struct weston_compositor *compositor; 169 | 170 | self = g_new0(WhXwayland, 1); 171 | self->core = core; 172 | self->pid = -1; 173 | 174 | compositor = wh_core_get_compositor(self->core); 175 | 176 | if ( weston_compositor_load_xwayland(compositor) < 0 ) 177 | return NULL; 178 | 179 | self->api = weston_xwayland_get_api(compositor); 180 | if ( self->api == NULL ) 181 | { 182 | g_warning("Failed to get the xwayland module API."); 183 | return NULL; 184 | } 185 | 186 | self->xwayland = self->api->get(compositor); 187 | if ( self->xwayland == NULL) 188 | { 189 | g_warning("Failed to get the xwayland object."); 190 | return NULL; 191 | } 192 | 193 | if ( self->api->listen(self->xwayland, self, _wh_xwayland_spawn_xserver) < 0 ) 194 | return NULL; 195 | 196 | return self; 197 | } 198 | 199 | void 200 | wh_xwayland_free(WhXwayland *self) 201 | { 202 | if ( self->pid != -1 ) 203 | g_spawn_close_pid(self->pid); 204 | 205 | g_free(self); 206 | } 207 | -------------------------------------------------------------------------------- /compositor/src/xwayland.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #ifndef __WAYHOUSE_XWAYLAND_H__ 24 | #define __WAYHOUSE_XWAYLAND_H__ 25 | 26 | #include "types.h" 27 | 28 | WhXwayland *wh_xwayland_new(WhCore *core); 29 | void wh_xwayland_free(WhXwayland *xwayland); 30 | 31 | #endif /* __WAYHOUSE_XWAYLAND_H__ */ 32 | -------------------------------------------------------------------------------- /dock/meson.build: -------------------------------------------------------------------------------- 1 | executable('wh-dock', files( 2 | 'src/dock.c', 3 | ) + [ 4 | wayland_scanner_client.process(join_paths(ww_protocol_dir, 'unstable', 'dock-manager', 'dock-manager-unstable-v2.xml')), 5 | wayland_scanner_code.process(join_paths(ww_protocol_dir, 'unstable', 'dock-manager', 'dock-manager-unstable-v2.xml')), 6 | ], 7 | c_args: [ 8 | '-DG_LOG_DOMAIN="wh-dock"', 9 | ], 10 | dependencies: [ pango, cairo, libwhclient, libgwater_wayland, gio_platform, gio, libnkutils, glib ], 11 | install: true, 12 | ) 13 | -------------------------------------------------------------------------------- /dock/src/dock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #include "config.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include "client.h" 44 | #include "dock-manager-unstable-v2-client-protocol.h" 45 | 46 | /* Supported interface versions */ 47 | #define WL_COMPOSITOR_INTERFACE_VERSION 3 48 | #define WW_DOCK_MANAGER_INTERFACE_VERSION 1 49 | #define WL_SHM_INTERFACE_VERSION 1 50 | #define WL_SEAT_INTERFACE_VERSION 5 51 | #define WL_OUTPUT_INTERFACE_VERSION 2 52 | 53 | typedef enum { 54 | WW_DOCK_GLOBAL_COMPOSITOR, 55 | WW_DOCK_GLOBAL_DOCK_MANAGER, 56 | WW_DOCK_GLOBAL_SHM, 57 | _WW_DOCK_GLOBAL_SIZE, 58 | } WhDockGlobalName; 59 | 60 | typedef enum { 61 | WH_DOCK_CHILD_STATE_START = 0, 62 | WH_DOCK_CHILD_STATE_LINE_START, 63 | WH_DOCK_CHILD_STATE_SECTION, 64 | WH_DOCK_CHILD_STATE_SECTION_LENGTH, 65 | } WhDockChildState; 66 | 67 | typedef struct { 68 | GSubprocess *process; 69 | WhDockChildState state; 70 | GInputStream *stdout; 71 | GDataInputStream *data_stdout; 72 | gchar buf; 73 | gboolean stopped; 74 | gboolean urgent; 75 | } WhDockChild; 76 | 77 | typedef struct _WhDock WhDock; 78 | typedef struct { 79 | WhClient *client; 80 | struct wl_display *display; 81 | struct wl_registry *registry; 82 | uint32_t global_name; 83 | struct zww_dock_manager_v2 *dock_manager; 84 | WhDockChild child; 85 | NkColour background_colour; 86 | NkColour text_colour; 87 | WhDock *dock; 88 | } WhDockContext; 89 | 90 | typedef struct { 91 | PangoLayout *text; 92 | } WhText; 93 | 94 | struct _WhDock { 95 | WhDockContext *context; 96 | WhClientSurface *surface; 97 | struct zww_dock_v2 *dock; 98 | struct { 99 | gint ascent; 100 | } text; 101 | WhClientSize padding; 102 | WhClientSize size; 103 | guint trigger_handle; 104 | gsize pending; 105 | GList *pending_texts; 106 | GList *texts; 107 | }; 108 | 109 | static void 110 | _wh_dock_dock_protocol_configure(void *data, struct zww_dock_v2 *dock, int32_t min_width, int32_t min_height, int32_t max_width, int32_t max_height, enum zww_dock_manager_v2_position position) 111 | { 112 | WhDock *self = data; 113 | 114 | switch ( position ) 115 | { 116 | case ZWW_DOCK_MANAGER_V2_POSITION_TOP: 117 | case ZWW_DOCK_MANAGER_V2_POSITION_BOTTOM: 118 | break; 119 | case ZWW_DOCK_MANAGER_V2_POSITION_LEFT: 120 | case ZWW_DOCK_MANAGER_V2_POSITION_RIGHT: 121 | case ZWW_DOCK_MANAGER_V2_POSITION_DEFAULT: 122 | g_return_if_reached(); 123 | } 124 | 125 | PangoFontMetrics *metrics; 126 | gint height, em; 127 | 128 | metrics = wh_client_get_font_metrics(self->context->client); 129 | self->text.ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; 130 | height = ( pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics) ) / PANGO_SCALE; 131 | em = pango_font_metrics_get_approximate_char_width(metrics) / PANGO_SCALE; 132 | pango_font_metrics_unref(metrics); 133 | 134 | self->padding.width = em; 135 | self->padding.height = 2 * em / 3; 136 | self->size.width = max_width; 137 | self->size.height = MAX(min_height, height + self->padding.height * 2); 138 | } 139 | 140 | static const struct zww_dock_v2_listener _wh_dock_dock_interface = { 141 | .configure = _wh_dock_dock_protocol_configure, 142 | }; 143 | 144 | static void 145 | _wh_dock_frame_callback(void *data, struct wl_callback *callback, uint32_t time) 146 | { 147 | WhDock *self = data; 148 | 149 | wl_callback_destroy(callback); 150 | 151 | if ( ( self->pending > 2 ) && self->context->child.stopped ) 152 | { 153 | g_subprocess_send_signal(self->context->child.process, SIGUSR1); 154 | self->context->child.stopped = FALSE; 155 | } 156 | --self->pending; 157 | } 158 | 159 | static const struct wl_callback_listener _wh_dock_frame_wl_callback_listener = { 160 | .done = _wh_dock_frame_callback, 161 | }; 162 | 163 | static gboolean 164 | _wh_dock_draw(gpointer user_data) 165 | { 166 | WhDock *self = user_data; 167 | WhClientBuffer *buffer; 168 | 169 | self->trigger_handle = 0; 170 | 171 | buffer = wh_client_surface_get_buffer(self->surface); 172 | if ( buffer == NULL ) 173 | return FALSE; 174 | if ( ( self->pending > 1 ) && ( ! self->context->child.stopped ) ) 175 | { 176 | g_subprocess_send_signal(self->context->child.process, SIGUSR2); 177 | self->context->child.stopped = TRUE; 178 | } 179 | 180 | cairo_t *cr; 181 | 182 | cr = cairo_create(wh_client_buffer_get_surface(buffer)); 183 | 184 | cairo_set_source_rgba(cr, self->context->background_colour.red, self->context->background_colour.green, self->context->background_colour.blue, self->context->background_colour.alpha); 185 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); 186 | cairo_paint(cr); 187 | 188 | gint x = self->size.width - self->padding.width; 189 | gint y; 190 | gint text_width; 191 | gint text_height; 192 | gint text_baseline; 193 | cairo_set_source_rgba(cr, self->context->text_colour.red, self->context->text_colour.green, self->context->text_colour.blue, self->context->text_colour.alpha); 194 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); 195 | 196 | GList *text_; 197 | for ( text_ = self->texts ; text_ != NULL ; text_ = g_list_next(text_) ) 198 | { 199 | PangoLayout *text = text_->data; 200 | pango_layout_get_pixel_size(text, &text_width, &text_height); 201 | text_baseline = pango_layout_get_baseline(text) / PANGO_SCALE; 202 | x -= text_width; 203 | y = self->padding.height + self->text.ascent - text_baseline; 204 | cairo_move_to(cr, x, y); 205 | pango_cairo_update_layout(cr, text); 206 | pango_cairo_show_layout(cr, text); 207 | if ( g_list_next(text_) != NULL ) 208 | { 209 | x -= self->padding.width; 210 | cairo_rectangle(cr, x, self->padding.height, 0.5, self->size.height - 2 * self->padding.height); 211 | cairo_fill(cr); 212 | x -= (self->padding.width - 1); 213 | } 214 | } 215 | g_list_free_full(self->texts, g_object_unref); 216 | self->texts = NULL; 217 | 218 | cairo_destroy(cr); 219 | 220 | struct wl_callback *frame_cb; 221 | 222 | ++self->pending; 223 | wh_client_buffer_commit(buffer, &frame_cb); 224 | wl_callback_add_listener(frame_cb, &_wh_dock_frame_wl_callback_listener, self); 225 | 226 | return FALSE; 227 | } 228 | 229 | static void 230 | _wh_dock_trigger_drawing(WhDock *self) 231 | { 232 | if ( self->trigger_handle > 0 ) 233 | return; 234 | self->trigger_handle = g_idle_add(_wh_dock_draw, self); 235 | } 236 | 237 | static WhDock * 238 | _wh_dock_create(WhDockContext *context) 239 | { 240 | WhDock *self; 241 | self = g_new0(WhDock, 1); 242 | 243 | self->context = context; 244 | self->surface = wh_client_surface_new(self->context->client); 245 | if ( self->surface == NULL ) 246 | { 247 | g_warning("Could not create surface"); 248 | g_free(self); 249 | return NULL; 250 | } 251 | 252 | self->dock = zww_dock_manager_v2_create_dock(self->context->dock_manager, wh_client_surface_get_surface(self->surface), NULL, ZWW_DOCK_MANAGER_V2_POSITION_BOTTOM); 253 | if ( self->dock == NULL ) 254 | { 255 | g_warning("Could not create dock"); 256 | g_free(self); 257 | return NULL; 258 | } 259 | 260 | zww_dock_v2_add_listener(self->dock, &_wh_dock_dock_interface, self); 261 | wl_display_roundtrip(self->context->display); 262 | 263 | g_debug("SIZE %dx%d", self->size.width, self->size.height); 264 | 265 | if ( ( self->size.width < 1 ) || ( self->size.height < 1 ) || ( ! wh_client_surface_resize(self->surface, self->size) ) ) 266 | { 267 | zww_dock_v2_destroy(self->dock); 268 | wh_client_surface_free(self->surface); 269 | g_free(self); 270 | return NULL; 271 | } 272 | 273 | return self; 274 | } 275 | 276 | static void 277 | _wh_dock_free(WhDock *self) 278 | { 279 | zww_dock_v2_destroy(self->dock); 280 | wh_client_surface_free(self->surface); 281 | g_free(self); 282 | } 283 | 284 | static void _wh_dock_spawn_status_generator(WhDockContext *self); 285 | 286 | static void 287 | _wh_dock_child_existed(GObject *obj, GAsyncResult *res, gpointer user_data) 288 | { 289 | WhDockContext *self = user_data; 290 | GError *error = NULL; 291 | if ( g_subprocess_wait_check_finish(G_SUBPROCESS(obj), res, &error) ) 292 | return; 293 | 294 | if ( self->child.data_stdout != NULL ) 295 | { 296 | g_object_unref(self->child.data_stdout); 297 | self->child.data_stdout = NULL; 298 | } 299 | _wh_dock_spawn_status_generator(self); 300 | } 301 | 302 | static void 303 | _wh_dock_child_read_line_callback(GObject *obj, GAsyncResult *res, gpointer user_data) 304 | { 305 | WhDockContext *self = user_data; 306 | GError *error = NULL; 307 | gchar *line; 308 | 309 | line = g_data_input_stream_read_line_finish_utf8(G_DATA_INPUT_STREAM(obj), res, NULL, &error); 310 | if ( line == NULL ) 311 | { 312 | if ( error == NULL) 313 | return; 314 | g_subprocess_force_exit(self->child.process); 315 | } 316 | 317 | if ( self->child.buf != '\0' ) 318 | { 319 | gchar *tmp, buf[] = { self->child.buf, '\0' }; 320 | tmp = g_strconcat(buf, line, NULL); 321 | g_free(line); 322 | line = tmp; 323 | self->child.buf = '\0'; 324 | } 325 | g_debug("Read line: %s", line); 326 | if ( self->dock->texts == NULL ) 327 | self->dock->texts = g_list_prepend(self->dock->texts, wh_client_text_new(self->client, line, -1)); 328 | else 329 | { 330 | g_object_unref(self->dock->texts->data); 331 | self->dock->texts->data = wh_client_text_new(self->client, line, -1); 332 | } 333 | _wh_dock_trigger_drawing(self->dock); 334 | g_data_input_stream_read_line_async(self->child.data_stdout, G_PRIORITY_DEFAULT, NULL, _wh_dock_child_read_line_callback, self); 335 | } 336 | 337 | static void 338 | _wh_dock_child_read_callback(GObject *obj, GAsyncResult *res, gpointer user_data) 339 | { 340 | WhDockContext *self = user_data; 341 | GError *error = NULL; 342 | GBytes *bytes; 343 | 344 | bytes = g_input_stream_read_bytes_finish(G_INPUT_STREAM(obj), res, &error); 345 | if ( bytes == NULL ) 346 | { 347 | g_warning("Couldn’t read child output: %s", error->message); 348 | g_clear_error(&error); 349 | goto error; 350 | } 351 | 352 | gsize to_read = 0; 353 | switch ( self->child.state ) 354 | { 355 | case WH_DOCK_CHILD_STATE_START: 356 | { 357 | const guchar *type; 358 | 359 | type = g_bytes_get_data(bytes, NULL); 360 | switch ( *type ) 361 | { 362 | case '\0': 363 | self->child.state = WH_DOCK_CHILD_STATE_LINE_START; 364 | to_read = 1; 365 | break; 366 | default: 367 | self->child.buf = *type; 368 | g_bytes_unref(bytes); 369 | self->child.data_stdout = g_data_input_stream_new(self->child.stdout); 370 | g_data_input_stream_read_line_async(self->child.data_stdout, G_PRIORITY_DEFAULT, NULL, _wh_dock_child_read_line_callback, self); 371 | return; 372 | } 373 | } 374 | break; 375 | case WH_DOCK_CHILD_STATE_LINE_START: 376 | { 377 | const guchar *type; 378 | 379 | type = g_bytes_get_data(bytes, NULL); 380 | switch ( *type ) 381 | { 382 | case 's': 383 | self->child.state = WH_DOCK_CHILD_STATE_SECTION; 384 | to_read = sizeof(guint64); 385 | break; 386 | case 'u': 387 | self->child.urgent = TRUE; 388 | to_read = 1; 389 | break; 390 | case '\0': 391 | g_list_free_full(self->dock->texts, g_object_unref); 392 | self->dock->texts = self->dock->pending_texts; 393 | self->dock->pending_texts = NULL; 394 | if ( self->child.urgent && self->child.stopped ) 395 | zww_dock_v2_show(self->dock->dock); 396 | self->child.urgent = FALSE; 397 | _wh_dock_trigger_drawing(self->dock); 398 | to_read = 1; 399 | break; 400 | } 401 | } 402 | break; 403 | case WH_DOCK_CHILD_STATE_SECTION: 404 | { 405 | const guint64 *length; 406 | length = g_bytes_get_data(bytes, NULL); 407 | self->child.state = WH_DOCK_CHILD_STATE_SECTION_LENGTH; 408 | to_read = GUINT64_FROM_BE(*length); 409 | } 410 | break; 411 | case WH_DOCK_CHILD_STATE_SECTION_LENGTH: 412 | { 413 | PangoLayout *text; 414 | const gchar *data; 415 | gsize length; 416 | data = g_bytes_get_data(bytes, &length); 417 | text = wh_client_text_new(self->client, data, length); 418 | self->dock->pending_texts = g_list_prepend(self->dock->pending_texts, text); 419 | self->child.state = WH_DOCK_CHILD_STATE_LINE_START; 420 | to_read = 1; 421 | } 422 | break; 423 | } 424 | 425 | g_bytes_unref(bytes); 426 | 427 | if ( to_read > 0 ) 428 | g_input_stream_read_bytes_async(self->child.stdout, to_read, G_PRIORITY_DEFAULT, NULL, _wh_dock_child_read_callback, self); 429 | else 430 | error: 431 | g_subprocess_force_exit(self->child.process); 432 | } 433 | 434 | static void 435 | _wh_dock_spawn_status_generator(WhDockContext *self) 436 | { 437 | GError *error = NULL; 438 | gchar *child_argv[] = { 439 | "j4status", 440 | "-o", "pango", 441 | NULL 442 | }; 443 | 444 | self->child.process = g_subprocess_newv((const gchar * const *) child_argv, G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE, &error); 445 | if ( self->child.process == NULL ) 446 | { 447 | g_warning("Couldn’t launch child: %s", error->message); 448 | g_clear_error(&error); 449 | return; 450 | } 451 | 452 | self->child.stdout = g_subprocess_get_stdout_pipe(self->child.process); 453 | g_input_stream_read_bytes_async(self->child.stdout, 1, G_PRIORITY_DEFAULT, NULL, _wh_dock_child_read_callback, self); 454 | g_subprocess_wait_check_async(self->child.process, NULL, _wh_dock_child_existed, self); 455 | } 456 | 457 | static void 458 | _wh_dock_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) 459 | { 460 | WhDockContext *self = data; 461 | 462 | if ( g_strcmp0(interface, "zww_dock_manager_v2") == 0 ) 463 | { 464 | self->global_name = name; 465 | self->dock_manager = wl_registry_bind(registry, name, &zww_dock_manager_v2_interface, WW_DOCK_MANAGER_INTERFACE_VERSION); 466 | } 467 | } 468 | 469 | static void 470 | _wh_dock_registry_handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) 471 | { 472 | WhDockContext *self = data; 473 | 474 | if ( self->global_name == name ) 475 | { 476 | self->global_name = 0; 477 | zww_dock_manager_v2_destroy(self->dock_manager); 478 | self->dock_manager = NULL; 479 | } 480 | } 481 | 482 | static const struct wl_registry_listener _wh_dock_registry_listener = { 483 | .global = _wh_dock_registry_handle_global, 484 | .global_remove = _wh_dock_registry_handle_global_remove, 485 | }; 486 | 487 | static gboolean 488 | _wh_dock_parse_colour(const gchar *option_name, const gchar *value, gpointer data, GError **error) 489 | { 490 | WhDockContext *self = data; 491 | NkColour *colour; 492 | if ( option_name[1] == '-' ) 493 | option_name += 2; 494 | else 495 | option_name += 1; 496 | switch ( option_name[0] ) 497 | { 498 | case 'b': 499 | colour = &self->background_colour; 500 | break; 501 | case 't': 502 | colour = &self->text_colour; 503 | break; 504 | default: 505 | g_return_val_if_reached(FALSE); 506 | } 507 | return nk_colour_parse(value, colour); 508 | } 509 | 510 | int 511 | main(int argc, char *argv[]) 512 | { 513 | static WhDockContext self_; 514 | WhDockContext *self = &self_; 515 | 516 | setlocale(LC_ALL, ""); 517 | 518 | int retval = 0; 519 | GError *error = NULL; 520 | 521 | self->client = wh_client_new(); 522 | 523 | self->background_colour.alpha = 1.0; 524 | self->text_colour.red = 1.0; 525 | self->text_colour.green = 1.0; 526 | self->text_colour.blue = 1.0; 527 | self->text_colour.alpha = 1.0; 528 | 529 | GOptionContext *option_context = NULL; 530 | GOptionGroup *option_group = NULL; 531 | GOptionEntry entries[] = 532 | { 533 | { "background-colour", 'b', 0, G_OPTION_ARG_CALLBACK, _wh_dock_parse_colour, "Colour to use as background, defaults to #000000", "" }, 534 | { "text-colour", 't', 0, G_OPTION_ARG_CALLBACK, _wh_dock_parse_colour, "Colour to use for the text, defaults to #FFFFFF", "" }, 535 | { .long_name = NULL } 536 | }; 537 | 538 | option_context = g_option_context_new("- "); 539 | option_group = g_option_group_new("", "", "", self, NULL); 540 | g_option_group_add_entries(option_group, entries); 541 | g_option_group_set_translation_domain(option_group, GETTEXT_PACKAGE); 542 | g_option_context_set_main_group(option_context, option_group); 543 | wh_client_add_option_group(self->client, option_context); 544 | if ( ! g_option_context_parse(option_context, &argc, &argv, &error) ) 545 | { 546 | g_warning("Option parsing failed: %s\n", error->message); 547 | retval = 2; 548 | goto end; 549 | } 550 | g_option_context_free(option_context); 551 | 552 | self->display = wh_client_get_display(self->client); 553 | self->registry = wl_display_get_registry(self->display); 554 | wl_registry_add_listener(self->registry, &_wh_dock_registry_listener, self); 555 | wl_display_roundtrip(self->display); 556 | 557 | if ( self->dock_manager == NULL ) 558 | { 559 | wh_client_free(self->client); 560 | g_warning("No wh_dock_manager interface provided by the compositor"); 561 | return 4; 562 | } 563 | 564 | self->dock = _wh_dock_create(self); 565 | if ( self->dock == NULL ) 566 | return 5; 567 | 568 | _wh_dock_spawn_status_generator(self); 569 | 570 | retval = wh_client_run(self->client); 571 | 572 | g_subprocess_send_signal(self->child.process, SIGTERM); 573 | g_subprocess_wait(self->child.process, NULL, NULL); 574 | 575 | end: 576 | return retval; 577 | } 578 | -------------------------------------------------------------------------------- /libwhclient/include/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #ifndef __WAYHOUSE_CLIENT_H__ 24 | #define __WAYHOUSE_CLIENT_H__ 25 | 26 | typedef struct { 27 | gint32 width; 28 | gint32 height; 29 | } WhClientSize; 30 | 31 | typedef struct _WhClient WhClient; 32 | typedef struct _WhClientSurface WhClientSurface; 33 | typedef struct _WhClientBuffer WhClientBuffer; 34 | 35 | WhClient *wh_client_new(void); 36 | void wh_client_free(WhClient *client); 37 | 38 | void wh_client_add_option_group(WhClient *client, GOptionContext *option_context); 39 | gint wh_client_run(WhClient *client); 40 | 41 | struct wl_display *wh_client_get_display(WhClient *client); 42 | PangoFontMetrics *wh_client_get_font_metrics(WhClient *client); 43 | 44 | PangoLayout *wh_client_text_new(WhClient *self, const gchar *text, gsize length); 45 | 46 | WhClientSurface *wh_client_surface_new(WhClient *client); 47 | void wh_client_surface_free(WhClientSurface *surface); 48 | struct wl_surface *wh_client_surface_get_surface(WhClientSurface *surface); 49 | 50 | gboolean wh_client_surface_resize(WhClientSurface *surface, WhClientSize size); 51 | WhClientBuffer *wh_client_surface_get_buffer(WhClientSurface *surface); 52 | void wh_client_buffer_commit(WhClientBuffer *buffer, struct wl_callback **frame_callback); 53 | 54 | cairo_surface_t *wh_client_buffer_get_surface(WhClientBuffer *buffer); 55 | 56 | #endif /* __WAYHOUSE_CLIENT_H__ */ 57 | -------------------------------------------------------------------------------- /libwhclient/meson.build: -------------------------------------------------------------------------------- 1 | libwhclient_inc = include_directories('include') 2 | libwhclient_deps = [ pango, cairo, libgwater_wayland, wayland_client, libnkutils, glib ] 3 | libwhclient_lib = static_library('libwhclient', files( 4 | 'src/client.c' 5 | ), 6 | c_args: [ 7 | '-DG_LOG_DOMAIN="libwhclient"' 8 | ], 9 | include_directories: libwhclient_inc, 10 | dependencies: libwhclient_deps, 11 | ) 12 | 13 | libwhclient = declare_dependency(link_with: libwhclient_lib, include_directories: libwhclient_inc, dependencies: libwhclient_deps) 14 | -------------------------------------------------------------------------------- /libwhclient/src/client.c: -------------------------------------------------------------------------------- 1 | /* 2 | * WayHouse - A Wayland compositor based on libweston 3 | * 4 | * Copyright © 2016-2017 Quentin "Sardem FF7" Glidic 5 | * 6 | * This file is part of WayHouse. 7 | * 8 | * WayHouse is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WayHouse is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WayHouse. If not, see . 20 | * 21 | */ 22 | 23 | #include "config.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "client.h" 42 | 43 | typedef struct _WhClientBufferPool WhClientBufferPool; 44 | 45 | /* Supported interface versions */ 46 | #define WL_COMPOSITOR_INTERFACE_VERSION 3 47 | #define WL_SHM_INTERFACE_VERSION 1 48 | #define WL_SEAT_INTERFACE_VERSION 5 49 | #define WL_OUTPUT_INTERFACE_VERSION 2 50 | 51 | #define WAYLAND_OUTPUTS_MAX_NUMBER 32 52 | 53 | typedef enum { 54 | WW_DOCK_GLOBAL_COMPOSITOR, 55 | WW_DOCK_GLOBAL_SHM, 56 | _WW_DOCK_GLOBAL_SIZE, 57 | } WhGlobalName; 58 | 59 | struct _WhClient { 60 | gchar *runtime_dir; 61 | GMainLoop *loop; 62 | GWaterWaylandSource *source; 63 | struct wl_display *display; 64 | struct wl_registry *registry; 65 | uint32_t global_names[_WW_DOCK_GLOBAL_SIZE]; 66 | struct wl_compositor *compositor; 67 | struct wl_shm *shm; 68 | gint64 buffer_count; 69 | struct { 70 | gchar *theme_name; 71 | gchar **name; 72 | struct wl_cursor_theme *theme; 73 | struct wl_cursor *cursor; 74 | struct wl_cursor_image *image; 75 | struct wl_surface *surface; 76 | struct wl_callback *frame_cb; 77 | } cursor; 78 | gboolean print_version; 79 | GHashTable *seats; 80 | GHashTable *outputs; 81 | PangoContext *pango_context; 82 | }; 83 | 84 | typedef struct { 85 | WhClient *context; 86 | uint32_t global_name; 87 | struct wl_seat *seat; 88 | struct wl_pointer *pointer; 89 | } WhSeat; 90 | 91 | typedef struct { 92 | WhClient *context; 93 | uint32_t global_name; 94 | struct wl_output *output; 95 | int32_t width; 96 | int32_t height; 97 | int32_t scale; 98 | } WhOutput; 99 | 100 | struct _WhClientBuffer { 101 | WhClientBufferPool *pool; 102 | struct wl_buffer *buffer; 103 | //guint8 *data; 104 | cairo_surface_t *cairo_surface; 105 | //gsize size; 106 | gboolean released; 107 | }; 108 | 109 | struct _WhClientBufferPool { 110 | WhClient *client; 111 | WhClientSurface *surface; 112 | gint32 scale; 113 | guint8 *data; 114 | gsize size; 115 | gboolean to_free; 116 | WhClientBuffer *buffers; 117 | }; 118 | 119 | typedef struct { 120 | PangoLayout *text; 121 | } WhText; 122 | 123 | struct _WhClientSurface { 124 | WhClient *context; 125 | struct wl_list link; 126 | struct wl_surface *surface; 127 | WhClientBufferPool *pool; 128 | WhClientSize size; 129 | WhOutput *outputs[WAYLAND_OUTPUTS_MAX_NUMBER]; 130 | GList *texts; 131 | }; 132 | 133 | static WhOutput * 134 | _wh_get_output(WhClient *self, struct wl_output *wl_output) 135 | { 136 | return g_hash_table_lookup(self->outputs, wl_output); 137 | } 138 | 139 | static void 140 | _wh_buffer_cleanup(WhClientBufferPool *self) 141 | { 142 | if ( ! self->to_free ) 143 | return; 144 | 145 | gint64 i, count = 0; 146 | for ( i = 0 ; i < self->client->buffer_count ; ++i ) 147 | { 148 | if ( ( self->buffers[i].released ) && ( self->buffers[i].buffer != NULL ) ) 149 | { 150 | cairo_surface_destroy(self->buffers[i].cairo_surface); 151 | wl_buffer_destroy(self->buffers[i].buffer); 152 | self->buffers[i].buffer = NULL; 153 | } 154 | if ( self->buffers[i].buffer == NULL ) 155 | ++count; 156 | } 157 | 158 | if ( count < self->client->buffer_count ) 159 | return; 160 | 161 | munmap(self->data, self->size); 162 | g_free(self); 163 | } 164 | 165 | static void 166 | _wh_buffer_release(void *data, struct wl_buffer *buffer) 167 | { 168 | WhClientBufferPool *self = data; 169 | 170 | gint64 i; 171 | for ( i = 0 ; i < self->client->buffer_count ; ++i ) 172 | { 173 | if ( self->buffers[i].buffer == buffer ) 174 | self->buffers[i].released = TRUE; 175 | } 176 | 177 | _wh_buffer_cleanup(self); 178 | } 179 | 180 | static void 181 | _wh_buffer_pool_free(WhClientBufferPool *self) 182 | { 183 | if ( self == NULL ) 184 | return; 185 | 186 | self->to_free = TRUE; 187 | _wh_buffer_cleanup(self); 188 | } 189 | 190 | static const struct wl_buffer_listener _wh_buffer_listener = { 191 | _wh_buffer_release 192 | }; 193 | 194 | static WhClientBufferPool * 195 | _wh_create_buffer_pool(WhClientSurface *surface, gint32 width, gint32 height, gint32 scale) 196 | { 197 | WhClient *client = surface->context; 198 | struct wl_shm_pool *pool; 199 | int fd; 200 | uint8_t *data; 201 | int32_t stride; 202 | size_t size; 203 | size_t pool_size; 204 | 205 | width *= scale; 206 | height *= scale; 207 | 208 | stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); 209 | size = stride * height; 210 | pool_size = size * client->buffer_count; 211 | 212 | gchar *filename; 213 | filename = g_build_filename(client->runtime_dir, "wayland-surface", NULL); 214 | fd = g_open(filename, O_CREAT | O_RDWR | O_CLOEXEC, 0); 215 | g_unlink(filename); 216 | g_free(filename); 217 | if ( fd < 0 ) 218 | { 219 | g_warning("creating a file failed: %s\n", g_strerror(errno)); 220 | return NULL; 221 | } 222 | if ( ftruncate(fd, pool_size) < 0 ) 223 | { 224 | g_warning("truncating file to %zu B failed: %s\n", pool_size, g_strerror(errno)); 225 | close(fd); 226 | return NULL; 227 | } 228 | 229 | data = mmap(NULL, pool_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 230 | if ( data == MAP_FAILED ) 231 | { 232 | g_warning("mmap failed: %s\n", g_strerror(errno)); 233 | close(fd); 234 | return NULL; 235 | } 236 | 237 | WhClientBufferPool *self; 238 | self = g_new0(WhClientBufferPool, 1); 239 | self->client = client; 240 | self->surface = surface; 241 | self->buffers = g_new0(WhClientBuffer, client->buffer_count); 242 | self->scale = scale; 243 | 244 | pool = wl_shm_create_pool(client->shm, fd, pool_size); 245 | gint64 i; 246 | for ( i = 0 ; i < client->buffer_count ; ++i ) 247 | { 248 | self->buffers[i].pool = self; 249 | self->buffers[i].buffer = wl_shm_pool_create_buffer(pool, size * i, width, height, stride, WL_SHM_FORMAT_ARGB8888); 250 | //self->buffers[i].data = data + size * i; 251 | self->buffers[i].cairo_surface = cairo_image_surface_create_for_data(data + size * i, CAIRO_FORMAT_ARGB32, width, height, stride); 252 | cairo_surface_set_device_scale(self->buffers[i].cairo_surface, scale, scale); 253 | self->buffers[i].released = TRUE; 254 | wl_buffer_add_listener(self->buffers[i].buffer, &_wh_buffer_listener, self); 255 | } 256 | wl_shm_pool_destroy(pool); 257 | close(fd); 258 | 259 | return self; 260 | } 261 | 262 | static void 263 | _wh_surface_protocol_enter(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output) 264 | { 265 | WhClientSurface *self = data; 266 | WhOutput *output; 267 | 268 | output = g_hash_table_lookup(self->context->outputs, wl_output); 269 | if ( output == NULL ) 270 | return; 271 | 272 | gsize i; 273 | for ( i = 0 ; i < WAYLAND_OUTPUTS_MAX_NUMBER ; ++i ) 274 | { 275 | if ( self->outputs[i] == NULL ) 276 | break; 277 | } 278 | if ( i == WAYLAND_OUTPUTS_MAX_NUMBER ) 279 | return; 280 | self->outputs[i] = output; 281 | } 282 | 283 | static void 284 | _wh_surface_protocol_leave(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output) 285 | { 286 | WhClientSurface *self = data; 287 | WhOutput *output; 288 | 289 | output = _wh_get_output(self->context, wl_output); 290 | if ( output == NULL ) 291 | return; 292 | 293 | gsize i; 294 | for ( i = 0 ; i < WAYLAND_OUTPUTS_MAX_NUMBER ; ++i ) 295 | { 296 | if ( self->outputs[i] == output ) 297 | break; 298 | } 299 | if ( i == WAYLAND_OUTPUTS_MAX_NUMBER ) 300 | return; 301 | 302 | for ( ; i < (WAYLAND_OUTPUTS_MAX_NUMBER - 1) ; ++i ) 303 | { 304 | self->outputs[i] = self->outputs[i+1]; 305 | } 306 | self->outputs[WAYLAND_OUTPUTS_MAX_NUMBER - 1] = NULL; 307 | } 308 | 309 | static const struct wl_surface_listener _wh_surface_interface = { 310 | .enter = _wh_surface_protocol_enter, 311 | .leave = _wh_surface_protocol_leave, 312 | }; 313 | 314 | WhClientSurface * 315 | wh_client_surface_new(WhClient *client) 316 | { 317 | WhClientSurface *self; 318 | self = g_new0(WhClientSurface, 1); 319 | 320 | self->context = client; 321 | self->surface = wl_compositor_create_surface(self->context->compositor); 322 | if ( self->surface == NULL ) 323 | { 324 | g_free(self); 325 | return NULL; 326 | } 327 | 328 | wl_surface_add_listener(self->surface, &_wh_surface_interface, self); 329 | 330 | return self; 331 | } 332 | 333 | void 334 | wh_client_surface_free(WhClientSurface *self) 335 | { 336 | wl_surface_destroy(self->surface); 337 | _wh_buffer_pool_free(self->pool); 338 | g_free(self); 339 | } 340 | 341 | gboolean 342 | wh_client_surface_resize(WhClientSurface *self, WhClientSize size) 343 | { 344 | WhClientBufferPool *pool; 345 | gint32 scale = 1; 346 | 347 | gsize i; 348 | for ( i = 0 ; ( i < WAYLAND_OUTPUTS_MAX_NUMBER ) && ( self->outputs[i] != NULL ) ; ++i ) 349 | { 350 | if ( scale < self->outputs[i]->scale ) 351 | scale = self->outputs[i]->scale; 352 | } 353 | g_debug("Resize %dx%d@%d", size.width, size.height, scale); 354 | pool = _wh_create_buffer_pool(self, size.width, size.height, scale); 355 | if ( ( pool == NULL ) && ( self->pool == NULL ) ) 356 | return FALSE; 357 | _wh_buffer_pool_free(self->pool); 358 | self->pool = pool; 359 | self->size = size; 360 | return TRUE; 361 | } 362 | 363 | struct wl_surface * 364 | wh_client_surface_get_surface(WhClientSurface *self) 365 | { 366 | return self->surface; 367 | } 368 | 369 | WhClientBuffer * 370 | wh_client_surface_get_buffer(WhClientSurface *surface) 371 | { 372 | WhClientBuffer *buffer = NULL; 373 | 374 | gint64 i; 375 | for ( i = 0 ; ( buffer == NULL ) && ( i < surface->context->buffer_count ) ; ++i ) 376 | { 377 | buffer = surface->pool->buffers + i; 378 | if ( ! buffer->released ) 379 | buffer = NULL; 380 | } 381 | if ( buffer == NULL ) 382 | return NULL; 383 | buffer->released = FALSE; 384 | 385 | return buffer; 386 | } 387 | 388 | void 389 | wh_client_buffer_commit(WhClientBuffer *self, struct wl_callback **frame_cb) 390 | { 391 | WhClientSurface *surface = self->pool->surface; 392 | 393 | cairo_surface_flush(self->cairo_surface); 394 | 395 | wl_surface_damage(surface->surface, 0, 0, surface->size.width, surface->size.height); 396 | wl_surface_attach(surface->surface, self->buffer, 0, 0); 397 | if ( wl_surface_get_version(surface->surface) >= WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION ) 398 | wl_surface_set_buffer_scale(surface->surface, self->pool->scale); 399 | if ( frame_cb != NULL ) 400 | *frame_cb = wl_surface_frame(surface->surface); 401 | wl_surface_commit(surface->surface); 402 | } 403 | 404 | cairo_surface_t * 405 | wh_client_buffer_get_surface(WhClientBuffer *self) 406 | { 407 | return self->cairo_surface; 408 | } 409 | 410 | PangoLayout * 411 | wh_client_text_new(WhClient *self, const gchar *text, gsize length) 412 | { 413 | PangoLayout *layout; 414 | 415 | layout = pango_layout_new(self->pango_context); 416 | pango_layout_set_markup(layout, text, length); 417 | 418 | return layout; 419 | } 420 | 421 | static void 422 | _wh_cursor_set_image(WhClient *self, int i) 423 | { 424 | struct wl_buffer *buffer; 425 | struct wl_cursor_image *image; 426 | image = self->cursor.cursor->images[i]; 427 | 428 | self->cursor.image = image; 429 | buffer = wl_cursor_image_get_buffer(self->cursor.image); 430 | wl_surface_attach(self->cursor.surface, buffer, 0, 0); 431 | wl_surface_damage(self->cursor.surface, 0, 0, self->cursor.image->width, self->cursor.image->height); 432 | wl_surface_commit(self->cursor.surface); 433 | } 434 | 435 | static void _wh_cursor_frame_callback(void *data, struct wl_callback *callback, uint32_t time); 436 | 437 | static const struct wl_callback_listener _wh_cursor_frame_wl_callback_listener = { 438 | .done = _wh_cursor_frame_callback, 439 | }; 440 | 441 | static void 442 | _wh_cursor_frame_callback(void *data, struct wl_callback *callback, uint32_t time) 443 | { 444 | WhClient *self = data; 445 | int i; 446 | 447 | if ( self->cursor.frame_cb != NULL ) 448 | wl_callback_destroy(self->cursor.frame_cb); 449 | self->cursor.frame_cb = wl_surface_frame(self->cursor.surface); 450 | wl_callback_add_listener(self->cursor.frame_cb, &_wh_cursor_frame_wl_callback_listener, self); 451 | 452 | i = wl_cursor_frame(self->cursor.cursor, time); 453 | _wh_cursor_set_image(self, i); 454 | } 455 | 456 | static void 457 | _wh_pointer_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y) 458 | { 459 | WhSeat *self = data; 460 | WhClient *context = self->context; 461 | 462 | if ( context->cursor.surface == NULL ) 463 | return; 464 | 465 | if ( context->cursor.cursor->image_count < 2 ) 466 | _wh_cursor_set_image(context, 0); 467 | else 468 | _wh_cursor_frame_callback(context, context->cursor.frame_cb, 0); 469 | 470 | wl_pointer_set_cursor(self->pointer, serial, context->cursor.surface, context->cursor.image->hotspot_x, context->cursor.image->hotspot_y); 471 | } 472 | 473 | static void 474 | _wh_pointer_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface) 475 | { 476 | WhSeat *self = data; 477 | WhClient *context = self->context; 478 | 479 | if ( context->cursor.frame_cb != NULL ) 480 | wl_callback_destroy(context->cursor.frame_cb); 481 | } 482 | 483 | static void 484 | _wh_pointer_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y) 485 | { 486 | } 487 | 488 | static void 489 | _wh_pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, enum wl_pointer_button_state state) 490 | { 491 | } 492 | 493 | static void 494 | _wh_pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, enum wl_pointer_axis axis, wl_fixed_t value) 495 | { 496 | } 497 | 498 | static void 499 | _wh_pointer_frame(void *data, struct wl_pointer *pointer) 500 | { 501 | } 502 | 503 | static void 504 | _wh_pointer_axis_source(void *data, struct wl_pointer *pointer, enum wl_pointer_axis_source axis_source) 505 | { 506 | } 507 | 508 | static void 509 | _wh_pointer_axis_stop(void *data, struct wl_pointer *pointer, uint32_t time, enum wl_pointer_axis axis) 510 | { 511 | } 512 | 513 | static void 514 | _wh_pointer_axis_discrete(void *data, struct wl_pointer *pointer, enum wl_pointer_axis axis, int32_t discrete) 515 | { 516 | } 517 | 518 | static const struct wl_pointer_listener _wh_pointer_listener = { 519 | .enter = _wh_pointer_enter, 520 | .leave = _wh_pointer_leave, 521 | .motion = _wh_pointer_motion, 522 | .button = _wh_pointer_button, 523 | .axis = _wh_pointer_axis, 524 | .frame = _wh_pointer_frame, 525 | .axis_source = _wh_pointer_axis_source, 526 | .axis_stop = _wh_pointer_axis_stop, 527 | .axis_discrete = _wh_pointer_axis_discrete, 528 | }; 529 | 530 | static void 531 | _wh_pointer_release(WhSeat *self) 532 | { 533 | if ( self->pointer == NULL ) 534 | return; 535 | 536 | if ( wl_pointer_get_version(self->pointer) >= WL_POINTER_RELEASE_SINCE_VERSION ) 537 | wl_pointer_release(self->pointer); 538 | else 539 | wl_pointer_destroy(self->pointer); 540 | 541 | self->pointer = NULL; 542 | } 543 | 544 | static void 545 | _wh_seat_release(gpointer user_data) 546 | { 547 | WhSeat *self = user_data; 548 | 549 | _wh_pointer_release(self); 550 | 551 | if ( wl_seat_get_version(self->seat) >= WL_SEAT_RELEASE_SINCE_VERSION ) 552 | wl_seat_release(self->seat); 553 | else 554 | wl_seat_destroy(self->seat); 555 | 556 | free(self); 557 | } 558 | 559 | static void 560 | _wh_seat_capabilities(void *data, struct wl_seat *seat, uint32_t capabilities) 561 | { 562 | WhSeat *self = data; 563 | if ( ( capabilities & WL_SEAT_CAPABILITY_POINTER ) && ( self->pointer == NULL ) ) 564 | { 565 | self->pointer = wl_seat_get_pointer(self->seat); 566 | wl_pointer_add_listener(self->pointer, &_wh_pointer_listener, self); 567 | } 568 | else if ( ( ! ( capabilities & WL_SEAT_CAPABILITY_POINTER ) ) && ( self->pointer != NULL ) ) 569 | _wh_pointer_release(self); 570 | } 571 | 572 | static void 573 | _wh_seat_name(void *data, struct wl_seat *seat, const char *name) 574 | { 575 | } 576 | 577 | static const struct wl_seat_listener _wh_seat_listener = { 578 | .capabilities = _wh_seat_capabilities, 579 | .name = _wh_seat_name, 580 | }; 581 | 582 | static void 583 | _wh_output_release(gpointer user_data) 584 | { 585 | WhOutput *self = user_data; 586 | 587 | if ( wl_output_get_version(self->output) >= WL_OUTPUT_RELEASE_SINCE_VERSION ) 588 | wl_output_release(self->output); 589 | else 590 | wl_output_destroy(self->output); 591 | 592 | free(self); 593 | } 594 | 595 | static void 596 | _wh_output_done(void *data, struct wl_output *output) 597 | { 598 | } 599 | 600 | static void 601 | _wh_output_geometry(void *data, struct wl_output *output, int32_t x, int32_t y, int32_t width, int32_t height, int32_t subpixel, const char *make, const char *model, int32_t transform) 602 | { 603 | } 604 | 605 | static void 606 | _wh_output_mode(void *data, struct wl_output *output, enum wl_output_mode flags, int32_t width, int32_t height, int32_t refresh) 607 | { 608 | } 609 | 610 | static void 611 | _wh_output_scale(void *data, struct wl_output *output, int32_t scale) 612 | { 613 | WhOutput *self = data; 614 | 615 | self->scale = scale; 616 | } 617 | 618 | static const struct wl_output_listener _wh_output_listener = { 619 | .geometry = _wh_output_geometry, 620 | .mode = _wh_output_mode, 621 | .scale = _wh_output_scale, 622 | .done = _wh_output_done, 623 | }; 624 | 625 | static const char * const _wh_cursor_names[] = { 626 | "left_ptr", 627 | "default", 628 | "top_left_arrow", 629 | "left-arrow", 630 | NULL 631 | }; 632 | 633 | static void 634 | _wh_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) 635 | { 636 | WhClient *self = data; 637 | 638 | if ( g_strcmp0(interface, "wl_compositor") == 0 ) 639 | { 640 | self->global_names[WW_DOCK_GLOBAL_COMPOSITOR] = name; 641 | self->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, MIN(version, WL_COMPOSITOR_INTERFACE_VERSION)); 642 | } 643 | else if ( g_strcmp0(interface, "wl_shm") == 0 ) 644 | { 645 | self->global_names[WW_DOCK_GLOBAL_SHM] = name; 646 | self->shm = wl_registry_bind(registry, name, &wl_shm_interface, MIN(version, WL_SHM_INTERFACE_VERSION)); 647 | } 648 | else if ( g_strcmp0(interface, "wl_seat") == 0 ) 649 | { 650 | WhSeat *seat = g_new0(WhSeat, 1); 651 | seat->context = self; 652 | seat->global_name = name; 653 | seat->seat = wl_registry_bind(registry, name, &wl_seat_interface, MIN(version, WL_SEAT_INTERFACE_VERSION)); 654 | 655 | g_hash_table_insert(self->seats, seat->seat, seat); 656 | 657 | wl_seat_add_listener(seat->seat, &_wh_seat_listener, seat); 658 | } 659 | else if ( g_strcmp0(interface, "wl_output") == 0 ) 660 | { 661 | WhOutput *output = g_new0(WhOutput, 1); 662 | output->context = self; 663 | output->global_name = name; 664 | output->output = wl_registry_bind(registry, name, &wl_output_interface, MIN(version, WL_OUTPUT_INTERFACE_VERSION)); 665 | output->scale = 1; 666 | 667 | g_hash_table_insert(self->outputs, output->output, output); 668 | 669 | wl_output_add_listener(output->output, &_wh_output_listener, output); 670 | } 671 | 672 | if ( ( self->cursor.theme == NULL ) && ( self->compositor != NULL ) && ( self->shm != NULL ) ) 673 | { 674 | self->cursor.theme = wl_cursor_theme_load(self->cursor.theme_name, 32, self->shm); 675 | if ( self->cursor.theme != NULL ) 676 | { 677 | const char * const *cname = (const char * const *) self->cursor.name; 678 | for ( cname = ( cname != NULL ) ? cname : _wh_cursor_names ; ( self->cursor.cursor == NULL ) && ( *cname != NULL ) ; ++cname ) 679 | self->cursor.cursor = wl_cursor_theme_get_cursor(self->cursor.theme, *cname); 680 | if ( self->cursor.cursor == NULL ) 681 | { 682 | wl_cursor_theme_destroy(self->cursor.theme); 683 | self->cursor.theme = NULL; 684 | } 685 | else 686 | self->cursor.surface = wl_compositor_create_surface(self->compositor); 687 | } 688 | } 689 | } 690 | 691 | static gboolean 692 | _wh_client_find_global(gpointer key, gpointer value, gpointer user_data) 693 | { 694 | struct { 695 | WhClient *context; 696 | uint32_t global_name; 697 | } *global = value; 698 | uint32_t *name = user_data; 699 | return ( global->global_name == *name ); 700 | } 701 | 702 | static void 703 | _wh_registry_handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) 704 | { 705 | WhClient *self = data; 706 | 707 | WhGlobalName i; 708 | for ( i = 0 ; i < _WW_DOCK_GLOBAL_SIZE ; ++i ) 709 | { 710 | if ( self->global_names[i] != name ) 711 | continue; 712 | self->global_names[i] = 0; 713 | 714 | switch ( i ) 715 | { 716 | case WW_DOCK_GLOBAL_COMPOSITOR: 717 | wl_compositor_destroy(self->compositor); 718 | self->compositor = NULL; 719 | break; 720 | case WW_DOCK_GLOBAL_SHM: 721 | wl_shm_destroy(self->shm); 722 | self->shm = NULL; 723 | break; 724 | case _WW_DOCK_GLOBAL_SIZE: 725 | g_return_if_reached(); 726 | } 727 | return; 728 | } 729 | if ( ( self->cursor.theme != NULL ) && ( ( self->compositor == NULL ) || ( self->shm == NULL ) ) ) 730 | { 731 | if ( self->cursor.frame_cb != NULL ) 732 | wl_callback_destroy(self->cursor.frame_cb); 733 | self->cursor.frame_cb = NULL; 734 | 735 | wl_surface_destroy(self->cursor.surface); 736 | wl_cursor_theme_destroy(self->cursor.theme); 737 | self->cursor.surface = NULL; 738 | self->cursor.image = NULL; 739 | self->cursor.cursor = NULL; 740 | self->cursor.theme = NULL; 741 | } 742 | 743 | WhSeat *seat; 744 | seat = g_hash_table_find(self->seats, _wh_client_find_global, &name); 745 | if ( seat != NULL ) 746 | { 747 | g_hash_table_remove(self->seats, seat->seat); 748 | return; 749 | } 750 | 751 | WhOutput *output; 752 | output = g_hash_table_find(self->outputs, _wh_client_find_global, &name); 753 | { 754 | g_hash_table_remove(self->outputs, output->output); 755 | _wh_output_release(output); 756 | return; 757 | } 758 | } 759 | 760 | static const struct wl_registry_listener _wh_registry_listener = { 761 | .global = _wh_registry_handle_global, 762 | .global_remove = _wh_registry_handle_global_remove, 763 | }; 764 | 765 | 766 | WhClient * 767 | wh_client_new(void) 768 | { 769 | gchar *runtime_dir; 770 | runtime_dir = g_build_filename(g_get_user_runtime_dir(), PACKAGE_NAME, NULL); 771 | 772 | if ( g_mkdir_with_parents(runtime_dir, 0755) < 0 ) 773 | { 774 | g_free(runtime_dir); 775 | return NULL; 776 | } 777 | 778 | WhClient *self; 779 | self = g_new0(WhClient, 1); 780 | 781 | self->buffer_count = 3; 782 | 783 | self->runtime_dir = runtime_dir; 784 | 785 | self->source = g_water_wayland_source_new(NULL, NULL); 786 | if ( self->source == NULL ) 787 | { 788 | g_free(self->runtime_dir); 789 | g_free(self); 790 | return NULL; 791 | } 792 | 793 | self->display = g_water_wayland_source_get_display(self->source); 794 | self->registry = wl_display_get_registry(self->display); 795 | wl_registry_add_listener(self->registry, &_wh_registry_listener, self); 796 | 797 | self->seats = g_hash_table_new_full(NULL, NULL, NULL, _wh_seat_release); 798 | self->outputs = g_hash_table_new_full(NULL, NULL, NULL, _wh_output_release); 799 | 800 | self->pango_context = pango_context_new(); 801 | pango_context_set_font_map(self->pango_context, pango_cairo_font_map_get_default()); 802 | 803 | return self; 804 | } 805 | 806 | void 807 | wh_client_free(WhClient *self) 808 | { 809 | g_free(self->runtime_dir); 810 | 811 | g_hash_table_unref(self->outputs); 812 | g_hash_table_unref(self->seats); 813 | 814 | WhGlobalName i; 815 | for ( i = 0 ; i < _WW_DOCK_GLOBAL_SIZE ; ++i ) 816 | { 817 | if ( self->global_names[i] != 0 ) 818 | _wh_registry_handle_global_remove(self, self->registry, self->global_names[i]); 819 | } 820 | 821 | wl_registry_destroy(self->registry); 822 | self->registry = NULL; 823 | 824 | if ( self->source != NULL ) 825 | g_water_wayland_source_free(self->source); 826 | self->display = NULL; 827 | self->source = NULL; 828 | 829 | g_free(self); 830 | } 831 | 832 | static gboolean 833 | _wh_client_option_parse_font(const gchar *option_name, const gchar *value, gpointer user_data, GError **error) 834 | { 835 | WhClient *self = user_data; 836 | PangoFontDescription *font; 837 | 838 | font = pango_font_description_from_string(value); 839 | pango_context_set_font_description(self->pango_context, font); 840 | 841 | return TRUE; 842 | } 843 | 844 | void 845 | wh_client_add_option_group(WhClient *self, GOptionContext *option_context) 846 | { 847 | GOptionGroup *option_group; 848 | GOptionEntry entries[] = 849 | { 850 | { "font", 'f', 0, G_OPTION_ARG_CALLBACK, _wh_client_option_parse_font, "The font to use", "" }, 851 | { "cursor-theme", 'C', 0, G_OPTION_ARG_STRING, &self->cursor.theme_name, "The cursor theme to use", "" }, 852 | { "version", 'V', 0, G_OPTION_ARG_NONE, &self->print_version, "Print version", NULL }, 853 | { .long_name = NULL } 854 | }; 855 | 856 | option_group = g_option_group_new("client", "WayHouse clients common options", "", self, NULL); 857 | g_option_group_add_entries(option_group, entries); 858 | g_option_group_set_translation_domain(option_group, GETTEXT_PACKAGE); 859 | g_option_context_add_group(option_context, option_group); 860 | } 861 | 862 | gint 863 | wh_client_run(WhClient *self) 864 | { 865 | if ( self->print_version ) 866 | { 867 | g_printf(PACKAGE_NAME " " WAYHOUSE_VERSION "\n"); 868 | return 0; 869 | } 870 | 871 | if ( self->shm == NULL ) 872 | { 873 | g_warning("No wl_shm interface provided by the compositor"); 874 | return 4; 875 | } 876 | 877 | self->loop = g_main_loop_new(NULL, FALSE); 878 | g_main_loop_run(self->loop); 879 | g_main_loop_unref(self->loop); 880 | 881 | return 0; 882 | } 883 | 884 | struct wl_display * 885 | wh_client_get_display(WhClient *self) 886 | { 887 | return self->display; 888 | } 889 | 890 | PangoFontMetrics * 891 | wh_client_get_font_metrics(WhClient *self) 892 | { 893 | PangoFont *font; 894 | PangoFontMetrics *metrics; 895 | 896 | font = pango_font_map_load_font(pango_cairo_font_map_get_default(), self->pango_context, pango_context_get_font_description(self->pango_context)); 897 | metrics = pango_font_get_metrics(font, pango_language_get_default()); 898 | 899 | g_object_unref(font); 900 | 901 | return metrics; 902 | } 903 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | project('wayhouse', 'c', 2 | version: '0', 3 | meson_version: '>=0.39.1', 4 | license: [ 'GPL3+', 'MIT' ], 5 | default_options: [ 6 | 'c_std=gnu11', 7 | 'warning_level=2', 8 | ], 9 | ) 10 | 11 | wayhouse_version = meson.project_version() 12 | 13 | git = find_program('git', required: false) 14 | if git.found() 15 | git_version = run_command(git, '--git-dir', join_paths(meson.source_root(), '.git'), 'describe', '--tags', '--always', '--dirty') 16 | git_branch = run_command(git, '--git-dir', join_paths(meson.source_root(), '.git'), 'describe', '--tags', '--always', '--all') 17 | if git_version.returncode() == 0 and git_branch.returncode() == 0 18 | git_branch_parts = [] 19 | foreach b : git_branch.stdout().strip().split('/') 20 | if b != 'heads' 21 | git_branch_parts += b 22 | endif 23 | endforeach 24 | wayhouse_version = '@0@ - @1@ (@2@)'.format(meson.project_version(), git_version.stdout().strip(), '/'.join(git_branch_parts)) 25 | endif 26 | endif 27 | 28 | is_unix = host_machine.system() != 'windows' 29 | 30 | headers = [ 31 | 'locale.h', 32 | 'errno.h', 33 | 'sys/mman.h', 34 | 'stdbool.h', 35 | 'sys/stat.h', 36 | 'fcntl.h', 37 | ] 38 | c_compiler = meson.get_compiler('c') 39 | foreach h : headers 40 | if not c_compiler.has_header(h) 41 | error('Header @0@ was not found, but is required'.format(h)) 42 | endif 43 | endforeach 44 | 45 | glib_min_major='2' 46 | glib_min_minor='40' 47 | glib_min_version='.'.join([glib_min_major, glib_min_minor]) 48 | wayland_min_version='1.12.92' 49 | weston_supported_majors = [ 50 | '3', 51 | '2', 52 | ] 53 | last_weston_major = weston_supported_majors[weston_supported_majors.length() - 1] 54 | weston_min_version='1.12.90' 55 | 56 | glib = dependency('glib-2.0', version: '>= @0@'.format(glib_min_version)) 57 | gobject = dependency('gobject-2.0') 58 | gmodule = dependency('gmodule-2.0') 59 | gio = dependency('gio-2.0') 60 | if is_unix 61 | gio_platform = dependency('gio-unix-2.0') 62 | else 63 | gio_platform = dependency('gio-windows-2.0') 64 | endif 65 | wayland_server = dependency('wayland-server', version: '>= @0@'.format(wayland_min_version)) 66 | wayland_client = [ 67 | dependency('wayland-client', version: '>= @0@'.format(wayland_min_version)), 68 | dependency('wayland-cursor'), 69 | ] 70 | libgwater_wayland = subproject('libgwater/wayland').get_variable('libgwater_wayland') 71 | libgwater_wayland_server = subproject('libgwater/wayland-server').get_variable('libgwater_wayland_server') 72 | weston_major = '' 73 | foreach try_weston_major : weston_supported_majors 74 | if weston_major == '' 75 | libweston = dependency('libweston-@0@'.format(try_weston_major), required: last_weston_major == try_weston_major) 76 | libweston_desktop = dependency('libweston-desktop-@0@'.format(try_weston_major), required: last_weston_major == try_weston_major) 77 | if libweston.found() 78 | weston_major = try_weston_major 79 | endif 80 | endif 81 | endforeach 82 | weston = dependency('weston') 83 | xkbcommon = dependency('xkbcommon') 84 | libinput = dependency('libinput') 85 | cairo = dependency('cairo') 86 | pango = [ 87 | dependency('pango'), 88 | dependency('pangocairo'), 89 | ] 90 | 91 | header_conf = configuration_data() 92 | header_conf.set_quoted('PACKAGE_NAME', meson.project_name()) 93 | header_conf.set_quoted('WAYHOUSE_VERSION', wayhouse_version) 94 | header_conf.set_quoted('GETTEXT_PACKAGE', meson.project_name()) 95 | 96 | header_conf.set('WAYHOUSE_EXPORT', '__attribute__((visibility("default")))') 97 | 98 | header_conf.set('GLIB_VERSION_MIN_REQUIRED', '(G_ENCODE_VERSION(@0@,@1@))'.format(glib_min_major, glib_min_minor)) 99 | header_conf.set('G_LOG_USE_STRUCTURED', true) 100 | 101 | header_conf.set_quoted('WAYHOUSE_LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir'))) 102 | header_conf.set_quoted('WESTON_PLUGINS_DIR', join_paths(weston.get_pkgconfig_variable('libdir'), 'weston')) 103 | header_conf.set_quoted('LIBWESTON_PLUGINS_DIR', join_paths(libweston.get_pkgconfig_variable('libdir'), 'libweston-@0@'.format(weston_major))) 104 | 105 | header_conf.set('WAYHOUSE_DEBUG', get_option('enable-debug')) 106 | 107 | config_h = configure_file(output: 'config.h', configuration: header_conf) 108 | 109 | add_project_arguments( 110 | '-fvisibility=hidden', 111 | '-I@0@'.format(meson.build_root()), 112 | language: 'c' 113 | ) 114 | flags = [ 115 | '-Wformat=2', 116 | '-Wno-unused-parameter', 117 | ] 118 | foreach f : flags 119 | if c_compiler.has_argument(f) 120 | add_project_arguments(f, language: 'c') 121 | endif 122 | endforeach 123 | 124 | nk_modules = [ 125 | 'enum=true', 126 | 'colour=true', 127 | 'bindings=true', 128 | ] 129 | nk = subproject('libnkutils', default_options: nk_modules) 130 | nk_options = nk.get_variable('nk_options') 131 | foreach o : nk_modules + nk_options 132 | if not nk_modules.contains(o) or not nk_options.contains(o) 133 | error('You must not change libnkutils options @0@ != @1@'.format('|'.join(nk_modules), '|'.join(nk_options))) 134 | endif 135 | endforeach 136 | libnkutils = nk.get_variable('libnkutils') 137 | 138 | wayland_scanner = find_program('wayland-scanner') 139 | wayland_protocols = dependency('wayland-protocols') 140 | wayland_wall = dependency('wayland-wall') 141 | wp_protocol_dir = wayland_protocols.get_pkgconfig_variable('pkgdatadir') 142 | ww_protocol_dir = wayland_wall.get_pkgconfig_variable('pkgdatadir') 143 | 144 | wayland_scanner_client = generator(wayland_scanner, output: '@BASENAME@-client-protocol.h', arguments: ['client-header', '@INPUT@', '@OUTPUT@']) 145 | wayland_scanner_server = generator(wayland_scanner, output: '@BASENAME@-server-protocol.h', arguments: ['server-header', '@INPUT@', '@OUTPUT@']) 146 | wayland_scanner_code = generator(wayland_scanner, output: '@BASENAME@-protocol.c', arguments: ['code', '@INPUT@', '@OUTPUT@']) 147 | 148 | subdir('compositor') 149 | subdir('libwhclient') 150 | subdir('dock') 151 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option('enable-debug', type: 'boolean', value: true, description: 'debug output') 2 | 3 | --------------------------------------------------------------------------------