├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md └── src ├── config.c ├── config.h ├── endlesswm.c ├── grid.c ├── grid.h ├── keyboard.c ├── keyboard.h ├── keystroke.c ├── keystroke.h ├── metamanager.c ├── metamanager.h ├── mouse.c ├── mouse.h ├── painting.c └── painting.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | 55 | 56 | 57 | # Clion 58 | .idea/ 59 | 60 | # CMake 61 | cmake-build-debug/ 62 | cmake-build-release/ 63 | 64 | # CMake . 65 | CMakeCache.txt 66 | CMakeFiles/ 67 | Makefile 68 | cmake_install.cmake 69 | endlesswm 70 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | project(endlesswm) 3 | 4 | set(CMAKE_CXX_STANDARD 11) 5 | 6 | set(SOURCE_FILES 7 | src/config.c 8 | src/config.h 9 | src/endlesswm.c 10 | src/grid.c 11 | src/grid.h 12 | src/keyboard.c 13 | src/keyboard.h 14 | src/keystroke.c 15 | src/keystroke.h 16 | src/mouse.c 17 | src/mouse.h 18 | src/painting.c 19 | src/painting.h 20 | src/metamanager.c 21 | src/metamanager.h) 22 | 23 | add_executable(endlesswm ${SOURCE_FILES}) 24 | 25 | find_package(PkgConfig REQUIRED) 26 | pkg_check_modules(DEPS REQUIRED wlc wayland-server x11 glib-2.0) 27 | target_link_libraries(endlesswm ${DEPS_LIBRARIES}) 28 | target_include_directories(endlesswm PUBLIC ${DEPS_INCLUDE_DIRS}) 29 | target_compile_options(endlesswm PUBLIC ${DEPS_CFLAGS_OTHER}) 30 | 31 | target_link_libraries(endlesswm m) 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 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 | {project} Copyright (C) {year} {fullname} 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 | # EndlessWM 2 | A proof of concept of a scrolling window manager. 3 | 4 | ![demonstration](https://user-images.githubusercontent.com/22796326/114304454-811efa00-9ad3-11eb-914d-8c09dab338c3.gif) 5 | 6 | ### A what? 7 | A window manager where the width of the workspace is not limited by the width of the screen, and where the user can then scroll through the width of the workspace. 8 | 9 | ### Why? 10 | I like tiling window managers, because they save me time arranging windows, but I agree with the criticism that automatically changing the width of windows can be annoying. 11 | A horizontally scrolling window manager solves that by only maximizing the height of windows, and leaving their width entirely to the user's control. 12 | Because the workspace is infinitely wide, when a new window is opened, it can simply be placed to the right of the existing windows without making them smaller. 13 | 14 | ### The program 15 | EndlessWM is a Wayland compositor that uses the (now deprecated) [wlc](https://github.com/Cloudef/wlc) library. 16 | It is a working proof of concept, but it is not intended to be actually used for your daily window managing needs. 17 | 18 | ## Building 19 | 20 | #### Debug 21 | ``` 22 | cmake -DCMAKE_BUILD_TYPE=Debug -B ./cmake-build-debug 23 | cmake --build ./cmake-build-debug 24 | ``` 25 | 26 | #### Release 27 | ``` 28 | cmake -DCMAKE_BUILD_TYPE=Release -B ./cmake-build-release 29 | cmake --build ./cmake-build-release 30 | ``` 31 | 32 | ## Other scrolling WMs 33 | - [Niri](https://github.com/YaLTeR/niri) 34 | - [Karousel](https://github.com/peterfajdiga/karousel) 35 | - [PaperWM](https://github.com/paperwm/PaperWM) 36 | - [Cardboard](https://gitlab.com/cardboardwm/cardboard) 37 | -------------------------------------------------------------------------------- /src/config.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define CONFIG_FILE_PATH "/.config/endlesswm" 9 | 10 | // Appearance 11 | bool appearance_dimInactive; 12 | 13 | // Behavior 14 | double behavior_scrollMult; 15 | 16 | // Grid 17 | bool grid_horizontal; 18 | bool grid_minimizeEmptySpace; 19 | bool grid_floatingDialogs; 20 | uint32_t grid_windowSpacing; 21 | 22 | // Keybindings 23 | uint32_t MOD_WM0; 24 | struct Keystroke keystroke_terminate; 25 | struct Keystroke keystroke_closeWindow; 26 | struct Keystroke keystroke_launch; 27 | struct Keystroke keystroke_focusWindowUp; 28 | struct Keystroke keystroke_focusWindowDown; 29 | struct Keystroke keystroke_focusWindowLeft; 30 | struct Keystroke keystroke_focusWindowRight; 31 | struct Keystroke keystroke_moveWindowUp; 32 | struct Keystroke keystroke_moveWindowDown; 33 | struct Keystroke keystroke_moveWindowLeft; 34 | struct Keystroke keystroke_moveWindowRight; 35 | struct Keystroke keystroke_moveRowBack; 36 | struct Keystroke keystroke_moveRowForward; 37 | 38 | // Mousebindings 39 | struct Keystroke mousestroke_move; 40 | struct Keystroke mousestroke_resize; 41 | 42 | // Application Shortcuts 43 | struct ApplicationShortcut* applicationShortcuts; 44 | size_t applicationShortcutCount; 45 | 46 | static void initDefaults() { 47 | // Appearance 48 | appearance_dimInactive = false; 49 | 50 | // Behavior 51 | behavior_scrollMult = 5.0; 52 | 53 | // Grid 54 | grid_horizontal = true; 55 | grid_minimizeEmptySpace = true; 56 | grid_floatingDialogs = true; 57 | grid_windowSpacing = 8; 58 | 59 | // Keybindings 60 | keystroke_terminate = (struct Keystroke){WLC_BIT_MOD_CTRL | WLC_BIT_MOD_ALT, XKB_KEY_Delete}; 61 | keystroke_closeWindow = (struct Keystroke){WLC_BIT_MOD_ALT, XKB_KEY_F4}; 62 | keystroke_launch = (struct Keystroke){WLC_BIT_MOD_ALT, XKB_KEY_F2}; 63 | // the other keybindings defaults are set in setMainMod() 64 | 65 | // Application shortcuts (see readConfig() for defaults) 66 | applicationShortcuts = NULL; 67 | applicationShortcutCount = 0; 68 | } 69 | 70 | // run before reading keybindings 71 | static void setMainMod(bool const useAlt) { 72 | MOD_WM0 = useAlt ? WLC_BIT_MOD_ALT : WLC_BIT_MOD_LOGO; 73 | 74 | // Keybindings 75 | keystroke_focusWindowUp = (struct Keystroke){MOD_WM0, XKB_KEY_Up}; 76 | keystroke_focusWindowDown = (struct Keystroke){MOD_WM0, XKB_KEY_Down}; 77 | keystroke_focusWindowLeft = (struct Keystroke){MOD_WM0, XKB_KEY_Left}; 78 | keystroke_focusWindowRight = (struct Keystroke){MOD_WM0, XKB_KEY_Right}; 79 | keystroke_moveWindowUp = (struct Keystroke){MOD_WM1, XKB_KEY_Up}; 80 | keystroke_moveWindowDown = (struct Keystroke){MOD_WM1, XKB_KEY_Down}; 81 | keystroke_moveWindowLeft = (struct Keystroke){MOD_WM1, XKB_KEY_Left}; 82 | keystroke_moveWindowRight = (struct Keystroke){MOD_WM1, XKB_KEY_Right}; 83 | keystroke_moveRowBack = (struct Keystroke){MOD_WM2, XKB_KEY_Up}; 84 | keystroke_moveRowForward = (struct Keystroke){MOD_WM2, XKB_KEY_Down}; 85 | 86 | // Mousebindings (not configurable) 87 | mousestroke_move = (struct Keystroke){MOD_WM0, BTN_LEFT}; 88 | mousestroke_resize = (struct Keystroke){MOD_WM0, BTN_RIGHT}; 89 | } 90 | 91 | // needs to be freed afterwards 92 | // relativeFilePath needs to be prefixed with '/' 93 | char* getHomeFilePath(const char* relativeFilePath) { 94 | char* homePath = getenv("HOME"); 95 | const size_t homePathLength = strlen(homePath); 96 | const size_t configFileNameLength = strlen(relativeFilePath); 97 | char* retval = malloc(homePathLength + configFileNameLength + 1); 98 | strcpy(retval, homePath); 99 | strcat(retval, relativeFilePath); 100 | return retval; 101 | } 102 | 103 | static GKeyFile* configFile; 104 | static const char* group; 105 | static GError* error = NULL; 106 | static bool changesMade = false; 107 | 108 | static void readKeybinding(struct Keystroke* pref, const char* key) { 109 | char* prefStr = g_key_file_get_value(configFile, group, key, &error); 110 | if (error != NULL) { 111 | char* keystrokeString = keystrokeToString(pref); 112 | g_key_file_set_value(configFile, group, key, keystrokeString); 113 | free(keystrokeString); 114 | changesMade = true; 115 | error = NULL; 116 | } else { 117 | *pref = parseKeystroke(prefStr); 118 | } 119 | g_free(prefStr); 120 | } 121 | 122 | static void readBoolean(bool* pref, const char* key) { 123 | const bool value = (bool)g_key_file_get_boolean(configFile, group, key, &error); 124 | if (error != NULL) { 125 | g_key_file_set_boolean(configFile, group, key, *pref); 126 | changesMade = true; 127 | error = NULL; 128 | } else { 129 | *pref = value; 130 | } 131 | } 132 | 133 | static void readInteger(uint32_t* pref, const char* key) { 134 | const uint32_t value = (uint32_t)g_key_file_get_integer(configFile, group, key, &error); 135 | if (error != NULL) { 136 | g_key_file_set_integer(configFile, group, key, *pref); 137 | changesMade = true; 138 | error = NULL; 139 | } else { 140 | *pref = value; 141 | } 142 | } 143 | 144 | static void readDouble(double* pref, const char* key) { 145 | const double value = g_key_file_get_double(configFile, group, key, &error); 146 | if (error != NULL) { 147 | g_key_file_set_double(configFile, group, key, *pref); 148 | changesMade = true; 149 | error = NULL; 150 | } else { 151 | *pref = value; 152 | } 153 | } 154 | 155 | void readConfig() { 156 | initDefaults(); 157 | configFile = g_key_file_new(); 158 | 159 | char* configFilePath = getHomeFilePath(CONFIG_FILE_PATH); 160 | if (!g_key_file_load_from_file(configFile, configFilePath, G_KEY_FILE_NONE, NULL)){ 161 | fprintf(stderr, "Could not read config file %s\nUsing defaults\n", configFilePath); 162 | } 163 | 164 | group = "Appearance"; 165 | readBoolean(&appearance_dimInactive, "dimInactive"); 166 | 167 | group = "Behavior"; 168 | readDouble(&behavior_scrollMult, "scrollSpeed"); 169 | 170 | group = "Grid"; 171 | readBoolean(&grid_horizontal , "rootHorizontal"); 172 | readBoolean(&grid_minimizeEmptySpace, "minimizeEmptySpace"); 173 | readBoolean(&grid_floatingDialogs , "floatingDialogs"); 174 | readInteger(&grid_windowSpacing , "windowSpacing"); 175 | 176 | group = "Keybindings"; 177 | bool keystroke_useAltAsMainMod = false; 178 | readBoolean(&keystroke_useAltAsMainMod, "useAltAsMainMod"); 179 | setMainMod(keystroke_useAltAsMainMod); // must be run before reading keybindings 180 | readKeybinding(&keystroke_terminate , "terminate"); 181 | readKeybinding(&keystroke_closeWindow , "closeWindow"); 182 | readKeybinding(&keystroke_launch , "launch"); 183 | readKeybinding(&keystroke_focusWindowUp , "focusWindowUp"); 184 | readKeybinding(&keystroke_focusWindowDown , "focusWindowDown"); 185 | readKeybinding(&keystroke_focusWindowLeft , "focusWindowLeft"); 186 | readKeybinding(&keystroke_focusWindowRight, "focusWindowRight"); 187 | readKeybinding(&keystroke_moveWindowUp , "moveWindowUp"); 188 | readKeybinding(&keystroke_moveWindowDown , "moveWindowDown"); 189 | readKeybinding(&keystroke_moveWindowLeft , "moveWindowLeft"); 190 | readKeybinding(&keystroke_moveWindowRight , "moveWindowRight"); 191 | readKeybinding(&keystroke_moveRowBack , "moveRowBack"); 192 | readKeybinding(&keystroke_moveRowForward , "moveRowForward"); 193 | 194 | group = "Application Shortcuts"; 195 | if (g_key_file_has_group(configFile, group)) { 196 | // read settings 197 | gchar** keys = g_key_file_get_keys(configFile, group, &applicationShortcutCount, &error); 198 | applicationShortcuts = malloc(applicationShortcutCount * sizeof(struct ApplicationShortcut)); // TODO: free 199 | for (size_t i = 0; i < applicationShortcutCount; i++) { 200 | size_t valLen; 201 | gchar** value = g_key_file_get_string_list(configFile, group, keys[i], &valLen, &error); 202 | if (valLen != 2 || error != NULL) { 203 | fprintf(stderr, "Invalid format of Application Shortcut %s\n", keys[i]); 204 | } else { 205 | applicationShortcuts[i].binding = parseKeystroke(value[0]); 206 | applicationShortcuts[i].name = keys[i]; 207 | applicationShortcuts[i].command = malloc(strlen(value[1])); 208 | strcpy(applicationShortcuts[i].command, value[1]); 209 | } 210 | g_strfreev(value); 211 | } 212 | g_strfreev(keys); 213 | } else { 214 | // setup default settings 215 | applicationShortcuts = malloc(sizeof(struct ApplicationShortcut)); // TODO: free 216 | applicationShortcutCount = 1; 217 | applicationShortcuts[0].binding = (struct Keystroke){WLC_BIT_MOD_LOGO, XKB_KEY_t}; 218 | applicationShortcuts[0].name = "terminal"; 219 | applicationShortcuts[0].command = "konsole"; 220 | // write default settings 221 | for (size_t i = 0; i < applicationShortcutCount; i++) { 222 | char** prefVal = malloc(2 * sizeof(char*)); 223 | prefVal[0] = keystrokeToString(&applicationShortcuts[i].binding); 224 | prefVal[1] = applicationShortcuts[i].command; 225 | g_key_file_set_string_list(configFile, group, applicationShortcuts[i].name, (const char**)prefVal, 2); 226 | free(prefVal[0]); 227 | free(prefVal); 228 | } 229 | changesMade = true; 230 | } 231 | 232 | if (changesMade) { 233 | g_key_file_save_to_file(configFile, configFilePath, &error); 234 | if (error != NULL) { 235 | fprintf(stderr, "Error writing config file to %s\n", configFilePath); 236 | } 237 | } 238 | 239 | free(configFilePath); 240 | g_key_file_free(configFile); 241 | } 242 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "keystroke.h" 6 | 7 | #define MOD_WM1 (MOD_WM0 | WLC_BIT_MOD_SHIFT) 8 | #define MOD_WM2 (MOD_WM0 | WLC_BIT_MOD_CTRL) 9 | 10 | struct ApplicationShortcut { 11 | struct Keystroke binding; 12 | char* name; 13 | char* command; 14 | }; 15 | 16 | // Appearance 17 | extern bool appearance_dimInactive; 18 | 19 | // Behavior 20 | extern double behavior_scrollMult; 21 | 22 | // Grid 23 | extern bool grid_horizontal; 24 | extern bool grid_minimizeEmptySpace; 25 | extern bool grid_floatingDialogs; 26 | extern uint32_t grid_windowSpacing; 27 | 28 | // Keybindings 29 | extern uint32_t MOD_WM0; 30 | extern struct Keystroke keystroke_terminate; 31 | extern struct Keystroke keystroke_closeWindow; 32 | extern struct Keystroke keystroke_launch; 33 | extern struct Keystroke keystroke_focusWindowUp; 34 | extern struct Keystroke keystroke_focusWindowDown; 35 | extern struct Keystroke keystroke_focusWindowLeft; 36 | extern struct Keystroke keystroke_focusWindowRight; 37 | extern struct Keystroke keystroke_moveWindowUp; 38 | extern struct Keystroke keystroke_moveWindowDown; 39 | extern struct Keystroke keystroke_moveWindowLeft; 40 | extern struct Keystroke keystroke_moveWindowRight; 41 | extern struct Keystroke keystroke_moveRowBack; 42 | extern struct Keystroke keystroke_moveRowForward; 43 | 44 | // Mousebindings 45 | extern struct Keystroke mousestroke_move; 46 | extern struct Keystroke mousestroke_resize; 47 | 48 | // Application Shortcuts 49 | extern struct ApplicationShortcut* applicationShortcuts; 50 | extern size_t applicationShortcutCount; 51 | 52 | char* getHomeFilePath(const char* relativeFilePath); 53 | void readConfig(); 54 | -------------------------------------------------------------------------------- /src/endlesswm.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include "grid.h" 3 | #include "keyboard.h" 4 | #include "mouse.h" 5 | #include "painting.h" 6 | #include "metamanager.h" 7 | 8 | #include 9 | #include 10 | 11 | #define STARTUP_SCRIPT_PATH "/.xprofile" 12 | 13 | static bool view_created(wlc_handle view) { 14 | wlc_view_set_mask(view, wlc_output_get_mask(wlc_view_get_output(view))); 15 | onViewCreated(view); 16 | wlc_view_focus(view); 17 | return true; 18 | } 19 | 20 | static void view_destroyed(wlc_handle view) { 21 | mouseHandleViewClosed(view); 22 | onViewDestroyed(view); 23 | } 24 | 25 | static void view_request_move(wlc_handle view, const struct wlc_point* origin) { 26 | fprintf(stderr, "Request move view %d\n", view); 27 | } 28 | 29 | static void view_request_resize(wlc_handle view, uint32_t edges, const struct wlc_point* origin) { 30 | fprintf(stderr, "Request resize view %d\n", view); 31 | } 32 | 33 | static void view_request_geometry(wlc_handle view, const struct wlc_geometry* g) { 34 | if (!viewResized(view)) { 35 | wlc_view_set_geometry(view, 0, g); 36 | } 37 | } 38 | 39 | static void view_focus(wlc_handle view, bool focus) { 40 | wlc_view_set_state(view, WLC_BIT_ACTIVATED, focus); 41 | if (focus) { 42 | if (getWindow(view) == NULL) { 43 | wlc_view_bring_to_front(view); 44 | } 45 | scrollToView(view); 46 | } 47 | } 48 | 49 | static bool output_created(wlc_handle const output) { 50 | return onOutputCreated(output) != NULL; 51 | } 52 | 53 | static void output_destroyed(wlc_handle const output) { 54 | onOutputDestroyed(output); 55 | } 56 | 57 | // TODO: resolution changed 58 | 59 | static void runStartupScript() { 60 | char* startupScriptPath = getHomeFilePath(STARTUP_SCRIPT_PATH); 61 | system(startupScriptPath); 62 | free(startupScriptPath); 63 | } 64 | 65 | int main(int argc, char *argv[]) { 66 | readConfig(); 67 | meta_init(); 68 | grid_init(); 69 | 70 | wlc_set_view_created_cb (&view_created); 71 | wlc_set_view_destroyed_cb (&view_destroyed); 72 | wlc_set_view_focus_cb (&view_focus); 73 | wlc_set_keyboard_key_cb (&keyboard_key); 74 | wlc_set_pointer_button_cb (&pointer_button); 75 | wlc_set_pointer_motion_cb_v2 (&pointer_motion); 76 | wlc_set_pointer_scroll_cb (&pointer_scroll); 77 | wlc_set_view_request_move_cb (&view_request_move); 78 | wlc_set_view_request_resize_cb (&view_request_resize); 79 | wlc_set_view_request_geometry_cb(&view_request_geometry); 80 | wlc_set_output_created_cb (&output_created); 81 | wlc_set_output_destroyed_cb (&output_destroyed); 82 | wlc_set_compositor_ready_cb (&runStartupScript); 83 | wlc_set_output_render_pre_cb (&output_render_pre); 84 | wlc_set_output_render_post_cb (&output_render_post); 85 | 86 | if (!wlc_init()) 87 | return EXIT_FAILURE; 88 | 89 | wlc_run(); 90 | meta_free(); 91 | return EXIT_SUCCESS; 92 | } 93 | -------------------------------------------------------------------------------- /src/grid.c: -------------------------------------------------------------------------------- 1 | #include "grid.h" 2 | #include "config.h" 3 | #include "metamanager.h" 4 | #include "mouse.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define ROW_EDGE_GRAB_SIZE (grid_windowSpacing / 2 + 24) 13 | 14 | static uint32_t GRIDDABLE_TYPES = 0; 15 | 16 | void grid_init() { 17 | if (!grid_floatingDialogs) { 18 | GRIDDABLE_TYPES |= WLC_BIT_MODAL; 19 | } 20 | } 21 | 22 | // getters 23 | 24 | struct Grid* getGrid(wlc_handle const output) { 25 | return getOutput(output)->grid; 26 | } 27 | 28 | static wlc_handle getGriddedParentView(wlc_handle view) { 29 | while (view > 0 && !isGridded(view)) { 30 | view = wlc_view_get_parent(view); 31 | } 32 | return view; 33 | } 34 | 35 | struct Window* getWindow(wlc_handle const view) { 36 | return getView(view)->window; 37 | } 38 | 39 | bool isGriddable(wlc_handle const view) { 40 | return !(wlc_view_get_type(view) & ~GRIDDABLE_TYPES); 41 | } 42 | 43 | bool isGridded(wlc_handle const view) { 44 | return getWindow(view) != NULL; 45 | } 46 | 47 | bool isFloating(wlc_handle const view) { 48 | return getWindow(view) == NULL && view > 0; 49 | } 50 | 51 | uint32_t getMaxRowLength(wlc_handle const output) { 52 | if (grid_horizontal) { 53 | return wlc_output_get_virtual_resolution(output)->h - grid_windowSpacing; 54 | } else { 55 | return wlc_output_get_virtual_resolution(output)->w - grid_windowSpacing; 56 | } 57 | } 58 | 59 | uint32_t getPageLength(wlc_handle const output) { 60 | if (grid_horizontal) { 61 | return wlc_output_get_virtual_resolution(output)->w - grid_windowSpacing; 62 | } else { 63 | return wlc_output_get_virtual_resolution(output)->h - grid_windowSpacing; 64 | } 65 | } 66 | 67 | // grid operations 68 | 69 | struct Grid* createGrid(wlc_handle output) { 70 | struct Grid* grid = malloc(sizeof(struct Grid)); 71 | grid->firstRow = NULL; 72 | grid->lastRow = NULL; 73 | grid->output = output; 74 | grid->scroll = 0.0; 75 | } 76 | 77 | void destroyGrid(wlc_handle output) { 78 | // nothing to do 79 | } 80 | 81 | void layoutGrid(struct Grid* grid) { 82 | layoutGridAt(grid->firstRow); 83 | } 84 | 85 | void layoutGridAt(struct Row* row) { 86 | while (row != NULL) { 87 | positionRow(row); 88 | applyRowGeometry(row); 89 | row = row->next; 90 | } 91 | } 92 | 93 | static void applyGridGeometry(struct Grid* grid) { 94 | struct Row* row = grid->firstRow; 95 | while (row != NULL) { 96 | applyRowGeometry(row); 97 | row = row->next; 98 | } 99 | } 100 | 101 | static void clearGrid(struct Grid* grid) { 102 | while (grid->firstRow != NULL) { 103 | struct Row* row = grid->firstRow; 104 | while (row->firstWindow != NULL) { 105 | struct Window* window = row->firstWindow; 106 | wlc_handle const view = window->view; 107 | wlc_view_close(view); 108 | destroyWindow(view); 109 | // window is freed by function destroyWindow 110 | } 111 | // row is freed by function destroyWindow 112 | } 113 | } 114 | 115 | // row operations 116 | 117 | void addRowToGrid(struct Row* row, struct Grid* grid) { 118 | addRowToGridAfter(row, grid, grid->lastRow); 119 | } 120 | 121 | void addRowToGridAfter(struct Row* row, struct Grid* grid, struct Row* prev) { 122 | // row must not yet be in a Grid 123 | assert (row->prev == NULL); 124 | assert (row->next == NULL); 125 | assert (row->parent == NULL); 126 | 127 | struct Row* next; 128 | row->prev = prev; 129 | row->parent = grid; 130 | if (prev == NULL) { 131 | // placing as firstRow 132 | next = grid->firstRow; 133 | row->next = grid->firstRow; 134 | grid->firstRow = row; 135 | } else { 136 | assert (grid->firstRow != NULL); 137 | assert (grid->lastRow != NULL); 138 | next = prev->next; 139 | row->next = prev->next; 140 | prev->next = row; 141 | } 142 | if (prev == grid->lastRow) { 143 | grid->lastRow = row; 144 | } 145 | if (next != NULL) { 146 | next->prev = row; 147 | } 148 | 149 | layoutGridAt(row); 150 | } 151 | 152 | void removeRow(struct Row* row) { 153 | struct Grid* grid = row->parent; 154 | struct Row* above = row->prev; 155 | struct Row* below = row->next; 156 | row->prev = NULL; // probably unnecessary (except for asserts) 157 | row->next = NULL; // probably unnecessary (except for asserts) 158 | row->parent = NULL; // unnecessary (except for asserts) 159 | 160 | if (grid->firstRow == row) { 161 | grid->firstRow = below; 162 | } 163 | if (grid->lastRow == row) { 164 | grid->lastRow = above; 165 | } 166 | 167 | if (above != NULL) { 168 | above->next = below; 169 | } 170 | if (below != NULL) { 171 | below->prev = above; 172 | layoutGridAt(below); 173 | } 174 | ensureSensibleScroll(grid); 175 | } 176 | 177 | void resizeWindowsIfNecessary(struct Row* const row) { 178 | assert (row->firstWindow != NULL); // rows are never empty 179 | assert (row->lastWindow != NULL); // rows are never empty 180 | uint32_t windowsSizeSum = 0; 181 | uint32_t windowsPreferredSizeSum = 0; 182 | uint32_t maxRowLength = getMaxRowLength(row->parent->output); 183 | struct Window* window = row->firstWindow; 184 | while (window != NULL) { 185 | uint32_t const preferredSize = getWindowPreferredSize(window); 186 | windowsSizeSum += window->size; 187 | windowsPreferredSizeSum += preferredSize; 188 | maxRowLength -= grid_windowSpacing; 189 | window->size = preferredSize; 190 | window = window->next; 191 | } 192 | if (windowsPreferredSizeSum > maxRowLength || grid_minimizeEmptySpace) { 193 | double ratio = (double)maxRowLength / windowsPreferredSizeSum; 194 | window = row->firstWindow; 195 | while (window != NULL) { 196 | window->size = (uint32_t)round(getWindowPreferredSize(window) * ratio); 197 | window = window->next; 198 | } 199 | } 200 | layoutRow(row); 201 | } 202 | 203 | // creates a new Row to house view 204 | struct Row* createRow(wlc_handle view) { 205 | struct Grid* grid = getGrid(wlc_view_get_output(view)); 206 | 207 | struct wlc_size const viewSize = wlc_view_get_geometry(view)->size; 208 | uint32_t rowSize = grid_horizontal ? viewSize.w : viewSize.h; 209 | 210 | struct Row* row = malloc(sizeof(struct Row)); 211 | row->prev = NULL; // probably unnecessary (except for asserts) 212 | row->next = NULL; // probably unnecessary (except for asserts) 213 | row->firstWindow = NULL; 214 | row->lastWindow = NULL; 215 | row->parent = NULL; // probably unnecessary (except for asserts) 216 | row->size = rowSize; 217 | 218 | addRowToGrid(row, grid); 219 | return row; 220 | } 221 | struct Row* createRowAndPlaceAfter(wlc_handle view, struct Row* prev) { 222 | struct Grid* grid = getGrid(wlc_view_get_output(view)); 223 | 224 | struct wlc_size const viewSize = wlc_view_get_geometry(view)->size; 225 | uint32_t rowSize = grid_horizontal ? viewSize.w : viewSize.h; 226 | 227 | struct Row* row = malloc(sizeof(struct Row)); 228 | row->prev = NULL; // probably unnecessary (except for asserts) 229 | row->next = NULL; // probably unnecessary (except for asserts) 230 | row->firstWindow = NULL; 231 | row->lastWindow = NULL; 232 | row->parent = NULL; // probably unnecessary (except for asserts) 233 | row->size = rowSize; 234 | 235 | addRowToGridAfter(row, grid, prev); 236 | return row; 237 | } 238 | 239 | bool isLastRow(const struct Row* row) { 240 | // TODO: Remove if unneeded 241 | return row->parent->lastRow == row; 242 | } 243 | 244 | bool isRowEdge(enum wlc_resize_edge edge) { 245 | bool horizontalEdge = edge & (WLC_RESIZE_EDGE_TOP | WLC_RESIZE_EDGE_BOTTOM); 246 | return !grid_horizontal != !horizontalEdge; // ! converts to bool (0 or 1) 247 | } 248 | 249 | void layoutRow(struct Row* row) { 250 | struct Window* window = row->firstWindow; 251 | while (window != NULL) { 252 | positionWindow(window); 253 | window = window->next; 254 | } 255 | applyRowGeometry(row); 256 | } 257 | 258 | void positionRow(struct Row* row) { 259 | if (row->prev == NULL) { 260 | row->origin = grid_windowSpacing; 261 | } else { 262 | row->origin = row->prev->origin + grid_windowSpacing + row->prev->size; 263 | } 264 | } 265 | 266 | void applyRowGeometry(const struct Row* row) { 267 | struct Window* window = row->firstWindow; 268 | while (window != NULL) { 269 | applyWindowGeometry(window); 270 | window = window->next; 271 | } 272 | } 273 | 274 | void scrollToRow(const struct Row* row) { 275 | struct Grid* const grid = row->parent; 276 | uint32_t const screenLength = getPageLength(grid->output); 277 | 278 | int32_t const row_top = row->origin; 279 | int32_t const row_btm = row_top + row->size; 280 | int32_t const screen_top = (int32_t)grid->scroll; 281 | int32_t const screen_btm = screen_top + screenLength; 282 | 283 | int32_t const margin_top = row_top - screen_top; 284 | int32_t const margin_btm = screen_btm - row_btm; 285 | 286 | if (margin_top < 0) { 287 | // row is above the screen 288 | if (margin_btm < 0) { 289 | // row is also below the screen, therefore it's already visible and there's no need to scroll 290 | return; 291 | } 292 | // scroll up, so that row_top == screen_top 293 | grid->scroll = (double)row_top; 294 | 295 | } else if (margin_btm < 0) { 296 | // row is below the screen 297 | // scroll down, so that row_btm == screen_btm 298 | grid->scroll = (double)(row_btm - screenLength); 299 | 300 | } else { 301 | assert (margin_top >= 0 && margin_btm >= 0); 302 | // row visible, no need to scroll 303 | return; 304 | } 305 | 306 | // do scroll 307 | applyGridGeometry(grid); 308 | 309 | hoveredEdge = NULL; 310 | } 311 | 312 | void resizeRow(struct Row* row, int32_t sizeDelta) { 313 | row->size += sizeDelta; 314 | ensureMinSize(&row->size); 315 | for (struct Window* window = row->firstWindow; window != NULL; window = window->next) { 316 | if (grid_horizontal) { 317 | window->preferredWidth = row->size; 318 | } else { 319 | window->preferredHeight = row->size; 320 | } 321 | } 322 | layoutGridAt(row); 323 | } 324 | 325 | // window operations 326 | 327 | struct Window* createWindow(wlc_handle const view) { 328 | if (!isGriddable(view)) { 329 | return NULL; 330 | } 331 | wlc_handle const output = wlc_view_get_output(view); 332 | assert (getGrid(output) != NULL); // grid already created by function output_created 333 | 334 | struct wlc_size const viewSize = wlc_view_get_geometry(view)->size; 335 | uint32_t windowSize = grid_horizontal ? viewSize.h : viewSize.w; 336 | 337 | struct Window* window = malloc(sizeof(struct Window)); 338 | window->prev = NULL; // probably unnecessary (except for asserts) 339 | window->next = NULL; // probably unnecessary (except for asserts) 340 | window->parent = NULL; // probably unnecessary (except for asserts) 341 | window->view = view; 342 | window->size = windowSize; 343 | window->preferredWidth = viewSize.w; 344 | window->preferredHeight = viewSize.h; 345 | 346 | struct Row* row = createRow(view); 347 | addWindowToRow(window, row); 348 | return window; 349 | } 350 | 351 | void destroyWindow(wlc_handle const view) { 352 | hoveredEdge = NULL; 353 | 354 | struct Window* window = getWindow(view); 355 | if (window == NULL) { 356 | return; 357 | } 358 | 359 | // focus next window 360 | struct Window *nextWindow = window->next; 361 | if (nextWindow == NULL) { 362 | nextWindow = window->prev; 363 | } 364 | if (nextWindow == NULL) { 365 | nextWindow = getWindowParallelNext(window); 366 | } 367 | if (nextWindow == NULL) { 368 | nextWindow = getWindowParallelPrev(window); 369 | } 370 | if (nextWindow != NULL) { 371 | wlc_view_focus(nextWindow->view); 372 | } 373 | 374 | // free 375 | removeWindow(window); 376 | free(window); 377 | } 378 | 379 | bool isLastWindow(const struct Window* window) { 380 | // TODO: Remove if unneeded 381 | return window->parent->lastWindow == window; 382 | } 383 | 384 | // returns true if resizing handled by grid 385 | bool viewResized(wlc_handle const view) { 386 | // TODO: Remove if unneeded 387 | struct Window* window = getWindow(view); 388 | if (window == NULL) { 389 | return false; 390 | } 391 | return true; 392 | } 393 | 394 | void addWindowToRow(struct Window* window, struct Row* row) { 395 | addWindowToRowAfter(window, row, row->lastWindow); 396 | } 397 | 398 | void addWindowToRowAfter(struct Window* window, struct Row* row, struct Window* prev) { 399 | // window must not yet be in a Row 400 | assert (window->prev == NULL); 401 | assert (window->next == NULL); 402 | assert (window->parent == NULL); 403 | 404 | struct Window* next; 405 | window->prev = prev; 406 | window->parent = row; 407 | window->size = getWindowPreferredSize(window); 408 | if (prev == NULL) { 409 | // placing as firstWindow 410 | next = row->firstWindow; 411 | window->next = row->firstWindow; 412 | row->firstWindow = window; 413 | } else { 414 | assert (row->firstWindow != NULL); 415 | assert (row->lastWindow != NULL); 416 | next = prev->next; 417 | window->next = prev->next; 418 | prev->next = window; 419 | } 420 | if (prev == row->lastWindow) { 421 | row->lastWindow = window; 422 | } 423 | if (next != NULL) { 424 | next->prev = window; 425 | } 426 | resizeWindowsIfNecessary(row); 427 | } 428 | 429 | void removeWindow(struct Window* const window) { 430 | struct Row* row = window->parent; 431 | struct Window* left = window->prev; 432 | struct Window* right = window->next; 433 | window->prev = NULL; // probably unnecessary (except for asserts) 434 | window->next = NULL; // probably unnecessary (except for asserts) 435 | window->parent = NULL; // probably unnecessary (except for asserts) 436 | 437 | if (left != NULL) { 438 | left->next = right; 439 | } 440 | if (right != NULL) { 441 | right->prev = left; 442 | } 443 | 444 | if (row->firstWindow == window) { 445 | row->firstWindow = right; 446 | } 447 | if (row->lastWindow == window) { 448 | row->lastWindow = left; 449 | } 450 | 451 | if (row->firstWindow == NULL) { 452 | assert (row->lastWindow == NULL); 453 | // destroy row if empty 454 | removeRow(row); 455 | free(row); 456 | } else { 457 | assert (row->lastWindow != NULL); 458 | // otherwise recalculate window sizes and positions 459 | resizeWindowsIfNecessary(row); 460 | } 461 | 462 | resetWindowSize(window); 463 | } 464 | 465 | void positionWindow(struct Window* window) { 466 | if (window->prev == NULL) { 467 | window->origin = grid_windowSpacing; 468 | } else { 469 | window->origin = window->prev->origin + grid_windowSpacing + window->prev->size; 470 | } 471 | } 472 | 473 | void applyWindowGeometry(const struct Window* window) { 474 | struct Row* row = window->parent; 475 | uint32_t offset = -(uint32_t)round(row->parent->scroll); 476 | struct wlc_geometry geometry; 477 | 478 | // hide offscreen views 479 | const uint32_t pageLength = getPageLength(window->parent->parent->output); 480 | const bool visible = (int32_t)(row->origin + offset) <= (int32_t)pageLength && 481 | (int32_t)(row->origin + offset + row->size) >= 0; 482 | wlc_view_set_mask(window->view, (uint32_t)visible); 483 | 484 | if (visible) { 485 | // calculate geometry 486 | if (grid_horizontal) { 487 | geometry.origin.x = row->origin + offset; 488 | geometry.origin.y = window->origin; 489 | geometry.size.w = row->size; 490 | geometry.size.h = window->size; 491 | } else { 492 | geometry.origin.x = window->origin; 493 | geometry.origin.y = row->origin + offset; 494 | geometry.size.w = window->size; 495 | geometry.size.h = row->size; 496 | } 497 | wlc_view_set_geometry(window->view, 0, &geometry); 498 | } 499 | } 500 | 501 | uint32_t getWindowPreferredSize(const struct Window* window) { 502 | return grid_horizontal ? window->preferredHeight : window->preferredWidth; 503 | } 504 | 505 | void resizeWindow(struct Window* window, int32_t sizeDelta) { 506 | if (sizeDelta < 0) { 507 | // resizedWindow is shrinking 508 | int32_t minAllowedDelta_minSize = MIN_WINDOW_SIZE - window->size; 509 | if (sizeDelta < minAllowedDelta_minSize) { 510 | sizeDelta = minAllowedDelta_minSize; 511 | } 512 | 513 | // try restoring the size of following windows 514 | int32_t availableRoom = -sizeDelta; 515 | struct Window* next = window->next; 516 | while (next != NULL && availableRoom > 0) { 517 | int32_t desiredNextGrowth = grid_minimizeEmptySpace ? INT32_MAX : getWindowPreferredSize(next) - next->size; 518 | if (desiredNextGrowth > 0) { 519 | if (desiredNextGrowth > availableRoom) { 520 | desiredNextGrowth = availableRoom; 521 | } 522 | next->size += desiredNextGrowth; 523 | availableRoom -= desiredNextGrowth; 524 | } 525 | next = next->next; 526 | } 527 | 528 | } else { 529 | // resizedWindow is growing 530 | const struct Row* row = window->parent; 531 | int32_t maxAllowedDelta_rowLength = getMaxRowLength(row->parent->output) - (row->lastWindow->origin + row->lastWindow->size); 532 | 533 | int32_t desiredNextShrinkage = sizeDelta - maxAllowedDelta_rowLength; 534 | if (desiredNextShrinkage > 0) { // same as sizeDelta > maxAllowedDelta_rowLength 535 | // there's not enough room in the row, but maybe we can shrink the next window 536 | struct Window* const next = window->next; 537 | if (next != NULL) { 538 | int32_t maxAllowedNextShrinkage = next->size - MIN_WINDOW_SIZE; 539 | if (maxAllowedNextShrinkage > 0) { 540 | maxAllowedDelta_rowLength += desiredNextShrinkage; 541 | next->size -= desiredNextShrinkage; 542 | } 543 | } 544 | sizeDelta = maxAllowedDelta_rowLength; 545 | } 546 | } 547 | 548 | // apply new geometry 549 | window->size += sizeDelta; 550 | if (grid_horizontal) { 551 | window->preferredHeight = window->size; 552 | } else { 553 | window->preferredWidth = window->size; 554 | } 555 | layoutRow(window->parent); 556 | } 557 | 558 | static void resetWindowSize(struct Window* window) { 559 | struct wlc_geometry geom; 560 | geom.origin = wlc_view_get_geometry(window->view)->origin; 561 | geom.size.w = window->preferredWidth; 562 | geom.size.h = window->preferredHeight; 563 | wlc_view_set_geometry(window->view, 0, &geom); 564 | } 565 | 566 | // presentation 567 | 568 | void printGrid(const struct Grid* grid) { 569 | fprintf(stderr, "Grid:\n"); 570 | struct Row* row = grid->firstRow; 571 | while (row != NULL) { 572 | struct Window* window = row->firstWindow; 573 | while (window != NULL) { 574 | fprintf(stderr, "%d ", window->view); 575 | window = window->next; 576 | } 577 | fprintf(stderr, "\n"); 578 | row = row->next; 579 | } 580 | } 581 | 582 | void scrollGrid(struct Grid* grid, double amount) { 583 | grid->scroll += amount; 584 | ensureSensibleScroll(grid); 585 | hoveredEdge = NULL; 586 | } 587 | 588 | void ensureSensibleScroll(struct Grid* grid) { 589 | if (grid->scroll < 0.0) { 590 | grid->scroll = 0.0; 591 | } else { 592 | const struct Row* const lastRow = grid->lastRow; 593 | if (lastRow == NULL) { 594 | // grid is empty, can't scroll 595 | grid->scroll = 0.0; 596 | } else { 597 | int32_t const overflow = (lastRow->origin + lastRow->size) - getPageLength(grid->output); 598 | if (overflow < 0) { 599 | grid->scroll = 0.0; 600 | } else if (grid->scroll > overflow) { 601 | grid->scroll = overflow; 602 | } 603 | } 604 | } 605 | layoutGrid(grid); 606 | } 607 | 608 | // neighboring Windows 609 | 610 | struct Window* getWindowParallelPrev(const struct Window* window) { 611 | // TODO: determine closest 612 | if (window->parent->prev == NULL) { 613 | return NULL; 614 | } 615 | return window->parent->prev->firstWindow; 616 | } 617 | 618 | struct Window* getWindowParallelNext(const struct Window* window) { 619 | // TODO: determine closest 620 | if (window->parent->next == NULL) { 621 | return NULL; 622 | } 623 | return window->parent->next->firstWindow; 624 | } 625 | 626 | struct Window* getWindowAbove(const struct Window* window) { 627 | if (grid_horizontal) { 628 | return window->prev; 629 | } 630 | return getWindowParallelPrev(window); 631 | } 632 | 633 | struct Window* getWindowBelow(const struct Window* window) { 634 | if (grid_horizontal) { 635 | return window->next; 636 | } 637 | return getWindowParallelNext(window); 638 | } 639 | 640 | struct Window* getWindowLeft(const struct Window* window) { 641 | if (grid_horizontal) { 642 | return getWindowParallelPrev(window); 643 | } 644 | return window->prev; 645 | } 646 | 647 | struct Window* getWindowRight(const struct Window* window) { 648 | if (grid_horizontal) { 649 | return getWindowParallelNext(window); 650 | } 651 | return window->next; 652 | } 653 | 654 | // view management 655 | 656 | void focusRow(size_t const index, wlc_handle const currentView) { 657 | // get selected row 658 | const struct Row* selectedRow = getGrid(wlc_get_focused_output())->firstRow; 659 | for (size_t i = 0; i < index && selectedRow != NULL; i++) { 660 | selectedRow = selectedRow->next; 661 | } 662 | if (selectedRow == NULL) { 663 | return; 664 | } 665 | 666 | // if already in selected row, move focus to its next window 667 | const struct Window* const currentWindow = getWindow(getGriddedParentView(currentView)); 668 | if (currentWindow != NULL) { 669 | const struct Row* const currentRow = currentWindow->parent; 670 | if (currentRow == selectedRow && currentWindow->next != NULL) { 671 | // focus next window 672 | wlc_view_focus(currentWindow->next->view); 673 | return; 674 | } 675 | } 676 | 677 | // focus selected row 678 | assert(selectedRow->firstWindow != NULL); 679 | wlc_view_focus(selectedRow->firstWindow->view); 680 | } 681 | 682 | typedef struct Window* (*WindowNeighborGetter)(const struct Window* window); 683 | static void focusViewInner(wlc_handle const view, WindowNeighborGetter getNeighbor) { 684 | const struct Window* currentWindow = getWindow(getGriddedParentView(view)); 685 | if (currentWindow == NULL) { 686 | return; 687 | } 688 | const struct Window* targetWindow = getNeighbor(currentWindow); 689 | if (targetWindow != NULL) { 690 | wlc_view_focus(targetWindow->view); 691 | } 692 | } 693 | void focusViewAbove(wlc_handle const view) { 694 | focusViewInner(view, &getWindowAbove); 695 | } 696 | void focusViewBelow(wlc_handle const view) { 697 | focusViewInner(view, &getWindowBelow); 698 | } 699 | void focusViewLeft(wlc_handle const view) { 700 | focusViewInner(view, &getWindowLeft); 701 | } 702 | void focusViewRight(wlc_handle const view) { 703 | focusViewInner(view, &getWindowRight); 704 | } 705 | 706 | // returns true if correct action done 707 | static void moveViewInner(wlc_handle const view, WindowNeighborGetter const getNeighbor, bool const stayInRow, bool const forward) { 708 | struct Window* const window = getWindow(view); 709 | if (window == NULL) { 710 | return; 711 | } 712 | struct Row* const row = window->parent; 713 | bool const onlyChild = row->firstWindow == row->lastWindow; 714 | assert (onlyChild == (row->firstWindow == window && row->lastWindow == window)); 715 | 716 | if (stayInRow || onlyChild) { 717 | struct Window* targetWindow = getNeighbor(window); 718 | if (targetWindow == NULL) { 719 | // window already at edge, can't move further 720 | // or 721 | // window's own private row already at edge, can't move further 722 | return; 723 | } 724 | struct Row* targetRow = targetWindow->parent; 725 | if (stayInRow && targetWindow != window->next) { 726 | targetWindow = targetWindow->prev; 727 | } 728 | removeWindow(window); 729 | addWindowToRowAfter(window, targetRow, targetWindow); 730 | 731 | } else { 732 | // put window into its own row 733 | removeWindow(window); 734 | struct Row* newRow = createRowAndPlaceAfter(view, forward ? row : row->prev); 735 | addWindowToRow(window, newRow); 736 | } 737 | } 738 | void moveViewUp(wlc_handle const view) { 739 | moveViewInner(view, &getWindowAbove, grid_horizontal, false); 740 | } 741 | void moveViewDown(wlc_handle const view) { 742 | moveViewInner(view, &getWindowBelow, grid_horizontal, true); 743 | } 744 | void moveViewLeft(wlc_handle const view) { 745 | moveViewInner(view, &getWindowLeft, !grid_horizontal, false); 746 | } 747 | void moveViewRight(wlc_handle const view) { 748 | moveViewInner(view, &getWindowRight, !grid_horizontal, true); 749 | } 750 | 751 | void moveRowBack(wlc_handle const view) { 752 | const struct Window* window = getWindow(view); 753 | if (window == NULL) { 754 | return; 755 | } 756 | struct Row* row = window->parent; 757 | if (row->prev == NULL) { 758 | // already at the top 759 | return; 760 | } 761 | struct Grid* grid = row->parent; 762 | struct Row* targetRow = row->prev->prev; 763 | removeRow(row); 764 | addRowToGridAfter(row, grid, targetRow); 765 | } 766 | 767 | void moveRowForward(wlc_handle const view) { 768 | const struct Window* window = getWindow(view); 769 | if (window == NULL) { 770 | return; 771 | } 772 | struct Row* row = window->parent; 773 | if (row->next == NULL) { 774 | // already at the bottom 775 | return; 776 | } 777 | struct Grid* grid = row->parent; 778 | struct Row* targetRow = row->next; 779 | removeRow(row); 780 | addRowToGridAfter(row, grid, targetRow); 781 | } 782 | 783 | void scrollToView(wlc_handle const view) { 784 | const struct Window* window = getWindow(getGriddedParentView(view)); 785 | if (window == NULL) { 786 | return; 787 | } 788 | scrollToRow(window->parent); 789 | } 790 | 791 | void getPointerPositionWithScroll(const struct Grid* grid, double* longPos, double* latPos) { 792 | double x, y; 793 | wlc_pointer_get_position_v2(&x, &y); 794 | 795 | if (grid_horizontal) { 796 | *longPos = x + grid->scroll; 797 | *latPos = y; 798 | } else { 799 | *longPos = y + grid->scroll; 800 | *latPos = x; 801 | } 802 | } 803 | 804 | enum wlc_resize_edge getNearestEdgeOfView(wlc_handle view) { 805 | double x, y; 806 | wlc_pointer_get_position_v2(&x, &y); 807 | const struct wlc_geometry* geom = wlc_view_get_geometry(view); 808 | double distToTop = y - geom->origin.y; 809 | double distToBtm = geom->origin.y + geom->size.h - y; 810 | double distToLeft = x - geom->origin.x; 811 | double distToRight = geom->origin.x + geom->size.w - x; 812 | 813 | if (distToTop < distToBtm) { 814 | if (distToTop < distToLeft) { 815 | if (distToTop < distToRight) { 816 | return WLC_RESIZE_EDGE_TOP; 817 | } else { 818 | return WLC_RESIZE_EDGE_RIGHT; 819 | } 820 | } else { 821 | if (distToLeft < distToRight) { 822 | return WLC_RESIZE_EDGE_LEFT; 823 | } else { 824 | return WLC_RESIZE_EDGE_RIGHT; 825 | } 826 | } 827 | } else { 828 | if (distToBtm < distToLeft) { 829 | if (distToBtm < distToRight) { 830 | return WLC_RESIZE_EDGE_BOTTOM; 831 | } else { 832 | return WLC_RESIZE_EDGE_RIGHT; 833 | } 834 | } else { 835 | if (distToLeft < distToRight) { 836 | return WLC_RESIZE_EDGE_LEFT; 837 | } else { 838 | return WLC_RESIZE_EDGE_RIGHT; 839 | } 840 | } 841 | } 842 | } 843 | 844 | enum wlc_resize_edge getNearestCornerOfView(wlc_handle view) { 845 | double x, y; 846 | wlc_pointer_get_position_v2(&x, &y); 847 | const struct wlc_geometry* geom = wlc_view_get_geometry(view); 848 | double distToTop = y - geom->origin.y; 849 | double distToBtm = geom->origin.y + geom->size.h - y; 850 | double distToLeft = x - geom->origin.x; 851 | double distToRight = geom->origin.x + geom->size.w - x; 852 | 853 | enum wlc_resize_edge closestHorizontalEdge = distToTop < distToBtm ? WLC_RESIZE_EDGE_TOP : WLC_RESIZE_EDGE_BOTTOM; 854 | enum wlc_resize_edge closestVerticalEdge = distToLeft < distToRight ? WLC_RESIZE_EDGE_LEFT : WLC_RESIZE_EDGE_RIGHT; 855 | 856 | return closestHorizontalEdge | closestVerticalEdge; 857 | } 858 | 859 | // bottom edge is considered part of row 860 | // returns last row if pointer is below last row 861 | struct Row* getHoveredRow(const struct Grid* grid) { 862 | double longPos, latPos; 863 | getPointerPositionWithScroll(grid, &longPos, &latPos); 864 | 865 | for (struct Row* row = grid->firstRow; row != NULL; row = row->next) { 866 | if ((int32_t)row->origin + row->size + grid_windowSpacing > longPos) { 867 | return row; 868 | } 869 | } 870 | assert (grid->firstRow == NULL || longPos > grid->firstRow->origin - grid_windowSpacing); 871 | return grid->lastRow; 872 | } 873 | 874 | // free after use 875 | struct Edge* getNearestEdge(const struct Grid* grid) { 876 | double longPos, latPos; 877 | getPointerPositionWithScroll(grid, &longPos, &latPos); 878 | 879 | struct Row* row_hovered = getHoveredRow(grid); 880 | if (row_hovered == NULL) { 881 | return NULL; 882 | } 883 | struct Row* row_nearestBtmEdge; 884 | if (longPos < (int32_t)row_hovered->origin + row_hovered->size / 2) { 885 | // cursor in the upper half of row_hovered 886 | row_nearestBtmEdge = row_hovered->prev; 887 | 888 | } else { 889 | // cursor in the lower half of row_hovered 890 | row_nearestBtmEdge = row_hovered; 891 | 892 | if (longPos > (int32_t)row_hovered->origin + row_hovered->size + grid_windowSpacing) { 893 | assert (isLastRow(row_hovered)); 894 | // cursor below row, don't check windows 895 | struct Edge* retval = malloc(sizeof(struct Edge)); 896 | retval->type = EDGE_ROW; 897 | retval->row = row_nearestBtmEdge; 898 | retval->window = NULL; 899 | return retval; 900 | } 901 | } 902 | 903 | double rowEdgePos = grid_windowSpacing / 2; 904 | if (row_nearestBtmEdge != NULL) { 905 | rowEdgePos += (int32_t)row_nearestBtmEdge->origin + row_nearestBtmEdge->size; 906 | } 907 | double const distToRowEdge = fabs(rowEdgePos - longPos); 908 | 909 | assert (row_hovered->lastWindow != NULL); // rows can't be empty 910 | if (distToRowEdge > ROW_EDGE_GRAB_SIZE && latPos > row_hovered->lastWindow->origin + row_hovered->lastWindow->size) { 911 | // cursor after last window 912 | struct Edge* retval = malloc(sizeof(struct Edge)); 913 | retval->type = EDGE_WINDOW; 914 | retval->row = row_hovered; 915 | retval->window = row_hovered->lastWindow; 916 | return retval; 917 | } 918 | 919 | double distToWindowEdge = fabs(grid_windowSpacing - latPos); // first edge 920 | struct Window *window_nearestRightEdge = NULL; 921 | for (struct Window *window = row_hovered->firstWindow; window != NULL; window = window->next) { 922 | double const winPos = window->origin + window->size - grid_windowSpacing / 2; 923 | double const distToWindowEdge_current = fabs(winPos - latPos); 924 | if (distToWindowEdge_current >= distToWindowEdge) { 925 | // we've gone too far 926 | break; 927 | } 928 | distToWindowEdge = distToWindowEdge_current; 929 | window_nearestRightEdge = window; 930 | } 931 | 932 | struct Edge* retval = malloc(sizeof(struct Edge)); 933 | if (distToRowEdge > distToWindowEdge) { 934 | retval->type = EDGE_WINDOW; 935 | retval->row = row_hovered; 936 | retval->window = window_nearestRightEdge; 937 | } else { 938 | retval->type = EDGE_ROW; 939 | retval->row = row_nearestBtmEdge; 940 | retval->window = NULL; 941 | } 942 | 943 | return retval; 944 | } 945 | 946 | // free after use 947 | struct Edge* getExactEdge(const struct Grid* grid) { 948 | double longPos, latPos; 949 | getPointerPositionWithScroll(grid, &longPos, &latPos); 950 | 951 | struct Row* row_hovered = getHoveredRow(grid); 952 | if (row_hovered == NULL) { 953 | return NULL; 954 | } 955 | 956 | uint32_t const rowBtmEdge = row_hovered->origin + row_hovered->size; 957 | if (longPos < rowBtmEdge) { 958 | // inside of row hovered 959 | for (struct Window* window = row_hovered->firstWindow; window != NULL; window = window->next) { 960 | uint32_t windowRightEdge = window->origin + window->size; 961 | uint32_t windowRightEdgeEnd = windowRightEdge + grid_windowSpacing; 962 | if (latPos < windowRightEdge) { 963 | // inside of window hovered 964 | return NULL; 965 | } else if (latPos < windowRightEdgeEnd) { 966 | // window edge hovered 967 | struct Edge* edge = malloc(sizeof(struct Edge)); 968 | edge->type = EDGE_WINDOW; 969 | edge->row = row_hovered; 970 | edge->window = window; 971 | return edge; 972 | } 973 | } 974 | // pointer is placed after last window 975 | struct Edge* edge = malloc(sizeof(struct Edge)); 976 | edge->type = EDGE_WINDOW; 977 | edge->row = row_hovered; 978 | edge->window = row_hovered->lastWindow; 979 | return edge; 980 | 981 | } else { 982 | // top edge hovered 983 | struct Edge* edge = malloc(sizeof(struct Edge)); 984 | edge->type = EDGE_ROW; 985 | edge->row = row_hovered; 986 | edge->window = NULL; 987 | return edge; 988 | } 989 | } 990 | 991 | bool doesEdgeBelongToView(const struct Edge* const edge, wlc_handle const view) { 992 | const struct Window* const window = getWindow(view); 993 | if (window == NULL) { 994 | // not a gridded window, therefore it has no Edges 995 | return false; 996 | } 997 | 998 | switch (edge->type) { 999 | case EDGE_ROW: { 1000 | bool const isOnlyWindow = window->prev == NULL && window->next == NULL; 1001 | return isOnlyWindow && (edge->row == window->parent || edge->row == window->parent->prev); 1002 | } 1003 | case EDGE_WINDOW: { 1004 | bool const isSameRow = edge->row == window->parent; 1005 | return isSameRow && (edge->window == window || edge->window == window->prev); 1006 | } 1007 | case EDGE_CORNER: // TODO 1008 | default: return false; 1009 | } 1010 | } 1011 | 1012 | void moveViewToEdge(wlc_handle const view, struct Edge *edge) { 1013 | struct Window* const window = getWindow(view); 1014 | assert (window != NULL); // only gridded windows can be moved 1015 | assert (!doesEdgeBelongToView(edge, view)); // crash early 1016 | removeWindow(window); 1017 | switch (edge->type) { 1018 | case EDGE_ROW: { 1019 | struct Row* const newRow = createRowAndPlaceAfter(window->view, edge->row); 1020 | addWindowToRow(window, newRow); 1021 | break; 1022 | } 1023 | case EDGE_WINDOW: { 1024 | addWindowToRowAfter(window, edge->row, edge->window); 1025 | break; 1026 | } 1027 | case EDGE_CORNER: assert (false); 1028 | } 1029 | } 1030 | 1031 | // output management 1032 | 1033 | void evacuateOutput(wlc_handle const output) { 1034 | struct Grid* grid = getGrid(output); 1035 | if (grid == NULL) { 1036 | return; 1037 | } 1038 | 1039 | // find target grid 1040 | struct Output* targetOutput = getAnOutput(); 1041 | 1042 | if (targetOutput == NULL) { 1043 | // we can't evacuate anywhere, close all windows 1044 | clearGrid(grid); 1045 | } else { 1046 | assert (targetOutput->grid != NULL); // all outputs have grids 1047 | struct Grid* targetGrid = targetOutput->grid; 1048 | // move all rows to targetGrid 1049 | while (grid->firstRow != NULL) { 1050 | struct Row* firstRow = grid->firstRow; 1051 | removeRow(firstRow); 1052 | addRowToGrid(firstRow, targetGrid); 1053 | } 1054 | } 1055 | 1056 | destroyGrid(output); 1057 | } 1058 | 1059 | bool ensureMinSize(uint32_t* size) { 1060 | if (*size < MIN_WINDOW_SIZE) { 1061 | *size = MIN_WINDOW_SIZE; 1062 | return true; 1063 | } 1064 | return false; 1065 | } 1066 | -------------------------------------------------------------------------------- /src/grid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define MIN_WINDOW_SIZE 64 6 | 7 | struct Grid { 8 | struct Row* firstRow; 9 | struct Row* lastRow; 10 | wlc_handle output; 11 | double scroll; 12 | }; 13 | 14 | struct Row { 15 | struct Row* prev; 16 | struct Row* next; 17 | struct Window* firstWindow; 18 | struct Window* lastWindow; 19 | struct Grid* parent; 20 | int32_t origin; 21 | uint32_t size; 22 | }; 23 | 24 | struct Window { 25 | struct Window* prev; 26 | struct Window* next; 27 | wlc_handle view; 28 | struct Row* parent; 29 | uint32_t origin; 30 | uint32_t size; 31 | uint32_t preferredWidth; 32 | uint32_t preferredHeight; 33 | }; 34 | 35 | enum EdgeType { 36 | EDGE_ROW, 37 | EDGE_WINDOW, 38 | EDGE_CORNER 39 | }; 40 | 41 | struct Edge { 42 | enum EdgeType type; 43 | struct Row* row; // row before edge 44 | struct Window* window; // window before edge 45 | }; 46 | 47 | void grid_init(); 48 | 49 | // getters 50 | struct Grid* getGrid(wlc_handle output); 51 | struct Window* getWindow(wlc_handle view); 52 | bool isGriddable(wlc_handle view); 53 | bool isGridded(wlc_handle view); 54 | bool isFloating(wlc_handle view); 55 | uint32_t getMaxRowLength(wlc_handle output); 56 | uint32_t getPageLength(wlc_handle output); 57 | 58 | // grid operations 59 | struct Grid* createGrid(wlc_handle output); 60 | void destroyGrid(wlc_handle output); 61 | static void layoutGrid(struct Grid* grid); 62 | void layoutGridAt(struct Row* row); 63 | static void applyGridGeometry(struct Grid* grid); 64 | static void clearGrid(struct Grid* grid); 65 | 66 | // row operations 67 | static struct Row* createRow(wlc_handle view); // creates a new Row to house the given view 68 | static struct Row* createRowAndPlaceAfter(wlc_handle view, struct Row* prev); 69 | bool isLastRow(const struct Row* row); 70 | bool isRowEdge(enum wlc_resize_edge edge); 71 | static void addRowToGrid(struct Row* row, struct Grid* grid); 72 | static void addRowToGridAfter(struct Row* row, struct Grid* grid, struct Row* prev); 73 | static void removeRow(struct Row* row); 74 | static void resizeWindowsIfNecessary(struct Row* row); 75 | void layoutRow(struct Row* row); 76 | static void positionRow(struct Row* row); 77 | static void applyRowGeometry(const struct Row* row); 78 | static void scrollToRow(const struct Row* row); 79 | void resizeRow(struct Row* row, int32_t sizeDelta); 80 | 81 | // window operations 82 | struct Window* createWindow(wlc_handle view); 83 | void destroyWindow(wlc_handle view); 84 | bool isLastWindow(const struct Window* window); 85 | bool viewResized(wlc_handle view); // returns true if resizing handled by grid 86 | static void addWindowToRow(struct Window* window, struct Row* row); 87 | static void addWindowToRowAfter(struct Window* window, struct Row* row, struct Window* prev); 88 | static void removeWindow(struct Window* window); 89 | static void positionWindow(struct Window* window); 90 | static void applyWindowGeometry(const struct Window* window); 91 | uint32_t getWindowPreferredSize(const struct Window* window); 92 | void resizeWindow(struct Window* window, int32_t sizeDelta); 93 | static void resetWindowSize(struct Window* window); 94 | 95 | // presentation 96 | void printGrid(const struct Grid* grid); 97 | void scrollGrid(struct Grid* grid, double amount); 98 | static void ensureSensibleScroll(struct Grid* grid); 99 | 100 | // neighboring Windows 101 | static struct Window* getWindowParallelPrev(const struct Window* window); 102 | static struct Window* getWindowParallelNext(const struct Window* window); 103 | static struct Window* getWindowAbove(const struct Window* window); 104 | static struct Window* getWindowBelow(const struct Window* window); 105 | static struct Window* getWindowLeft(const struct Window* window); 106 | static struct Window* getWindowRight(const struct Window* window); 107 | 108 | // view management 109 | void focusRow(size_t index, wlc_handle currentView); 110 | void focusViewAbove(wlc_handle view); 111 | void focusViewBelow(wlc_handle view); 112 | void focusViewLeft(wlc_handle view); 113 | void focusViewRight(wlc_handle view); 114 | void moveViewUp(wlc_handle view); 115 | void moveViewDown(wlc_handle view); 116 | void moveViewLeft(wlc_handle view); 117 | void moveViewRight(wlc_handle view); 118 | void moveRowBack(wlc_handle view); 119 | void moveRowForward(wlc_handle view); 120 | void scrollToView(wlc_handle view); 121 | void getPointerPositionWithScroll(const struct Grid* grid, double* longPos, double* latPos); 122 | enum wlc_resize_edge getNearestEdgeOfView(wlc_handle view); 123 | enum wlc_resize_edge getNearestCornerOfView(wlc_handle view); 124 | struct Row* getHoveredRow(const struct Grid* grid); // bottom edge is considered part of row 125 | // returns last row if pointer is below last row 126 | struct Edge* getNearestEdge(const struct Grid* grid); // free after use 127 | struct Edge* getExactEdge(const struct Grid* grid); // free after use 128 | bool doesEdgeBelongToView(const struct Edge* edge, wlc_handle view); 129 | void moveViewToEdge(wlc_handle view, struct Edge *edge); 130 | 131 | // output management 132 | void evacuateOutput(wlc_handle output); 133 | 134 | // misc 135 | bool ensureMinSize(uint32_t* size); // returns true if size was too small 136 | -------------------------------------------------------------------------------- /src/keyboard.c: -------------------------------------------------------------------------------- 1 | #include "keyboard.h" 2 | #include "grid.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | bool testKeystroke(const struct Keystroke* const keystroke, uint32_t const mods, uint32_t const sym) { 10 | return keystroke->mods == mods && keystroke->sym == sym; 11 | } 12 | 13 | void sendKey(wlc_handle const view, const struct Keystroke* const keystroke) { 14 | struct wl_client* const client = wlc_view_get_wl_client(view); 15 | if (client == NULL) { 16 | return; 17 | } 18 | struct wl_resource* const client_pointer = wl_client_get_object(client, 14); 19 | if (client_pointer == NULL) { 20 | return; 21 | } 22 | assert (strcmp(client_pointer->object.interface->name, "wl_keyboard") == 0); 23 | 24 | uint32_t const serial = wl_display_next_serial(wlc_get_wl_display()); 25 | struct timespec ts; 26 | clock_gettime(CLOCK_MONOTONIC, &ts); 27 | uint32_t const time = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; 28 | 29 | wl_keyboard_send_key(client_pointer, serial, time, 20, WL_KEYBOARD_KEY_STATE_PRESSED); 30 | wl_keyboard_send_key(client_pointer, serial, time, 20, WL_KEYBOARD_KEY_STATE_RELEASED); 31 | } 32 | 33 | bool keyboard_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t key, enum wlc_key_state state) { 34 | uint32_t const sym = wlc_keyboard_get_keysym_for_key(key, NULL); 35 | uint32_t const mods = modifiers->mods; 36 | 37 | if (state == WLC_KEY_STATE_PRESSED) { 38 | if (view) { 39 | 40 | // view-related keys 41 | 42 | if (isGridded(view)) { 43 | if (testKeystroke(&keystroke_focusWindowUp, mods, sym)) { 44 | focusViewAbove(view); 45 | return true; 46 | 47 | } else if (testKeystroke(&keystroke_focusWindowDown, mods, sym)) { 48 | focusViewBelow(view); 49 | return true; 50 | 51 | } else if (testKeystroke(&keystroke_focusWindowLeft, mods, sym)) { 52 | focusViewLeft(view); 53 | return true; 54 | 55 | } else if (testKeystroke(&keystroke_focusWindowRight, mods, sym)) { 56 | focusViewRight(view); 57 | return true; 58 | 59 | } else if (testKeystroke(&keystroke_moveRowBack, mods, sym)) { 60 | moveRowBack(view); 61 | return true; 62 | 63 | } else if (testKeystroke(&keystroke_moveRowForward, mods, sym)) { 64 | moveRowForward(view); 65 | return true; 66 | 67 | } else if (testKeystroke(&keystroke_moveWindowUp, mods, sym)) { 68 | moveViewUp(view); 69 | return true; 70 | 71 | } else if (testKeystroke(&keystroke_moveWindowDown, mods, sym)) { 72 | moveViewDown(view); 73 | return true; 74 | 75 | } else if (testKeystroke(&keystroke_moveWindowLeft, mods, sym)) { 76 | moveViewLeft(view); 77 | return true; 78 | 79 | } else if (testKeystroke(&keystroke_moveWindowRight, mods, sym)) { 80 | moveViewRight(view); 81 | return true; 82 | 83 | } 84 | } 85 | 86 | if (testKeystroke(&keystroke_closeWindow, mods, sym)) { 87 | wlc_view_close(view); 88 | return true; 89 | } 90 | } 91 | 92 | // global keys 93 | 94 | if (testKeystroke(&keystroke_terminate, mods, sym)) { 95 | wlc_terminate(); 96 | return true; 97 | 98 | } else { 99 | // Application shortcuts 100 | for (size_t i = 0; i < applicationShortcutCount; i++) { 101 | if (testKeystroke(&applicationShortcuts[i].binding, mods, sym)) { 102 | char* command = applicationShortcuts[i].command; 103 | wlc_exec(command, (char* const[]){ command, NULL }); 104 | return true; 105 | } 106 | } 107 | } 108 | 109 | // win+number row switching 110 | if (mods == MOD_WM0 && sym >= '0' && sym <= '9') { 111 | focusRow((sym - '0' + 9) % 10, view); // '0' is 9, '1' is 0, '2' is 1, ... 112 | return true; 113 | } 114 | } 115 | 116 | return false; 117 | } 118 | -------------------------------------------------------------------------------- /src/keyboard.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "config.h" 6 | 7 | bool testKeystroke(const struct Keystroke* keystroke, uint32_t mods, uint32_t sym); 8 | void sendKey(wlc_handle view, const struct Keystroke* keystroke); 9 | 10 | bool keyboard_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t key, enum wlc_key_state state); 11 | -------------------------------------------------------------------------------- /src/keystroke.c: -------------------------------------------------------------------------------- 1 | #include "keystroke.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | struct Keystroke parseKeystroke(const char* str) { 8 | struct Keystroke retval; 9 | retval.mods = 0; 10 | retval.sym = XKB_KEY_NoSymbol; 11 | 12 | const size_t strLength = strlen(str); 13 | char* strCopy = malloc(strLength + 1); 14 | strcpy(strCopy, str); 15 | char* token = strtok(strCopy, "+"); 16 | 17 | while (token != NULL) { 18 | if (strcmp(token, "Ctrl") == 0) { 19 | retval.mods |= WLC_BIT_MOD_CTRL; 20 | 21 | } else if (strcmp(token, "Alt") == 0) { 22 | retval.mods |= WLC_BIT_MOD_ALT; 23 | 24 | } else if (strcmp(token, "Shift") == 0) { 25 | retval.mods |= WLC_BIT_MOD_SHIFT; 26 | 27 | } else if (strcmp(token, "Logo") == 0) { 28 | retval.mods |= WLC_BIT_MOD_LOGO; 29 | 30 | } else if (retval.sym == XKB_KEY_NoSymbol) { 31 | // sym not set yet 32 | retval.sym = XStringToKeysym(token); 33 | 34 | } else { 35 | // sym already set (there can be only one sym) 36 | retval.sym = XKB_KEY_NoSymbol; 37 | break; 38 | } 39 | token = strtok(NULL, "+"); 40 | } 41 | free(strCopy); 42 | 43 | if (retval.sym == XKB_KEY_NoSymbol) { 44 | fprintf(stderr, "Not a valid keystroke: %s\n", str); 45 | } 46 | return retval; 47 | } 48 | 49 | // you must free returned value after use 50 | char* keystrokeToString(const struct Keystroke* keystroke) { 51 | char* retval = malloc(128); 52 | retval[0] = 0; 53 | const enum wlc_modifier_bit mods = keystroke->mods; 54 | 55 | if (mods & WLC_BIT_MOD_CTRL) strcat(retval, "Ctrl+"); 56 | if (mods & WLC_BIT_MOD_ALT) strcat(retval, "Alt+"); 57 | if (mods & WLC_BIT_MOD_SHIFT) strcat(retval, "Shift+"); 58 | if (mods & WLC_BIT_MOD_LOGO) strcat(retval, "Logo+"); 59 | 60 | strcat(retval, XKeysymToString(keystroke->sym)); 61 | 62 | return retval; 63 | } 64 | -------------------------------------------------------------------------------- /src/keystroke.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct Keystroke { 6 | uint32_t mods; 7 | uint32_t sym; 8 | }; 9 | 10 | struct Keystroke parseKeystroke(const char* str); 11 | 12 | // you must free returned value after use 13 | char* keystrokeToString(const struct Keystroke* keystroke); 14 | -------------------------------------------------------------------------------- /src/metamanager.c: -------------------------------------------------------------------------------- 1 | #include "metamanager.h" 2 | 3 | #include 4 | 5 | #define MIN_VIEW_COUNT 32 6 | 7 | static struct Output** outputs = NULL; 8 | static size_t outputCount = 0; 9 | static struct View** views = NULL; 10 | static size_t viewCount = 0; 11 | 12 | void meta_init() { 13 | views = malloc(MIN_VIEW_COUNT * sizeof(struct Window*)); 14 | viewCount = MIN_VIEW_COUNT; 15 | for (size_t i = 0; i < viewCount; i++) { 16 | views[i] = NULL; 17 | } 18 | } 19 | 20 | void meta_free() { 21 | free(views); 22 | free(outputs); 23 | } 24 | 25 | static size_t getViewsOccupancy() { 26 | // TODO: Instead of iterating, just remember highest view handle 27 | size_t const lowestShrinkThreshold = MIN_VIEW_COUNT/2 - 1; 28 | for (size_t i = viewCount - 1; i >= lowestShrinkThreshold; i--) { 29 | if (views[i] != NULL) { 30 | return i+1; 31 | } 32 | } 33 | return lowestShrinkThreshold; // or less, we don't care 34 | } 35 | 36 | struct Output* getOutput(wlc_handle output) { 37 | if (output >= outputCount) { 38 | return NULL; 39 | } 40 | return outputs[output]; 41 | } 42 | 43 | struct View* getView(wlc_handle view) { 44 | if (view >= viewCount) { 45 | return NULL; 46 | } 47 | return views[view]; 48 | } 49 | 50 | struct Output* onOutputCreated(wlc_handle output) { 51 | if (output >= outputCount) { 52 | size_t oldGridCount = outputCount; 53 | outputCount = output + 1; 54 | outputs = realloc(outputs, outputCount * sizeof(struct Grid*)); 55 | for (size_t i = oldGridCount; i < output; i++) { 56 | outputs[i] = NULL; 57 | } 58 | } 59 | 60 | struct Output* outputMeta = malloc(sizeof(struct Output)); // TODO: check for failure 61 | outputMeta->grid = createGrid(output); // TODO: check for failure 62 | 63 | // wallpaper (this should be done in a client, but I'm lazy) 64 | const struct wlc_size* resolution = wlc_output_get_resolution(output); 65 | uint32_t const width = resolution->w; 66 | uint32_t const height = resolution->h; 67 | outputMeta->wallpaper = malloc(width * height * sizeof(uint32_t)); 68 | for (size_t y = 0; y < height; y++) { 69 | size_t startX = y * width; 70 | for (size_t x = 0; x < width; x++) { 71 | outputMeta->wallpaper[startX + x] = 0xff804000; 72 | } 73 | } 74 | 75 | outputs[output] = outputMeta; 76 | return outputMeta; 77 | } 78 | 79 | struct View* onViewCreated(wlc_handle view) { 80 | if (view >= viewCount) { 81 | viewCount *= 2; 82 | views = realloc(views, viewCount * sizeof(struct Window*)); 83 | } 84 | 85 | struct View* viewMeta = malloc(sizeof(struct View)); 86 | viewMeta->window = createWindow(view); 87 | 88 | views[view] = viewMeta; 89 | return viewMeta; 90 | } 91 | 92 | void onOutputDestroyed(wlc_handle output) { 93 | struct Output* outputMeta = getOutput(output); 94 | assert (outputMeta != NULL); 95 | if (outputMeta->wallpaper != NULL) { 96 | free(outputMeta->wallpaper); 97 | } 98 | free(outputMeta); 99 | outputs[output] = NULL; 100 | // probably no need to shrink the array, people don't have THAT many screens 101 | } 102 | 103 | void onViewDestroyed(wlc_handle view) { 104 | destroyWindow(view); 105 | 106 | free(views[view]); 107 | views[view] = NULL; 108 | 109 | // shrink the array if below threshold 110 | size_t const shrinkThreshold = viewCount / 4; 111 | size_t const targetSize = viewCount / 2; 112 | if (targetSize >= MIN_VIEW_COUNT && getViewsOccupancy() <= shrinkThreshold) { 113 | views = realloc(views, targetSize * sizeof(struct Window*)); 114 | } 115 | } 116 | 117 | struct Output* getAnOutput() { 118 | for (size_t i = 0; i < outputCount; i++) { 119 | if (outputs[i] != NULL) { 120 | return outputs[i]; 121 | } 122 | } 123 | return NULL; 124 | } 125 | -------------------------------------------------------------------------------- /src/metamanager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "grid.h" 4 | 5 | struct Output { 6 | struct Grid* grid; 7 | uint32_t* wallpaper; // TODO: Do in a client 8 | }; 9 | 10 | struct View { 11 | struct Window* window; 12 | }; 13 | 14 | void meta_init(); 15 | void meta_free(); 16 | 17 | struct Output* getOutput(wlc_handle output); 18 | struct View* getView(wlc_handle view); 19 | 20 | struct Output* onOutputCreated(wlc_handle output); 21 | struct View* onViewCreated(wlc_handle view); 22 | 23 | void onOutputDestroyed(wlc_handle output); 24 | void onViewDestroyed(wlc_handle view); 25 | 26 | struct Output* getAnOutput(); 27 | -------------------------------------------------------------------------------- /src/mouse.c: -------------------------------------------------------------------------------- 1 | #include "mouse.h" 2 | #include "config.h" 3 | #include "keyboard.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | enum MouseModState { 12 | UNPRESSED, 13 | PRESSED, 14 | ACTION_PERFORMED 15 | }; 16 | static enum MouseModState mouseBackMod = UNPRESSED; 17 | static enum MouseModState mouseForwardMod = UNPRESSED; 18 | static void setMouseModActionPerformed(enum MouseModState* outState) { 19 | if (*outState == PRESSED) { 20 | *outState = ACTION_PERFORMED; 21 | } 22 | } 23 | 24 | enum MouseState mouseState = NORMAL; 25 | 26 | static double prevMouseX, prevMouseY; 27 | wlc_handle movedView = 0; 28 | static struct Window* resizedWindow = NULL; 29 | static struct Row* resizedRow = NULL; 30 | struct Edge* hoveredEdge = NULL; 31 | struct Edge* insertEdge = NULL; 32 | 33 | void sendButton(wlc_handle const view, uint32_t const button) { 34 | struct wl_client* const client = wlc_view_get_wl_client(view); 35 | if (client == NULL) { 36 | return; 37 | } 38 | struct wl_resource* const client_pointer = wl_client_get_object(client, 13); 39 | if (client_pointer == NULL) { 40 | return; 41 | } 42 | assert (strcmp(client_pointer->object.interface->name, "wl_pointer") == 0); 43 | 44 | uint32_t const serial = wl_display_next_serial(wlc_get_wl_display()); 45 | struct timespec ts; 46 | clock_gettime(CLOCK_MONOTONIC, &ts); 47 | uint32_t const time = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; 48 | 49 | wl_pointer_send_button(client_pointer, serial, time, button, WL_POINTER_BUTTON_STATE_PRESSED); 50 | wl_pointer_send_button(client_pointer, serial, time, button, WL_POINTER_BUTTON_STATE_RELEASED); 51 | } 52 | 53 | bool pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t button, enum wlc_button_state state, const struct wlc_point *position) { 54 | uint32_t mods = modifiers->mods; 55 | 56 | if (mouseBackMod > UNPRESSED) { 57 | mods |= MOD_WM0; 58 | } 59 | if (mouseForwardMod > UNPRESSED) { 60 | mods |= MOD_WM1; 61 | } 62 | 63 | switch (mouseState) { 64 | case NORMAL: { 65 | if (state == WLC_BUTTON_STATE_PRESSED) { 66 | if (view) { 67 | 68 | // view-related mouse events 69 | 70 | if (testKeystroke(&mousestroke_move, mods, button)) { 71 | movedView = view; 72 | setMouseModActionPerformed(&mouseBackMod); 73 | if (isFloating(view)) { 74 | mouseState = MOVING_FLOATING; 75 | wlc_view_bring_to_front(movedView); 76 | } else { 77 | mouseState = MOVING_GRIDDED; 78 | } 79 | return true; 80 | } 81 | 82 | if (testKeystroke(&mousestroke_resize, mods, button)) { 83 | setMouseModActionPerformed(&mouseBackMod); 84 | if (isFloating(view)) { 85 | movedView = view; 86 | mouseState = RESIZING_FLOATING; 87 | wlc_view_bring_to_front(movedView); 88 | } else { 89 | struct Window* window = getWindow(view); 90 | assert (window != NULL); // because we know it's not floating (must be gridded) 91 | enum wlc_resize_edge edge = getNearestEdgeOfView(view); 92 | bool previousEdge = edge & (WLC_RESIZE_EDGE_TOP | WLC_RESIZE_EDGE_LEFT); 93 | bool resizingRow = isRowEdge(edge); 94 | if (resizingRow) { 95 | resizedRow = previousEdge ? window->parent->prev : window->parent; 96 | if (resizedRow != NULL) { 97 | mouseState = RESIZING_ROW; 98 | } 99 | } else { 100 | resizedWindow = previousEdge ? window->prev : window; 101 | if (resizedWindow != NULL) { 102 | mouseState = RESIZING_WINDOW; 103 | } 104 | } 105 | } 106 | return true; 107 | } 108 | 109 | wlc_view_focus(view); 110 | 111 | } else { 112 | 113 | // edge mouse events (no view hovered) 114 | 115 | if (hoveredEdge != NULL && (button == BTN_LEFT || button == BTN_RIGHT)) { 116 | if (testKeystroke(&mousestroke_resize, mods, button)) { 117 | setMouseModActionPerformed(&mouseBackMod); 118 | } 119 | switch (hoveredEdge->type) { 120 | case EDGE_ROW: 121 | mouseState = RESIZING_ROW; 122 | resizedRow = hoveredEdge->row; 123 | break; 124 | case EDGE_WINDOW: 125 | mouseState = RESIZING_WINDOW; 126 | resizedWindow = hoveredEdge->window; 127 | break; 128 | case EDGE_CORNER: // TODO 129 | default: 130 | break; 131 | } 132 | return true; 133 | } 134 | } 135 | 136 | // global mouse events 137 | 138 | if (mods == 0) { 139 | switch (button) { 140 | case BTN_EXTRA: 141 | case BTN_BACK: mouseBackMod = PRESSED; return true; 142 | case BTN_SIDE: 143 | case BTN_FORWARD: mouseForwardMod = PRESSED; return true; 144 | default: break; 145 | } 146 | } 147 | } 148 | break; 149 | } 150 | 151 | case MOVING_FLOATING: { 152 | if (state == WLC_BUTTON_STATE_RELEASED && button == BTN_LEFT) { 153 | movedView = 0; 154 | mouseState = NORMAL; 155 | return true; 156 | } 157 | break; 158 | } 159 | 160 | case MOVING_GRIDDED: { 161 | if (state == WLC_BUTTON_STATE_RELEASED && button == BTN_LEFT) { 162 | if (insertEdge != NULL) { 163 | moveViewToEdge(movedView, insertEdge); 164 | free(insertEdge); 165 | insertEdge = NULL; 166 | } 167 | movedView = 0; 168 | mouseState = NORMAL; 169 | return true; 170 | } 171 | break; 172 | } 173 | 174 | case RESIZING_FLOATING: { 175 | if (state == WLC_BUTTON_STATE_RELEASED && button == BTN_RIGHT) { 176 | movedView = 0; 177 | mouseState = NORMAL; 178 | return true; 179 | } 180 | break; 181 | } 182 | 183 | case RESIZING_WINDOW: 184 | case RESIZING_ROW: { 185 | if (state == WLC_BUTTON_STATE_RELEASED && (button == BTN_LEFT || button == BTN_RIGHT)) { 186 | movedView = 0; 187 | mouseState = NORMAL; 188 | return true; 189 | } 190 | break; 191 | } 192 | } 193 | 194 | if (state == WLC_BUTTON_STATE_RELEASED) { 195 | switch (button) { 196 | case BTN_EXTRA: 197 | case BTN_BACK: { 198 | if (mouseBackMod != ACTION_PERFORMED) { 199 | sendButton(view, BTN_EXTRA); 200 | } 201 | mouseBackMod = UNPRESSED; 202 | return true; 203 | } 204 | case BTN_SIDE: 205 | case BTN_FORWARD: { 206 | if (mouseForwardMod != ACTION_PERFORMED) { 207 | sendButton(view, BTN_SIDE); 208 | } 209 | mouseForwardMod = UNPRESSED; 210 | return true; 211 | } 212 | default: break; 213 | } 214 | } 215 | 216 | return false; 217 | } 218 | 219 | bool pointer_motion(wlc_handle view, uint32_t time, double x, double y) { 220 | // In order to give the compositor control of the pointer placement it needs 221 | // to be explicitly set after receiving the motion event: 222 | wlc_pointer_set_position_v2(x, y); 223 | 224 | free(insertEdge); 225 | insertEdge = NULL; 226 | 227 | switch (mouseState) { 228 | case NORMAL: { 229 | free(hoveredEdge); 230 | hoveredEdge = view ? NULL : getExactEdge(getGrid(wlc_get_focused_output())); 231 | break; 232 | } 233 | case MOVING_FLOATING: { 234 | const struct wlc_geometry* geom_start = wlc_view_get_geometry(movedView); 235 | struct wlc_geometry geom_new; 236 | geom_new.origin.x = geom_start->origin.x + (uint32_t)round(x - prevMouseX); 237 | geom_new.origin.y = geom_start->origin.y + (uint32_t)round(y - prevMouseY); 238 | geom_new.size = geom_start->size; 239 | wlc_view_set_geometry(movedView, 0, &geom_new); 240 | break; 241 | } 242 | case RESIZING_FLOATING: { 243 | // TODO: Enable resizing in all directions (all edges) 244 | const struct wlc_geometry* geom_start = wlc_view_get_geometry(movedView); 245 | struct wlc_geometry geom_new; 246 | geom_new.origin = geom_start->origin; 247 | geom_new.size.w = geom_start->size.w + (uint32_t)round(x - prevMouseX); 248 | geom_new.size.h = geom_start->size.h + (uint32_t)round(y - prevMouseY); 249 | ensureMinSize(&geom_new.size.w); 250 | ensureMinSize(&geom_new.size.h); 251 | wlc_view_set_geometry(movedView, WLC_RESIZE_EDGE_BOTTOM_RIGHT, &geom_new); 252 | break; 253 | } 254 | case MOVING_GRIDDED: { 255 | insertEdge = getNearestEdge(getGrid(wlc_get_focused_output())); 256 | 257 | // don't allow moving to the same position 258 | if (doesEdgeBelongToView(insertEdge, movedView)) { 259 | free(insertEdge); 260 | insertEdge = NULL; 261 | } 262 | break; 263 | } 264 | case RESIZING_ROW: { 265 | assert (resizedRow != NULL); // because of condition for RESIZING_ROW 266 | if (grid_horizontal) { 267 | resizeRow(resizedRow, (int32_t)round(x - prevMouseX)); 268 | } else { 269 | resizeRow(resizedRow, (int32_t)round(y - prevMouseY)); 270 | } 271 | break; 272 | } 273 | case RESIZING_WINDOW: { 274 | assert (resizedWindow); // because of condition for RESIZING_WINDOW 275 | if (grid_horizontal) { 276 | resizeWindow(resizedWindow, (int32_t)round(y - prevMouseY)); 277 | } else { 278 | resizeWindow(resizedWindow, (int32_t)round(x - prevMouseX)); 279 | } 280 | break; 281 | } 282 | } 283 | 284 | prevMouseX = x; 285 | prevMouseY = y; 286 | return false; 287 | } 288 | 289 | bool pointer_scroll(wlc_handle view, uint32_t time, const struct wlc_modifiers* modifiers, uint8_t axis_bits, double amount[2]) { 290 | uint32_t mods = modifiers->mods; 291 | 292 | if (mouseBackMod > UNPRESSED) { 293 | mods |= MOD_WM0; 294 | } 295 | if (mouseForwardMod > UNPRESSED) { 296 | mods |= MOD_WM1; 297 | } 298 | 299 | if (mods == MOD_WM0) { 300 | wlc_handle output = wlc_get_focused_output(); 301 | scrollGrid(getGrid(output), amount[0] * behavior_scrollMult); 302 | return true; 303 | } 304 | 305 | return false; 306 | } 307 | 308 | void mouseHandleViewClosed(wlc_handle view) { 309 | mouseState = NORMAL; 310 | } 311 | -------------------------------------------------------------------------------- /src/mouse.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "grid.h" 4 | 5 | #include 6 | 7 | extern enum MouseState { 8 | NORMAL, 9 | MOVING_FLOATING, 10 | RESIZING_FLOATING, 11 | MOVING_GRIDDED, 12 | RESIZING_WINDOW, 13 | RESIZING_ROW 14 | } mouseState; 15 | 16 | extern wlc_handle movedView; 17 | extern struct Edge* hoveredEdge; 18 | extern struct Edge* insertEdge; 19 | 20 | void sendButton(wlc_handle view, uint32_t button); 21 | 22 | bool pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers* modifiers, uint32_t button, enum wlc_button_state state, const struct wlc_point *position); 23 | bool pointer_motion(wlc_handle handle, uint32_t time, double x, double y); 24 | bool pointer_scroll(wlc_handle view, uint32_t time, const struct wlc_modifiers* modifiers, uint8_t axis_bits, double amount[2]); 25 | void mouseHandleViewClosed(wlc_handle view); 26 | -------------------------------------------------------------------------------- /src/painting.c: -------------------------------------------------------------------------------- 1 | #include "painting.h" 2 | #include "config.h" 3 | #include "grid.h" 4 | #include "mouse.h" 5 | #include "metamanager.h" 6 | 7 | #include 8 | #include 9 | 10 | #define EDGE_WIDTH (grid_windowSpacing / 4) 11 | #define EDGE_START ((grid_windowSpacing - EDGE_WIDTH) / 2) 12 | #define EDGE_START_FROM_END ((EDGE_WIDTH + grid_windowSpacing) / 2) 13 | 14 | #define EDGE_RESIZE_COLOR 0x80FFFFFF 15 | #define EDGE_MOVE_COLOR 0x800000FF 16 | #define WINDOW_MOVE_TINT 0x80000040 17 | #define WINDOW_INACTIVE_TINT 0xA0000000 18 | 19 | static void paintGeomColor(const struct wlc_geometry* geom, uint32_t color) { 20 | uint32_t width = geom->size.w; 21 | uint32_t height = geom->size.h; 22 | uint32_t* data = malloc(width * height * sizeof(uint32_t)); 23 | for (size_t y = 0; y < height; y++) { 24 | size_t startX = y * width; 25 | for (size_t x = 0; x < width; x++) { 26 | data[startX + x] = color; 27 | } 28 | } 29 | wlc_pixels_write(WLC_RGBA8888, geom, data); 30 | free(data); 31 | } 32 | 33 | static void tintView(wlc_handle const view, uint32_t color) { 34 | paintGeomColor(wlc_view_get_geometry(view), color); 35 | } 36 | 37 | static void tintViewEdge(wlc_handle const view, enum wlc_resize_edge edge, uint32_t color) { 38 | struct wlc_geometry geom = *wlc_view_get_geometry(view); 39 | switch (edge) { 40 | case WLC_RESIZE_EDGE_BOTTOM: 41 | geom.origin.y += geom.size.h + grid_windowSpacing; 42 | case WLC_RESIZE_EDGE_TOP: 43 | geom.origin.y -= EDGE_START_FROM_END; 44 | geom.size.h = EDGE_WIDTH; 45 | break; 46 | case WLC_RESIZE_EDGE_RIGHT: 47 | geom.origin.x += geom.size.w + grid_windowSpacing; 48 | case WLC_RESIZE_EDGE_LEFT: 49 | geom.origin.x -= EDGE_START_FROM_END; 50 | geom.size.w = EDGE_WIDTH; 51 | break; 52 | default: break; 53 | } 54 | if (isRowEdge(edge)) { 55 | if (grid_horizontal) { 56 | geom.origin.y = grid_windowSpacing; 57 | geom.size.h = getMaxRowLength(wlc_view_get_output(view)) - grid_windowSpacing; 58 | } else { 59 | geom.origin.x = grid_windowSpacing; 60 | geom.size.w = getMaxRowLength(wlc_view_get_output(view)) - grid_windowSpacing; 61 | } 62 | } 63 | paintGeomColor(&geom, color); 64 | } 65 | 66 | static void tintEdge(struct Edge* edge, uint32_t color) { 67 | assert (edge != NULL); 68 | double longScreenPos, latScreenPos; 69 | uint32_t longSize, latSize; 70 | 71 | switch (edge->type) { 72 | case EDGE_ROW: { 73 | struct Row* row = edge->row; 74 | latScreenPos = grid_windowSpacing; 75 | longSize = EDGE_WIDTH; 76 | latSize = getMaxRowLength(wlc_get_focused_output()) - grid_windowSpacing; 77 | if (row == NULL) { 78 | longScreenPos = EDGE_START; 79 | } else { 80 | longScreenPos = (int32_t) row->origin + row->size - row->parent->scroll + EDGE_START; 81 | } 82 | break; 83 | } 84 | 85 | case EDGE_WINDOW: { 86 | struct Row* row = edge->row; 87 | struct Window* window = edge->window; 88 | longScreenPos = (int32_t)row->origin - row->parent->scroll; 89 | longSize = row->size; 90 | latSize = EDGE_WIDTH; 91 | if (window == NULL) { 92 | latScreenPos = EDGE_START; 93 | } else { 94 | latScreenPos = window->origin + window->size + EDGE_START; 95 | } 96 | break; 97 | } 98 | 99 | case EDGE_CORNER: // TODO 100 | 101 | default: return; 102 | } 103 | 104 | struct wlc_geometry geom; 105 | if (grid_horizontal) { 106 | geom.origin.x = (uint32_t)round(longScreenPos); 107 | geom.origin.y = (uint32_t)round(latScreenPos); 108 | geom.size.w = longSize; 109 | geom.size.h = latSize; 110 | } else { 111 | geom.origin.x = (uint32_t)round(latScreenPos); 112 | geom.origin.y = (uint32_t)round(longScreenPos); 113 | geom.size.w = latSize; 114 | geom.size.h = longSize; 115 | } 116 | paintGeomColor(&geom, color); 117 | } 118 | 119 | void output_render_pre(wlc_handle const output) { 120 | // wallpaper (this should be done in a client, but I'm lazy) 121 | struct Output* outputMeta = getOutput(output); 122 | assert (outputMeta != NULL); 123 | if (outputMeta->wallpaper != NULL) { 124 | struct wlc_geometry geom; 125 | geom.origin = (struct wlc_point) {0, 0}; 126 | geom.size = *wlc_output_get_resolution(output); 127 | wlc_pixels_write(WLC_RGBA8888, &geom, outputMeta->wallpaper); 128 | } 129 | } 130 | 131 | void output_render_post(wlc_handle const output) { 132 | if (hoveredEdge != NULL) { 133 | tintEdge(hoveredEdge, EDGE_RESIZE_COLOR); 134 | } 135 | if (insertEdge != NULL) { 136 | tintEdge(insertEdge, EDGE_MOVE_COLOR); 137 | } 138 | if (mouseState == MOVING_GRIDDED && movedView > 0) { 139 | tintView(movedView, WINDOW_MOVE_TINT); 140 | } 141 | /*const struct Row* hoveredRow = getHoveredRow(getGrid(output)); 142 | if (hoveredRow != NULL) { 143 | paintGeomColor(wlc_view_get_geometry(hoveredRow->firstWindow->view), 0x800000FF); 144 | }*/ 145 | 146 | // dim inactive views 147 | if (appearance_dimInactive) { 148 | size_t viewCount; 149 | const wlc_handle *views = wlc_output_get_views(output, &viewCount); 150 | for (size_t i = 0; i < viewCount; i++) { 151 | wlc_handle view = views[i]; 152 | if (wlc_view_get_state(view) & WLC_BIT_ACTIVATED) { 153 | // view active 154 | } else { 155 | // view inactive 156 | tintView(view, WINDOW_INACTIVE_TINT); 157 | } 158 | } 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/painting.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | void output_render_pre(wlc_handle output); 6 | void output_render_post(wlc_handle output); 7 | --------------------------------------------------------------------------------