├── .gitignore ├── .gitlab-ci.yml ├── Cargo.lock ├── Cargo.toml ├── LICENSE-GPL ├── LICENSE-MIT ├── README.md ├── apps ├── 40_calculator ├── 50_calendar └── 60_viewer ├── apps_deprecated ├── 20_file_manager ├── 30_editor └── 70_character_map ├── calculator ├── .cargo │ └── config.toml ├── Cargo.toml ├── build.rs ├── src │ └── main.rs └── ui │ └── app.slint ├── launcher ├── Cargo.toml └── src │ ├── main.rs │ ├── package.rs │ └── theme.rs └── orbutils ├── Cargo.toml └── src ├── background └── main.rs ├── calendar ├── main.rs └── theme.css ├── character_map └── main.rs ├── editor └── main.rs ├── file_manager ├── main.rs └── theme.css ├── orblogin └── main.rs └── viewer └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | .idea 3 | _imports/ 4 | 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | build:linux: 2 | image: "redoxos/redoxer" 3 | before_script: 4 | - apt-get update 5 | - apt-get install cmake libsdl2-dev libfreetype6-dev libexpat1-dev -y 6 | script: 7 | - cargo +nightly build --bin calendar 8 | - cargo +nightly build --bin character_map 9 | - cargo +nightly build --bin editor 10 | - cargo +nightly build --bin file_manager 11 | - cargo +nightly build --bin viewer 12 | 13 | test:linux: 14 | image: "redoxos/redoxer" 15 | before_script: 16 | - apt-get update 17 | - apt-get install cmake libsdl2-dev libfreetype6-dev libexpat1-dev -y 18 | script: 19 | - cargo +nightly test --bin calendar 20 | - cargo +nightly test --bin character_map 21 | - cargo +nightly test --bin editor 22 | - cargo +nightly test --bin file_manager 23 | - cargo +nightly test --bin viewer 24 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "orbutils", 4 | "calculator", 5 | "launcher", 6 | ] 7 | resolver = "2" 8 | 9 | [patch.crates-io] 10 | softbuffer = { git = "https://gitlab.redox-os.org/redox-os/softbuffer", branch = "redox-0.2" } 11 | winit = { git = "https://gitlab.redox-os.org/redox-os/winit", branch = "redox-0.28.6" } 12 | -------------------------------------------------------------------------------- /LICENSE-GPL: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any 2 | person obtaining a copy of this software and associated 3 | documentation files (the "Software"), to deal in the 4 | Software without restriction, including without 5 | limitation the rights to use, copy, modify, merge, 6 | publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software 8 | is furnished to do so, subject to the following 9 | conditions: 10 | 11 | The above copyright notice and this permission notice 12 | shall be included in all copies or substantial portions 13 | of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OrbUtils 2 | 3 | The Orbital Utilities a setup of desktop applications. Compatible with Redox and SDL2 platforms. 4 | 5 | [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE-MIT) 6 | [![crates.io](http://meritbadge.herokuapp.com/orbutils)](https://crates.io/crates/orbutils) 7 | 8 | ## Cross Platform Support 9 | Some of the applications in this crate can be developed and ran across multiple operating systems 10 | (namely redox-os, linux and macos) thanks to the display being rendered via the `orbclient` crate which in turn uses 11 | `sdl2` 12 | 13 | There are three applications that are more fundamental to redox-os, that interact with orbital more directly and are 14 | (currently) deemed to not make sense on other platforms that are running other windowing systems or display managers. 15 | These are namely: 16 | - launcher 17 | - orblogin 18 | - background 19 | 20 | ## Quick setup 21 | 22 | To run on Linux/OSX you will need SDL2 23 | 24 | Install SDL2 on Debian-based systems 25 | ``` 26 | sudo apt-get install libsdl2-dev 27 | ``` 28 | 29 | Install on OSX using Homebrew 30 | ``` 31 | brew install sdl2 32 | ``` 33 | 34 | You will need Rust nightly installed 35 | ``` 36 | curl https://sh.rustup.rs -sSf | sh 37 | rustup override set nightly 38 | ``` 39 | 40 | Clone and run 41 | ``` 42 | git clone https://github.com/redox-os/orbutils.git 43 | cargo run --bin calculator 44 | ``` 45 | 46 | ## How to run Slint ports 47 | 48 | For the `Slint` ports `SDL2` is not necessary. On `Redox` the port will run with 49 | [slint_orbclient](https://gitlab.redox-os.org/redox-os/slint_orbclient) backend and on other platforms Slint will 50 | choose a suitable e.g. `winit` or `qt`. 51 | 52 | To can use the `slint_orbclient` also on other platform you can run for example 53 | `cargo run --bin calculator --no-default-features --features=orbclient` 54 | 55 | ## Current project status 56 | 57 | After the sunset of [OrbTk](https://gitlab.redox-os.org/redox-os/orbtk) the `OrbUtils` will be 58 | ported [Slint](https://slint-ui.com). 59 | With this also a new CI pipeline for GitLab will be used. 60 | 61 | ### Slint ports done 62 | 63 | * calculator 64 | 65 | ## License 66 | 67 | The source code of the OrbUtils is available under the terms the MIT license (See [LICENSE-MIT](LICENSE-MIT) for details.) 68 | 69 | However, because of the use of GPL dependencies, the OrbUtils, as a whole, is licensed 70 | under the terms of the GPLv3 (See [LICENSE-GPL](LICENSE-GPL)) 71 | 72 | -------------------------------------------------------------------------------- /apps/40_calculator: -------------------------------------------------------------------------------- 1 | name=Calculator 2 | binary=/usr/bin/calculator 3 | icon=/ui/icons/apps/accessories-calculator.png 4 | author=Jeremy Soller 5 | description=Calculator for Redox 6 | -------------------------------------------------------------------------------- /apps/50_calendar: -------------------------------------------------------------------------------- 1 | name=Calendar 2 | binary=/usr/bin/calendar 3 | icon=/ui/icons/apps/calendar.png 4 | author=Bojan Kogoj 5 | description=Calendar for Redox 6 | -------------------------------------------------------------------------------- /apps/60_viewer: -------------------------------------------------------------------------------- 1 | name=Viewer 2 | binary=/usr/bin/viewer 3 | icon=/ui/icons/apps/multimedia-photo-viewer.png 4 | accept=*.bmp 5 | accept=*.jpg 6 | accept=*.jpeg 7 | accept=*.png 8 | author=Jeremy Soller 9 | description=Image Viewer for Redox 10 | -------------------------------------------------------------------------------- /apps_deprecated/20_file_manager: -------------------------------------------------------------------------------- 1 | name=File Manager 2 | binary=/usr/bin/file_manager 3 | icon=/ui/icons/apps/system-file-manager.png 4 | accept=*/ 5 | author=Jeremy Soller 6 | description=File Manager for Redox 7 | -------------------------------------------------------------------------------- /apps_deprecated/30_editor: -------------------------------------------------------------------------------- 1 | name=Editor 2 | binary=/usr/bin/editor 3 | icon=/ui/icons/apps/accessories-text-editor.png 4 | accept=*.asm 5 | accept=*.conf 6 | accept=*.html 7 | accept=*.ion 8 | accept=*.list 9 | accept=*.lua 10 | accept=*.md 11 | accept=*.rc 12 | accept=*.rs 13 | accept=*.sh 14 | accept=*.toml 15 | accept=*.txt 16 | author=Jeremy Soller 17 | description=Editor for Redox 18 | -------------------------------------------------------------------------------- /apps_deprecated/70_character_map: -------------------------------------------------------------------------------- 1 | name=Character Map 2 | binary=/usr/bin/character_map 3 | icon=/ui/icons/apps/accessories-character-map.png 4 | accept=*.ttf 5 | author=Jeremy Soller 6 | description=Character Map for Redox 7 | -------------------------------------------------------------------------------- /calculator/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [env] 2 | RUST_FONTCONFIG_DLOPEN = "on" 3 | -------------------------------------------------------------------------------- /calculator/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "calculator" 3 | version = "0.2.0" 4 | license-file = "../LICENSE-MIT" 5 | authors = ["Redox OS Developers "] 6 | edition = "2021" 7 | build = "build.rs" 8 | 9 | [[bin]] 10 | name = "calculator" 11 | path = "src/main.rs" 12 | 13 | [dependencies] 14 | calculate = { git = "https://gitlab.redox-os.org/redox-os/calc.git" } 15 | slint = { git = "https://github.com/slint-ui/slint", default-features = false, features = ["compat-1-0", "renderer-winit-software"], rev = "a01726537688fac2522156ced5f4cb836e96ac03" } 16 | 17 | [build-dependencies] 18 | slint-build = { git = "https://github.com/slint-ui/slint", rev = "a01726537688fac2522156ced5f4cb836e96ac03" } 19 | coop_widgets = { git = "https://codeberg.org/flovansl/co_sl", rev = "e5f2f10644f9c7a06df6d82246d7ceebbdfaecf1" } 20 | 21 | [features] 22 | default = [] 23 | slint-default = ["slint/default"] 24 | -------------------------------------------------------------------------------- /calculator/build.rs: -------------------------------------------------------------------------------- 1 | #[cfg(not(feature = "slint-default"))] 2 | fn main() { 3 | coop_widgets::generate_import().unwrap(); 4 | let config = slint_build::CompilerConfiguration::new() 5 | .embed_resources(slint_build::EmbedResourcesKind::EmbedForSoftwareRenderer); 6 | slint_build::compile_with_config("ui/app.slint", config).unwrap(); 7 | slint_build::print_rustc_flags().unwrap(); 8 | } 9 | 10 | #[cfg(feature = "slint-default")] 11 | fn main() { 12 | coop_widgets::generate_import().unwrap(); 13 | slint_build::compile("ui/app.slint").unwrap(); 14 | } -------------------------------------------------------------------------------- /calculator/src/main.rs: -------------------------------------------------------------------------------- 1 | #[allow(clippy::all)] 2 | mod generated_code { 3 | slint::include_modules!(); 4 | } 5 | 6 | pub use generated_code::*; 7 | 8 | use slint::SharedString; 9 | 10 | fn eval(input: &str) -> String { 11 | match calc::eval(input) { 12 | Ok(s) => s.to_string(), 13 | Err(e) => e.into(), 14 | } 15 | } 16 | 17 | pub fn main() { 18 | let app = App::new().unwrap(); 19 | app.global::().set_embedded_helper(true); 20 | 21 | app.on_backspace(backspace); 22 | app.on_calculate(calculate); 23 | app.on_validate(validate); 24 | 25 | app.run().unwrap(); 26 | } 27 | 28 | fn backspace(input: SharedString) -> SharedString { 29 | let mut input = input.to_string(); 30 | input.pop(); 31 | input.into() 32 | } 33 | 34 | fn calculate(input: SharedString) -> SharedString { 35 | eval(input.as_str()).into() 36 | } 37 | 38 | fn validate(input: SharedString) -> SharedString { 39 | let valid = match input.as_str() { 40 | "(" | ")" | "^" | "/" | "*" | "-" | "+" | "." | " " => true, 41 | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" => true, 42 | _ => false, 43 | }; 44 | 45 | if valid { 46 | return input; 47 | } 48 | 49 | SharedString::default() 50 | } 51 | 52 | #[cfg(test)] 53 | mod tests { 54 | use slint::platform::Key; 55 | 56 | use super::*; 57 | 58 | #[test] 59 | fn test_backspace() { 60 | assert_eq!( 61 | backspace(SharedString::from("5+3")), 62 | SharedString::from("5+") 63 | ); 64 | assert_eq!(backspace(SharedString::from("5+")), SharedString::from("5")); 65 | assert_eq!(backspace(SharedString::from("5")), SharedString::from("")); 66 | assert_eq!(backspace(SharedString::from("")), SharedString::from("")); 67 | } 68 | 69 | #[test] 70 | fn test_calculate() { 71 | assert_eq!( 72 | calculate(SharedString::from("6/2")), 73 | SharedString::from("3") 74 | ); 75 | assert_eq!( 76 | calculate(SharedString::from("5+3")), 77 | SharedString::from("8") 78 | ); 79 | assert_eq!( 80 | calculate(SharedString::from("5 + 3")), 81 | SharedString::from("8") 82 | ); 83 | assert_eq!( 84 | calculate(SharedString::from("(5 + 3)")), 85 | SharedString::from("8") 86 | ); 87 | assert_eq!( 88 | calculate(SharedString::from("5*3")), 89 | SharedString::from("15") 90 | ); 91 | assert_eq!( 92 | calculate(SharedString::from("5 * 3")), 93 | SharedString::from("15") 94 | ); 95 | assert_eq!( 96 | calculate(SharedString::from("(5 * 3)")), 97 | SharedString::from("15") 98 | ); 99 | assert_eq!( 100 | calculate(SharedString::from("5/2")), 101 | SharedString::from("2.5") 102 | ); 103 | assert_eq!( 104 | calculate(SharedString::from("5 / 2")), 105 | SharedString::from("2.5") 106 | ); 107 | assert_eq!( 108 | calculate(SharedString::from("(5 / 2)")), 109 | SharedString::from("2.5") 110 | ); 111 | assert_eq!( 112 | calculate(SharedString::from("2*5+3")), 113 | SharedString::from("13") 114 | ); 115 | assert_eq!( 116 | calculate(SharedString::from("2 * 5 + 3")), 117 | SharedString::from("13") 118 | ); 119 | assert_eq!( 120 | calculate(SharedString::from("(2 * 5) + 3")), 121 | SharedString::from("13") 122 | ); 123 | } 124 | 125 | #[test] 126 | fn test_validate() { 127 | assert_eq!(validate(SharedString::from("(")), SharedString::from("(")); 128 | assert_eq!(validate(SharedString::from(")")), SharedString::from(")")); 129 | assert_eq!(validate(SharedString::from("^")), SharedString::from("^")); 130 | assert_eq!(validate(SharedString::from("/")), SharedString::from("/")); 131 | assert_eq!(validate(SharedString::from("*")), SharedString::from("*")); 132 | assert_eq!(validate(SharedString::from("-")), SharedString::from("-")); 133 | assert_eq!(validate(SharedString::from("+")), SharedString::from("+")); 134 | assert_eq!(validate(SharedString::from(".")), SharedString::from(".")); 135 | assert_eq!(validate(SharedString::from(" ")), SharedString::from(" ")); 136 | assert_eq!(validate(SharedString::from("0")), SharedString::from("0")); 137 | assert_eq!(validate(SharedString::from("1")), SharedString::from("1")); 138 | assert_eq!(validate(SharedString::from("2")), SharedString::from("2")); 139 | assert_eq!(validate(SharedString::from("3")), SharedString::from("3")); 140 | assert_eq!(validate(SharedString::from("4")), SharedString::from("4")); 141 | assert_eq!(validate(SharedString::from("5")), SharedString::from("5")); 142 | assert_eq!(validate(SharedString::from("6")), SharedString::from("6")); 143 | assert_eq!(validate(SharedString::from("7")), SharedString::from("7")); 144 | assert_eq!(validate(SharedString::from("8")), SharedString::from("8")); 145 | assert_eq!(validate(SharedString::from("9")), SharedString::from("9")); 146 | assert_eq!(validate(SharedString::from("=")), SharedString::from("")); 147 | assert_eq!( 148 | validate(SharedString::from(Key::Shift)), 149 | SharedString::from("") 150 | ); 151 | assert_eq!( 152 | validate(SharedString::from(Key::Menu)), 153 | SharedString::from("") 154 | ); 155 | assert_eq!( 156 | validate(SharedString::from(Key::Control)), 157 | SharedString::from("") 158 | ); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /calculator/ui/app.slint: -------------------------------------------------------------------------------- 1 | import { CoopWindow, RoundButton, MediumTitle, Button, Theme } from "_imports/coop_widgets.slint"; 2 | 3 | export { Theme } 4 | 5 | export component App inherits CoopWindow { 6 | private property display_result; 7 | private property text <=> i_text.text; 8 | 9 | callback calculate(string) -> string; 10 | callback backspace(string) -> string; 11 | callback validate(string) -> string; 12 | 13 | title: "Calculator"; 14 | width: 200px; 15 | height: 222px; 16 | accent_color: #5294E2; 17 | on_accent_color: white; 18 | forward-focus: i_focus_scope; 19 | 20 | VerticalLayout { 21 | padding_top: Theme.spaces.medium; 22 | padding_left: Theme.spaces.small; 23 | padding_right: Theme.spaces.small; 24 | padding_bottom: Theme.spaces.small; 25 | spacing: Theme.spaces.medium; 26 | 27 | Rectangle { 28 | vertical-stretch: 0; 29 | clip: true; 30 | i_text := MediumTitle { 31 | width: 100%; 32 | height: 100%; 33 | vertical_alignment: center; 34 | horizontal-alignment: right; 35 | } 36 | } 37 | 38 | GridLayout { 39 | 40 | spacing: Theme.spaces.extra-small; 41 | 42 | Row { 43 | Button { 44 | text: "("; 45 | clicked => { root.input(self.text); } 46 | } 47 | 48 | Button { 49 | text: ")"; 50 | clicked => { root.input(self.text); } 51 | } 52 | 53 | Button { 54 | text: "^"; 55 | clicked => { root.input(self.text); } 56 | } 57 | 58 | Button { 59 | primary: true; 60 | text: "/"; 61 | clicked => { root.input(self.text); } 62 | } 63 | } 64 | 65 | Row { 66 | Button { 67 | text: "7"; 68 | clicked => { root.input(self.text); } 69 | } 70 | 71 | Button { 72 | text: "8"; 73 | clicked => { root.input(self.text); } 74 | } 75 | 76 | Button { 77 | text: "9"; 78 | clicked => { root.input(self.text); } 79 | } 80 | 81 | Button { 82 | primary: true; 83 | text: "*"; 84 | clicked => { root.input(self.text); } 85 | } 86 | } 87 | 88 | Row { 89 | Button { 90 | text: "4"; 91 | clicked => { root.input(self.text); } 92 | } 93 | 94 | Button { 95 | text: "5"; 96 | clicked => { root.input(self.text); } 97 | } 98 | 99 | Button { 100 | text: "6"; 101 | clicked => { root.input(self.text); } 102 | } 103 | 104 | Button { 105 | primary: true; 106 | text: "-"; 107 | clicked => { root.input(self.text); } 108 | } 109 | } 110 | 111 | Row { 112 | Button { 113 | text: "1"; 114 | clicked => { root.input(self.text); } 115 | } 116 | 117 | Button { 118 | text: "2"; 119 | clicked => { root.input(self.text); } 120 | } 121 | 122 | Button { 123 | text: "3"; 124 | clicked => { root.input(self.text); } 125 | } 126 | 127 | Button { 128 | primary: true; 129 | text: "+"; 130 | clicked => { root.input(self.text); } 131 | } 132 | } 133 | 134 | Row { 135 | Button { 136 | text: "0"; 137 | clicked => { root.input(self.text); } 138 | } 139 | 140 | Button { 141 | text: "."; 142 | clicked => { root.input(self.text); } 143 | } 144 | 145 | Button { 146 | text: "C"; 147 | clicked => { root.clear(); } 148 | } 149 | 150 | i_result_button := Button { 151 | primary: true; 152 | text: "="; 153 | clicked => { 154 | root.text = root.calculate(root.text); 155 | display_result = true; 156 | } 157 | } 158 | } 159 | } 160 | } 161 | 162 | i_focus_scope := FocusScope { 163 | width: 0px; 164 | 165 | key_pressed(e) => { 166 | if(e.text == Key.Backspace) { 167 | root.text = root.backspace(root.text); 168 | return accept; 169 | } 170 | 171 | if(e.text == Key.Return || e.text == "=") { 172 | i_result_button.clicked(); 173 | return accept; 174 | } 175 | 176 | if(e.text == "C") { 177 | root.clear(); 178 | return accept; 179 | } 180 | 181 | root.input(e.text); 182 | accept 183 | } 184 | } 185 | 186 | function input(text: string) { 187 | if(display_result) { 188 | root.text = ""; 189 | root.display_result = false; 190 | } 191 | root.text += validate(text); 192 | } 193 | 194 | function clear() { 195 | root.display_result = false; 196 | root.text = ""; 197 | } 198 | } -------------------------------------------------------------------------------- /launcher/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "launcher" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | freedesktop_entry_parser = "1" 8 | freedesktop-icons = "0.2" 9 | lazy_static = "1" 10 | libc = "0.2" 11 | libredox = { version = "0.1.3", default-features = false, features = ["std", "call"] } 12 | log = "0.4.14" 13 | orbclient = "0.3" 14 | orbfont = "0.1" 15 | orbimage = "0.1" 16 | redox-log = "0.1" 17 | redox_event = "0.4.1" 18 | resvg = "0.44" 19 | shlex = "1" 20 | xdg = "2" 21 | -------------------------------------------------------------------------------- /launcher/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate event; 2 | extern crate freedesktop_entry_parser; 3 | extern crate libredox; 4 | extern crate log; 5 | extern crate orbclient; 6 | extern crate orbfont; 7 | extern crate orbimage; 8 | extern crate redox_log; 9 | 10 | use event::{user_data, EventQueue}; 11 | use libredox::data::TimeSpec; 12 | use libredox::flag; 13 | use log::{debug, error, info}; 14 | use redox_log::{OutputBuilder, RedoxLogger}; 15 | use std::collections::BTreeMap; 16 | use std::fs::File; 17 | use std::io::{ErrorKind, Read, Write}; 18 | use std::os::unix::io::AsRawFd; 19 | use std::path::Path; 20 | use std::process::{Child, Command}; 21 | use std::sync::atomic::{AtomicIsize, Ordering}; 22 | use std::{env, io, mem}; 23 | 24 | use orbclient::{Color, EventOption, Renderer, Window, WindowFlag, K_ESC}; 25 | use orbfont::Font; 26 | use orbimage::Image; 27 | 28 | use package::{IconSource, Package}; 29 | use theme::{BAR_COLOR, BAR_HIGHLIGHT_COLOR, TEXT_COLOR, TEXT_HIGHLIGHT_COLOR}; 30 | 31 | mod package; 32 | mod theme; 33 | 34 | static SCALE: AtomicIsize = AtomicIsize::new(1); 35 | 36 | fn chooser_width() -> u32 { 37 | 200 * SCALE.load(Ordering::Relaxed) as u32 38 | } 39 | 40 | fn font_size() -> i32 { 41 | 16 * SCALE.load(Ordering::Relaxed) as i32 42 | } 43 | 44 | fn icon_size() -> i32 { 45 | 48 * SCALE.load(Ordering::Relaxed) as i32 46 | } 47 | 48 | fn icon_small_size() -> i32 { 49 | 32 * SCALE.load(Ordering::Relaxed) as i32 50 | } 51 | 52 | #[cfg(target_os = "redox")] 53 | static UI_PATH: &'static str = "/ui"; 54 | 55 | #[cfg(not(target_os = "redox"))] 56 | static UI_PATH: &'static str = "ui"; 57 | 58 | fn exec_to_command(exec: &str, path_opt: Option<&str>) -> Option { 59 | let args_vec: Vec = shlex::split(exec)?; 60 | let mut args = args_vec.iter(); 61 | let mut command = Command::new(args.next()?); 62 | for arg in args { 63 | if arg.starts_with('%') { 64 | match arg.as_str() { 65 | "%f" | "%F" | "%u" | "%U" => { 66 | if let Some(path) = &path_opt { 67 | command.arg(path); 68 | } 69 | } 70 | _ => { 71 | log::warn!("unsupported Exec code {:?} in {:?}", arg, exec); 72 | return None; 73 | } 74 | } 75 | } else { 76 | command.arg(arg); 77 | } 78 | } 79 | Some(command) 80 | } 81 | 82 | fn spawn_exec(exec: &str, path_opt: Option<&str>) { 83 | match exec_to_command(exec, path_opt) { 84 | Some(mut command) => match command.spawn() { 85 | Ok(_) => {} 86 | Err(err) => { 87 | error!("failed to launch {}: {}", exec, err); 88 | } 89 | }, 90 | None => { 91 | error!("failed to parse {}", exec); 92 | } 93 | } 94 | } 95 | 96 | #[cfg(not(target_os = "redox"))] 97 | fn wait(status: &mut i32) -> io::Result { 98 | extern crate libc; 99 | 100 | use std::io::Error; 101 | 102 | let pid = unsafe { libc::waitpid(0, status as *mut i32, libc::WNOHANG) }; 103 | if pid < 0 { 104 | Err(io::Error::new( 105 | ErrorKind::Other, 106 | format!("waitpid failed: {}", Error::last_os_error()), 107 | )) 108 | } 109 | Ok(pid as usize) 110 | } 111 | 112 | #[cfg(target_os = "redox")] 113 | fn wait(status: &mut i32) -> io::Result { 114 | libredox::call::waitpid(0, status, libc::WNOHANG).map_err(|e| { 115 | io::Error::new( 116 | ErrorKind::Other, 117 | format!("Error in waitpid(): {}", e.to_string()), 118 | ) 119 | }) 120 | } 121 | 122 | fn size_icon(icon: Image, small: bool) -> Image { 123 | let size = if small { 124 | icon_small_size() 125 | } else { 126 | icon_size() 127 | } as u32; 128 | if icon.width() == size && icon.height() == size { 129 | icon 130 | } else { 131 | icon.resize(size, size, orbimage::ResizeType::Lanczos3) 132 | .unwrap() 133 | } 134 | } 135 | 136 | fn load_icon>(path: P) -> Image { 137 | let icon = Image::from_path(path).unwrap_or(Image::default()); 138 | size_icon(icon, false) 139 | } 140 | 141 | fn load_icon_small>(path: P) -> Image { 142 | let icon = Image::from_path(path).unwrap_or(Image::default()); 143 | size_icon(icon, true) 144 | } 145 | 146 | lazy_static::lazy_static! { 147 | static ref USVG_OPTIONS: resvg::usvg::Options<'static> = { 148 | let mut opt = resvg::usvg::Options::default(); 149 | opt.fontdb_mut().load_system_fonts(); 150 | opt 151 | }; 152 | } 153 | 154 | fn load_icon_svg>(path: P, small: bool) -> Option { 155 | let tree = { 156 | let svg_data = std::fs::read(path).ok()?; 157 | resvg::usvg::Tree::from_data(&svg_data, &USVG_OPTIONS).ok()? 158 | }; 159 | 160 | let pixmap_size = tree.size().to_int_size(); 161 | let mut pixmap = resvg::tiny_skia::Pixmap::new(pixmap_size.width(), pixmap_size.height())?; 162 | resvg::render( 163 | &tree, 164 | resvg::tiny_skia::Transform::default(), 165 | &mut pixmap.as_mut(), 166 | ); 167 | 168 | let width = pixmap.width(); 169 | let height = pixmap.height(); 170 | let mut data = Vec::with_capacity(width as usize * height as usize); 171 | for rgba in pixmap.take().chunks_exact(4) { 172 | data.push(Color::rgba(rgba[0], rgba[1], rgba[2], rgba[3])); 173 | } 174 | 175 | let icon = Image::from_data(width, height, data.into()).ok()?; 176 | Some(size_icon(icon, small)) 177 | } 178 | 179 | fn get_packages() -> Vec { 180 | let mut packages: Vec = Vec::new(); 181 | 182 | if let Ok(read_dir) = Path::new(&format!("{}/apps/", UI_PATH)).read_dir() { 183 | for entry_res in read_dir { 184 | let entry = match entry_res { 185 | Ok(x) => x, 186 | Err(_) => continue, 187 | }; 188 | if entry 189 | .file_type() 190 | .expect("failed to get file_type") 191 | .is_file() 192 | { 193 | packages.push(Package::from_path(&entry.path().display().to_string())); 194 | } 195 | } 196 | } 197 | 198 | if let Ok(xdg_dirs) = xdg::BaseDirectories::new() { 199 | for path in xdg_dirs.find_data_files("applications") { 200 | if let Ok(read_dir) = path.read_dir() { 201 | for dir_entry_res in read_dir { 202 | let Ok(dir_entry) = dir_entry_res else { 203 | continue; 204 | }; 205 | let Ok(id) = dir_entry.file_name().into_string() else { 206 | continue; 207 | }; 208 | if let Some(package) = Package::from_desktop_entry(id, &dir_entry.path()) { 209 | packages.push(package); 210 | } 211 | } 212 | } 213 | } 214 | } 215 | 216 | packages.sort_by(|a, b| a.name.cmp(&b.name)); 217 | packages 218 | } 219 | 220 | fn draw_chooser(window: &mut Window, font: &Font, packages: &mut Vec, selected: i32) { 221 | let w = window.width(); 222 | 223 | window.set(BAR_COLOR); 224 | 225 | let mut y = 0; 226 | for (i, package) in packages.iter_mut().enumerate() { 227 | if i as i32 == selected { 228 | window.rect(0, y, w, icon_small_size() as u32, BAR_HIGHLIGHT_COLOR); 229 | } 230 | 231 | package.icon_small.image().draw(window, 0, y); 232 | 233 | font.render(&package.name, font_size() as f32).draw( 234 | window, 235 | icon_small_size() + 8, 236 | y + 8, 237 | if i as i32 == selected { 238 | TEXT_HIGHLIGHT_COLOR 239 | } else { 240 | TEXT_COLOR 241 | }, 242 | ); 243 | 244 | y += icon_small_size(); 245 | } 246 | 247 | window.sync(); 248 | } 249 | 250 | struct Bar { 251 | children: Vec<(String, Child)>, 252 | packages: Vec, 253 | start: Image, 254 | start_packages: Vec, 255 | category_packages: BTreeMap>, 256 | font: Font, 257 | width: u32, 258 | height: u32, 259 | window: Window, 260 | selected: i32, 261 | selected_window: Window, 262 | time: String, 263 | } 264 | 265 | impl Bar { 266 | fn new(width: u32, height: u32) -> Bar { 267 | let all_packages = get_packages(); 268 | 269 | // Handle packages with categories 270 | let mut root_packages = Vec::new(); 271 | let mut category_packages = BTreeMap::>::new(); 272 | for package in all_packages { 273 | if package.categories.is_empty() { 274 | // Packages without a category go on the bar 275 | root_packages.push(package); 276 | } else { 277 | // Packages with a category are collected 278 | //TODO: since this clones the package, use an Arc to prevent icon reloads? 279 | for category in package.categories.iter() { 280 | match category_packages.get_mut(category) { 281 | Some(packages) => { 282 | packages.push(package.clone()); 283 | } 284 | None => { 285 | category_packages.insert(category.clone(), vec![package.clone()]); 286 | } 287 | } 288 | } 289 | } 290 | } 291 | 292 | // Sort root packages by ID 293 | root_packages.sort_by(|a, b| a.id.cmp(&b.id)); 294 | 295 | let mut start_packages = Vec::new(); 296 | 297 | for (category, packages) in category_packages.iter_mut() { 298 | start_packages.push({ 299 | let mut package = Package::new(); 300 | package.name = category.to_string(); 301 | let icon = format!("{}/icons/mimetypes/inode-directory.png", UI_PATH); 302 | package.icon.source = IconSource::Path(icon.clone().into()); 303 | package.icon_small.source = IconSource::Path(icon.into()); 304 | package.exec = format!("category={}", category); 305 | package 306 | }); 307 | 308 | packages.push({ 309 | let mut package = Package::new(); 310 | package.name = "Go back".to_string(); 311 | let icon = format!("{}/icons/mimetypes/inode-directory.png", UI_PATH); 312 | package.icon.source = IconSource::Path(icon.clone().into()); 313 | package.icon_small.source = IconSource::Path(icon.into()); 314 | package.exec = "exit".to_string(); 315 | package 316 | }); 317 | } 318 | 319 | start_packages.push({ 320 | let mut package = Package::new(); 321 | package.name = "Logout".to_string(); 322 | let icon = format!("{}/icons/actions/system-log-out.png", UI_PATH); 323 | package.icon.source = IconSource::Path(icon.clone().into()); 324 | package.icon_small.source = IconSource::Path(icon.into()); 325 | package.exec = "exit".to_string(); 326 | package 327 | }); 328 | 329 | Bar { 330 | children: Vec::new(), 331 | packages: root_packages, 332 | start: load_icon(&format!("{}/icons/places/start-here.png", UI_PATH)), 333 | start_packages, 334 | category_packages, 335 | font: Font::find(Some("Sans"), None, None).unwrap(), 336 | width, 337 | height, 338 | window: Window::new_flags( 339 | 0, 340 | height as i32 - icon_size(), 341 | width, 342 | icon_size() as u32, 343 | "", 344 | &[ 345 | WindowFlag::Async, 346 | WindowFlag::Borderless, 347 | WindowFlag::Transparent, 348 | ], 349 | ) 350 | .expect("launcher: failed to open window"), 351 | selected: -1, 352 | selected_window: Window::new_flags( 353 | 0, 354 | height as i32, 355 | width, 356 | (font_size() + 8) as u32, 357 | "", 358 | &[ 359 | WindowFlag::Async, 360 | WindowFlag::Borderless, 361 | WindowFlag::Transparent, 362 | ], 363 | ) 364 | .expect("launcher: failed to open selected window"), 365 | time: String::new(), 366 | } 367 | } 368 | 369 | fn update_time(&mut self) { 370 | let time = libredox::call::clock_gettime(flag::CLOCK_REALTIME) 371 | .expect("launcher: failed to read time"); 372 | 373 | let ts = time.tv_sec; 374 | let s = ts % 86400; 375 | let h = s / 3600; 376 | let m = s / 60 % 60; 377 | self.time = format!("{:>02}:{:>02}", h, m) 378 | } 379 | 380 | fn draw(&mut self) { 381 | self.window.set(BAR_COLOR); 382 | 383 | let mut x = 0; 384 | let mut y = 0; 385 | let mut i = 0; 386 | 387 | { 388 | if i == self.selected { 389 | self.window.rect( 390 | x as i32, 391 | y as i32, 392 | self.start.width() as u32, 393 | self.start.height() as u32, 394 | BAR_HIGHLIGHT_COLOR, 395 | ); 396 | } 397 | 398 | self.start.draw(&mut self.window, x as i32, y as i32); 399 | 400 | x += self.start.width() as i32; 401 | i += 1; 402 | } 403 | 404 | for package in self.packages.iter_mut() { 405 | if i == self.selected { 406 | let image = package.icon.image(); 407 | self.window.rect( 408 | x as i32, 409 | y as i32, 410 | image.width() as u32, 411 | image.height() as u32, 412 | BAR_HIGHLIGHT_COLOR, 413 | ); 414 | 415 | self.selected_window.set(Color::rgba(0, 0, 0, 0)); 416 | 417 | let text = self.font.render(&package.name, font_size() as f32); 418 | self.selected_window 419 | .rect(x, 0, text.width() + 8, text.height() + 8, BAR_COLOR); 420 | text.draw(&mut self.selected_window, x + 4, 4, TEXT_HIGHLIGHT_COLOR); 421 | 422 | self.selected_window.sync(); 423 | let sw_y = self.window.y() - self.selected_window.height() as i32 - 4; 424 | self.selected_window.set_pos(0, sw_y); 425 | } 426 | 427 | let image = package.icon.image(); 428 | image.draw(&mut self.window, x as i32, y as i32); 429 | 430 | let mut count = 0; 431 | for (exec, _) in self.children.iter() { 432 | if exec == &package.exec { 433 | count += 1; 434 | } 435 | } 436 | if count > 0 { 437 | self.window.rect( 438 | x as i32 + 4, 439 | y as i32, 440 | image.width() - 8, 441 | 2, 442 | TEXT_HIGHLIGHT_COLOR, 443 | ); 444 | } 445 | 446 | x += image.width() as i32; 447 | i += 1; 448 | } 449 | 450 | let text = self.font.render(&self.time, (font_size() * 2) as f32); 451 | x = self.width as i32 - text.width() as i32 - 8; 452 | y = (icon_size() - text.height() as i32) / 2; 453 | text.draw(&mut self.window, x, y, TEXT_HIGHLIGHT_COLOR); 454 | 455 | self.window.sync(); 456 | } 457 | 458 | fn start_window(&mut self, category_opt: Option<&String>) -> Option { 459 | let packages = match category_opt { 460 | Some(category) => self.category_packages.get_mut(category)?, 461 | None => &mut self.start_packages, 462 | }; 463 | 464 | let start_h = packages.len() as u32 * icon_small_size() as u32; 465 | let mut start_window = Window::new_flags( 466 | 0, 467 | self.height as i32 - icon_size() - start_h as i32, 468 | chooser_width(), 469 | start_h, 470 | "Start", 471 | &[WindowFlag::Borderless, WindowFlag::Transparent], 472 | ) 473 | .unwrap(); 474 | 475 | let mut selected = -1; 476 | let mut mouse_y = 0; 477 | let mut mouse_left = false; 478 | let mut last_mouse_left = false; 479 | draw_chooser(&mut start_window, &self.font, packages, selected); 480 | 'start_choosing: loop { 481 | for event in start_window.events() { 482 | let redraw = match event.to_option() { 483 | EventOption::Mouse(mouse_event) => { 484 | mouse_y = mouse_event.y; 485 | true 486 | } 487 | EventOption::Button(button_event) => { 488 | mouse_left = button_event.left; 489 | true 490 | } 491 | EventOption::Key(key_event) => match key_event.scancode { 492 | K_ESC => break 'start_choosing, 493 | _ => false, 494 | }, 495 | EventOption::Focus(focus_event) => { 496 | if !focus_event.focused { 497 | break 'start_choosing; 498 | } else { 499 | false 500 | } 501 | } 502 | EventOption::Quit(_) => break 'start_choosing, 503 | _ => false, 504 | }; 505 | 506 | if redraw { 507 | let mut now_selected = -1; 508 | 509 | let mut y = 0; 510 | for (j, _package) in packages.iter().enumerate() { 511 | if mouse_y >= y && mouse_y < y + icon_small_size() { 512 | now_selected = j as i32; 513 | } 514 | y += icon_small_size(); 515 | } 516 | 517 | if now_selected != selected { 518 | selected = now_selected; 519 | draw_chooser(&mut start_window, &self.font, packages, selected); 520 | } 521 | 522 | if !mouse_left && last_mouse_left { 523 | let mut y = 0; 524 | for package_i in 0..packages.len() { 525 | if mouse_y >= y && mouse_y < y + icon_small_size() { 526 | return Some(packages[package_i].exec.to_string()); 527 | } 528 | y += icon_small_size(); 529 | } 530 | } 531 | 532 | last_mouse_left = mouse_left; 533 | } 534 | } 535 | } 536 | None 537 | } 538 | 539 | fn spawn(&mut self, exec: String) { 540 | match exec_to_command(&exec, None) { 541 | Some(mut command) => match command.spawn() { 542 | Ok(child) => { 543 | self.children.push((exec, child)); 544 | //TODO: should redraw be done here? 545 | self.draw(); 546 | } 547 | Err(err) => error!("failed to spawn {}: {}", exec, err), 548 | }, 549 | None => error!("failed to parse {}", exec), 550 | } 551 | } 552 | } 553 | 554 | fn bar_main(width: u32, height: u32) -> io::Result<()> { 555 | let mut bar = Bar::new(width, height); 556 | 557 | match Command::new("background").spawn() { 558 | Ok(child) => bar.children.push(("background".to_string(), child)), 559 | Err(err) => error!("failed to launch background: {}", err), 560 | } 561 | 562 | user_data! { 563 | enum Event { 564 | Time, 565 | Window, 566 | } 567 | } 568 | let event_queue = EventQueue::::new().expect("launcher: failed to create event queue"); 569 | 570 | let mut time_file = File::open(&format!("/scheme/time/{}", flag::CLOCK_MONOTONIC))?; 571 | 572 | event_queue 573 | .subscribe( 574 | time_file.as_raw_fd() as usize, 575 | Event::Time, 576 | event::EventFlags::READ, 577 | ) 578 | .expect("launcher: failed to subscribe to timer"); 579 | event_queue 580 | .subscribe( 581 | bar.window.as_raw_fd() as usize, 582 | Event::Window, 583 | event::EventFlags::READ, 584 | ) 585 | .expect("launcher: failed to subscribe to timer"); 586 | 587 | let mut mouse_x = -1; 588 | let mut mouse_y = -1; 589 | let mut mouse_left = false; 590 | let mut last_mouse_left = false; 591 | 592 | let all_events = core::array::IntoIter::new([Event::Time, Event::Window]); 593 | 594 | 'events: for event in all_events 595 | .chain(event_queue.map(|e| e.expect("launcher: failed to get next event").user_data)) 596 | { 597 | match event { 598 | Event::Time => { 599 | let mut time_buf = [0_u8; core::mem::size_of::()]; 600 | if time_file.read(&mut time_buf)? < mem::size_of::() { 601 | continue; 602 | } 603 | 604 | let mut i = 0; 605 | while i < bar.children.len() { 606 | let remove = match bar.children[i].1.try_wait() { 607 | Ok(None) => false, 608 | Ok(Some(status)) => { 609 | info!( 610 | "{} ({}) exited with {}", 611 | bar.children[i].0, 612 | bar.children[i].1.id(), 613 | status 614 | ); 615 | true 616 | } 617 | Err(err) => { 618 | error!( 619 | "failed to wait for {} ({}): {}", 620 | bar.children[i].0, 621 | bar.children[i].1.id(), 622 | err 623 | ); 624 | true 625 | } 626 | }; 627 | if remove { 628 | bar.children.remove(i); 629 | } else { 630 | i += 1; 631 | } 632 | } 633 | 634 | loop { 635 | let mut status = 0; 636 | let pid = wait(&mut status)?; 637 | if pid == 0 { 638 | break; 639 | } 640 | } 641 | 642 | bar.update_time(); 643 | bar.draw(); 644 | 645 | match libredox::data::timespec_from_mut_bytes(&mut time_buf) { 646 | time => { 647 | time.tv_sec += 1; 648 | time.tv_nsec = 0; 649 | } 650 | } 651 | time_file.write(&time_buf)?; 652 | } 653 | Event::Window => { 654 | for event in bar.window.events() { 655 | //TODO: remove hack for super event 656 | if event.code >= 0x1000_0000 { 657 | let mut super_event = event; 658 | super_event.code -= 0x1000_0000; 659 | 660 | //TODO: configure super keybindings 661 | let event_option = super_event.to_option(); 662 | debug!("launcher: super {:?}", event_option); 663 | match event_option { 664 | EventOption::Key(key_event) => match key_event.scancode { 665 | orbclient::K_B => { 666 | if key_event.pressed { 667 | bar.spawn("netsurf-fb".to_string()); 668 | } 669 | } 670 | orbclient::K_F => { 671 | if key_event.pressed { 672 | bar.spawn("cosmic-files".to_string()); 673 | } 674 | } 675 | orbclient::K_T => { 676 | if key_event.pressed { 677 | bar.spawn("cosmic-term".to_string()); 678 | } 679 | } 680 | _ => (), 681 | }, 682 | _ => (), 683 | } 684 | 685 | continue; 686 | } 687 | 688 | let redraw = match event.to_option() { 689 | EventOption::Mouse(mouse_event) => { 690 | mouse_x = mouse_event.x; 691 | mouse_y = mouse_event.y; 692 | true 693 | } 694 | EventOption::Button(button_event) => { 695 | mouse_left = button_event.left; 696 | true 697 | } 698 | EventOption::Screen(screen_event) => { 699 | bar.width = screen_event.width; 700 | bar.height = screen_event.height; 701 | bar.window 702 | .set_pos(0, screen_event.height as i32 - icon_size()); 703 | bar.window.set_size(screen_event.width, icon_size() as u32); 704 | bar.selected = -2; // Force bar redraw 705 | bar.selected_window.set_pos(0, screen_event.height as i32); 706 | bar.selected_window 707 | .set_size(screen_event.width, (font_size() + 8) as u32); 708 | true 709 | } 710 | EventOption::Hover(hover_event) => { 711 | if hover_event.entered { 712 | false 713 | } else { 714 | mouse_x = -1; 715 | mouse_y = -1; 716 | true 717 | } 718 | } 719 | EventOption::Quit(_) => break 'events, 720 | _ => false, 721 | }; 722 | 723 | if redraw { 724 | let mut now_selected = -1; 725 | 726 | { 727 | let mut x = 0; 728 | let y = 0; 729 | let mut i = 0; 730 | 731 | { 732 | if mouse_y >= y 733 | && mouse_x >= x 734 | && mouse_x < x + bar.start.width() as i32 735 | { 736 | now_selected = i; 737 | } 738 | x += bar.start.width() as i32; 739 | i += 1; 740 | } 741 | 742 | for package in bar.packages.iter_mut() { 743 | let image = package.icon.image(); 744 | if mouse_y >= y 745 | && mouse_x >= x 746 | && mouse_x < x + image.width() as i32 747 | { 748 | now_selected = i; 749 | } 750 | x += image.width() as i32; 751 | i += 1; 752 | } 753 | } 754 | 755 | if now_selected != bar.selected { 756 | bar.selected = now_selected; 757 | let sw_y = bar.height as i32; 758 | bar.selected_window.set_pos(0, sw_y); 759 | bar.draw(); 760 | } 761 | 762 | if !mouse_left && last_mouse_left { 763 | let mut i = 0; 764 | 765 | if i == bar.selected { 766 | let mut category_opt = None; 767 | while let Some(exec) = bar.start_window(category_opt.as_ref()) { 768 | if exec.starts_with("category=") { 769 | let category = &exec[9..]; 770 | category_opt = Some(category.to_string()); 771 | } else if exec == "exit" { 772 | if category_opt.is_some() { 773 | category_opt = None; 774 | } else { 775 | break 'events; 776 | } 777 | } else { 778 | bar.spawn(exec); 779 | break; 780 | } 781 | } 782 | } 783 | i += 1; 784 | 785 | for package_i in 0..bar.packages.len() { 786 | if i == bar.selected { 787 | let exec = bar.packages[package_i].exec.clone(); 788 | bar.spawn(exec); 789 | } 790 | i += 1; 791 | } 792 | } 793 | 794 | last_mouse_left = mouse_left; 795 | } 796 | } 797 | } 798 | } 799 | } 800 | 801 | debug!("Launcher exiting, killing {} children", bar.children.len()); 802 | for (exec, child) in bar.children.iter_mut() { 803 | let pid = child.id(); 804 | match child.kill() { 805 | Ok(()) => debug!("Successfully killed child: {}", pid), 806 | Err(err) => error!("failed to kill {} ({}): {}", exec, pid, err), 807 | } 808 | match child.wait() { 809 | Ok(status) => info!("{} ({}) exited with {}", exec, pid, status), 810 | Err(err) => error!("failed to wait for {} ({}): {}", exec, pid, err), 811 | } 812 | } 813 | 814 | // kill any descendents of one of the children killed above that are still running 815 | debug!("Launcher exiting, reaping all zombie processes"); 816 | let mut status = 0; 817 | while wait(&mut status).is_ok() {} 818 | 819 | Ok(()) 820 | } 821 | 822 | fn chooser_main(paths: env::Args) { 823 | for ref path in paths.skip(1) { 824 | let mut packages = get_packages(); 825 | 826 | packages.retain(|package| -> bool { 827 | for accept in package.accepts.iter() { 828 | if (accept.starts_with('*') && path.ends_with(&accept[1..])) 829 | || (accept.ends_with('*') && path.starts_with(&accept[..accept.len() - 1])) 830 | { 831 | return true; 832 | } 833 | } 834 | false 835 | }); 836 | 837 | if packages.len() > 1 { 838 | let mut window = Window::new( 839 | -1, 840 | -1, 841 | chooser_width(), 842 | packages.len() as u32 * icon_small_size() as u32, 843 | path, 844 | ) 845 | .expect("launcher: failed to open window"); 846 | let font = Font::find(Some("Sans"), None, None).expect("launcher: failed to open font"); 847 | 848 | let mut selected = -1; 849 | let mut mouse_y = 0; 850 | let mut mouse_left = false; 851 | let mut last_mouse_left = false; 852 | 853 | draw_chooser(&mut window, &font, &mut packages, selected); 854 | 'choosing: loop { 855 | for event in window.events() { 856 | let redraw = match event.to_option() { 857 | EventOption::Mouse(mouse_event) => { 858 | mouse_y = mouse_event.y; 859 | true 860 | } 861 | EventOption::Button(button_event) => { 862 | mouse_left = button_event.left; 863 | true 864 | } 865 | EventOption::Quit(_) => break 'choosing, 866 | _ => false, 867 | }; 868 | 869 | if redraw { 870 | let mut now_selected = -1; 871 | 872 | let mut y = 0; 873 | for (i, _package) in packages.iter().enumerate() { 874 | if mouse_y >= y && mouse_y < y + icon_size() { 875 | now_selected = i as i32; 876 | } 877 | y += icon_small_size(); 878 | } 879 | 880 | if now_selected != selected { 881 | selected = now_selected; 882 | draw_chooser(&mut window, &font, &mut packages, selected); 883 | } 884 | 885 | if !mouse_left && last_mouse_left { 886 | let mut y = 0; 887 | for package in packages.iter() { 888 | if mouse_y >= y && mouse_y < y + icon_small_size() { 889 | spawn_exec(&package.exec, Some(&path)); 890 | break 'choosing; 891 | } 892 | y += icon_small_size(); 893 | } 894 | } 895 | 896 | last_mouse_left = mouse_left; 897 | } 898 | } 899 | } 900 | } else if let Some(package) = packages.get(0) { 901 | spawn_exec(&package.exec, Some(&path)); 902 | } else { 903 | error!("no application found for '{}'", path); 904 | } 905 | } 906 | } 907 | 908 | fn start_logging() { 909 | if let Err(e) = RedoxLogger::new() 910 | .with_output( 911 | OutputBuilder::stdout() 912 | .with_filter(log::LevelFilter::Debug) 913 | .with_ansi_escape_codes() 914 | .build(), 915 | ) 916 | .with_process_name("launcher".into()) 917 | .enable() 918 | { 919 | eprintln!("Launcher could not start logging: {}", e); 920 | } 921 | } 922 | 923 | fn main() -> Result<(), String> { 924 | start_logging(); 925 | 926 | let (width, height) = orbclient::get_display_size()?; 927 | SCALE.store((height as isize / 1600) + 1, Ordering::Relaxed); 928 | let paths = env::args(); 929 | if paths.len() > 1 { 930 | chooser_main(paths); 931 | } else { 932 | bar_main(width, height).map_err(|e| e.to_string())?; 933 | } 934 | 935 | Ok(()) 936 | } 937 | -------------------------------------------------------------------------------- /launcher/src/package.rs: -------------------------------------------------------------------------------- 1 | use std::collections::BTreeSet; 2 | use std::ffi::OsStr; 3 | use std::fs::File; 4 | use std::io::Read; 5 | use std::path::{Path, PathBuf}; 6 | use std::sync::atomic::Ordering; 7 | 8 | use orbimage::Image; 9 | 10 | use super::{load_icon, load_icon_small, load_icon_svg}; 11 | 12 | #[derive(Clone, Debug)] 13 | pub enum IconSource { 14 | None, 15 | Name(String), 16 | Path(PathBuf), 17 | } 18 | 19 | impl IconSource { 20 | pub fn lookup(&mut self, small: bool) -> Option<&Path> { 21 | match self { 22 | IconSource::Name(name) => { 23 | let size = if small { 32 } else { 48 }; 24 | let scale = crate::SCALE.load(Ordering::Relaxed) as u16; 25 | if let Some(path) = freedesktop_icons::lookup(name) 26 | .with_size(size) 27 | .with_scale(scale) 28 | .with_theme("Cosmic") 29 | .find() 30 | { 31 | *self = IconSource::Path(path) 32 | } else { 33 | log::warn!("failed to find icon {name} with size {size} and scale {scale}"); 34 | } 35 | } 36 | _ => {} 37 | } 38 | match self { 39 | IconSource::Path(path) => Some(path), 40 | _ => None, 41 | } 42 | } 43 | } 44 | 45 | #[derive(Clone)] 46 | pub struct Icon { 47 | pub source: IconSource, 48 | small: bool, 49 | image_opt: Option, 50 | } 51 | 52 | impl Icon { 53 | pub fn empty(small: bool) -> Self { 54 | Self { 55 | source: IconSource::None, 56 | small, 57 | image_opt: None, 58 | } 59 | } 60 | 61 | pub fn image(&mut self) -> &Image { 62 | if self.image_opt.is_none() { 63 | log::info!("loading {:?}", self.source); 64 | self.image_opt = if let Some(path) = self.source.lookup(self.small) { 65 | if path.extension() == Some(OsStr::new("png")) { 66 | Some(if self.small { 67 | load_icon_small(&path) 68 | } else { 69 | load_icon(&path) 70 | }) 71 | } else if path.extension() == Some(OsStr::new("svg")) { 72 | load_icon_svg(&path, self.small) 73 | } else { 74 | None 75 | } 76 | } else { 77 | None 78 | }; 79 | if self.image_opt.is_none() { 80 | println!("failed to load icon {:?}", self.source); 81 | self.image_opt = Some(Image::default()); 82 | } 83 | } 84 | self.image_opt.as_ref().unwrap() 85 | } 86 | } 87 | 88 | /// A package (_REDOX content serialized) 89 | #[derive(Clone)] 90 | pub struct Package { 91 | /// The ID of the package 92 | pub id: String, 93 | /// The name of the package 94 | pub name: String, 95 | /// The categories for the package 96 | pub categories: BTreeSet, 97 | /// The exec string for the package, parsed by shlex 98 | pub exec: String, 99 | /// The icon for the package 100 | pub icon: Icon, 101 | /// A smaller icon for the package 102 | pub icon_small: Icon, 103 | /// The accepted extensions 104 | pub accepts: Vec, 105 | /// The author(s) of the package 106 | pub authors: Vec, 107 | /// The description of the package 108 | pub descriptions: Vec, 109 | } 110 | 111 | impl Package { 112 | pub fn new() -> Self { 113 | Package { 114 | id: String::new(), 115 | name: String::new(), 116 | categories: BTreeSet::new(), 117 | exec: String::new(), 118 | icon: Icon::empty(false), 119 | icon_small: Icon::empty(true), 120 | accepts: Vec::new(), 121 | authors: Vec::new(), 122 | descriptions: Vec::new(), 123 | } 124 | } 125 | 126 | /// Create package from URL 127 | pub fn from_path(path: &str) -> Self { 128 | let mut package = Package::new(); 129 | 130 | for part in path.rsplit('/') { 131 | if !part.is_empty() { 132 | package.id = part.to_string(); 133 | break; 134 | } 135 | } 136 | 137 | let mut info = String::new(); 138 | 139 | if let Ok(mut file) = File::open(path) { 140 | let _ = file.read_to_string(&mut info); 141 | } 142 | 143 | for line in info.lines() { 144 | if line.starts_with("name=") { 145 | package.name = line[5..].to_string(); 146 | } else if line.starts_with("category=") { 147 | let category = &line[9..]; 148 | if !category.is_empty() { 149 | package.categories.insert(category.into()); 150 | } 151 | } else if line.starts_with("binary=") { 152 | match shlex::try_quote(&line[7..]) { 153 | Ok(binary) => { 154 | // This adds %f to the binary for use in launching files 155 | package.exec = format!("{binary} %f"); 156 | } 157 | Err(err) => { 158 | log::error!("failed to parse package info: {:?}: {}", line, err); 159 | } 160 | } 161 | } else if line.starts_with("icon=") { 162 | let path = Path::new(&line[5..]); 163 | package.icon.source = IconSource::Path(path.into()); 164 | package.icon_small.source = IconSource::Path(path.into()); 165 | } else if line.starts_with("accept=") { 166 | package.accepts.push(line[7..].to_string()); 167 | } else if line.starts_with("author=") { 168 | package.authors.push(line[7..].to_string()); 169 | } else if line.starts_with("description=") { 170 | package.descriptions.push(line[12..].to_string()); 171 | } else { 172 | log::error!("unknown package info: {}", line); 173 | } 174 | } 175 | 176 | package 177 | } 178 | 179 | pub fn from_desktop_entry(id: String, path: &Path) -> Option { 180 | let entry = freedesktop_entry_parser::parse_entry(path).ok()?; 181 | let mut package = Package::new(); 182 | package.id = id; 183 | let section = entry.section("Desktop Entry"); 184 | if let Some(name) = section.attr("Name") { 185 | package.name = name.into(); 186 | } 187 | if let Some(categories) = section.attr("Categories") { 188 | // From https://specifications.freedesktop.org/menu-spec/latest/category-registry.html#main-category-registry 189 | let main_categories = [ 190 | "AudioVideo", 191 | "Audio", 192 | "Video", 193 | "Development", 194 | "Education", 195 | "Game", 196 | "Graphics", 197 | "Network", 198 | "Office", 199 | "Science", 200 | "Settings", 201 | "System", 202 | "Utility", 203 | ]; 204 | for category in categories.split_terminator(';') { 205 | if main_categories.contains(&category) { 206 | // Some categories are renamed here 207 | package.categories.insert( 208 | match category { 209 | "AudioVideo" | "Audio" | "Video" => "Multimedia", 210 | "Game" => "Games", 211 | _ => category, 212 | } 213 | .into(), 214 | ); 215 | } 216 | } 217 | } 218 | if let Some(exec) = section.attr("Exec") { 219 | package.exec = exec.into(); 220 | } 221 | if let Some(icon) = section.attr("Icon") { 222 | package.icon.source = IconSource::Name(icon.into()); 223 | package.icon_small.source = IconSource::Name(icon.into()); 224 | } 225 | Some(package) 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /launcher/src/theme.rs: -------------------------------------------------------------------------------- 1 | use orbclient::Color; 2 | 3 | pub const BAR_COLOR: Color = Color::rgba(0x1B, 0x1B, 0x1B, 224); 4 | pub const BAR_HIGHLIGHT_COLOR: Color = Color::rgba(0x36, 0x36, 0x36, 224); 5 | pub const TEXT_COLOR: Color = Color::rgb(0xE7, 0xE7, 0xE7); 6 | pub const TEXT_HIGHLIGHT_COLOR: Color = Color::rgb(0xE7, 0xE7, 0xE7); 7 | -------------------------------------------------------------------------------- /orbutils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "orbutils" 3 | description = "The Orbital Utilities" 4 | repository = "https://gitlab.redox-os.org/redox-os/orbutils" 5 | version = "0.1.16" 6 | license-file = "LICENSE" 7 | readme = "README.md" 8 | authors = ["Jeremy Soller "] 9 | 10 | [[bin]] 11 | name = "background" 12 | path = "src/background/main.rs" 13 | 14 | [[bin]] 15 | name = "orblogin" 16 | path = "src/orblogin/main.rs" 17 | 18 | # Deprecated 19 | #[[bin]] 20 | #name = "character_map" 21 | #path = "src/character_map/main.rs" 22 | 23 | # Deprecated in favor of cosmic-edit 24 | #[[bin]] 25 | #name = "editor" 26 | #path = "src/editor/main.rs" 27 | 28 | # Deprecated in favor of cosmic-files 29 | #[[bin]] 30 | #name = "file_manager" 31 | #path = "src/file_manager/main.rs" 32 | 33 | [[bin]] 34 | name = "viewer" 35 | path = "src/viewer/main.rs" 36 | 37 | [[bin]] 38 | name = "calendar" 39 | path = "src/calendar/main.rs" 40 | 41 | [dependencies] 42 | calculate = { git = "https://gitlab.redox-os.org/redox-os/calc.git" } 43 | chrono = "0.4.6" 44 | mime_guess = "1.8.6" 45 | mime = "0.2.6" 46 | orbclient = "0.3.47" 47 | orbfont = "0.1.8" 48 | orbimage = "0.1.17" 49 | orbtk = "0.2.29" 50 | redox_users = "0.4" 51 | redox-log = "0.1" 52 | log = "0.4.14" 53 | dirs = "5.0.0" 54 | libc = "0.2.50" 55 | 56 | [target.'cfg(not(target_os = "redox"))'.dependencies] 57 | libc = "0.2.50" 58 | 59 | [target.'cfg(target_os = "redox")'.dependencies] 60 | redox_event = "0.4.1" 61 | libredox = { version = "0.1.3", default-features = false, features = ["std", "call"] } 62 | -------------------------------------------------------------------------------- /orbutils/src/background/main.rs: -------------------------------------------------------------------------------- 1 | extern crate orbclient; 2 | extern crate orbimage; 3 | extern crate redox_log; 4 | extern crate log; 5 | extern crate event; 6 | extern crate libredox; 7 | extern crate dirs; 8 | 9 | use std::{ 10 | collections::HashMap, env, fs::File, os::unix::io::{AsRawFd, FromRawFd, RawFd}, rc::Rc 11 | }; 12 | use libredox::flag; 13 | use log::error; 14 | 15 | use orbclient::{Color, EventOption, Renderer, Window, WindowFlag}; 16 | use orbimage::Image; 17 | use redox_log::{OutputBuilder, RedoxLogger}; 18 | 19 | use event::RawEventQueue; 20 | 21 | struct DisplayRect { 22 | pub x: i32, 23 | pub y: i32, 24 | pub width: u32, 25 | pub height: u32, 26 | } 27 | 28 | #[derive(Clone, Copy, Debug)] 29 | enum BackgroundMode { 30 | /// Do not resize the image, just center it 31 | Center, 32 | /// Resize the image to the display size 33 | Fill, 34 | /// Resize the image - keeping its aspect ratio, and fit it to the display with blank space 35 | Scale, 36 | /// Resize the image - keeping its aspect ratio, and crop to remove all blank space 37 | Zoom, 38 | } 39 | 40 | impl BackgroundMode { 41 | fn from_str(string: &str) -> BackgroundMode { 42 | match string { 43 | "center" => BackgroundMode::Center, 44 | "fill" => BackgroundMode::Fill, 45 | "scale" => BackgroundMode::Scale, 46 | _ => BackgroundMode::Zoom, 47 | } 48 | } 49 | } 50 | 51 | fn find_scale(image: &Image, mode: BackgroundMode, display_width: u32, display_height: u32) -> (u32, u32) { 52 | match mode { 53 | BackgroundMode::Center => { 54 | (image.width(), image.height()) 55 | }, 56 | BackgroundMode::Fill => { 57 | (display_width, display_height) 58 | }, 59 | BackgroundMode::Scale => { 60 | let d_w = display_width as f64; 61 | let d_h = display_height as f64; 62 | let i_w = image.width() as f64; 63 | let i_h = image.height() as f64; 64 | 65 | let scale = if d_w / d_h > i_w / i_h { 66 | d_h / i_h 67 | } else { 68 | d_w / i_w 69 | }; 70 | 71 | ((i_w * scale) as u32, (i_h * scale) as u32) 72 | }, 73 | BackgroundMode::Zoom => { 74 | let d_w = display_width as f64; 75 | let d_h = display_height as f64; 76 | let i_w = image.width() as f64; 77 | let i_h = image.height() as f64; 78 | 79 | let scale = if d_w / d_h < i_w / i_h { 80 | d_h / i_h 81 | } else { 82 | d_w / i_w 83 | }; 84 | 85 | ((i_w * scale) as u32, (i_h * scale) as u32) 86 | } 87 | } 88 | } 89 | 90 | fn find_background() -> String { 91 | match dirs::home_dir() { 92 | Some(home) => { 93 | for name in &[ 94 | "background.png", 95 | "background.jpg", 96 | ] { 97 | let path = home.join(name); 98 | if path.is_file() { 99 | if let Some(path_str) = path.to_str() { 100 | return path_str.to_string(); 101 | } 102 | } 103 | } 104 | } 105 | _ => (), 106 | } 107 | 108 | "/ui/background.jpg".to_string() 109 | } 110 | 111 | fn get_full_url(path: &str) -> Result { 112 | let file = match libredox::call::open(path, flag::O_CLOEXEC | flag::O_PATH, 0) { 113 | Ok(ok) => unsafe { File::from_raw_fd(ok as RawFd) }, 114 | Err(err) => return Err(format!("{}", err)), 115 | }; 116 | 117 | let mut buf: [u8; 4096] = [0; 4096]; 118 | let count = libredox::call::fpath(file.as_raw_fd() as usize, &mut buf) 119 | .map_err(|err| format!("{}", err))?; 120 | 121 | String::from_utf8(Vec::from(&buf[..count])) 122 | .map_err(|err| format!("{}", err)) 123 | } 124 | 125 | //TODO: determine x, y of display by talking to orbital instead of guessing! 126 | fn get_display_rects() -> Result, String> { 127 | let url = get_full_url( 128 | &env::var("DISPLAY").or(Err("DISPLAY not set"))? 129 | )?; 130 | 131 | let mut url_parts = url.split(':'); 132 | let scheme_name = url_parts.next().ok_or(format!("no scheme name"))?; 133 | let path = url_parts.next().ok_or(format!("no path"))?; 134 | 135 | let mut path_parts = path.split('/'); 136 | let vt_screen = path_parts.next().unwrap_or(""); 137 | let width = path_parts.next().unwrap_or("").parse::().unwrap_or(0); 138 | let height = path_parts.next().unwrap_or("").parse::().unwrap_or(0); 139 | 140 | let mut display_rects = vec![DisplayRect { 141 | x: 0, 142 | y: 0, 143 | width, 144 | height, 145 | }]; 146 | 147 | // If display server supports multiple displays in a VT 148 | if vt_screen.contains('.') { 149 | // Look for other screens in the same VT 150 | let mut parts = vt_screen.split('.'); 151 | let vt_i = parts.next().unwrap_or("").parse::().unwrap_or(0); 152 | let start_screen_i = parts.next().unwrap_or("").parse::().unwrap_or(0); 153 | //TODO: determine maximum number of screens 154 | for screen_i in start_screen_i + 1..1024 { 155 | let url = match get_full_url(&format!("/scheme/{}/{}.{}", scheme_name, vt_i, screen_i)) { 156 | Ok(ok) => ok, 157 | //TODO: only check for ENOENT? 158 | Err(_err) => break, 159 | }; 160 | 161 | let mut url_parts = url.split(':'); 162 | let _scheme_name = url_parts.next().ok_or(format!("no scheme name"))?; 163 | let path = url_parts.next().ok_or(format!("no path"))?; 164 | 165 | let mut path_parts = path.split('/'); 166 | let _vt_screen = path_parts.next().unwrap_or(""); 167 | let width = path_parts.next().unwrap_or("").parse::().unwrap_or(0); 168 | let height = path_parts.next().unwrap_or("").parse::().unwrap_or(0); 169 | 170 | let x = if let Some(last) = display_rects.last() { 171 | last.x + last.width as i32 172 | } else { 173 | 0 174 | }; 175 | 176 | display_rects.push(DisplayRect { 177 | x, 178 | y: 0, 179 | width, 180 | height, 181 | }); 182 | } 183 | } 184 | 185 | Ok(display_rects) 186 | } 187 | 188 | fn main() { 189 | // Ignore possible errors while enabling logging 190 | let _ = RedoxLogger::new() 191 | .with_output( 192 | OutputBuilder::stdout() 193 | .with_filter(log::LevelFilter::Debug) 194 | .with_ansi_escape_codes() 195 | .build() 196 | ) 197 | .with_process_name("background".into()) 198 | .enable(); 199 | 200 | let mut args = env::args().skip(1); 201 | 202 | let path = match args.next() { 203 | Some(arg) => arg, 204 | None => find_background(), 205 | }; 206 | 207 | let mode = BackgroundMode::from_str(&args.next().unwrap_or_default()); 208 | 209 | match Image::from_path(&path).map(Rc::new) { 210 | Ok(image) => { 211 | let event_queue = RawEventQueue::new().expect("background: failed to create event queue"); 212 | 213 | let mut handlers = HashMap::>::new(); 214 | 215 | for display in get_display_rects().expect("background: failed to get display rects") { 216 | let mut window = Window::new_flags( 217 | display.x, display.y, display.width, display.height, "", 218 | &[WindowFlag::Async, WindowFlag::Back, WindowFlag::Borderless, WindowFlag::Unclosable] 219 | ).unwrap(); 220 | 221 | let image = image.clone(); 222 | let mut scaled_image = (*image).clone(); 223 | let mut resize = Some((display.width, display.height)); 224 | 225 | event_queue.subscribe(window.as_raw_fd() as usize, window.as_raw_fd() as usize, event::EventFlags::READ) 226 | .expect("background: failed to add event"); 227 | 228 | let window_raw_fd = window.as_raw_fd(); 229 | let mut handler: Box = Box::new(move || { 230 | for event in window.events() { 231 | match event.to_option() { 232 | EventOption::Resize(resize_event) => { 233 | resize = Some((resize_event.width, resize_event.height)); 234 | }, 235 | EventOption::Screen(screen_event) => { 236 | window.set_size(screen_event.width, screen_event.height); 237 | resize = Some((screen_event.width, screen_event.height)); 238 | }, 239 | _ => () 240 | } 241 | } 242 | 243 | if let Some((w, h)) = resize.take() { 244 | let (width, height) = find_scale(&image, mode, w, h); 245 | 246 | if width == scaled_image.width() && height == scaled_image.height() { 247 | // Do not resize scaled image 248 | } else if width == image.width() && height == image.height() { 249 | scaled_image = (*image).clone(); 250 | } else { 251 | scaled_image = image.resize(width, height, orbimage::ResizeType::Lanczos3).unwrap(); 252 | } 253 | 254 | let (crop_x, crop_w) = if width > w { 255 | ((width - w)/2, w) 256 | } else { 257 | (0, width) 258 | }; 259 | 260 | let (crop_y, crop_h) = if height > h { 261 | ((height - h)/2, h) 262 | } else { 263 | (0, height) 264 | }; 265 | 266 | window.set(Color::rgb(0, 0, 0)); 267 | 268 | let x = (w as i32 - crop_w as i32)/2; 269 | let y = (h as i32 - crop_h as i32)/2; 270 | scaled_image.roi( 271 | crop_x, crop_y, 272 | crop_w, crop_h, 273 | ).draw( 274 | &mut window, 275 | x, y 276 | ); 277 | 278 | window.sync(); 279 | } 280 | }); 281 | handler(); 282 | handlers.insert(window_raw_fd as usize, handler); 283 | } 284 | 285 | for event in event_queue.map(|e| e.expect("background: failed to get next event")) { 286 | let Some(handler) = handlers.get_mut(&event.fd) else { 287 | continue; 288 | }; 289 | (*handler)(); 290 | } 291 | }, 292 | Err(err) => { 293 | error!("error loading {}: {}", path, err); 294 | } 295 | } 296 | } 297 | -------------------------------------------------------------------------------- /orbutils/src/calendar/main.rs: -------------------------------------------------------------------------------- 1 | extern crate orbtk; 2 | extern crate chrono; 3 | extern crate orbclient; 4 | extern crate redox_log; 5 | 6 | use orbtk::{Rect, Window, WindowBuilder, Grid, Label, Button, Style}; 7 | use orbtk::traits::{Place, Text, Click}; 8 | use orbtk::theme::Theme; 9 | use chrono::prelude::*; 10 | use chrono::Duration; 11 | use std::ops::{Sub, Add}; 12 | use std::sync::Arc; 13 | use std::sync::mpsc::{channel, Receiver}; 14 | use redox_log::{OutputBuilder, RedoxLogger}; 15 | 16 | static CALENDAR_THEME_CSS: &'static str = include_str!("theme.css"); 17 | 18 | pub struct TimeMachine { 19 | date: DateTime, 20 | } 21 | 22 | impl TimeMachine { 23 | 24 | pub fn new() -> Self { 25 | TimeMachine { 26 | date: Local::now(), 27 | } 28 | } 29 | 30 | pub fn increase_month(&mut self) { 31 | self.date = self.date.add(Duration::days(31)) 32 | .with_day(1) 33 | .unwrap(); 34 | } 35 | 36 | pub fn decrease_month(&mut self) { 37 | self.date = self.date.sub(Duration::days(28)) 38 | .with_day(1) 39 | .unwrap(); 40 | } 41 | 42 | pub fn get_date(&mut self) -> DateTime { 43 | self.date 44 | } 45 | } 46 | 47 | enum CalendarCommand { 48 | IncreaseMonth(), 49 | DecreaseMonth(), 50 | } 51 | 52 | pub struct Calendar { 53 | window: Window, 54 | window_width: u32, 55 | cell_width: u32, 56 | cell_height: u32, 57 | cell_day_name_height: u32, 58 | date: TimeMachine, 59 | grid_calendar: Arc, 60 | label_date: Arc