├── .gitignore ├── CHANGELOG.asciidoc ├── LICENSE ├── Makefile ├── README.asciidoc ├── classes.h ├── functions.h ├── man └── setroot.1 ├── setroot.c └── util.h /.gitignore: -------------------------------------------------------------------------------- 1 | man/setroot.1.txt 2 | arch/ 3 | arch/** 4 | arch/**/** 5 | -------------------------------------------------------------------------------- /CHANGELOG.asciidoc: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | ========= 3 | 4 | Release 5 | ------- 6 | 7 | v2.0 8 | ------ 9 | 10 | - code rewrite 11 | 12 | v1.5 13 | ------ 14 | 15 | - fixed desktop_window() 16 | 17 | v1.4.6 18 | ------ 19 | 20 | - merged pull request #11 21 | 22 | v1.4.5 23 | ------ 24 | 25 | - added some msgs for `--on` option if `setroot` was compiled without Xinerama support. 26 | 27 | v1.4.4 28 | ------ 29 | 30 | - fixed issue with --solid-color treating hex code as image 31 | - unfortunately had to use a third level of indentation (sorry Mr. Torvalds for skirting the line) 32 | 33 | v1.4.3 34 | ------ 35 | 36 | - merged pull request (c. vain) that fixes --use-[xy]-geometry argument not being parsed 37 | 38 | v1.4.2 39 | ------ 40 | 41 | - fixed bugs (very, very rare) caused by hash marks in cli arguments when re/storing 42 | - `setroot` now adds a backslash to escape the hash marks in `.setroot-restore` 43 | - currently does not escape backslashes on their own... if anyone complains i'll add it :) 44 | 45 | v1.4.1 46 | ------ 47 | 48 | - code base changes 49 | - added error handling cases for --store and --on 50 | 51 | v1.4 52 | ---- 53 | 54 | - handle spaces, special characters, allows you to set wallpaper in advance for unconnected monitors 55 | - making libxinerama an optional dependency 56 | 57 | v1.3 58 | ---- 59 | 60 | - autocreates the appropriate config directory 61 | 62 | v1.2 63 | ---- 64 | 65 | - _--store_ and _--restore_ now use _$\{XDG_CONFIG_DIR:-$HOME/.config\}_ 66 | 67 | v1.1 68 | ---- 69 | 70 | - added _greyscale_ option 71 | 72 | v1.0 73 | ---- 74 | 75 | - added manpage, PKGBUILD 76 | - code cleanup 77 | - awaiting feature requests 78 | 79 | 80 | Pre-Release 81 | ----------- 82 | 83 | v0.95 84 | ----- 85 | 86 | - added ability to specifiy monitor arrangement (see README) 87 | 88 | v0.9 89 | ---- 90 | 91 | - added ability to assign a wall to a monitor by number 92 | 93 | v0.8 94 | ---- 95 | 96 | - restructured code to be simpler 97 | 98 | v0.7 99 | ---- 100 | 101 | - clamped a bunch of bugs and headaches 102 | - stable, but am planning to add ability to specify monitor before moving to v1.0 103 | 104 | v0.6 105 | ---- 106 | 107 | - added image manipulation option brightness and contrast 108 | - added ability to specify bg color of blank walls 109 | 110 | v0.5 111 | ---- 112 | 113 | - added image manipulation option tint 114 | - fixed some more bugs with memory 115 | - moved `show_help()` and `show_ver()` to another file 116 | 117 | v0.4 118 | ---- 119 | 120 | - added image manipulation options flip, sharpen, blur 121 | - fixed some more bugs 122 | 123 | v0.3 124 | ---- 125 | 126 | - fixed bugs introduced by new algorithms 127 | - made program easier to refactor 128 | 129 | v0.2 130 | ---- 131 | 132 | - revamped the sizing algorithms, much faster now, cutting down SLOC 133 | - started version numbering :) 134 | 135 | v0.1 136 | ---- 137 | 138 | - Initial alpha 139 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PREFIX ?= /usr/local 2 | DESTDIR ?= 3 | MANDIR ?= ${PREFIX}/share/man/man1 4 | BINDIR ?= ${PREFIX}/bin 5 | 6 | NAME ?= setroot 7 | CC ?= gcc 8 | PKG_CONFIG ?= pkg-config 9 | OFLAG ?= 10 | CFLAGS ?= -std=c99 -Wall -g -Wextra ${OFLAG} 11 | 12 | CFLAGS+=$(shell $(PKG_CONFIG) imlib2 --cflags) 13 | LDFLAGS+=$(shell $(PKG_CONFIG) imlib2 --libs) 14 | 15 | CFLAGS+=$(shell $(PKG_CONFIG) x11 --cflags) 16 | LDFLAGS+=$(shell $(PKG_CONFIG) x11 --libs) 17 | 18 | SRC := setroot.c 19 | 20 | ifeq (${xinerama},1) 21 | DEFINES += -DHAVE_LIBXINERAMA 22 | CFLAGS+=$(shell $(PKG_CONFIG) xinerama --cflags) 23 | LDFLAGS+=$(shell $(PKG_CONFIG) xinerama --libs) 24 | endif 25 | 26 | all: 27 | ${CC} ${SRC} ${CFLAGS} ${LDFLAGS} ${DEFINES} -o ${NAME} 28 | 29 | install: ${NAME} man/${NAME}.1 30 | mkdir -p ${DESTDIR}${BINDIR} 31 | mkdir -p ${DESTDIR}${MANDIR} 32 | cp ${NAME} ${DESTDIR}${BINDIR} 33 | cp man/${NAME}.1 ${DESTDIR}${MANDIR} 34 | 35 | uninstall: 36 | rm -rf -i ${DESTDIR}${BINDIR}/${NAME} 37 | rm -rf -i ${DESTDIR}${MANDIR}/${NAME}.1 38 | 39 | clean: 40 | rm -f ${NAME} 41 | -------------------------------------------------------------------------------- /README.asciidoc: -------------------------------------------------------------------------------- 1 | NAME 2 | ---- 3 | 4 | *setroot* - sets your wallpaper. 5 | 6 | VERSION 7 | ------- 8 | 9 | `release: version 2.0 - 2016-03-13` 10 | 11 | 12 | ABOUT 13 | ----- 14 | 15 | This program was written as a way for me to learn some C, and also to serve as a 16 | personal replacement to the excellent `imlibsetroot` and `feh` programs. 17 | 18 | I liked `feh` 's syntax, but I had no use for its image viewing capabilities, so I 19 | tried out `imlibsetroot`. I encountered some segfaults/Imlib errors during 20 | usage, so I started hacking it, but ended up just writing my own program based 21 | off of it, stripped of extraneous features I saw no need for. 22 | 23 | This program in no way constitutes good code. I have absolutely no experience in 24 | formal programming or software development, I am merely a lowly math major. 25 | 26 | Please, if you have stumbled upon this repository somehow and actually use this 27 | program, feel free to critique the hell out of my code and help me improve. My 28 | ego died many ages ago in undergrad. 29 | 30 | 31 | INSTALLATION 32 | ------------ 33 | 34 | If you have `libxinerama` installed: 35 | 36 | ---- 37 | sudo make xinerama=1 38 | sudo make install (clean) 39 | ---- 40 | 41 | If you don't have `libxinerama` installed: 42 | 43 | ---- 44 | sudo make xinerama=0 45 | sudo make install (clean) 46 | ---- 47 | 48 | DEPENDENCIES 49 | ------------ 50 | 51 | `imlib2` 52 | 53 | `libxinerama` is an optional dependency (see section *INSTALLATION*). 54 | 55 | 56 | INVOCATION 57 | ---------- 58 | 59 | *setroot* [_storage flag_] [_global flag_] { [_image flags, manipulations, options_] }+ [_monitor flag_] 60 | 61 | The order of the filenames determines which monitor the wallpaper is set to. The first invoked filename is set to the first Xinerama monitor, the second to the second, and so on. 62 | 63 | If more than one image option is applied, the last one takes effect. 64 | 65 | If _n_ filenames are supplied for _k_ monitors, where _n_ > _k_, any invoked filename after the first _k_ will be ignored, unless it is passed a valid `--on` option (see section *IMAGE_FLAGS*). 66 | 67 | An illegal invocation sequence will result in setroot terminating with exit status 1. 68 | 69 | 70 | STORAGE FLAGS 71 | ------------- 72 | 73 | *--store*:: 74 | 75 | creates executable file `.setroot-restore` located in directory `${XDG_CONFIG_HOME:-$HOME/.config}/setroot` 76 | 77 | If the directory path and/or file does not exist, it will be created (see section *FILES*) 78 | 79 | *--restore*:: 80 | 81 | looks for `${XDG_CONFIG_HOME:-$HOME/.config}/setroot/.setroot-restore` and executes it in shell (restores your previously set wallpapers and options) 82 | 83 | 84 | GLOBAL FLAGS 85 | ------------ 86 | 87 | *--blank-color* _#RRGGBB_:: 88 | 89 | sets background color of blank walls, unless overriden by _--bg-color_ option 90 | 91 | 92 | IMAGE FLAGS 93 | ----------- 94 | 95 | *--span*:: 96 | 97 | have image span all screens (no cropping). 98 | 99 | If more than one image is specified, the later image will be spanned. 100 | 101 | Note that this overrides the _--on_ option. Note also that further images that are set (in the case of multiple monitors) will "cover" the spanned image. 102 | 103 | *--bg-color* _#RRGGBB_:: 104 | 105 | set empty space around image to color 106 | 107 | *--on* _n_:: 108 | 109 | assign image to be wallpaper on Xinerama monitor _n_ 110 | 111 | If not all images are passed this option, the unassigned walls will be placed on monitors by their position in the invocation sequence. Images which do have a specified assignment will then be assigned to their monitors, replacing any images which may have already been assigned. 112 | 113 | If _--on_ is supplied a screen which does not exist, no error is raised and the other walls are set as normal. This can be used with `setroot --store` to "preset" an unconnected monitor's wallpaper. 114 | 115 | If `setroot` was not compiled with Xinerama support (see section *INSTALLATION*) then `--on` is considered an invalid command and the program will terminate with exit status 1. 116 | 117 | 118 | IMAGE MANIPULATIONS 119 | ------------------- 120 | 121 | *--blur* __:: 122 | 123 | blur image 124 | 125 | *--sharpen* __:: 126 | 127 | sharpen image 128 | 129 | *--brighten* __:: 130 | 131 | modify image brightness by amount (between -1 and 1) 132 | 133 | *--contrast* __:: 134 | 135 | modify contrast of image by amount (between -100 and 100) 136 | 137 | *--flip*[_hvd_]:: 138 | 139 | flip image [_h_]orizontally, [_v_]ertically, or [_d_]iagonally 140 | 141 | *--tint* _#RRGGBB_:: 142 | 143 | tint image with color _#RRGGBB_ (also accepts valid XColor) 144 | 145 | *--greyscale*:: 146 | 147 | renders image as greyscale (uses luminosity algorithm) 148 | 149 | 150 | IMAGE OPTIONS 151 | ------------- 152 | 153 | *-c, --center*:: 154 | 155 | place unscaled image centered and cropped to screen 156 | 157 | *-t, --tiled*:: 158 | 159 | tile image on invoked screen (Xinerama aware) 160 | 161 | *-s, --stretch*:: 162 | 163 | stretch image (disregard aspect) on invoked screen 164 | 165 | *-z, --zoom*:: 166 | 167 | scale image (preserve aspect) to fit screen completely (could cut off image) 168 | 169 | *-f, --fit*:: 170 | 171 | scale image (preserve aspect) to fit screen (entire image on screen) - default 172 | 173 | *-fh, --fit-height*:: 174 | 175 | scale image (preserve aspect) until height matches invoked screen 176 | 177 | *-fw, --fit-width*:: 178 | 179 | scale image (preserve aspect) until width matches invoked screen 180 | 181 | *-gx, --gravity-x*:: 182 | 183 | set the image gravity center in the X axis at position (an integer absolute position or a float percentage) - default: 50% 184 | 185 | *-gy, --gravity-y*:: 186 | 187 | set the image gravity center in the Y axis at position (an integer absolute position or a float percentage) - default: 50% 188 | 189 | *-sc, --solid-color #RRGGBB*:: 190 | 191 | set background to solid color #RRGGBB (hex code) 192 | 193 | 194 | MONITOR FLAGS 195 | ------------- 196 | 197 | *--use-x-geometry*:: 198 | 199 | number Xinerama monitors from leftmost to rightmost 200 | 201 | *--use-y-geometry*:: 202 | 203 | number Xinerama monitors from topmost to bottommost 204 | 205 | GRAVITY 206 | ------- 207 | 208 | When the `-z` option is used, the image is zoomed in to fill the screen and 209 | cropped if neccessary. The `--gravity-x` and `--gravity-y` parameters let you 210 | choose the 'gravity center' of the image: `setroot` will try to match that 211 | center with the display center if possible. 212 | 213 | Both parameters can be given in two formats, both relative to the image 214 | dimensions: as an integer, which means an absolute coordinate; or as a decimal 215 | percentage of the total width or height. 216 | 217 | 218 | FILES 219 | ----- 220 | 221 | `setroot` creates the directory `${XDG_CONFIG_HOME:-$HOME/.config}/setroot` and places an executable file `.setroot-restore` there when `setroot --store` is invoked for the first time. 222 | 223 | `setroot --restore` executes this file to restore the most recent (valid) invocation of `setroot`. 224 | 225 | AUTHOR 226 | ------ 227 | 228 | *(C) 2014*-2016* Tim Zhou 229 | 230 | CONTRIBUTORS 231 | ------------ 232 | 233 | José Miguel Sánchez García (jmi2k) 234 | 235 | 236 | ACKNOWLEDGMENTS 237 | --------------- 238 | 239 | `set_pixmap_property()` is *(C) 1998* Michael Jennings 240 | 241 | `find_desktop()` is a modification of `get_desktop_window()` + 242 | *(C) 2004-2012* Jonathan Koren 243 | -------------------------------------------------------------------------------- /classes.h: -------------------------------------------------------------------------------- 1 | typedef enum FIT_TYPE { 2 | CENTER, 3 | TILE, 4 | STRETCH, 5 | FIT_AUTO, 6 | FIT_HEIGHT, 7 | FIT_WIDTH, 8 | ZOOM 9 | } fit_t; 10 | 11 | typedef enum FLIP_TYPE { 12 | NONE, 13 | HORIZONTAL, 14 | VERTICAL, 15 | DIAGONAL 16 | } flip_t; 17 | 18 | typedef enum GRAVITY_TYPE { 19 | PERCENTAGE, 20 | POSITION 21 | } gravity_t; 22 | 23 | struct rgb_triple { int r, g, b; }; 24 | 25 | #ifdef HAVE_LIBXINERAMA 26 | // used for quicksort 27 | struct pair { 28 | unsigned int index; 29 | int value; 30 | }; 31 | 32 | // comparison functions for pairs 33 | int 34 | ascending( const void *a, const void *b ) 35 | { 36 | return ( (*((struct pair*) a)).value - (*((struct pair*) b)).value); 37 | } 38 | 39 | int 40 | descending( const void *a, const void *b ) 41 | { 42 | return ( (*((struct pair*) b)).value - (*((struct pair*) a)).value); 43 | } 44 | #endif 45 | 46 | struct screen { 47 | struct monitor **monitors; 48 | unsigned int num_mons; 49 | unsigned int screen_width; 50 | unsigned int screen_height; 51 | }; 52 | 53 | struct monitor { 54 | unsigned int width; 55 | unsigned int height; 56 | 57 | unsigned int xpos; 58 | unsigned int ypos; 59 | 60 | struct wallpaper *wall; 61 | }; 62 | 63 | struct wallpaper { 64 | Imlib_Image image; 65 | char *image_path; 66 | 67 | unsigned int span; 68 | unsigned int monitor; 69 | 70 | unsigned int width; 71 | unsigned int height; 72 | 73 | int xpos; 74 | int ypos; 75 | 76 | gravity_t xg_type; 77 | gravity_t yg_type; 78 | 79 | float xg; 80 | float yg; 81 | 82 | struct rgb_triple *bgcol; 83 | struct rgb_triple *tint; 84 | 85 | unsigned int greyscale; 86 | unsigned int blur; 87 | unsigned int sharpen; 88 | float contrast; 89 | float brightness; 90 | 91 | fit_t option; 92 | flip_t axis; 93 | }; 94 | 95 | -------------------------------------------------------------------------------- /functions.h: -------------------------------------------------------------------------------- 1 | void set_pixmap_property( Pixmap p ); 2 | Window find_desktop( Window window ); 3 | 4 | void show_ver(); 5 | void show_help(); 6 | 7 | void store_wall( int argc, char** line ); 8 | void restore_wall(); 9 | 10 | struct wallpaper *init_wall(); 11 | struct monitor *init_monitor( unsigned int w, unsigned int h, 12 | unsigned int xp, unsigned int yp ); 13 | 14 | struct screen *init_screen( unsigned int sw, unsigned int sh ); 15 | 16 | struct rgb_triple *parse_color( const char *col ); 17 | 18 | void clean_wall( struct wallpaper *w ); 19 | void clean_monitor( struct monitor *m ); 20 | void clean_screen( struct screen *s ); 21 | 22 | #ifdef HAVE_LIBXINERAMA 23 | void sort_mons_by( struct screen *s, int sort_opt ); 24 | #endif 25 | 26 | void blank_screen( struct screen *s, const char *blank_color, Pixmap *canvas ); 27 | 28 | void center_wall( struct monitor *mon ); 29 | void stretch_wall( struct monitor *mon ); 30 | void fit_height( struct monitor *mon ); 31 | void fit_width( struct monitor *mon ); 32 | void fit_auto( struct monitor *mon ); 33 | void zoom_fill( struct monitor *mon ); 34 | void tile_wall( struct monitor *mon ); 35 | void solid_color( struct monitor *mon ); 36 | 37 | void make_greyscale( struct wallpaper *w ); 38 | void tint_image( struct wallpaper *w ); 39 | void flip_image( struct wallpaper *w ); 40 | 41 | void change_contrast( struct wallpaper * w); 42 | void change_brightness( struct wallpaper * w); 43 | 44 | void blur_wall( struct wallpaper * w); 45 | void sharpen_wall( struct wallpaper * w); 46 | 47 | void parse_opts( unsigned int argc, char **args ); 48 | 49 | Pixmap make_bg( struct screen *s ); 50 | -------------------------------------------------------------------------------- /man/setroot.1: -------------------------------------------------------------------------------- 1 | '\" t 2 | .\" Title: setroot 3 | .\" Author: [see the "AUTHOR" section] 4 | .\" Generator: DocBook XSL Stylesheets v1.78.1 5 | .\" Date: 11/13/2014 6 | .\" Manual: \ \& 7 | .\" Source: \ \& 8 | .\" Language: English 9 | .\" 10 | .TH "SETROOT" "1" "03/13/2016" "v2\&.0" "Setroot Manual" 11 | .\" ----------------------------------------------------------------- 12 | .\" * Define some portability stuff 13 | .\" ----------------------------------------------------------------- 14 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | .\" http://bugs.debian.org/507673 16 | .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html 17 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 18 | .ie \n(.g .ds Aq \(aq 19 | .el .ds Aq ' 20 | .\" ----------------------------------------------------------------- 21 | .\" * set default formatting 22 | .\" ----------------------------------------------------------------- 23 | .\" disable hyphenation 24 | .nh 25 | .\" disable justification (adjust text to left margin only) 26 | .ad l 27 | .\" ----------------------------------------------------------------- 28 | .\" * MAIN CONTENT STARTS HERE * 29 | .\" ----------------------------------------------------------------- 30 | .SH "NAME" 31 | setroot \- sets your wallpaper\&. 32 | .SH "SYNOPSIS" 33 | .sp 34 | \fBsetroot\fR [\fIstorage flag\fR] [\fIglobal flag\fR] { [\fIimage flags, manipulations, options\fR] }+ [\fImonitor flag\fR] 35 | .SH "DESCRIPTION" 36 | .sp 37 | \fBsetroot\fR is a lightweight Xinerama\-aware CLI background setter in the vein of imlibsetroot, hsetroot, and feh\&. Its only non\-obvious dependency is \fIimlib2\fR\&. 38 | .SH "INVOCATION" 39 | .sp 40 | The order of the filenames determines which monitor the wallpaper is set to\&. The first invoked filename is set to the first Xinerama monitor; the second to the second; and so on\&. 41 | .sp 42 | If more than one image option is applied, the last one takes effect\&. 43 | .sp 44 | If \fIn\fR filenames are supplied for \fIk\fR monitors, where \fIn\fR > \fIk\fR, only the first \fIk\fR filenames will be processed\&. 45 | .sp 46 | An illegal invocation sequence will result in setroot terminating with exit status \fB1\fR\&. 47 | .SH "STORAGE FLAGS" 48 | .PP 49 | \fB\-\-store\fR 50 | .RS 4 51 | creates an executable file ".setroot-restore" located in directory 52 | "${XDG_CONFIG_HOME:-$HOME/.config}/setroot/\&.setroot\-restore" 53 | .sp 54 | If the directory path and/or file does not exist, it will be created (see section \fBFILES\fR)\&. 55 | .RE 56 | .PP 57 | \fB\-\-restore\fR 58 | .RS 4 59 | looks for 60 | "${XDG_CONFIG_HOME:-$HOME/.config}/setroot/\&.setroot\-restore" 61 | and executes it in shell (restores your previously set wallpapers and options) 62 | .RE 63 | .SH "GLOBAL FLAGS" 64 | .PP 65 | \fB\-\-blank\-color\fR \fI#RRGGBB\fR 66 | .RS 4 67 | sets background color of blank walls, unless overriden by 68 | \fI\-\-bg\-color\fR 69 | option 70 | .RE 71 | .SH "IMAGE FLAGS" 72 | .PP 73 | \fB\-\-span\fR 74 | .RS 4 75 | have image span all screens (no cropping)\&. 76 | .sp 77 | If more than one image is specified, the later image will be spanned\&. 78 | .sp 79 | Note that this overrides the \fI\-\-on\fR option\&. Note also that further images that are set (in the case of multiple monitors) will "cover" the spanned image\&. 80 | .RE 81 | .PP 82 | \fB\-\-bg\-color\fR \fI#RRGGBB\fR 83 | .RS 4 84 | set empty space around image to color 85 | .RE 86 | .PP 87 | \fB\-\-on\fR \fIn\fR 88 | .RS 4 89 | assign image to be wallpaper on Xinerama monitor 90 | \fIn\fR 91 | .sp 92 | If not all images are passed this option, the unassigned walls will be placed on monitors by their position in the invocation sequence\&. 93 | .sp 94 | Images which do have a specified assignment will then be assigned to their monitors, replacing any images which may have already been assigned\&. 95 | .sp 96 | If \fI\-\-on\fR is supplied a screen which does not exist, no error is raised and the other walls are set as normal\&. This can be used with \fBsetroot --store\fR to "preset" an unconnected monitor's wallpaper\&. 97 | .sp 98 | If \fBsetroot\fR was not compiled with Xinerama support then \fB--on\fR is considered an invalid command and the program will terminate will terminate with exit status 1. 99 | .RE 100 | .SH "IMAGE MANIPULATIONS" 101 | .PP 102 | \fB\-\-blur\fR \fI\fR 103 | .RS 4 104 | blur image 105 | .RE 106 | .PP 107 | \fB\-\-sharpen\fR \fI\fR 108 | .RS 4 109 | sharpen image 110 | .RE 111 | .PP 112 | \fB\-\-brighten\fR \fI\fR 113 | .RS 4 114 | modify image brightness by amount (between \-1 and 1) 115 | .RE 116 | .PP 117 | \fB\-\-contrast\fR \fI\fR 118 | .RS 4 119 | modify contrast of image by amount (between \-100 and 100) 120 | .RE 121 | .PP 122 | \fB\-\-flip\fR[\fIhvd\fR] 123 | .RS 4 124 | flip image [\fIh\fR]orizontally, [\fIv\fR]ertically, or [\fId\fR]iagonally 125 | .RE 126 | .PP 127 | \fB\-\-tint\fR \fI#RRGGBB\fR 128 | .RS 4 129 | tint image with color \fI#RRGGBB\fR (also accepts valid XColor) 130 | .RE 131 | .PP 132 | \fB\-\-greyscale\fR 133 | .RS 4 134 | renders image as greyscale (uses luminosity algorithm) 135 | .RE 136 | .SH "IMAGE OPTIONS" 137 | .PP 138 | \fB\-c, \-\-center\fR 139 | .RS 4 140 | place unscaled image centered and cropped to screen 141 | .RE 142 | .PP 143 | \fB\-t, \-\-tiled\fR 144 | .RS 4 145 | tile image on invoked screen (Xinerama aware) 146 | .RE 147 | .PP 148 | \fB\-s, \-\-stretch\fR 149 | .RS 4 150 | stretch image (disregard aspect) on invoked screen 151 | .RE 152 | .PP 153 | \fB\-z, \-\-zoom\fR 154 | .RS 4 155 | scale image (preserve aspect) to fit screen completely (could cut off image) 156 | .RE 157 | .PP 158 | \fB\-f, \-\-fit\-auto\fR 159 | .RS 4 160 | scale image (preserve aspect) to fit screen (entire image on screen) \- default 161 | .RE 162 | .PP 163 | \fB\-fh, \-\-fit\-height\fR 164 | .RS 4 165 | scale image (preserve aspect) until height matches invoked screen 166 | .RE 167 | .PP 168 | \fB\-fw, \-\-fit\-width\fR 169 | .RS 4 170 | scale image (preserve aspect) until width matches invoked screen 171 | .RE 172 | .PP 173 | \fB\-gx, \-\-gravity\-x\fB \fI\fR 174 | .RS 4 175 | set the image gravity center in the X axis at \fIposition\fR (an integer absolute 176 | position or a float percentage) - default: 50% 177 | .RE 178 | .PP 179 | \fB\-gy, \-\-gravity\-y\fB \fI\fR 180 | .RS 4 181 | set the image gravity center in the Y axis at \fIposition\fR (an integer absolute 182 | position or a float percentage) - default: 50% 183 | .RE 184 | .PP 185 | \fB\-sc, \-\-solid\-color\fB \fI#RRGGBB\fR 186 | .RS 4 187 | set background to solid color \fI#RRGGBB\fR (hex code, also accepts valid XColor) 188 | .RE 189 | .SH "MONITOR FLAGS" 190 | .PP 191 | \fB\-\-use\-x\-geometry\fR 192 | .RS 4 193 | number Xinerama monitors from leftmost to rightmost 194 | .RE 195 | .PP 196 | \fB\-\-use\-y\-geometry\fR 197 | .RS 4 198 | number Xinerama monitors from topmost to bottommost 199 | .RE 200 | .SH "GRAVITY" 201 | .sp 202 | When the \fI\-z\fR option is used, the image is zoomed in to fill the screen 203 | and cropped if neccessary. The \fI\-\-gravity\-x\fR and \fI\-\-gravity\-y\fR 204 | parameters let you choose the 'gravity center' of the image: \fBsetroot\fR will try 205 | to match that center with the display center if possible. 206 | .sp 207 | Both parameters can be given in two formats, both relative to the image 208 | dimensions: as an integer, which means an absolute coordinate; or as a 209 | decimal percentage of the total width or height. 210 | .SH "FILES" 211 | .sp 212 | \fBsetroot\fR creates the directory "${XDG_CONFIG_HOME:-$HOME/.config}/setroot" and places an executable file \fB.setroot-restore\fR there when \fBsetroot --store\fR is invoked for the first time\&. 213 | .sp 214 | \fBsetroot --restore\fR uses this file to restore the most recent (valid) invocation of \fBsetroot\fR\&. 215 | .SH "AUTHOR" 216 | .sp 217 | \fB\(co 2016\fR Tim Zhou 218 | .SH "ACKNOWLEDGMENTS" 219 | .sp 220 | \fIset_pixmap_property()\fR is \fB\(co 1998\fR Michael Jennings 221 | .sp 222 | \fIfind_desktop()\fR is a modification of get_desktop_window() \fB\(co 2004\-2012\fR Jonathan Koren 223 | -------------------------------------------------------------------------------- /setroot.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * 3 | * Copyright (c) 2014-2016 Tim Zhou 4 | * 5 | * set_pixmap_property() is (c) 1998 Michael Jennings 6 | * 7 | * find_desktop() is a modification of: get_desktop_window() (c) 2004-2012 8 | * Jonathan Koren 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | *****************************************************************************/ 24 | 25 | #define _POSIX_C_SOURCE 200809L // for getline 26 | #define _DEFAULT_SOURCE // for realpath 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | #ifdef HAVE_LIBXINERAMA 43 | #include 44 | #endif 45 | 46 | #include 47 | 48 | #include "classes.h" 49 | #include "functions.h" 50 | #include "util.h" 51 | 52 | /* globals */ 53 | Display *XDPY; 54 | unsigned int XSCRN_NUM; 55 | Screen *XSCRN; 56 | Window ROOT_WIN; 57 | int BITDEPTH; 58 | Colormap COLORMAP; 59 | Visual *VISUAL; 60 | 61 | struct screen *SCREEN = NULL; 62 | unsigned int NUM_MONS = 0; 63 | 64 | /* runtime variables */ 65 | static char *program_name = "setroot"; 66 | static const char *BLANK_COLOR = "black"; 67 | 68 | static const int IMLIB_CACHE_SIZE = 10240*1024; // I like big walls 69 | static const int IMLIB_COLOR_USAGE = 256; 70 | static const int DITHER_SWITCH = 0; 71 | 72 | static const int SORT_BY_XINM = 0; 73 | static const int SORT_BY_XORG = 1; 74 | static const int SORT_BY_YORG = 2; 75 | 76 | /***************************************************************************** 77 | * 78 | * set_pixmap_property() is (c) 1998 Michael Jennings 79 | * 80 | * Original idea goes to Nat Friedman; his email is . This is 81 | * according to Michael Jennings, who published this program on the 82 | * Enlightenment website. See http://www.eterm.org/docs/view.php?doc=ref. 83 | * 84 | * The following function is taken from esetroot.c, which was a way for Eterm, 85 | * a part of the Enlightenment project, to implement pseudotransparency. 86 | * 87 | * I do not take credit for any of this code nor do I intend to use it in any 88 | * way for self-gain. 89 | * 90 | * For explanation, see http://www.eterm.org/docs/view.php?doc=ref and read 91 | * section titled "Transparency". 92 | * 93 | * This is used if you use a compositor that looks for _XROOTPMAP_ID. 94 | * 95 | *****************************************************************************/ 96 | 97 | void 98 | set_pixmap_property(Pixmap p) 99 | { 100 | Atom prop_root, prop_esetroot, type; 101 | int format; 102 | unsigned long length, after; 103 | unsigned char *data_root, *data_esetroot; 104 | 105 | prop_root = XInternAtom(XDPY, "_XROOTPMAP_ID", True); 106 | prop_esetroot = XInternAtom(XDPY, "ESETROOT_PMAP_ID", True); 107 | 108 | if ((prop_root != None) && (prop_esetroot != None)) { 109 | XGetWindowProperty(XDPY, ROOT_WIN, prop_root, 0L, 1L, False, 110 | AnyPropertyType, &type, &format, 111 | &length, &after, &data_root); 112 | 113 | if (type == XA_PIXMAP) { 114 | XGetWindowProperty(XDPY, ROOT_WIN, prop_esetroot, 0L, 1L, 115 | False, AnyPropertyType, &type, &format, 116 | &length, &after, &data_esetroot); 117 | 118 | if (data_root && data_esetroot) 119 | if ((type == XA_PIXMAP) && 120 | (*((Pixmap *) data_root) == *((Pixmap *) data_esetroot))) 121 | 122 | XKillClient(XDPY, *((Pixmap *) data_root)); 123 | 124 | if (data_esetroot) { free(data_esetroot); } 125 | } 126 | if (data_root) { free(data_root); } 127 | } 128 | 129 | prop_root = XInternAtom(XDPY, "_XROOTPMAP_ID", False); 130 | prop_esetroot = XInternAtom(XDPY, "ESETROOT_PMAP_ID", False); 131 | 132 | if (prop_root == None || prop_esetroot == None) 133 | die(1, "creation of pixmap property failed"); 134 | 135 | XChangeProperty(XDPY, ROOT_WIN, prop_root, XA_PIXMAP, 32, 136 | PropModeReplace, (unsigned char *) &p, 1); 137 | XChangeProperty(XDPY, ROOT_WIN, prop_esetroot, XA_PIXMAP, 32, 138 | PropModeReplace, (unsigned char *) &p, 1); 139 | 140 | XSetCloseDownMode(XDPY, RetainPermanent); 141 | XFlush(XDPY); 142 | } 143 | 144 | /***************************************************************************** 145 | * 146 | * find_desktop() is a slight modification of: get_desktop_window() 147 | * which is (c) 2004-2012 Jonathan Koren 148 | * 149 | * find_desktop() finds the window that draws the desktop and sets wallpaper. 150 | * This is mainly for those weird DEs that don't draw backgrounds 151 | * to root window. 152 | * 153 | * The original code was taken from imlibsetroot, by Jonathan Koren. 154 | * His email is . 155 | * 156 | * We call this on the root window to start, in main. 157 | * 158 | *****************************************************************************/ 159 | 160 | Window 161 | find_desktop( Window window ) 162 | { 163 | Atom prop_desktop, prop_type; 164 | 165 | Atom ret_type; 166 | int ret_format; 167 | unsigned long n_ret, ret_bytes_left; 168 | Atom *ret_props = NULL; 169 | 170 | Atom prop; 171 | 172 | int has_property = 0; 173 | int has_children = 0; 174 | unsigned int n_children = 0; 175 | 176 | Window root; 177 | Window parent; 178 | Window child; 179 | Window *children; 180 | 181 | prop_type = XInternAtom(XDPY, "_NET_WM_WINDOW_TYPE", True); 182 | prop_desktop = XInternAtom(XDPY, "_NET_WM_WINDOW_TYPE_DESKTOP", True); 183 | 184 | if (prop_type == None) { 185 | fprintf(stderr, "Could not find window with _NET_WM_WINDOW_TYPE set. " 186 | "Defaulting to root window.\n"); 187 | return None; 188 | } 189 | 190 | // check current window 191 | has_property = XGetWindowProperty(XDPY, window, prop_type, 192 | 0L, sizeof(Atom), 193 | False, 194 | XA_ATOM, 195 | &ret_type, 196 | &ret_format, 197 | &n_ret, &ret_bytes_left, 198 | (unsigned char **) &ret_props); 199 | 200 | if (has_property == Success && 201 | ret_props && n_ret > 0 && ret_type == XA_ATOM) { 202 | 203 | for (unsigned int i = 0; i < n_ret; i++) { 204 | prop = ret_props[i]; 205 | if (prop == prop_desktop) { 206 | XFree(ret_props); 207 | return window; 208 | } 209 | } XFree(ret_props); 210 | } 211 | // otherwise, recursively check children; first call XQueryTree 212 | has_children = XQueryTree(XDPY, window, 213 | &root, &parent, 214 | &children, &n_children); 215 | 216 | if (!has_children) { 217 | fprintf(stderr, "XQueryTree() failed!\n"); 218 | exit(1); 219 | } 220 | 221 | for (unsigned int i = 0; i < n_children; i++) { 222 | child = find_desktop(children[i]); 223 | if (child == None) 224 | continue; 225 | 226 | return child; 227 | } if (n_children) XFree(children); 228 | 229 | return None; 230 | } 231 | 232 | void 233 | store_call( int argc, char** args ) 234 | { 235 | /*CREATE THE DIRECTORY AND FILE*/ 236 | char *cfg_dir,*fn, *fullpath; 237 | unsigned int buflen; 238 | 239 | if (getenv("XDG_CONFIG_HOME") == NULL) { 240 | buflen = strlen(getenv("HOME")) + strlen("/.config/setroot") + 1; 241 | cfg_dir = malloc(buflen); verify(cfg_dir); 242 | snprintf(cfg_dir, buflen, "%s/%s/%s", getenv("HOME"), 243 | ".config", 244 | "setroot"); 245 | } else { 246 | buflen = strlen(getenv("XDG_CONFIG_HOME")) + strlen("/setroot") + 1; 247 | cfg_dir = malloc(buflen); verify(cfg_dir); 248 | snprintf(cfg_dir, buflen, "%s/%s", getenv("XDG_CONFIG_HOME"), 249 | "setroot"); 250 | } 251 | /*CREATE DIRECTORY*/ 252 | if (mkdir(cfg_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 253 | && errno != EEXIST) { 254 | 255 | fprintf(stderr, "Could not create directory %s.\n", cfg_dir); 256 | exit(1); 257 | } 258 | buflen += strlen(".setroot-restore") + 1; 259 | fn = malloc(buflen); verify(fn); 260 | snprintf(fn, buflen, "%s/%s", cfg_dir, ".setroot-restore"); 261 | 262 | /*WRITE TO THE FILE*/ 263 | FILE *f = fopen(fn, "w"); 264 | if (!f) { 265 | fprintf(stderr, "Could not write to file %s.\n", fn); 266 | exit(1); 267 | } 268 | 269 | fprintf(f, "setroot"); // the initial call 270 | for (int i = 2; i < argc; i++) { // jump past --store 271 | fullpath = realpath(args[i], NULL); 272 | 273 | if (fullpath == NULL) { 274 | fprintf(f, " \'%s\'", args[i]); 275 | continue; 276 | } 277 | unsigned int pathlen = strlen(fullpath); 278 | /* if does not contain a period, or it does but ends in a digit, */ 279 | /* then assume it is a flag or a flag option */ 280 | if ((strpbrk(fullpath, ".") == NULL) || isdigit(fullpath[pathlen - 1])) 281 | fprintf(f, " \'%s\'", args[i]); 282 | else 283 | fprintf(f, " \'%s\'", fullpath); 284 | free(fullpath); 285 | } fclose(f); 286 | 287 | /*GIVE FILE PROPER PERMISSIONS*/ 288 | if (chmod(fn, S_IRWXU | S_IRGRP | S_IROTH | S_IXOTH) != 0) { 289 | fprintf(stderr, "Could not make file \'%s\' executable.\n", fn); 290 | exit(1); 291 | } free(fn); free(cfg_dir); 292 | } 293 | 294 | void 295 | restore() 296 | { 297 | char *fn; 298 | unsigned int dirlen; 299 | 300 | if (getenv("XDG_CONFIG_HOME") == NULL) { 301 | dirlen = (strlen(getenv("HOME")) \ 302 | + strlen("/.config/setroot/.setroot-restore") + 1); 303 | fn = malloc(dirlen); verify(fn); 304 | snprintf(fn, dirlen, "%s/%s/%s/%s", \ 305 | getenv("HOME"), ".config", "setroot", ".setroot-restore"); 306 | } else { 307 | dirlen = (strlen(getenv("XDG_CONFIG_HOME")) \ 308 | + strlen("/setroot/.setroot-restore") + 1); 309 | fn = malloc(dirlen); verify(fn); 310 | snprintf(fn, dirlen, "%s/%s/%s", \ 311 | getenv("XDG_CONFIG_HOME"), "setroot", ".setroot-restore"); 312 | } 313 | if (system(fn) != 0) { 314 | fprintf(stderr, "Could not restore wallpaper. Check file %s.\n", fn); 315 | exit(127); 316 | } free(fn); 317 | } 318 | 319 | struct screen 320 | *init_screen( unsigned int sw, unsigned int sh ) 321 | { 322 | struct screen *s = malloc(sizeof(struct screen)); 323 | verify(s); 324 | 325 | unsigned int nm = 1; 326 | 327 | #ifdef HAVE_LIBXINERAMA 328 | XineramaScreenInfo *XSI = XineramaQueryScreens(XDPY, (int *) &nm); 329 | 330 | if (nm == 0) { 331 | fprintf(stderr, "Problem detecting Xinerama screens!" 332 | "Exiting program!\n"); 333 | exit(1); 334 | } 335 | #endif 336 | 337 | s->num_mons = nm; 338 | s->screen_width = sw; 339 | s->screen_height = sh; 340 | 341 | s->monitors = (struct monitor **) malloc(nm*sizeof(struct monitor *)); 342 | verify(s->monitors); 343 | 344 | #ifdef HAVE_LIBXINERAMA 345 | unsigned int i; 346 | struct monitor *m = NULL; 347 | 348 | for (i = 0; i < nm; i++) { 349 | m = init_monitor(XSI[i].width, 350 | XSI[i].height, 351 | XSI[i].x_org, 352 | XSI[i].y_org); 353 | 354 | (s->monitors)[i] = m; 355 | } XFree(XSI); 356 | #else 357 | (s->monitors)[0] = init_monitor(sw, sh, 0, 0); 358 | #endif 359 | XSync(XDPY, False); 360 | return s; 361 | } 362 | 363 | struct monitor 364 | *init_monitor( unsigned int w, unsigned int h, 365 | unsigned int xp, unsigned int yp ) 366 | { 367 | struct monitor *m = malloc(sizeof(struct monitor)); 368 | verify(m); 369 | 370 | m->width = w; 371 | m->height = h; 372 | 373 | m->xpos = xp; 374 | m->ypos = yp; 375 | 376 | m->wall = NULL; 377 | 378 | return m; 379 | } 380 | 381 | struct wallpaper 382 | *init_wall() 383 | { 384 | struct wallpaper *w = malloc(sizeof(struct wallpaper)); 385 | verify(w); 386 | 387 | w->height = w->width = 0; 388 | w->xpos = w->ypos = 0; // relative to monitor! 389 | w->span = w->monitor = 0; 390 | 391 | w->xg_type = PERCENTAGE; 392 | w->yg_type = PERCENTAGE; 393 | 394 | w->xg = 0.5; 395 | w->yg = 0.5; 396 | 397 | w->option = FIT_AUTO; 398 | w->axis = NONE; 399 | 400 | w->brightness = 0; 401 | w->contrast = 1.0; 402 | 403 | w->blur = w->sharpen = 0; 404 | w->brightness = 0; 405 | w->contrast = 1.0; 406 | w->greyscale = 0; 407 | 408 | w->bgcol = NULL; 409 | w->tint = NULL; 410 | w->image = NULL; 411 | 412 | return w; 413 | } 414 | 415 | void 416 | clean_screen( struct screen *s ) 417 | { 418 | unsigned int i; 419 | unsigned int nm = s->num_mons; 420 | 421 | if (s->monitors == NULL || nm == 0) return; 422 | 423 | for (i = 0; i < nm; i++) { 424 | clean_monitor((s->monitors)[i]); 425 | free((s->monitors)[i]); 426 | } free(s->monitors); 427 | 428 | s->monitors = NULL; 429 | } 430 | 431 | void 432 | clean_monitor( struct monitor *m ) 433 | { 434 | if (m->wall == NULL) return; 435 | 436 | clean_wall(m->wall); 437 | free(m->wall); 438 | m->wall = NULL; 439 | } 440 | 441 | void 442 | clean_wall( struct wallpaper *w ) 443 | { 444 | if (w->bgcol != NULL) { 445 | free(w->bgcol); 446 | w->bgcol = NULL; 447 | } 448 | if (w->tint != NULL) { 449 | free(w->tint); 450 | w->tint = NULL; 451 | } 452 | if (w->image != NULL) { 453 | imlib_context_set_image(w->image); 454 | imlib_free_image_and_decache(); 455 | w->image = NULL; 456 | } 457 | } 458 | 459 | #ifdef HAVE_LIBXINERAMA 460 | void sort_mons_by( struct screen *s, int sort_opt ) 461 | { 462 | unsigned int i; 463 | unsigned int nm = s->num_mons; 464 | 465 | struct pair values[nm]; 466 | struct monitor *new_order[nm]; 467 | 468 | if (sort_opt == SORT_BY_XORG) { 469 | for ( i = 0; i < nm; i++ ) { 470 | values[i].value = (s->monitors)[i]->xpos; 471 | values[i].index = i; 472 | } 473 | qsort(values, nm, sizeof(struct pair), ascending); 474 | } else if (sort_opt == SORT_BY_YORG) { 475 | for ( i = 0; i < nm; i++ ) { 476 | values[i].value = (s->monitors)[i]->ypos; 477 | values[i].index = i; 478 | } 479 | qsort(values, nm, sizeof(struct pair), descending); 480 | } else { 481 | for ( i = 0; i < nm; i++ ) { 482 | values[i].value = 0; 483 | values[i].index = i; 484 | } 485 | } 486 | 487 | for ( i = 0 ; i < nm ; i++ ) 488 | new_order[i] = (s->monitors)[values[i].index]; 489 | 490 | for ( i = 0 ; i < nm ; i++ ) 491 | (s->monitors)[i] = new_order[i]; 492 | } 493 | #endif 494 | 495 | struct rgb_triple *parse_color( const char *col ) 496 | { 497 | struct rgb_triple *rgb = malloc(sizeof(struct rgb_triple)); verify(rgb); 498 | 499 | if (col[0] == '#') { 500 | 501 | char *rr = malloc(3 * sizeof(char)); verify(rr); 502 | char *gg = malloc(3 * sizeof(char)); verify(gg); 503 | char *bb = malloc(3 * sizeof(char)); verify(bb); 504 | strncpy(rr, &(col[1]), 2); rr[2] = '\0'; 505 | strncpy(gg, &(col[3]), 2); gg[2] = '\0'; 506 | strncpy(bb, &(col[5]), 2); bb[2] = '\0'; 507 | rgb->r = hextoint(rr); 508 | rgb->g = hextoint(gg); 509 | rgb->b = hextoint(bb); 510 | 511 | if (!(rgb->r >= 0 && rgb->r <= 255) || 512 | !(rgb->g >= 0 && rgb->g <= 255) || 513 | !(rgb->b >= 0 && rgb->b <= 255) || 514 | strlen(col) != 7) { 515 | 516 | fprintf(stderr, 517 | "Invalid hex code %s; defaulting to #000000.\n", col); 518 | rgb->r = rgb->g = rgb->b = 0; 519 | } 520 | free(rr); free(gg); free(bb); 521 | } else { 522 | XColor c; 523 | if (XParseColor(XDPY, COLORMAP, col, &c)) { 524 | rgb->r = c.red / 257; // XParseColor returns 0 to 65535 525 | rgb->g = c.green / 257; 526 | rgb->b = c.blue / 257; 527 | } else { 528 | fprintf(stderr, "Invalid color %s; defaulting to black.\n", col); 529 | rgb->r = rgb->g = rgb->b = 0; 530 | } 531 | } 532 | return rgb; 533 | } 534 | 535 | void 536 | blank_screen( struct screen *s, const char *blank_color, Pixmap *canvas ) 537 | { 538 | struct rgb_triple *col = parse_color(blank_color); 539 | 540 | Imlib_Image bg = imlib_create_image(s->screen_width, 541 | s->screen_height); 542 | if (bg == NULL) 543 | die(1, "Failed to create image."); 544 | 545 | imlib_context_set_color(col->r, col->g, col->b, 255); 546 | imlib_context_set_drawable(*canvas); 547 | imlib_context_set_image(bg); 548 | imlib_image_fill_rectangle(0, 0, s->screen_width, s->screen_width); 549 | imlib_render_image_on_drawable(0, 0); 550 | imlib_free_image_and_decache(); 551 | free(col); 552 | } 553 | 554 | void 555 | solid_color( struct monitor *mon ) 556 | { 557 | struct wallpaper *wall = mon->wall; 558 | struct rgb_triple *col = wall->bgcol; // won't be null 559 | 560 | Imlib_Image solid_color = imlib_create_image(mon->width, mon->height); 561 | if (solid_color == NULL) 562 | die(1, "Failed to create image."); 563 | 564 | imlib_context_set_color(col->r, col->g, col->b, 255); 565 | imlib_context_set_image(solid_color); 566 | imlib_image_fill_rectangle(0, 0, mon->width, mon->height); 567 | wall->image = solid_color; 568 | } 569 | 570 | void 571 | center_wall( struct monitor *mon ) 572 | { 573 | struct wallpaper *wall = mon->wall; 574 | struct rgb_triple *col = wall->bgcol; 575 | 576 | Imlib_Image centered_image = imlib_create_image(mon->width, mon->height); 577 | imlib_context_set_image(centered_image); 578 | imlib_context_set_color(0, 0, 0, 255); 579 | 580 | if (col != NULL) 581 | imlib_context_set_color(col->r, col->g, col->b, 255); 582 | 583 | imlib_image_fill_rectangle(0, 0, mon->width, mon->height); 584 | imlib_context_set_blend(1); 585 | 586 | /* this is where we place the image in absolute coordinates */ 587 | /* this could lie outside the monitor, which is fine */ 588 | int xtl = ((int) mon->width - (int) wall->width) / 2; 589 | int ytl = ((int) mon->height - (int) wall->height) / 2; 590 | 591 | imlib_blend_image_onto_image(wall->image, 0, 592 | 0, 0, wall->width, wall->height, 593 | xtl + wall->xpos, ytl + wall->ypos, 594 | wall->width, wall->height); 595 | 596 | imlib_context_set_image(wall->image); 597 | imlib_free_image(); 598 | imlib_context_set_image(centered_image); 599 | wall->image = centered_image; 600 | imlib_context_set_blend(0); 601 | } 602 | 603 | void 604 | stretch_wall( struct monitor *mon ) 605 | { 606 | struct wallpaper *wall = mon->wall; 607 | struct rgb_triple *col = wall->bgcol; 608 | 609 | Imlib_Image stretched_image = imlib_create_image(mon->width, mon->height); 610 | imlib_context_set_image(stretched_image); 611 | imlib_context_set_color(0, 0, 0, 255); 612 | 613 | if (col != NULL) 614 | imlib_context_set_color(col->r, col->g, col->b, 255); 615 | 616 | imlib_image_fill_rectangle(0, 0, mon->width, mon->height); 617 | imlib_context_set_blend(1); 618 | 619 | imlib_blend_image_onto_image(wall->image, 0, 620 | 0, 0, wall->width, wall->height, 621 | wall->xpos, wall->ypos, 622 | mon->width, mon->height); 623 | 624 | imlib_context_set_image(wall->image); 625 | imlib_free_image_and_decache(); 626 | wall->image = stretched_image; 627 | imlib_context_set_blend(0); 628 | } 629 | 630 | void 631 | fit_height( struct monitor *mon ) 632 | { 633 | struct wallpaper *wall = mon->wall; 634 | struct rgb_triple *col = wall->bgcol; 635 | 636 | float xg = wall->xg; 637 | 638 | Imlib_Image fit_height_image = imlib_create_image(mon->width, mon->height); 639 | imlib_context_set_image(fit_height_image); 640 | imlib_context_set_color(0, 0, 0, 255); 641 | 642 | if (col != NULL) 643 | imlib_context_set_color(col->r, col->g, col->b, 255); 644 | 645 | imlib_image_fill_rectangle(0, 0, mon->width, mon->height); 646 | imlib_context_set_blend(1); 647 | 648 | float scaled_width = wall->width * mon->height * (1.0 / wall->height); 649 | 650 | if (wall->xg_type == PERCENTAGE) 651 | xg = xg * scaled_width; 652 | 653 | /* trust me, the math is good. */ 654 | float xtl = mon->width * 0.5 - xg; 655 | float max_xtl = abs(mon->width - scaled_width); 656 | 657 | if (scaled_width > mon->width) { 658 | if (xtl < -max_xtl) 659 | xtl = -max_xtl; 660 | else if (xtl > max_xtl) 661 | xtl = max_xtl; 662 | } 663 | 664 | imlib_blend_image_onto_image(wall->image, 0, 665 | 0, 0, wall->width, wall->height, 666 | xtl + wall->xpos, 0 + wall->ypos, 667 | scaled_width, mon->height); 668 | 669 | imlib_context_set_image(wall->image); 670 | imlib_free_image_and_decache(); 671 | wall->image = fit_height_image; 672 | imlib_context_set_blend(0); 673 | } 674 | 675 | void 676 | fit_width( struct monitor *mon ) 677 | { 678 | struct wallpaper *wall = mon->wall; 679 | struct rgb_triple *col = wall->bgcol; 680 | 681 | float yg = wall->yg; 682 | 683 | Imlib_Image fit_width_image = imlib_create_image(mon->width, mon->height); 684 | imlib_context_set_image(fit_width_image); 685 | imlib_context_set_color(0, 0, 0, 255); 686 | 687 | if (col != NULL) 688 | imlib_context_set_color(col->r, col->g, col->b, 255); 689 | 690 | imlib_image_fill_rectangle(0, 0, mon->width, mon->height); 691 | imlib_context_set_blend(1); 692 | 693 | float scaled_height = wall->height * mon->width * (1.0 / wall->width); 694 | 695 | if (wall->yg_type == PERCENTAGE) 696 | yg = yg * scaled_height; 697 | 698 | /* trust me, the math is good. */ 699 | float ytl = mon->height * 0.5 - yg; 700 | float max_ytl = abs(mon->height - scaled_height); 701 | 702 | if (scaled_height > mon->height) { 703 | if (ytl < -max_ytl) 704 | ytl = -max_ytl; 705 | else if (ytl > max_ytl) 706 | ytl = max_ytl; 707 | } 708 | 709 | imlib_blend_image_onto_image(wall->image, 0, 710 | 0, 0, wall->width, wall->height, 711 | 0 + wall->xpos, ytl + wall->ypos, 712 | mon->width, scaled_height); 713 | 714 | imlib_context_set_image(wall->image); 715 | imlib_free_image_and_decache(); 716 | wall->image = fit_width_image; 717 | imlib_context_set_blend(0); 718 | } 719 | 720 | void 721 | fit_auto( struct monitor *mon ) 722 | { 723 | if (mon->width >= mon->height) { // for normal monitors 724 | if ( mon->wall->width * (1.0 / mon->wall->height) 725 | >= mon->width * (1.0 / mon->height) ) 726 | fit_width(mon); 727 | else 728 | fit_height(mon); 729 | } else { // for weird ass vertical monitors 730 | if ( mon->wall->height * (1.0 / mon->wall->width) 731 | >= mon->height * (1.0 / mon->width) ) 732 | fit_height(mon); 733 | else 734 | fit_width(mon); 735 | } 736 | } 737 | 738 | void 739 | zoom_fill( struct monitor *mon ) 740 | { 741 | if (mon->width >= mon->height) { // for normal monitors 742 | if ( mon->wall->width * (1.0 / mon->wall->height) 743 | >= mon->width * (1.0 / mon->height) ) 744 | fit_height(mon); 745 | else 746 | fit_width(mon); 747 | } else { // for weird ass vertical monitors 748 | if ( mon->wall->height * (1.0 / mon->wall->width) 749 | >= mon->height * (1.0 / mon->width) ) 750 | fit_width(mon); 751 | else 752 | fit_height(mon); 753 | } 754 | } 755 | 756 | void 757 | tile( struct monitor *mon ) 758 | { 759 | struct wallpaper *wall = mon->wall; 760 | 761 | Imlib_Image tiled_image = imlib_create_image(mon->width, mon->height); 762 | imlib_context_set_image(tiled_image); 763 | imlib_context_set_blend(1); 764 | 765 | /* tile image; the excess is cut off automatically by image size */ 766 | for ( unsigned int yi = 0; yi <= mon->height; yi += (wall->height) ) 767 | for ( unsigned int xi = 0; xi <= mon->width; xi += (wall->width) ) 768 | imlib_blend_image_onto_image(wall->image, 0, 769 | 0, 0, 770 | wall->width, wall->height, 771 | xi, yi, 772 | wall->width, wall->height); 773 | 774 | imlib_context_set_image(wall->image); 775 | imlib_free_image_and_decache(); 776 | wall->image = tiled_image; 777 | imlib_context_set_blend(0); 778 | } 779 | 780 | void 781 | make_greyscale( struct wallpaper *w ) 782 | { 783 | Imlib_Color color; 784 | imlib_context_set_image(w->image); 785 | unsigned int width = imlib_image_get_width(); 786 | unsigned int height = imlib_image_get_height(); 787 | float avg = 0.0; 788 | 789 | for( unsigned int x = 0; x < width; x++) { 790 | for( unsigned int y = 0; y < height; y++) { 791 | imlib_image_query_pixel(x, y, &color); 792 | avg = 0.21 * color.red + 0.72 * color.green + 0.07 * color.blue; 793 | imlib_context_set_color(avg, avg, avg, color.alpha); 794 | imlib_image_draw_pixel(x, y, 0); 795 | } 796 | } 797 | } 798 | 799 | void 800 | tint_image( struct wallpaper *w ) 801 | { 802 | imlib_context_set_image(w->image); 803 | Imlib_Color_Modifier adjustments = imlib_create_color_modifier(); 804 | verify(adjustments); 805 | 806 | imlib_context_set_color_modifier(adjustments); 807 | 808 | DATA8 r[256], g[256], b[256], a[256]; 809 | imlib_get_color_modifier_tables (r, g, b, a); 810 | 811 | for (unsigned int i = 0; i < 256; i++) { 812 | r[i] = (DATA8) (((float) r[i] / 255.0) * (float) w->tint->r); 813 | g[i] = (DATA8) (((float) g[i] / 255.0) * (float) w->tint->g); 814 | b[i] = (DATA8) (((float) b[i] / 255.0) * (float) w->tint->b); 815 | } 816 | imlib_set_color_modifier_tables (r, g, b, a); 817 | imlib_apply_color_modifier(); 818 | imlib_free_color_modifier(); 819 | } 820 | 821 | void 822 | flip_image( struct wallpaper *w ) 823 | { 824 | imlib_context_set_image(w->image); 825 | 826 | switch (w->axis) { 827 | case HORIZONTAL: 828 | imlib_image_flip_horizontal(); 829 | break; 830 | case VERTICAL: 831 | imlib_image_flip_vertical(); 832 | break; 833 | case DIAGONAL: 834 | imlib_image_flip_diagonal(); 835 | break; 836 | default: 837 | break; 838 | } return; 839 | } 840 | 841 | void 842 | change_contrast( struct wallpaper *w ) 843 | { 844 | imlib_context_set_image(w->image); 845 | Imlib_Color_Modifier adjustments = imlib_create_color_modifier(); 846 | verify(adjustments); 847 | 848 | imlib_context_set_color_modifier(adjustments); 849 | imlib_modify_color_modifier_contrast(w->contrast); 850 | imlib_apply_color_modifier(); 851 | imlib_free_color_modifier(); 852 | } 853 | 854 | void 855 | change_brightness( struct wallpaper *w ) 856 | { 857 | imlib_context_set_image(w->image); 858 | Imlib_Color_Modifier adjustments = imlib_create_color_modifier(); 859 | verify(adjustments); 860 | 861 | imlib_context_set_color_modifier(adjustments); 862 | imlib_modify_color_modifier_contrast(w->brightness); 863 | imlib_apply_color_modifier(); 864 | imlib_free_color_modifier(); 865 | } 866 | 867 | void 868 | blur_wall( struct wallpaper *w ) 869 | { 870 | imlib_context_set_image(w->image); 871 | imlib_image_blur(w->blur); 872 | } 873 | 874 | void 875 | sharpen_wall( struct wallpaper *w ) 876 | { 877 | imlib_context_set_image(w->image); 878 | imlib_image_sharpen(w->sharpen); 879 | } 880 | 881 | void 882 | parse_opts( unsigned int argc, char **args ) 883 | { 884 | /*VARIOUS FLAGS*/ 885 | unsigned int store = 0; 886 | unsigned int span = 0; 887 | 888 | int assign_to_mon = -1; 889 | 890 | char *bg_col = NULL; 891 | char *tn_col = NULL; 892 | 893 | unsigned int blur_r = 0; 894 | unsigned int shrp_r = 0; 895 | float contrast_v = 1.0; 896 | float bright_v = 0.0; 897 | 898 | unsigned int greyscale = 0; 899 | 900 | fit_t aspect = FIT_AUTO; 901 | flip_t axis = NONE; 902 | 903 | gravity_t xg_type = PERCENTAGE; 904 | gravity_t yg_type = PERCENTAGE; 905 | 906 | float xg = 0.5; 907 | float yg = 0.5; 908 | 909 | char *image_path = NULL; 910 | 911 | /* argument counter and argument buffer */ 912 | unsigned int i; 913 | char *token; 914 | 915 | unsigned int max_mon_index = (SCREEN->num_mons) - 1; 916 | unsigned int cur_mon_index = 0; 917 | 918 | /*PARSE THE OPTIONS AND STORE IN APPROP. STRUCTS*/ 919 | for (i = 1; i < argc; i++) { 920 | 921 | token = args[i]; 922 | 923 | /*ignore geometry flags, these were already parsed in main*/ 924 | if (streq(token, "--use-x-geometry") || 925 | streq(token, "--use-y-geometry")) 926 | continue; 927 | 928 | /* if we have a flag and nothing after it */ 929 | if (argc == i + 1 && token[0] == '-') 930 | tfargs_error(token); 931 | 932 | /*STORE FLAG MUST BE FIRST*/ 933 | if (streq(token, "--store") && i == 1) { 934 | store = 1; 935 | 936 | /*GLOBAL OPTIONS*/ 937 | } else if (streq(token, "--blank-color")) { 938 | BLANK_COLOR = args[++i]; 939 | 940 | /*IMAGE FLAGS*/ 941 | } else if (streq(token, "--span")) { 942 | span = 1; 943 | } else if (streq(token, "--bg-color")) { 944 | bg_col = args[++i]; 945 | 946 | } else if (streq(token, "--on")) { 947 | #ifndef HAVE_LIBXINERAMA 948 | fprintf(stderr, "'setroot' was not compiled with Xinerama " 949 | "support. '--on' is not supported. " 950 | "Exiting with status 1.\n"); 951 | exit(1); 952 | #else 953 | assign_to_mon = parse_int(args[++i]); 954 | 955 | if (assign_to_mon < 0) { 956 | fprintf(stderr, "Monitor %d does not exist. " 957 | "Exiting with status 1.\n", 958 | assign_to_mon); 959 | exit(1); 960 | } 961 | #endif 962 | /* MANIPULATIONS */ 963 | } else if (streq(token, "--greyscale")) { 964 | greyscale = 1; 965 | 966 | } else if (streq(token, "--tint")) { 967 | tn_col = args[++i]; 968 | 969 | } else if (streq(token, "--blur")) { 970 | blur_r = parse_int(args[++i]); 971 | 972 | } else if (streq(token, "--sharpen")) { 973 | shrp_r = parse_int(args[++i]); 974 | 975 | } else if (streq(token, "--brighten")) { 976 | bright_v = parse_float(args[++i]); 977 | 978 | } else if (streq(token, "--contrast")) { 979 | contrast_v = parse_float(args[++i]); 980 | 981 | } else if (streq(token, "--fliph")) { 982 | axis = HORIZONTAL; 983 | } else if (streq(token, "--flipv")) { 984 | axis = VERTICAL; 985 | } else if (streq(token, "--flipd")) { 986 | axis = DIAGONAL; 987 | 988 | /* IMAGE OPTIONS */ 989 | } else if (streq(token, "-sc") || streq(token, "--solid-color" )) { 990 | bg_col = args[++i]; 991 | image_path = "__COLOR__"; 992 | 993 | } else if (streq(token, "-c") || streq(token, "--center")) { 994 | aspect = CENTER; 995 | } else if (streq(token, "-s") || streq(token, "--stretch")) { 996 | aspect = STRETCH; 997 | } else if (streq(token, "-fh") || streq(token, "--fit-height")) { 998 | aspect = FIT_HEIGHT; 999 | } else if (streq(token, "-fw") || streq(token, "--fit-width")) { 1000 | aspect = FIT_WIDTH; 1001 | } else if (streq(token, "-gx") || streq(token, "--gravity-x")) { 1002 | int last = strlen(args[++i]) - 1; 1003 | if (args[i][last] == '%') { 1004 | args[i][last] = '\0'; 1005 | xg_type = PERCENTAGE; 1006 | xg = (float)parse_float(args[i])/100; 1007 | } else { 1008 | xg_type = POSITION; 1009 | xg = parse_int(args[i]); 1010 | } 1011 | } else if (streq(token, "-gy") || streq(token, "--gravity-y")) { 1012 | int last = strlen(args[++i]) - 1; 1013 | if (args[i][last] == '%') { 1014 | args[i][last] = '\0'; 1015 | yg_type = PERCENTAGE; 1016 | yg = parse_float(args[i])/100; 1017 | } else { 1018 | yg_type = POSITION; 1019 | yg = (float)parse_int(args[i]); 1020 | } 1021 | } else if (streq(token, "-f") || streq(token, "--fit-auto")) { 1022 | aspect = FIT_AUTO; 1023 | } else if (streq(token, "-z") || streq(token, "--zoom")) { 1024 | aspect = ZOOM; 1025 | } else if (streq(token, "-t") || streq(token, "--tiled")) { 1026 | aspect = TILE; 1027 | 1028 | /* if all of the above fail, treat it like an image path */ 1029 | } else { 1030 | image_path = token; 1031 | } 1032 | /*assume anything that is not a flag ends one invocation sequence*/ 1033 | if (image_path == NULL) continue; 1034 | 1035 | /*if invocation blocks exceed number of monitors*/ 1036 | if (cur_mon_index > max_mon_index) { 1037 | cur_mon_index = max_mon_index; 1038 | goto RESET_FLAGS; 1039 | } 1040 | /*if no monitor is explicitly specified*/ 1041 | if (assign_to_mon == -1) 1042 | assign_to_mon = cur_mon_index; 1043 | 1044 | /*if assigning to non-existent monitor*/ 1045 | if (assign_to_mon > (int) max_mon_index) 1046 | goto RESET_FLAGS; 1047 | 1048 | cur_mon_index++; 1049 | 1050 | /* start creating the wall and assigning it to monitor */ 1051 | struct wallpaper *w = init_wall(); 1052 | 1053 | if (!streq(image_path, "__COLOR__")) { 1054 | Imlib_Image image = imlib_load_image(image_path); 1055 | imlib_context_set_image(image); 1056 | 1057 | w->image = image; 1058 | w->width = imlib_image_get_width(); 1059 | w->height = imlib_image_get_height(); 1060 | 1061 | if (image == NULL) invalid_img_error(image_path); 1062 | } 1063 | w->image_path = image_path; 1064 | w->option = aspect; 1065 | w->axis = axis; 1066 | w->span = span; 1067 | w->monitor = assign_to_mon; 1068 | w->xg_type = xg_type; 1069 | w->yg_type = yg_type; 1070 | 1071 | if (greyscale != 0) w->greyscale = greyscale; 1072 | if (blur_r != 0) w->blur = blur_r; 1073 | if (shrp_r != 0) w->sharpen = shrp_r; 1074 | 1075 | if (bright_v != 0.0) w->brightness = bright_v; 1076 | if (contrast_v != 0.0) w->contrast = contrast_v; 1077 | 1078 | if (bg_col != NULL) w->bgcol = parse_color(bg_col); 1079 | if (tn_col != NULL) w->tint = parse_color(tn_col); 1080 | 1081 | if (xg != 0.5) w->xg = xg; 1082 | if (yg != 0.5) w->yg = yg; 1083 | 1084 | /*if for some reason a wall was already assigned to*/ 1085 | /*designated monitor, clean it*/ 1086 | if ((SCREEN->monitors)[w->monitor]->wall != NULL) { 1087 | int taken_index = w->monitor; 1088 | 1089 | clean_wall((SCREEN->monitors)[taken_index]->wall); 1090 | free((SCREEN->monitors)[taken_index]->wall); 1091 | (SCREEN->monitors)[taken_index]->wall = NULL; 1092 | 1093 | } (SCREEN->monitors)[w->monitor]->wall = w; 1094 | 1095 | 1096 | RESET_FLAGS: 1097 | span = greyscale = blur_r = shrp_r = 0; 1098 | contrast_v = (bright_v = 0.0) + 1.0; 1099 | axis = NONE; 1100 | aspect = FIT_AUTO; 1101 | tn_col = bg_col = NULL; 1102 | image_path = NULL; 1103 | assign_to_mon = -1; 1104 | xg_type = PERCENTAGE; 1105 | yg_type = PERCENTAGE; 1106 | xg = 0.5; 1107 | yg = 0.5; 1108 | 1109 | } // end for loop 1110 | if (store) store_call(argc, args); 1111 | } 1112 | 1113 | Pixmap 1114 | make_bg( struct screen *s ) 1115 | { 1116 | imlib_context_set_display(XDPY); 1117 | imlib_context_set_visual(VISUAL); 1118 | imlib_context_set_colormap(COLORMAP); 1119 | 1120 | imlib_set_cache_size(IMLIB_CACHE_SIZE); 1121 | imlib_set_color_usage(IMLIB_COLOR_USAGE); 1122 | imlib_context_set_dither(DITHER_SWITCH); 1123 | 1124 | Pixmap canvas = XCreatePixmap(XDPY, 1125 | ROOT_WIN, 1126 | s->screen_width, 1127 | s->screen_height, 1128 | BITDEPTH); 1129 | 1130 | imlib_context_set_drawable(canvas); 1131 | blank_screen(s, BLANK_COLOR, &canvas); 1132 | 1133 | unsigned int i; 1134 | unsigned int nm = s->num_mons; 1135 | 1136 | for (i = 0; i < nm; i++) { 1137 | struct monitor *cur_mon = (s->monitors)[i]; 1138 | struct wallpaper *w = cur_mon->wall; 1139 | 1140 | if (w == NULL) continue; 1141 | 1142 | if (streq(w->image_path, "__COLOR__")) { 1143 | solid_color(cur_mon); 1144 | } else { 1145 | /* ADJUSTMENTS TO IMAGE */ 1146 | if (w->axis == DIAGONAL) { 1147 | int temp = w->height; 1148 | w->height = w->width; 1149 | w->width = temp; 1150 | } flip_image(w); 1151 | 1152 | if (w->greyscale == 1) make_greyscale(w); 1153 | if (w->brightness != 0.0) change_brightness(w); 1154 | if (w->contrast != 1.0) change_contrast(w); 1155 | if (w->tint != NULL) tint_image(w); 1156 | 1157 | /*if span, set dimensions of monitor to be screen*/ 1158 | if (w->span != 0) { 1159 | cur_mon->width = s->screen_width; 1160 | cur_mon->height = s->screen_height; 1161 | cur_mon->xpos = 0; 1162 | cur_mon->ypos = 0; 1163 | } 1164 | switch (w->option) { 1165 | case CENTER: 1166 | center_wall(cur_mon); 1167 | break; 1168 | case STRETCH: 1169 | stretch_wall(cur_mon); 1170 | break; 1171 | case FIT_HEIGHT: 1172 | fit_height(cur_mon); 1173 | break; 1174 | case FIT_WIDTH: 1175 | fit_width(cur_mon); 1176 | break; 1177 | case FIT_AUTO: 1178 | fit_auto(cur_mon); 1179 | break; 1180 | case ZOOM: 1181 | zoom_fill(cur_mon); 1182 | break; 1183 | case TILE: 1184 | tile(cur_mon); 1185 | break; 1186 | default: 1187 | break; 1188 | } 1189 | /*post process transformed image*/ 1190 | if (w->blur != 0) blur_wall(w); 1191 | if (w->sharpen != 0) sharpen_wall(w); 1192 | } 1193 | /*set context and render image to drawable*/ 1194 | imlib_context_set_image(w->image); 1195 | imlib_render_image_on_drawable(cur_mon->xpos + w->xpos, 1196 | cur_mon->ypos + w->ypos); 1197 | imlib_free_image_and_decache(); 1198 | w->image = NULL; 1199 | } 1200 | imlib_flush_loaders(); 1201 | return canvas; 1202 | } 1203 | 1204 | int main(int argc, char** args) 1205 | { 1206 | XDPY = XOpenDisplay(NULL); 1207 | if (!XDPY) { 1208 | fprintf(stderr, "%s: unable to open display '%s'\n", 1209 | program_name, XDisplayName(NULL)); 1210 | exit(1); 1211 | } 1212 | if (argc < 2) { 1213 | printf("No options were provided. Call \'man setroot\' for help.\n"); 1214 | exit(1); 1215 | } 1216 | 1217 | XSCRN_NUM = DefaultScreen(XDPY); 1218 | XSCRN = ScreenOfDisplay(XDPY, XSCRN_NUM); 1219 | ROOT_WIN = RootWindow(XDPY, XSCRN_NUM); 1220 | COLORMAP = DefaultColormap(XDPY, XSCRN_NUM); 1221 | VISUAL = DefaultVisual(XDPY, XSCRN_NUM); 1222 | BITDEPTH = DefaultDepth(XDPY, XSCRN_NUM); 1223 | SCREEN = init_screen(XSCRN->width, XSCRN->height); 1224 | 1225 | #ifdef HAVE_LIBXINERAMA 1226 | if (streq(args[argc - 1], "--use-x-geometry")) 1227 | sort_mons_by(SCREEN, SORT_BY_XORG); 1228 | else if (streq(args[argc - 1], "--use-y-geometry")) 1229 | sort_mons_by(SCREEN, SORT_BY_YORG); 1230 | else 1231 | sort_mons_by(SCREEN, SORT_BY_XINM); 1232 | #endif 1233 | 1234 | if (argc > 1 && streq(args[1], "--restore")) { 1235 | restore(); 1236 | goto CLEANUP; 1237 | } Window desktop_window = None; 1238 | 1239 | parse_opts(argc, args); 1240 | Pixmap bg = make_bg(SCREEN); 1241 | 1242 | if (bg != None) { 1243 | set_pixmap_property(bg); 1244 | XSetWindowBackgroundPixmap(XDPY, ROOT_WIN, bg); 1245 | 1246 | desktop_window = find_desktop(ROOT_WIN); 1247 | 1248 | if (desktop_window != None) { 1249 | XSetWindowBackgroundPixmap(XDPY, desktop_window, bg); 1250 | XClearWindow(XDPY, desktop_window); 1251 | } 1252 | } 1253 | CLEANUP: 1254 | 1255 | clean_screen(SCREEN); free(SCREEN); 1256 | 1257 | XClearWindow(XDPY, ROOT_WIN); 1258 | XFlush(XDPY); 1259 | XCloseDisplay(XDPY); 1260 | 1261 | return EXIT_SUCCESS; 1262 | } 1263 | -------------------------------------------------------------------------------- /util.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MEMORY_ERROR "Not enough memory for allocation." 5 | 6 | #define hextoint(hh) (int) strtol(hh, NULL, 16) 7 | #define streq(str, test) !strcmp(str, test) 8 | 9 | void 10 | die( unsigned int error_code, char* error_msg ) 11 | { 12 | fprintf(stderr, "Error in %s at line %d: %s\n", __FILE__, __LINE__, error_msg ); 13 | exit(error_code); 14 | } 15 | 16 | void 17 | verify( void *ptr ) 18 | { 19 | if (ptr == NULL) { die( 1, MEMORY_ERROR ); } 20 | } 21 | 22 | void 23 | tfargs_error( const char* flag ) 24 | { 25 | fprintf(stderr, "Not enough arguments provided to '%s'. " 26 | "Call 'man setroot' to see proper invocation sequence.\n", 27 | flag); 28 | exit(1); 29 | } 30 | 31 | void 32 | invalid_img_error( const char* path ) 33 | { 34 | fprintf(stderr, "Could not load image '%s'. " 35 | "Exiting with status 1.\n", 36 | path); 37 | exit(1); 38 | } 39 | 40 | int 41 | parse_int( const char* intstring ) 42 | { 43 | char **invalid_digits = malloc(sizeof(char*)); 44 | verify(invalid_digits); 45 | 46 | long int val = strtol(intstring, invalid_digits, 10); 47 | 48 | /* if we don't get an integer */ 49 | if ((*invalid_digits)[0] != '\0') { 50 | fprintf(stderr, "'%s' is not a valid integer. " 51 | "Exiting with status 1.\n", 52 | intstring); 53 | exit(1); 54 | } 55 | if (invalid_digits != NULL) { 56 | free(invalid_digits); 57 | invalid_digits = NULL; 58 | } 59 | return (int) val; 60 | } 61 | 62 | float 63 | parse_float( const char* floatstring ) 64 | { 65 | char **invalid_digits = malloc(sizeof(char*)); 66 | verify(invalid_digits); 67 | 68 | long int val = strtof(floatstring, invalid_digits); 69 | 70 | /* if we don't get a float*/ 71 | if ((*invalid_digits)[0] != '\0') { 72 | fprintf(stderr, "'%s' is not a valid float. " 73 | "Exiting with status 1.\n", 74 | floatstring); 75 | exit(1); 76 | } 77 | if (invalid_digits != NULL) { 78 | free(invalid_digits); 79 | invalid_digits = NULL; 80 | } 81 | return (float) val; 82 | } 83 | --------------------------------------------------------------------------------