├── .github └── workflows │ └── main.yml ├── .gitignore ├── LICENCE.txt ├── README.md ├── com.github.santileortiz.iconoscope.yml ├── common.h ├── data ├── 32 │ └── iconoscope.svg ├── 48 │ └── iconoscope.svg ├── 64 │ └── iconoscope.svg ├── 128 │ └── iconoscope.svg ├── appdata.xml ├── base_icon.svg ├── iconoscope.desktop ├── screenshot.png └── screenshot1.png ├── debian ├── changelog ├── compat ├── control ├── copyright ├── rules └── source │ └── format ├── fk_list_box.c ├── fk_paned.c ├── gtk_utils.c ├── icon_view.c ├── icon_view.h ├── iconoscope.c ├── mkpy ├── pymk.py └── utility.py ├── pymk.py ├── slo_timers.h └── timing_stats.txt /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | flatpak: 7 | runs-on: ubuntu-latest 8 | 9 | container: 10 | image: ghcr.io/elementary/flatpak-platform/runtime:6 11 | options: --privileged 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@v3 17 | with: 18 | bundle: MyApp.flatpak 19 | manifest-path: com.github.santileortiz.iconoscope.yml 20 | 21 | run-tests: true 22 | 23 | repository-name: appcenter 24 | repository-url: https://flatpak.elementary.io/repo.flatpakrepo 25 | cache-key: "flatpak-builder-${{ github.sha }}" 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | perf.data* 3 | bin 4 | gmon.out 5 | tags 6 | *__pycache__* 7 | *.pyc 8 | mkpy/cache 9 | 10 | debian/.debhelper 11 | debian/files 12 | debian/com.github.santileortiz.iconoscope* 13 | 14 | .flatpak-builder/ 15 | flatpak-build/ 16 | -------------------------------------------------------------------------------- /LICENCE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Iconoscope 2 | ========== 3 | 4 | Explore the icon database in your system. 5 | 6 | ![screenshot](data/screenshot.png) 7 | 8 | Easily visualize icons to find inconsistencies, or check the look of icons in 9 | different themes. Some useful features include: 10 | 11 | * Display icon information according to Freedesktop's 12 | [Icon Theme Specification][1] (size, scale, context, etc.). 13 | * Display icon file information (location, file size, image size, extension). 14 | * Compare the same icon across different installed themes. 15 | * Search all available icons by name. 16 | * Real time monitoring of an icon develompment folder (useful to catch 17 | inconcistencies at development time). 18 | 19 | [1]: https://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html 20 | 21 | Compilation 22 | ----------- 23 | 24 | Dependencies: 25 | * `gtk+-3.0` 26 | 27 | In elementaryOS/Ubuntu install them with: 28 | 29 | sudo apt-get install libgtk-3-dev 30 | 31 | Build with: 32 | 33 | ./pymk iconoscope 34 | -------------------------------------------------------------------------------- /com.github.santileortiz.iconoscope.yml: -------------------------------------------------------------------------------- 1 | app-id: com.github.santileortiz.iconoscope 2 | runtime: io.elementary.Platform 3 | runtime-version: '6' 4 | sdk: io.elementary.Sdk 5 | command: com.github.santileortiz.iconoscope 6 | 7 | finish-args: 8 | - '--share=ipc' 9 | - '--socket=fallback-x11' 10 | - '--socket=wayland' 11 | 12 | modules: 13 | - name: iconoscope 14 | buildsystem: simple 15 | build-commands: 16 | - ./pymk.py iconoscope --mode release 17 | - ./pymk.py install --destdir $FLATPAK_DEST/ 18 | sources: 19 | - type: dir 20 | path: . 21 | -------------------------------------------------------------------------------- /data/32/iconoscope.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | 55 | 58 | 59 | 61 | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | 125 | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 153 | 156 | 160 | 164 | 168 | 172 | 173 | 176 | 180 | 184 | 185 | 196 | 206 | 216 | 226 | 236 | 237 | 239 | 240 | 242 | image/svg+xml 243 | 245 | 246 | 247 | 248 | 249 | 254 | 260 | 267 | 273 | 279 | 287 | 295 | 301 | 307 | 313 | 318 | 323 | 329 | 334 | 340 | 347 | 353 | 359 | 365 | 368 | 373 | 379 | 384 | 389 | 394 | 395 | END 406 | 412 | 418 | 424 | 430 | 436 | 442 | 448 | 453 | 460 | 467 | 474 | 481 | 488 | 495 | 502 | 509 | 516 | 523 | 530 | 536 | 542 | 548 | 554 | 562 | 568 | 573 | 581 | 589 | 596 | 604 | 611 | 612 | 613 | -------------------------------------------------------------------------------- /data/48/iconoscope.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | 55 | 58 | 59 | 61 | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 89 | 92 | 96 | 100 | 104 | 108 | 109 | 112 | 116 | 120 | 124 | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | 160 | 164 | 168 | 172 | 173 | 176 | 180 | 184 | 188 | 192 | 196 | 200 | 201 | 204 | 208 | 212 | 216 | 217 | 220 | 224 | 228 | 232 | 236 | 237 | 240 | 244 | 248 | 249 | 252 | 256 | 260 | 264 | 268 | 269 | 272 | 276 | 280 | 281 | 292 | 302 | 312 | 322 | 333 | 343 | 353 | 363 | 374 | 375 | 377 | 378 | 380 | image/svg+xml 381 | 383 | 384 | 385 | 386 | 387 | 392 | 395 | 403 | 411 | 417 | 418 | 424 | 431 | 437 | 443 | 449 | 457 | 465 | 470 | 476 | 482 | 488 | 494 | 500 | 506 | 512 | 517 | 522 | 527 | 532 | 539 | 544 | 549 | 554 | 561 | 567 | 573 | 578 | 584 | 587 | 592 | 598 | 603 | 608 | 613 | 614 | END 625 | 630 | 636 | 642 | 648 | 654 | 660 | 666 | 672 | 677 | 682 | 685 | 692 | 699 | 706 | 713 | 720 | 727 | 733 | 739 | 745 | 751 | 757 | 763 | 769 | 775 | 782 | 789 | 796 | 803 | 810 | 817 | 824 | 831 | 838 | 839 | 840 | 841 | -------------------------------------------------------------------------------- /data/appdata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.github.santileortiz.iconoscope 5 | CC0 6 | GPL-3.0+ 7 | Iconoscope 8 | Explore the icon database in your system. 9 | 10 |

11 | Easily visualize icons to find inconsistencies, or check the look of icons in different themes. Some useful features include: 12 |

13 | 14 |
    15 |
  • Display icon information according to Freedesktop's Icon Theme Specification (size, scale, context, etc.).
  • 16 |
  • Display icon file information (location, file size, image size, etc.).
  • 17 |
  • Compare the same icon across different installed themes.
  • 18 |
  • Search all available icons by name.
  • 19 |
  • Real time monitoring of an icon develompment folder (useful to catch inconcistencies while designing icons).
  • 20 |
21 |
22 | 23 | 24 | 25 | 26 |

Initial submission for elementary OS 6

27 |
    28 |
  • Flatpak packaging.
  • 29 |
30 |
31 |
32 | 33 | 34 | 35 |

AppCenter updates were stuck at v0.1.4. Sorry about that!.

36 |
    37 |
  • 4 releases worth of features and improvements.
  • 38 |
39 |
40 |
41 | 42 | 43 | 44 |

Packaging fixes

45 |
    46 |
  • Update travis.
  • 47 |
  • Small bugfixes on the folder theme.
  • 48 |
49 |
50 |
51 | 52 | 53 | 54 |

New features for designers:

55 |
    56 |
  • Monitor icon development directories. Icon size will be guessed based on the name of the subdirectory it's in.
  • 57 |
  • Easily move icons into another application by using drag and drop. Useful when creating mockups.
  • 58 |
59 |
60 |
61 | 62 | 63 | 64 |

Easier navigation across themes and icons

65 |
    66 |
  • New "All" theme that includes all icons in the system.
  • 67 |
  • Easy comparison of the same icon across different themes.
  • 68 |
  • Allow to change the background color.
  • 69 |
  • Mark the selected icon.
  • 70 |
  • Improved reliability and performance.
  • 71 |
  • Convert text to path in Iconoscope's icon.
  • 72 |
73 |
74 |
75 | 76 | 77 | 78 |

Improved UI and make app ready for Juno

79 |
    80 |
  • Update code for Juno.
  • 81 |
  • Display information from the icon theme database (and make it selectable).
  • 82 |
  • Support for icons available in multiple scales.
  • 83 |
  • Show symbolic icons.
  • 84 |
85 |
86 |
87 | 88 | 89 | 90 |

Fix some requirements for AppCenter

91 |
    92 |
  • Use RDNN naming for icons
  • 93 |
  • Add changelog to appdata.xml
  • 94 |
95 |
96 |
97 |
98 | 99 | 100 | com.github.santileortiz.iconoscope 101 | 102 | 103 | 104 | 105 | https://raw.githubusercontent.com/santileortiz/Iconoscope/master/data/screenshot.png 106 | 107 | 108 | https://raw.githubusercontent.com/santileortiz/Iconoscope/master/data/screenshot1.png 109 | 110 | 111 | 112 | Santiago León O. 113 | 114 | https://github.com/santileortiz/Iconoscope 115 | https://github.com/santileortiz/Iconoscope/issues 116 | 117 | 118 | #ffed6b 119 | #692b00 120 | 10 121 | pk_live_m1a0iCIlIYlM4MvC5WO0C8Ef 122 | 123 | 124 | 125 | none 126 | none 127 | none 128 | none 129 | none 130 | none 131 | none 132 | none 133 | none 134 | none 135 | none 136 | none 137 | none 138 | none 139 | none 140 | none 141 | none 142 | none 143 | none 144 | none 145 | none 146 | none 147 | none 148 | none 149 | none 150 | none 151 | none 152 | 153 |
154 | -------------------------------------------------------------------------------- /data/iconoscope.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Iconoscope 3 | Comment=View installed icons and their properties 4 | Exec=com.github.santileortiz.iconoscope 5 | Icon=com.github.santileortiz.iconoscope 6 | Keywords=icons;themes; 7 | Terminal=false 8 | Type=Application 9 | Categories=Graphics;Utility; 10 | -------------------------------------------------------------------------------- /data/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/santileortiz/Iconoscope/e4dade83d21670039e8d49255f9875c1de2d67d3/data/screenshot.png -------------------------------------------------------------------------------- /data/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/santileortiz/Iconoscope/e4dade83d21670039e8d49255f9875c1de2d67d3/data/screenshot1.png -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | com.github.santileortiz.iconoscope (0.1) precise; urgency=low 2 | 3 | * Initial Release. 4 | 5 | -- Santiago León O. Wed, 14 Mar 2018 15:16:00 -0500 6 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: com.github.santileortiz.iconoscope 2 | Section: x11 3 | Priority: extra 4 | Maintainer: Santiago León O. 5 | Build-Depends: debhelper (>= 9), 6 | libc6-dev (>= 2.17), 7 | python3 (>=3.6), 8 | libgtk-3-dev 9 | Standards-Version: 3.9.7 10 | 11 | Package: com.github.santileortiz.iconoscope 12 | Architecture: any 13 | Depends: ${misc:Depends}, ${shlibs:Depends} 14 | Description: Icon viewer 15 | View icons installed in your system and their properties. 16 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://dep.debian.net/deps/dep5 2 | Upstream-Name: Iconoscope 3 | Source: https://github.com/santileortiz/Iconoscope 4 | 5 | Files: * 6 | Copyright: 2018 Santiago León O. 7 | License: GPL-3.0+ 8 | 9 | License: GPL-3.0+ 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 package 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 | On Debian systems, the complete text of the GNU General 24 | Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". 25 | 26 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | PACKAGENAME := $(shell awk 'NR==1{print $$1}' debian/changelog) 4 | 5 | %: 6 | dh $@ 7 | 8 | override_dh_auto_clean: 9 | rm -f bin/* 10 | dh_clean 11 | 12 | override_dh_auto_build: 13 | ./pymk.py iconoscope --mode release 14 | 15 | override_dh_auto_install: 16 | ./pymk.py install --destdir ${CURDIR}/debian/${PACKAGENAME}/usr/ 17 | 18 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) 2 | -------------------------------------------------------------------------------- /fk_list_box.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Santiago León O. 3 | */ 4 | 5 | // GtkListBox gets very slow as the number of row increases. Creation of the 6 | // widget, the call to gtk_widget_show(), and then gtk_widget_destroy() are the 7 | // slowest parts. For a widget of ~7000 rows it took more than 2 seconds to 8 | // create it and show it. Destruction took 1 second. 9 | // 10 | // This is a much faster implementation of this widget based on GtkDrawingArea. 11 | // It takes ~330us to create the same ~7000 row list. Render takes about 25ms, 12 | // and destruction about 20us. More than 6000 times faster than GtkListBox!. 13 | // 14 | // Memory wise, it allocates 24 bytes per row, that's ~160KB for the ~7000 row 15 | // widget. 16 | // 17 | // This doesn't duplicate any data from outside. Instead, each row stores a 18 | // pointer to data owned by the caller. We don't allocate/free this data 19 | // anywhere. 20 | // 21 | // TODO: 22 | // - Render time can be improved a lot by prerendering the list and just 23 | // blitting it when fk_list_box_draw_text_data is called. Then rendering the 24 | // selected row on top. @fast_render 25 | // 26 | // - Define an API to let the user render rows with data different than text. 27 | // Right now if it's required, the user can create a new render function 28 | // based on fk_list_box_draw_text_data() but this may get a bit complex if 29 | // @fast_render is implemented. 30 | // 31 | // - Don't hardcode styling, get it from the active CSS stylesheet. 32 | // 33 | // - Add example code to show how the API works. 34 | // 35 | // - Add test code that compares this to GtkListBox so it's easy to check when 36 | // it's better to use fk_list_box_t. 37 | 38 | // If the following is defined fk_list_box_destroy() is called automatically when 39 | // the widget gets destroyed. 40 | #define FK_LIST_BOX_DESTROY_WITH_WIDGET 41 | 42 | struct fk_list_box_t; 43 | 44 | #define FK_LIST_BOX_ROW_SELECTED_CB(name) void name(struct fk_list_box_t *fk_list_box, int idx) 45 | typedef FK_LIST_BOX_ROW_SELECTED_CB(fk_list_box_row_selected_cb_t); 46 | 47 | struct fk_list_box_row_t { 48 | bool hidden; 49 | void *data; 50 | }; 51 | 52 | struct fk_list_box_t { 53 | mem_pool_t pool; 54 | int num_rows; 55 | struct fk_list_box_row_t *rows; 56 | int num_visible_rows; 57 | struct fk_list_box_row_t **visible_rows; 58 | 59 | int selected_row_idx; 60 | struct fk_list_box_row_t *selected_row; 61 | double row_height; 62 | 63 | GtkWidget *widget; 64 | 65 | fk_list_box_row_selected_cb_t *row_selected_cb; 66 | 67 | // Number of rows that have been created 68 | int row_cnt; 69 | }; 70 | 71 | gboolean fk_list_box_draw_text_data (GtkWidget *widget, cairo_t *cr, gpointer data) 72 | { 73 | double margin_h = 6; 74 | double margin_v = 3; 75 | dvec4 text_color = RGB_255(66,66,66); 76 | dvec4 active_color = RGB_255(62,161,239); 77 | dvec4 active_text_color = RGB_255(255,255,255); 78 | dvec4 unfocused_color = RGB_255(204,204,204); 79 | dvec4 unfocused_text_color = RGB_255(51,51,51); 80 | 81 | struct fk_list_box_t *fk_list_box = (struct fk_list_box_t *)data; 82 | cairo_set_source_rgb (cr, 1, 1, 1); 83 | cairo_paint (cr); 84 | 85 | if (fk_list_box->num_visible_rows == 0) { 86 | // TODO: Show a "list empty" message 87 | return TRUE; 88 | } 89 | 90 | cairo_set_source_rgb (cr, ARGS_RGB(text_color)); 91 | 92 | cairo_select_font_face (cr, "Open Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); 93 | cairo_set_font_size (cr, 12); 94 | 95 | cairo_font_extents_t font_extents; 96 | cairo_font_extents (cr, &font_extents); 97 | 98 | double width = 0; 99 | double y = font_extents.ascent + margin_v; 100 | int i; 101 | for (i=0; inum_visible_rows; i++) { 102 | cairo_move_to (cr, margin_h, y); 103 | cairo_show_text (cr, fk_list_box->visible_rows[i]->data); 104 | 105 | cairo_text_extents_t extents; 106 | cairo_text_extents (cr, fk_list_box->visible_rows[i]->data, &extents); 107 | width = MAX(width, extents.width + 2*margin_h); 108 | y += font_extents.ascent + font_extents.descent + 2*margin_v; 109 | } 110 | y -= font_extents.ascent + margin_v; 111 | 112 | fk_list_box->row_height = font_extents.ascent + font_extents.descent + 2*margin_v; 113 | 114 | gtk_widget_set_size_request (widget, width, y); 115 | 116 | if (!fk_list_box->selected_row->hidden) { 117 | assert (fk_list_box->selected_row_idx != -1); 118 | 119 | gboolean has_focus = gtk_widget_has_focus (widget); 120 | dvec4 selected_bg = has_focus ? active_color : unfocused_color; 121 | dvec4 selected_color = has_focus ? active_text_color : unfocused_text_color; 122 | 123 | // The rectangle for the selected row must go all the way across the 124 | // widget, INFINITY would be good width but Cairo doesn't draw this, so 125 | // we just use a very big number. 126 | double infinity_width = 1000000; 127 | cairo_rectangle (cr, 128 | 0, fk_list_box->selected_row_idx*fk_list_box->row_height, 129 | infinity_width, fk_list_box->row_height); 130 | cairo_set_source_rgb (cr, ARGS_RGB(selected_bg)); 131 | cairo_fill (cr); 132 | 133 | cairo_move_to (cr, margin_h, 134 | fk_list_box->selected_row_idx*fk_list_box->row_height + 135 | font_extents.ascent + margin_v); 136 | cairo_set_source_rgb (cr, ARGS_RGB(selected_color)); 137 | cairo_show_text (cr, fk_list_box->visible_rows[fk_list_box->selected_row_idx]->data); 138 | } 139 | 140 | return TRUE; 141 | } 142 | 143 | void fk_list_box_rows_start (struct fk_list_box_t *fk_list_box, int num_rows) 144 | { 145 | fk_list_box->row_cnt = 0; 146 | fk_list_box->num_rows = num_rows; 147 | fk_list_box->num_visible_rows = num_rows; 148 | fk_list_box->rows = 149 | mem_pool_push_size (&fk_list_box->pool, 150 | fk_list_box->num_rows*sizeof(struct fk_list_box_row_t)); 151 | fk_list_box->visible_rows = 152 | mem_pool_push_size (&fk_list_box->pool, 153 | fk_list_box->num_rows*sizeof(struct fk_list_box_row_t*)); 154 | fk_list_box->selected_row_idx = 0; 155 | fk_list_box->selected_row = &fk_list_box->rows[0]; 156 | } 157 | 158 | struct fk_list_box_row_t* fk_list_box_row_new (struct fk_list_box_t *fk_list_box) 159 | { 160 | struct fk_list_box_row_t *new_row = NULL; 161 | if (fk_list_box->row_cnt < fk_list_box->num_rows) { 162 | new_row = &fk_list_box->rows[fk_list_box->row_cnt]; 163 | *new_row = ZERO_INIT (struct fk_list_box_row_t); 164 | fk_list_box->visible_rows[fk_list_box->row_cnt] = new_row; 165 | fk_list_box->row_cnt++; 166 | 167 | } else { 168 | printf ("fk_list_box_row_new(): Tried to allocate more rows than expected.\n"); 169 | } 170 | 171 | return new_row; 172 | } 173 | 174 | void fk_list_box_refresh_hidden (struct fk_list_box_t *fk_list_box) 175 | { 176 | int visible_cnt = 0; 177 | for (int i=0; inum_rows; i++) { 178 | if (!fk_list_box->rows[i].hidden) { 179 | fk_list_box->visible_rows[visible_cnt] = &fk_list_box->rows[i]; 180 | visible_cnt++; 181 | } 182 | } 183 | fk_list_box->num_visible_rows = visible_cnt; 184 | 185 | if (!fk_list_box->selected_row->hidden && 186 | fk_list_box->selected_row != fk_list_box->visible_rows[fk_list_box->selected_row_idx]) { 187 | // The selected row is visible and its index changed, compute the new one. 188 | // TODO: We can speed this up with binary search of pointers, as rows 189 | // have increasing addresses because they are in an array. Note that 190 | // this may break stuff if the user decides so sort rows by using the 191 | // visible_rows array. @performance 192 | for (int i=0; inum_visible_rows; i++) { 193 | if (fk_list_box->visible_rows[i] == fk_list_box->selected_row) { 194 | fk_list_box->selected_row_idx = i; 195 | break; 196 | } 197 | } 198 | } 199 | 200 | gtk_widget_queue_draw (fk_list_box->widget); 201 | } 202 | 203 | // This is used when the caller doesn't want the callbak to be called or a 204 | // redraw to be queried. Use fk_list_box_change_selected() if you do. 205 | // NOTE: idx is the index of the selected row in the visible_rows array. 206 | void fk_list_box_set_selected (struct fk_list_box_t *fk_list_box, int idx) 207 | { 208 | assert (idx >= 0 && idx < fk_list_box->num_visible_rows); 209 | 210 | fk_list_box->selected_row_idx = idx; 211 | fk_list_box->selected_row = fk_list_box->visible_rows[idx]; 212 | 213 | GtkWidget *parent = gtk_widget_get_parent (fk_list_box->widget); 214 | if (parent && GTK_IS_SCROLLABLE (parent)) { 215 | GtkAdjustment *adjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (parent)); 216 | 217 | double y = fk_list_box->selected_row_idx*fk_list_box->row_height; 218 | gtk_adjustment_clamp_page (adjustment, y, y + fk_list_box->row_height); 219 | } 220 | } 221 | 222 | // NOTE: idx is the index of the selected row in the visible_rows array. 223 | void fk_list_box_change_selected (struct fk_list_box_t *fk_list_box, int idx) 224 | { 225 | assert (idx >= 0 && idx < fk_list_box->num_visible_rows); 226 | 227 | fk_list_box_set_selected (fk_list_box, idx); 228 | fk_list_box->row_selected_cb (fk_list_box, fk_list_box->selected_row_idx); 229 | gtk_widget_queue_draw (fk_list_box->widget); 230 | } 231 | 232 | gboolean fk_list_box_button_release (GtkWidget *widget, GdkEvent *event, gpointer data) 233 | { 234 | GdkEventButton *e = (GdkEventButton*)event; 235 | struct fk_list_box_t *fk_list_box = (struct fk_list_box_t *)data; 236 | int idx = (int) (e->y/fk_list_box->row_height); 237 | gtk_widget_grab_focus (widget); 238 | 239 | if (idx < fk_list_box->num_visible_rows) { 240 | fk_list_box_change_selected (fk_list_box, idx); 241 | } 242 | return TRUE; 243 | } 244 | 245 | gboolean fk_list_box_key_press (GtkWidget *widget, GdkEventKey *e, gpointer data) 246 | { 247 | struct fk_list_box_t *fk_list_box = (struct fk_list_box_t *)data; 248 | int idx = -1; 249 | if (e->keyval == GDK_KEY_Up || e->keyval == GDK_KEY_KP_Up) { 250 | idx = MAX(0, fk_list_box->selected_row_idx-1); 251 | 252 | } else if (e->keyval == GDK_KEY_Down || e->keyval == GDK_KEY_KP_Down) { 253 | idx = MIN(fk_list_box->num_visible_rows-1, fk_list_box->selected_row_idx+1); 254 | } 255 | 256 | if (idx != -1) { 257 | fk_list_box_change_selected (fk_list_box, idx); 258 | return TRUE; 259 | } else { 260 | return FALSE; 261 | } 262 | } 263 | 264 | gboolean fk_list_box_unfocus (GtkWidget *widget, GdkEvent *event, gpointer data) 265 | { 266 | gtk_widget_queue_draw (widget); 267 | return TRUE; 268 | } 269 | 270 | void fk_list_box_destroy (struct fk_list_box_t *fk_list_box); 271 | void fk_list_box_destroy_cb (GtkWidget *object, gpointer data) 272 | { 273 | struct fk_list_box_t *fk_list_box = (struct fk_list_box_t *)data; 274 | fk_list_box_destroy (fk_list_box); 275 | } 276 | 277 | // NOTE: The caller should allocate a fk_list_box_t structure, and this function 278 | // will initialize it. If the caller is thinking about reusing this structure 279 | // better not to do that, use fk_list_box_new() and then the caller is only 280 | // responsible for a pointer, memory will be freed when fk_list_box_destroy() is 281 | // called (maybe called automatically when the GtkWidget is destroyed if the 282 | // macro FK_LIST_BOX_DESTROY_WITH_WIDGET was defined). 283 | GtkWidget* fk_list_box_init (struct fk_list_box_t *fk_list_box, 284 | fk_list_box_row_selected_cb_t *row_selected_cb) 285 | { 286 | *fk_list_box = ZERO_INIT (struct fk_list_box_t); 287 | fk_list_box->widget = gtk_drawing_area_new (); 288 | gtk_widget_set_vexpand (fk_list_box->widget, TRUE); 289 | gtk_widget_set_hexpand (fk_list_box->widget, TRUE); 290 | 291 | fk_list_box->row_selected_cb = row_selected_cb; 292 | 293 | // For some reason just adding GDK_BUTTON_RELEASE_MASK does not work... 294 | // GDK_BUTTON_PRESS_MASK is required too. 295 | gtk_widget_add_events (fk_list_box->widget, 296 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | 297 | GDK_KEY_PRESS_MASK | 298 | GDK_FOCUS_CHANGE_MASK ); 299 | 300 | g_signal_connect (G_OBJECT (fk_list_box->widget), 301 | "draw", 302 | G_CALLBACK (fk_list_box_draw_text_data), 303 | fk_list_box); 304 | 305 | g_signal_connect (G_OBJECT (fk_list_box->widget), 306 | "button-release-event", 307 | G_CALLBACK (fk_list_box_button_release), 308 | fk_list_box); 309 | 310 | g_signal_connect (G_OBJECT (fk_list_box->widget), 311 | "key-press-event", 312 | G_CALLBACK (fk_list_box_key_press), 313 | fk_list_box); 314 | 315 | gtk_widget_set_can_focus (fk_list_box->widget, TRUE); 316 | g_signal_connect (G_OBJECT (fk_list_box->widget), 317 | "focus-out-event", 318 | G_CALLBACK (fk_list_box_unfocus), 319 | fk_list_box); 320 | 321 | #ifdef FK_LIST_BOX_DESTROY_WITH_WIDGET 322 | g_signal_connect (G_OBJECT (fk_list_box->widget), 323 | "destroy", 324 | G_CALLBACK (fk_list_box_destroy_cb), 325 | fk_list_box); 326 | #endif 327 | 328 | return fk_list_box->widget; 329 | } 330 | 331 | // Create a fk_list_box_t with a different ownership pattern. Here the created 332 | // fk_list_box_t owns the memory of the fk_list_box_t structure. This is done by 333 | // bootstrapping it from its own pool. 334 | GtkWidget* fk_list_box_new (struct fk_list_box_t **fk_list_box, 335 | fk_list_box_row_selected_cb_t *row_selected_cb) 336 | { 337 | assert (fk_list_box != NULL && "You should get a pointer here so you can add rows"); 338 | 339 | mem_pool_t bootstrap = ZERO_INIT (mem_pool_t); 340 | struct fk_list_box_t *new_fk_list_box = 341 | mem_pool_push_size (&bootstrap, sizeof (struct fk_list_box_t)); 342 | new_fk_list_box->pool = bootstrap; 343 | *fk_list_box = new_fk_list_box; 344 | 345 | return fk_list_box_init (new_fk_list_box, row_selected_cb); 346 | } 347 | 348 | void fk_list_box_destroy (struct fk_list_box_t *fk_list_box) 349 | { 350 | mem_pool_destroy (&fk_list_box->pool); 351 | } 352 | -------------------------------------------------------------------------------- /fk_paned.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Santiago León O. 3 | */ 4 | 5 | // The implementation of GtkPaned is so broken that faking it by using a GtkGrid 6 | // works better. This still lacks the resizability which is why I use 7 | // fix_gtk_paned_new(), but at this point I think it will be much simpler to 8 | // just make my own implementation of a Paned container than try to make 9 | // GtkPaned work. Some of the issues found are: 10 | // 11 | // - There is no way to position the separator based on a percentage. Trying 12 | // to implement this required a lot of code, and even then, it didn't work. 13 | // 14 | // - Trying to set the position as pixels works, except when doing it from 15 | // inside the handler for size-allocate. Which is what made the 16 | // implementation of a percentage positioning not work. 17 | // 18 | // - Thin separators (1px) are broken. See the comment above in 19 | // fix_gtk_paned_new(). 20 | // 21 | // - Even after solving the bug and writing to the mailing list about it, I 22 | // got no response (it was a single line change). Which makes me think no 23 | // one really wants to touch that code. And with good reason, it's very 24 | // weird and has strange corner cases (why is there a position-set property 25 | // to activate/deactivate the position property?). 26 | // 27 | // - Even when working around the bugs, 1px separators are still useless. 28 | // The hitbox is 1px wide which makes them extremely annoying. 29 | // 30 | // - Sometimes (who knows why) the first child is not drawn, but it is 31 | // allocated. 32 | // 33 | // - Reproducing these bugs on simpler test cases is hard, because they depend 34 | // on the order in which size allocations happen. 35 | // 36 | // I'm very tired of this. This is the only way I found to create something that 37 | // looks like a static paned container, that actually shows both widgets at 38 | // startup, and where I can control the position to be tight around one of the 39 | // children. 40 | GtkWidget *fk_paned (GtkOrientation orientation, GtkWidget *child1, GtkWidget *child2) 41 | { 42 | GtkWidget *new_paned = gtk_grid_new (); 43 | GtkOrientation sep_or = orientation == GTK_ORIENTATION_VERTICAL? 44 | GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL; 45 | GtkWidget *sep = gtk_separator_new (sep_or); 46 | if (orientation == GTK_ORIENTATION_VERTICAL) { 47 | gtk_grid_attach (GTK_GRID(new_paned), child1, 0, 0, 1, 1); 48 | gtk_grid_attach (GTK_GRID(new_paned), sep, 0, 1, 1, 1); 49 | gtk_grid_attach (GTK_GRID(new_paned), child2, 0, 2, 1, 1); 50 | } else { 51 | gtk_grid_attach (GTK_GRID(new_paned), child1, 0, 0, 1, 1); 52 | gtk_grid_attach (GTK_GRID(new_paned), sep, 1, 0, 1, 1); 53 | gtk_grid_attach (GTK_GRID(new_paned), child2, 2, 0, 1, 1); 54 | } 55 | return new_paned; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /gtk_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Santiago León O. 3 | */ 4 | 5 | #define RGBA DVEC4 6 | #define RGB(r,g,b) DVEC4(r,g,b,1) 7 | #define ARGS_RGBA(c) (c).r, (c).g, (c).b, (c).a 8 | #define ARGS_RGB(c) (c.r), (c).g, (c).b 9 | #define RGBA_255(r,g,b,a) DVEC4(((double)(r))/255, \ 10 | ((double)(g))/255, \ 11 | ((double)(b))/255, \ 12 | ((double)(a))/255) 13 | #define RGB_255(r,g,b) RGBA_255(r,g,b,255) 14 | #define RGB_HEX(hex) DVEC4(((double)(((hex)&0xFF0000) >> 16))/255, \ 15 | ((double)(((hex)&0x00FF00) >> 8))/255, \ 16 | ((double)((hex)&0x0000FF))/255, 1) 17 | 18 | #define GDK_RGBA(r,g,b,a) ((GdkRGBA){.red=r, .green=g, .blue=b, .alpha=a}) 19 | #define GDK_RGBA_FROM_RGBA(rgba) ((GdkRGBA){.red=rgba.r, .green=rgba.g, .blue=rgba.b, .alpha=rgba.a}) 20 | 21 | void add_css_class (GtkWidget *widget, char *class) 22 | { 23 | GtkStyleContext *ctx = gtk_widget_get_style_context (widget); 24 | gtk_style_context_add_class (ctx, class); 25 | } 26 | 27 | void remove_css_class (GtkWidget *widget, char *class) 28 | { 29 | GtkStyleContext *ctx = gtk_widget_get_style_context (widget); 30 | gtk_style_context_remove_class (ctx, class); 31 | } 32 | 33 | GtkCssProvider* add_global_css (gchar *css_data) 34 | { 35 | GdkScreen *screen = gdk_screen_get_default (); 36 | GtkCssProvider *css_provider = gtk_css_provider_new (); 37 | gtk_css_provider_load_from_data (css_provider, css_data, -1, NULL); 38 | gtk_style_context_add_provider_for_screen (screen, 39 | GTK_STYLE_PROVIDER(css_provider), 40 | GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); 41 | return css_provider; 42 | } 43 | 44 | // NOTE: I tried to dynamiccally change CSS styles in a GtkBox, and had a hard 45 | // time. I added a custom CSS node named box with add_custom_css(), then I added 46 | // a new CSS node named .my_class to the same widget. I thought adding/removing 47 | // the class to the widget would switch styles but it didn't work, even when 48 | // specifying priorities both the box node and the .my_class node conflicted 49 | // with each other. I decided to only add custom CSS once to a widget, keep a 50 | // reference to the GtkCssProvider and then use replace_custom_css(). I wish it 51 | // wasn't so cumbersome. 52 | GtkCssProvider* add_custom_css (GtkWidget *widget, gchar *css_data) 53 | { 54 | GtkStyleContext *style_context = gtk_widget_get_style_context (widget); 55 | GtkCssProvider *css_provider = gtk_css_provider_new (); 56 | gtk_css_provider_load_from_data (css_provider, css_data, -1, NULL); 57 | gtk_style_context_add_provider (style_context, 58 | GTK_STYLE_PROVIDER(css_provider), 59 | GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); 60 | return css_provider; 61 | } 62 | 63 | GtkCssProvider* replace_custom_css (GtkWidget *widget, GtkCssProvider *custom_css, gchar *css_data) 64 | { 65 | GtkStyleContext *style_context = gtk_widget_get_style_context (widget); 66 | gtk_style_context_remove_provider (style_context, GTK_STYLE_PROVIDER(custom_css)); 67 | 68 | return add_custom_css (widget, css_data); 69 | } 70 | 71 | int gtk_radio_button_get_idx (GtkRadioButton *button) 72 | { 73 | GSList *group = gtk_radio_button_get_group (GTK_RADIO_BUTTON(button)); 74 | // Items are added at the beginning of the group, so the index is reversed 75 | // from the order in which they were added. 76 | return g_slist_length (group) - g_slist_index (group, button); 77 | } 78 | 79 | // Widget Wrapping Idiom 80 | // --------------------- 81 | // 82 | // Gtk uses reference counting of its objects. As a convenience for C 83 | // programming they have a feature called "floating references", this feature 84 | // makes most objects be created with a floating reference, instead of a normal 85 | // one. Then the object that will take ownership of it, calls 86 | // g_object_ref_sink() and becomes the owner of this floating reference making 87 | // it a normal one. This allows C code to not call g_object_unref() on the newly 88 | // created object and not leak a reference (and thus, not leak memory). 89 | // 90 | // The problem is this only work for objects that inherit from the 91 | // GInitialyUnowned class. In all the Gtk class hierarchy ~150 classes inherit 92 | // from GInitiallyUnowned and ~100 don't, which makes floating references the 93 | // common case. What I normally do is assume things use floating references, and 94 | // never call g_object_ref_sink() under the assumption that the function I'm 95 | // passing the object to will sink it. 96 | // 97 | // Doing this for GtkWidgets is very useful to implement changes in the UI 98 | // without creating a tangle of signals. What I do is completely replace widgets 99 | // that need to be updated, instead of trying to update the state of objects to 100 | // reflect changes. I keep weak references (C pointers, not even Gtk weak 101 | // references) to widgets that may need to be replaced, then I remove the widget 102 | // from it's container and replace it by a new one. Here not taking references 103 | // to any widget becomes useful as removing the widget form it's parent will 104 | // have the effect of destroying all the children objects (as long as Gtk 105 | // internally isn't leaking memory). 106 | // 107 | // The only issue I've found is that containers like GtkPaned or GtkGrid use 108 | // special _add methods with different declaration than gtk_container_add(). 109 | // It's very common to move widgets accross different kinds of containers, which 110 | // adds the burden of having to kneo where in the code we assumed something was 111 | // stored in a GtkGrid or a GtkPaned etc. What I do to alieviate this pain is 112 | // wrap widgets that will be replaced into a GtkBox with wrap_gtk_widget() and 113 | // then use replace_wrapped_widget() to replace it. 114 | // 115 | // Doing this ties the lifespan of an GInitiallyUnowned object to the lifespan 116 | // of the parent. Sometimes this is not desired, in those cases we must call 117 | // g_object_ref_sink() (NOT g_object_ref(), because as far as I understand it 118 | // will set refcount to 2 and never free them). Fortunatelly cases where this is 119 | // required will print lots of Critical warnings or crash the application so 120 | // they are easy to detect and fix, a memory leak is harder to detect/fix. 121 | // 122 | // NOTE: The approach of storing a pointer to the parent widget not only doubles 123 | // the number of pointers that need to be stored for a replacable widget, but 124 | // also doesn't work because we can't know the true parent of a widget. For 125 | // instance, GtkScrolledWindow wraps its child in a GtkViewPort. 126 | // 127 | // TODO: I need a way to detect when I'm using objects that don't inherit from 128 | // GInitiallyUnowned and be sure we are not leaking references. Also make sure 129 | // g_object_ref_sink() is used instead of g_object_ref(). 130 | GtkWidget* wrap_gtk_widget (GtkWidget *widget) 131 | { 132 | GtkWidget *wrapper = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); 133 | gtk_container_add (GTK_CONTAINER(wrapper), widget); 134 | return wrapper; 135 | } 136 | 137 | void replace_wrapped_widget (GtkWidget **original, GtkWidget *new_widget) 138 | { 139 | GtkWidget *parent = gtk_widget_get_parent (*original); 140 | gtk_container_remove (GTK_CONTAINER(parent), *original); 141 | 142 | *original = new_widget; 143 | gtk_container_add (GTK_CONTAINER(parent), new_widget); 144 | 145 | gtk_widget_show_all (new_widget); 146 | } 147 | 148 | // An issue with the wrapped widget idiom is that if a widget triggers a replace 149 | // of one of its ancestors, then we are effectiveley destroying ourselves from 150 | // the signal handler. I've found cases where Gtk does not like that and shows 151 | // lots of critical errors. I think these errors happen because the signal where 152 | // we triggered the destruction of the ancestor is not the only one being 153 | // handled, then after destruction, other handlers try to trigger inside the 154 | // widget that does not exist anymore. 155 | // 156 | // I don't know if this is a Gtk bug, or we are not supposed to trigger the 157 | // destruction of an object from the signal handler of a signal of the object 158 | // that will be destroyed. The case I found not to work was a GtkCombobox 159 | // destroying itself from the "changed" signal. A button destroying itself from 160 | // the "clicked" signal worked fine though. 161 | // 162 | // In any case, if this happens, the function replace_wrapped_widget_deferred() 163 | // splits widget replacement so that widget destruction is triggered, and then 164 | // in the handler for the destroy signal, we actually replace the widget. Not 165 | // nice, but seems to solve the issue. 166 | gboolean idle_widget_destroy (gpointer user_data) 167 | { 168 | gtk_widget_destroy ((GtkWidget *) user_data); 169 | return FALSE; 170 | } 171 | 172 | void replace_wrapped_widget_deferred_cb (GtkWidget *object, gpointer user_data) 173 | { 174 | // We do this here so we never add the old and new widgets to the wrapper 175 | // and end up increasing the allocation size and glitching/ 176 | gtk_widget_show_all ((GtkWidget *) user_data); 177 | } 178 | 179 | void replace_wrapped_widget_deferred (GtkWidget **original, GtkWidget *new_widget) 180 | { 181 | GtkWidget *parent = gtk_widget_get_parent (*original); 182 | gtk_container_add (GTK_CONTAINER(parent), new_widget); 183 | 184 | g_signal_connect (G_OBJECT(*original), "destroy", G_CALLBACK (replace_wrapped_widget_deferred_cb), new_widget); 185 | g_idle_add (idle_widget_destroy, *original); 186 | *original = new_widget; 187 | } 188 | 189 | // Convenience wrapper for setting properties in objects when they don't have 190 | // setters. 191 | void g_object_set_property_bool (GObject *object, const char *property_name, gboolean value) 192 | { 193 | GValue val = G_VALUE_INIT; 194 | g_value_init (&val, G_TYPE_BOOLEAN); 195 | g_value_set_boolean (&val, value); 196 | g_object_set_property (object, property_name, &val); 197 | } 198 | 199 | // FIXME: The following CSS is used to work around 2 issues with GtkPaned. One 200 | // is a failed assert which is a bug in GTK (see 201 | // https://github.com/elementary/stylesheet/issues/328). The other one is the 202 | // vanishing of the separator, which seems to be related to elementary OS using 203 | // a negative margin in the separator. 204 | GtkWidget *fix_gtk_paned_new (GtkOrientation orientation) 205 | { 206 | GtkWidget *res = gtk_paned_new (orientation); 207 | add_custom_css (res, "paned > separator {" 208 | " margin-right: 0;" 209 | " min-width: 2px;" 210 | " min-height: 2px;" 211 | "}"); 212 | return res; 213 | } 214 | 215 | // This is the only way I found to disable horizontal scrolling in a scrolled 216 | // window. I think calling gtk_adjustment_set_upper() 'should' work, but it 217 | // doesn't. 218 | void _gtk_scrolled_window_disable_hscroll_cb (GtkAdjustment *adjustment, gpointer user_data) 219 | { 220 | if (gtk_adjustment_get_value (adjustment) != 0) { 221 | gtk_adjustment_set_value (adjustment, 0); 222 | } 223 | } 224 | 225 | void gtk_scrolled_window_disable_hscroll (GtkScrolledWindow *scrolled_window) 226 | { 227 | gtk_scrolled_window_set_policy (scrolled_window, GTK_POLICY_EXTERNAL, GTK_POLICY_AUTOMATIC); 228 | GtkAdjustment *hadj = gtk_scrolled_window_get_hadjustment (scrolled_window); 229 | #if 1 230 | g_signal_connect (G_OBJECT(hadj), 231 | "value-changed", 232 | G_CALLBACK (_gtk_scrolled_window_disable_hscroll_cb), 233 | NULL); 234 | #else 235 | // FIXME: Why U not work!? 236 | gtk_adjustment_set_upper (hadj, 0); 237 | #endif 238 | } 239 | 240 | GtkWidget *labeled_combobox_new (char *label, GtkWidget **combobox) 241 | { 242 | assert (combobox != NULL && "You really need the combobox to fill it."); 243 | 244 | GtkWidget *label_widget = gtk_label_new (label); 245 | add_css_class (label_widget, "h4"); 246 | gtk_widget_set_margin_start (label_widget, 6); 247 | 248 | GtkWidget *combobox_widget = gtk_combo_box_text_new (); 249 | gtk_widget_set_margin_top (combobox_widget, 6); 250 | gtk_widget_set_margin_bottom (combobox_widget, 6); 251 | gtk_widget_set_margin_start (combobox_widget, 12); 252 | gtk_widget_set_margin_end (combobox_widget, 6); 253 | 254 | GtkWidget *container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); 255 | gtk_container_add (GTK_CONTAINER(container), label_widget); 256 | gtk_container_add (GTK_CONTAINER(container), combobox_widget); 257 | 258 | *combobox = combobox_widget; 259 | return container; 260 | } 261 | 262 | void combo_box_text_append_text_with_id (GtkComboBoxText *combobox, const gchar *text) 263 | { 264 | gtk_combo_box_text_append (combobox, text, text); 265 | } 266 | 267 | -------------------------------------------------------------------------------- /icon_view.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Santiago León O. 3 | */ 4 | 5 | #define UNSELECTED_ICON_BOX_STYLE \ 6 | "box {" \ 7 | " padding: 6px;" \ 8 | " border-radius: 3px;" \ 9 | " border: 1px solid rgba(0,0,0,0);" \ 10 | "}" 11 | 12 | #define SELECTED_ICON_BOX_STYLE \ 13 | "box {" \ 14 | " padding: 6px;" \ 15 | " border-radius: 3px;" \ 16 | " border: 1px solid #777;" \ 17 | "}" 18 | 19 | GtkWidget *spaced_grid_new (int spacing) 20 | { 21 | GtkWidget *new_grid = gtk_grid_new (); 22 | gtk_widget_set_margin_start (GTK_WIDGET(new_grid), spacing); 23 | gtk_widget_set_margin_end (GTK_WIDGET(new_grid), spacing); 24 | gtk_widget_set_margin_top (GTK_WIDGET(new_grid), spacing); 25 | gtk_widget_set_margin_bottom (GTK_WIDGET(new_grid), spacing); 26 | gtk_grid_set_row_spacing (GTK_GRID(new_grid), spacing); 27 | gtk_grid_set_column_spacing (GTK_GRID(new_grid), spacing); 28 | return new_grid; 29 | } 30 | 31 | void data_dpy_append (GtkWidget *data, char *title, char *value, int id) 32 | { 33 | GtkWidget *title_label = gtk_label_new (title); 34 | gtk_widget_set_halign (title_label, GTK_ALIGN_END); 35 | add_css_class (title_label, "h4"); 36 | 37 | GtkWidget *value_label = gtk_label_new (value); 38 | gtk_label_set_ellipsize (GTK_LABEL(value_label), PANGO_ELLIPSIZE_END); 39 | gtk_widget_set_halign (value_label, GTK_ALIGN_START); 40 | gtk_label_set_selectable (GTK_LABEL(value_label), TRUE); 41 | add_css_class (value_label, "h5"); 42 | 43 | gtk_grid_attach (GTK_GRID(data), title_label, 0, id, 1, 1); 44 | gtk_grid_attach (GTK_GRID(data), value_label, 1, id, 1, 1); 45 | } 46 | 47 | static inline 48 | char* str_or_dash (char *str) 49 | { 50 | if (str == NULL || *str == '\0') { 51 | static char *str = "-"; 52 | return str; 53 | } else { 54 | return str; 55 | } 56 | } 57 | 58 | // NOTE: requires #include 59 | void bytes_to_human_readable (off_t size, char *buff, size_t buff_len) 60 | { 61 | assert (buff_len > 9); 62 | 63 | int i = 0; 64 | float hr = size; 65 | while (hr > 1024) { 66 | i++; 67 | hr /= 1024; 68 | } 69 | 70 | char *unit = "?"; 71 | if (i == 0) { 72 | unit = "B"; 73 | } else if (i == 1) { 74 | unit = "K"; 75 | } else if (i == 2) { 76 | unit = "M"; 77 | } else if (i == 3) { 78 | unit = "G"; 79 | } else if (i == 4) { 80 | unit = "T"; 81 | } else if (i == 5) { 82 | unit = "P"; 83 | } else if (i == 6) { 84 | unit = "E"; 85 | } else if (i == 7) { 86 | unit = "Z"; 87 | } else if (i == 8) { 88 | unit = "Y"; 89 | } 90 | 91 | struct lconv *locale = localeconv(); 92 | int int_part = (int)hr; 93 | int dec_part = (int)((hr - int_part)*10); 94 | if (dec_part != 0) { 95 | snprintf (buff, buff_len, "%d%s%d %s", int_part, locale->decimal_point, dec_part, unit); 96 | } else { 97 | snprintf (buff, buff_len, "%d %s", int_part, unit); 98 | } 99 | } 100 | 101 | GtkWidget* image_data_dpy_new (struct icon_image_t *img) 102 | { 103 | GtkWidget *data = gtk_grid_new (); 104 | gtk_grid_set_column_spacing (GTK_GRID(data), 12); 105 | 106 | struct icon_image_t l_img = ZERO_INIT(struct icon_image_t); 107 | if (img == NULL) { 108 | img = &l_img; 109 | } 110 | 111 | int i = 0; 112 | char *str; 113 | char buff[10]; 114 | 115 | data_dpy_append (data, "Theme Path:", str_or_dash(img->theme_dir), i++); 116 | data_dpy_append (data, "File Path:", str_or_dash(img->path), i++); 117 | 118 | snprintf (buff, ARRAY_SIZE(buff), "%d x %d", img->width, img->height); 119 | str = img->width < 1 || img->height < 1 ? "-" : buff; 120 | data_dpy_append (data, "Image Size:", str, i++); 121 | 122 | bytes_to_human_readable (img->file_size, buff, ARRAY_SIZE(buff)); 123 | data_dpy_append (data, "File Size:", buff, i++); 124 | 125 | snprintf (buff, ARRAY_SIZE(buff), "%d", img->size); 126 | str = img->size < 1 ? "-" : buff; 127 | data_dpy_append (data, "Size:", str, i++); 128 | 129 | data_dpy_append (data, "Context:", str_or_dash(img->context), i++); 130 | data_dpy_append (data, "Type:", str_or_dash(img->type), i++); 131 | 132 | snprintf (buff, ARRAY_SIZE(buff), "%d - %d", img->min_size, img->max_size); 133 | str = img->min_size < 1 || img->max_size < 1 ? "-" : buff; 134 | data_dpy_append (data, "Size Range:", str, i++); 135 | return data; 136 | } 137 | 138 | void set_icon_box_border (struct icon_image_t *img) 139 | { 140 | img->custom_css = replace_custom_css (img->box, img->custom_css, SELECTED_ICON_BOX_STYLE); 141 | } 142 | 143 | void unset_icon_box_border (struct icon_image_t *img) 144 | { 145 | img->custom_css = replace_custom_css (img->box, img->custom_css, UNSELECTED_ICON_BOX_STYLE); 146 | } 147 | 148 | gboolean on_image_clicked (GtkWidget *widget, GdkEvent *event, gpointer user_data) 149 | { 150 | struct icon_image_t *img = (struct icon_image_t *)user_data; 151 | if (img->view->selected_img != img) { 152 | GtkWidget *image_data_dpy = image_data_dpy_new (img); 153 | g_assert (img->view->image_data_dpy != NULL); 154 | 155 | unset_icon_box_border (img->view->selected_img); 156 | 157 | img->view->selected_img = img; 158 | set_icon_box_border (img); 159 | 160 | // Replace image_data_dpy widget 161 | GtkWidget *parent = gtk_widget_get_parent (img->view->image_data_dpy); 162 | gtk_container_remove (GTK_CONTAINER(parent), img->view->image_data_dpy); 163 | gtk_container_add (GTK_CONTAINER(parent), image_data_dpy); 164 | img->view->image_data_dpy = image_data_dpy; 165 | gtk_widget_show_all (image_data_dpy); 166 | } 167 | 168 | // NOTE: We allways let the event go through so we have drag and drop even 169 | // if the image wasn't selected. 170 | return FALSE; 171 | } 172 | 173 | char* new_bgcolor_style_str (mem_pool_t *pool, char *node_name, dvec4 color) 174 | { 175 | char *str = 176 | pprintf (pool, 177 | "%s {" 178 | " background-color: rgba(%d,%d,%d,%d);" 179 | "}", 180 | node_name, 181 | (int)(color.r*255), (int)(color.g*255), (int)(color.b*255), (int)(color.a*255)); 182 | return str; 183 | } 184 | 185 | void icon_view_update_bg_color (struct icon_view_t *icon_view, dvec4 color) 186 | { 187 | mem_pool_t pool = {0}; 188 | char *style = new_bgcolor_style_str (&pool, "scrolledwindow", color); 189 | icon_view->scrolled_window_custom_css = 190 | replace_custom_css (icon_view->scrolled_window, icon_view->scrolled_window_custom_css, 191 | style); 192 | mem_pool_destroy (&pool); 193 | } 194 | 195 | void on_color_button_clicked (GtkColorButton *button, gpointer user_data) 196 | { 197 | struct icon_view_t *icon_view = (struct icon_view_t*)user_data; 198 | GdkRGBA gdk_color; 199 | gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(button), &gdk_color); 200 | dvec4 color = RGBA(gdk_color.red, gdk_color.green, gdk_color.blue, gdk_color.alpha); 201 | icon_view_update_bg_color (icon_view, color); 202 | app.bg_color = color; 203 | } 204 | 205 | void on_drag_data_get (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *data, 206 | guint info, guint time, gpointer user_data) 207 | { 208 | struct icon_image_t *img = (struct icon_image_t *)user_data; 209 | string_t uri = str_new ("file://"); 210 | str_cat_c (&uri, img->full_path); 211 | 212 | char *uris[] = {str_data(&uri), NULL}; 213 | gtk_selection_data_set_uris (data, uris); 214 | 215 | str_free (&uri); 216 | } 217 | 218 | GtkWidget* icon_view_create_icon_dpy (struct icon_view_t *icon_view, int scale) 219 | { 220 | // NOTE: At least one package (aptdaemon-data) provides animated icons in a 221 | // single file by appending the frames side by side. Here we detect that 222 | // case and instead display these icons vertically. 223 | GtkOrientation all_icons_or = icon_view->images[scale-1]->width/icon_view->images[scale-1]->height > 2 ? 224 | GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL; 225 | GtkWidget *all_icons = gtk_box_new (all_icons_or, 12); 226 | 227 | struct icon_image_t *last_img = NULL; 228 | struct icon_image_t *img = icon_view->images[scale-1]; 229 | 230 | while (img != NULL) { 231 | GtkWidget *box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); 232 | img->box = box; 233 | img->custom_css = add_custom_css (box, UNSELECTED_ICON_BOX_STYLE); 234 | 235 | gtk_widget_set_valign (box,GTK_ALIGN_END); 236 | gtk_widget_set_vexpand (box, FALSE); 237 | 238 | gtk_container_add (GTK_CONTAINER(box), img->image); 239 | 240 | if (img->label != NULL) { 241 | GtkWidget *label = gtk_label_new (img->label); 242 | gtk_widget_set_valign (label, GTK_ALIGN_START); 243 | gtk_label_set_justify (GTK_LABEL(label), GTK_JUSTIFY_CENTER); 244 | gtk_container_add (GTK_CONTAINER(box), label); 245 | } 246 | 247 | GtkWidget *hitbox = gtk_event_box_new (); 248 | g_signal_connect (G_OBJECT(hitbox), "button-press-event", G_CALLBACK(on_image_clicked), img); 249 | 250 | // Setup DnD of images 251 | { 252 | gtk_drag_source_set (hitbox, GDK_BUTTON1_MASK, NULL, 0, GDK_ACTION_COPY); 253 | gtk_drag_source_add_uri_targets (hitbox); 254 | GdkPixbuf *pixbuf = gtk_image_get_pixbuf (GTK_IMAGE(img->image)); 255 | gtk_drag_source_set_icon_pixbuf (hitbox, pixbuf); 256 | g_signal_connect (G_OBJECT(hitbox), "drag-data-get", G_CALLBACK(on_drag_data_get), img); 257 | } 258 | 259 | gtk_container_add (GTK_CONTAINER(hitbox), box); 260 | 261 | gtk_container_add (GTK_CONTAINER(all_icons), hitbox); 262 | 263 | if(img->next == NULL) { 264 | icon_view->selected_img = img; 265 | set_icon_box_border (img); 266 | last_img = img; 267 | } 268 | img = img->next; 269 | } 270 | 271 | // Place the icon list inside a GtkGrid so they are centered 272 | GtkWidget *icon_dpy = spaced_grid_new (12); 273 | gtk_widget_set_valign (icon_dpy, GTK_ALIGN_CENTER); 274 | gtk_widget_set_halign (icon_dpy, GTK_ALIGN_CENTER); 275 | gtk_widget_set_hexpand (icon_dpy, TRUE); 276 | gtk_widget_set_vexpand (icon_dpy, TRUE); 277 | gtk_grid_attach (GTK_GRID(icon_dpy), all_icons, 0, 0, 1, 1); 278 | 279 | if (icon_view->image_data_dpy == NULL) { 280 | icon_view->image_data_dpy = image_data_dpy_new (last_img); 281 | } else { 282 | replace_wrapped_widget (&icon_view->image_data_dpy, image_data_dpy_new (last_img)); 283 | } 284 | 285 | // Wrap icon_dpy into a GtkScrolledWindow 286 | GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL); 287 | mem_pool_t pool = {0}; 288 | icon_view->scrolled_window_custom_css = 289 | add_custom_css (scrolled_window, new_bgcolor_style_str (&pool, "scrolledwindow", app.bg_color)); 290 | mem_pool_destroy (&pool); 291 | icon_view->scrolled_window = scrolled_window; 292 | 293 | gtk_widget_set_hexpand (scrolled_window, TRUE); 294 | gtk_widget_set_vexpand (scrolled_window, TRUE); 295 | gtk_container_add (GTK_CONTAINER (scrolled_window), icon_dpy); 296 | 297 | GdkRGBA c = GDK_RGBA_FROM_RGBA(app.bg_color); 298 | GtkWidget *button = gtk_color_button_new_with_rgba (&c); 299 | gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(button), TRUE); 300 | add_custom_css (button, 301 | "button {" 302 | " background-color: @bg_color;" 303 | "}"); 304 | 305 | g_signal_connect (G_OBJECT(button), "color-set", G_CALLBACK(on_color_button_clicked), icon_view); 306 | GtkWidget *toolbar = spaced_grid_new (6); 307 | gtk_container_add (GTK_CONTAINER (toolbar), button); 308 | 309 | GtkWidget *overlay = gtk_overlay_new (); 310 | gtk_container_add (GTK_CONTAINER (overlay), scrolled_window); 311 | gtk_overlay_add_overlay (GTK_OVERLAY(overlay), toolbar); 312 | gtk_overlay_set_overlay_pass_through (GTK_OVERLAY(overlay), toolbar, TRUE); 313 | 314 | return overlay; 315 | } 316 | 317 | void on_scale_toggled (GtkToggleButton *button, gpointer user_data) 318 | { 319 | struct icon_view_t *icon_view = (struct icon_view_t *) user_data; 320 | 321 | if (gtk_toggle_button_get_active(button)) { 322 | int scale = gtk_radio_button_get_idx (GTK_RADIO_BUTTON(button)); 323 | GtkWidget *icon_dpy = icon_view_create_icon_dpy (icon_view, scale); 324 | replace_wrapped_widget (&icon_view->icon_dpy, icon_dpy); 325 | } 326 | } 327 | 328 | GtkWidget* scale_selector_new (struct icon_view_t *icon_view) 329 | { 330 | GtkWidget *selector = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); 331 | gtk_widget_set_halign (selector, GTK_ALIGN_END); 332 | gtk_button_box_set_layout (GTK_BUTTON_BOX(selector), GTK_BUTTONBOX_EXPAND); 333 | 334 | GSList *group = NULL; 335 | for (int i=0; iimages); i++) { 336 | char buff[3]; 337 | snprintf (buff, ARRAY_SIZE(buff), "%iX", i+1); 338 | GtkWidget *scale_button = gtk_radio_button_new_with_label (group, buff); 339 | gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON(scale_button), FALSE); 340 | gtk_container_add (GTK_CONTAINER(selector), scale_button); 341 | if (icon_view->images[i] != NULL) { 342 | g_signal_connect (G_OBJECT(scale_button), "toggled", G_CALLBACK(on_scale_toggled), icon_view); 343 | } else { 344 | gtk_widget_set_sensitive (scale_button, FALSE); 345 | } 346 | group = gtk_radio_button_get_group (GTK_RADIO_BUTTON(scale_button)); 347 | } 348 | 349 | return selector; 350 | } 351 | 352 | void on_icon_view_theme_changed (GtkComboBox *themes_combobox, gpointer user_data) 353 | { 354 | const char* theme_name = gtk_combo_box_get_active_id (themes_combobox); 355 | if (app.selected_theme_type == THEME_TYPE_ALL) { 356 | app_set_selected_theme (&app, theme_name); 357 | app_set_icon_view (&app, app.selected_icon); 358 | 359 | } else { 360 | app_set_normal_theme (&app, theme_name, app.selected_icon); 361 | } 362 | } 363 | 364 | GtkWidget* draw_icon_view (struct icon_view_t *icon_view) 365 | { 366 | icon_view->icon_dpy = icon_view_create_icon_dpy (icon_view, 1); 367 | 368 | // Create the icon data pane 369 | GtkWidget *data_pane = spaced_grid_new (12); 370 | GtkWidget *icon_name_label = gtk_label_new (icon_view->icon_name); 371 | add_css_class (icon_name_label, "h2"); 372 | gtk_label_set_selectable (GTK_LABEL(icon_name_label), TRUE); 373 | gtk_label_set_ellipsize (GTK_LABEL(icon_name_label), PANGO_ELLIPSIZE_END); 374 | gtk_widget_set_halign (icon_name_label, GTK_ALIGN_START); 375 | gtk_grid_attach (GTK_GRID(data_pane), icon_name_label, 0, 0, 1, 1); 376 | 377 | GtkWidget *icon_widgets = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18); 378 | GtkWidget *theme_selector = NULL; 379 | if (app.selected_theme_type == THEME_TYPE_ALL || app.selected_theme_type == THEME_TYPE_NORMAL) { 380 | GtkWidget *themes_combobox; 381 | theme_selector = labeled_combobox_new ("Theme:", &themes_combobox); 382 | for (struct icon_theme_t *curr_theme = app.themes; curr_theme; curr_theme = curr_theme->next) { 383 | if (g_hash_table_contains (curr_theme->icon_names, icon_view->icon_name)) { 384 | combo_box_text_append_text_with_id (GTK_COMBO_BOX_TEXT(themes_combobox), curr_theme->name); 385 | } 386 | } 387 | 388 | gtk_combo_box_set_active_id (GTK_COMBO_BOX(themes_combobox), app.selected_theme->name); 389 | g_signal_connect (G_OBJECT(themes_combobox), "changed", G_CALLBACK (on_icon_view_theme_changed), NULL); 390 | gtk_container_add (GTK_CONTAINER(icon_widgets), theme_selector); 391 | } 392 | 393 | GtkWidget *scale_selector = scale_selector_new (icon_view); 394 | 395 | GtkWidget *widget_to_align = theme_selector != NULL ? theme_selector : scale_selector; 396 | gtk_widget_set_halign (widget_to_align, GTK_ALIGN_END); 397 | gtk_widget_set_hexpand (widget_to_align, TRUE); 398 | 399 | gtk_container_add (GTK_CONTAINER(icon_widgets), scale_selector); 400 | 401 | gtk_grid_attach (GTK_GRID(data_pane), icon_widgets, 1, 0, 1, 1); 402 | 403 | gtk_grid_attach (GTK_GRID(data_pane), 404 | wrap_gtk_widget(icon_view->image_data_dpy), 405 | 0, 1, 1, 1); 406 | 407 | return fk_paned (GTK_ORIENTATION_VERTICAL, 408 | wrap_gtk_widget(icon_view->icon_dpy), 409 | data_pane); 410 | } 411 | -------------------------------------------------------------------------------- /icon_view.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Santiago León O. 3 | */ 4 | 5 | struct icon_image_t { 6 | GtkWidget *image; 7 | int width, height; 8 | char *label; // can be NULL 9 | 10 | // Information found in the index file 11 | char *theme_dir; 12 | char *path; 13 | char *full_path; 14 | off_t file_size; 15 | int size; 16 | int min_size; 17 | int max_size; 18 | int scale; 19 | char* type; // can be NULL 20 | char* context; // can be NULL 21 | bool is_scalable; // True if directory in index file contains "scalable" 22 | 23 | struct icon_image_t *next; 24 | struct icon_view_t *view; // Pointer to the icon_view_t this icon_image_t is member of. 25 | 26 | // UI Widgets 27 | GtkWidget *box; 28 | GtkCssProvider *custom_css; 29 | }; 30 | 31 | #define IV_MAX_SCALE 3 32 | struct icon_view_t { 33 | char *icon_name; 34 | 35 | int scale; 36 | struct icon_image_t *images[IV_MAX_SCALE]; 37 | struct icon_image_t *images_end[IV_MAX_SCALE]; 38 | int images_len[IV_MAX_SCALE]; 39 | 40 | // UI Widgets 41 | GtkWidget *icon_dpy; 42 | GtkWidget *image_data_dpy; 43 | struct icon_image_t *selected_img; 44 | 45 | GtkWidget *scrolled_window; 46 | GtkCssProvider *scrolled_window_custom_css; 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /mkpy/pymk.py: -------------------------------------------------------------------------------- 1 | # THIS IS NOT PYTHON CODE, it's BASH code installed into /usr/share/bash-completion/completions/ 2 | # to enable tab completions. 3 | _pymk() 4 | { 5 | local cur prev words cword 6 | _init_completion || return 7 | 8 | res="$(./pymk.py --get_completions "$COMP_POINT $COMP_LINE")" 9 | COMPREPLY=( $( compgen -W '$res' -- "$cur" ) ) 10 | [[ $COMPREPLY ]] || \ 11 | COMPREPLY=( $( compgen -f -- "$cur" ) ) 12 | } && 13 | complete -F _pymk "./pymk.py" 14 | 15 | # ex: ts=4 sw=4 et filetype=sh 16 | -------------------------------------------------------------------------------- /pymk.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | from mkpy import utility as cfg 3 | from mkpy.utility import * 4 | assert sys.version_info >= (3,2) 5 | 6 | RDNN_NAME = 'com.github.santileortiz.iconoscope' 7 | installation_info = { 8 | 'bin/iconoscope': 'bin/{RDNN_NAME}', 9 | 'data/iconoscope.desktop': 'share/applications/{RDNN_NAME}.desktop', 10 | 'data/appdata.xml': 'share/metainfo/{RDNN_NAME}.appdata.xml', 11 | 'data/128/iconoscope.svg': 'share/icons/hicolor/128x128/apps/{RDNN_NAME}.svg', 12 | 'data/64/iconoscope.svg': 'share/icons/hicolor/64x64/apps/{RDNN_NAME}.svg', 13 | 'data/48/iconoscope.svg': 'share/icons/hicolor/48x48/apps/{RDNN_NAME}.svg', 14 | 'data/32/iconoscope.svg': 'share/icons/hicolor/32x32/apps/{RDNN_NAME}.svg', 15 | } 16 | 17 | GTK_FLAGS = ex ('pkg-config --cflags --libs gtk+-3.0', ret_stdout=True, echo=False) 18 | 19 | modes = { 20 | 'debug': '-g -Wall', 21 | 'profile_debug': '-O3 -g -pg -Wall', 22 | 'release': '-O3 -DNDEBUG -DRELEASE_BUILD -Wall' 23 | } 24 | mode = store('mode', get_cli_arg_opt('-M,--mode', modes.keys()), 'debug') 25 | C_FLAGS = modes[mode] 26 | ensure_dir ("bin") 27 | 28 | def default(): 29 | target = store_get ('last_snip', 'iconoscope') 30 | call_user_function(target) 31 | 32 | def iconoscope (): 33 | ex ('gcc {C_FLAGS} -o bin/iconoscope iconoscope.c {GTK_FLAGS} -lm') 34 | 35 | def install (): 36 | dest_dir = get_cli_arg_opt ('--destdir') 37 | print (f'Installing Iconoscope into: {dest_dir}') 38 | installed_files = install_files (installation_info, dest_dir) 39 | 40 | if dest_dir == None or dest_dir == '/': 41 | for f in installed_files: 42 | if 'hicolor' in f: 43 | ex ('gtk-update-icon-cache-3.0 /usr/share/icons/hicolor/') 44 | break; 45 | 46 | def package_flatpak (): 47 | ex ("flatpak-builder --force-clean flatpak-build com.github.santileortiz.iconoscope.yml") 48 | 49 | def package_deb (): 50 | if ex("dpkg-checkbuilddeps", echo=False) == 0 and ex ("debuild -i -us -uc -b") == 0: 51 | print(f"\nOutput files are located at: {ecma_bold(os.path.abspath('..'))}") 52 | else: 53 | print(ecma_red("\nerror:") + " Could not create deb package.") 54 | 55 | cfg.builtin_completions = ['--get_run_deps', '--get_build_deps'] 56 | if __name__ == "__main__": 57 | # Everything above this line will be executed for each TAB press. 58 | # If --get_completions is set, handle_tab_complete() calls exit(). 59 | handle_tab_complete () 60 | 61 | pymk_default() 62 | 63 | -------------------------------------------------------------------------------- /slo_timers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Santiago León O. 3 | */ 4 | 5 | #if !defined(SLO_TIMERS_H) 6 | #include 7 | 8 | // Functions used for profiling and timming in general: 9 | // - A process clock that measures time used by this process. 10 | // - A wall clock that measures real world time. 11 | 12 | struct timespec proc_clock_info; 13 | struct timespec wall_clock_info; 14 | void validate_clock (struct timespec *clock_info) { 15 | if (clock_info->tv_sec != 0 || clock_info->tv_nsec != 1) { 16 | printf ("Error: We expect a 1ns resolution timer. %li s %li ns resolution instead.\n", 17 | clock_info->tv_sec, clock_info->tv_nsec); 18 | } 19 | } 20 | 21 | void setup_clocks () 22 | { 23 | if (-1 == clock_getres (CLOCK_PROCESS_CPUTIME_ID, &proc_clock_info)) { 24 | printf ("Error: could not get profiling clock resolution\n"); 25 | } 26 | validate_clock (&proc_clock_info); 27 | 28 | if (-1 == clock_getres (CLOCK_MONOTONIC, &wall_clock_info)) { 29 | printf ("Error: could not get wall clock resolution\n"); 30 | } 31 | validate_clock (&wall_clock_info); 32 | return; 33 | } 34 | 35 | void print_time_elapsed (struct timespec *time_start, struct timespec *time_end, char *str) 36 | { 37 | float time_in_ms = (time_end->tv_sec*1000-time_start->tv_sec*1000+ 38 | (float)(time_end->tv_nsec-time_start->tv_nsec)/1000000); 39 | if (time_in_ms < 0.0001) { 40 | printf ("[%ld ns]: %s\n", time_end->tv_nsec-time_start->tv_nsec, str); 41 | } else if (time_in_ms < 1) { 42 | printf ("[%f us]: %s\n", time_in_ms*1000, str); 43 | } else if (time_in_ms < 1000) { 44 | printf ("[%f ms]: %s\n", time_in_ms, str); 45 | } else { 46 | printf ("[%f s]: %s\n", time_in_ms/1000, str); 47 | } 48 | } 49 | 50 | float time_elapsed_in_ms (struct timespec *time_start, struct timespec *time_end) 51 | { 52 | return (time_end->tv_sec*1000-time_start->tv_sec*1000+ 53 | (float)(time_end->tv_nsec-time_start->tv_nsec)/1000000); 54 | } 55 | 56 | // Process clock 57 | // Usage: 58 | // BEGIN_TIME_BLOCK; 59 | // 60 | // END_TIME_BLOCK("Name of timed block"); 61 | 62 | struct timespec proc_ticks_start; 63 | struct timespec proc_ticks_end; 64 | #define BEGIN_TIME_BLOCK {clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &proc_ticks_start);} 65 | #define END_TIME_BLOCK(str) {\ 66 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &proc_ticks_end);\ 67 | print_time_elapsed(&proc_ticks_start, &proc_ticks_end, str);\ 68 | } 69 | 70 | // Wall timer 71 | // Usage: 72 | // BEGIN_WALL_CLOCK; //call once 73 | // 74 | // PROBE_WALL_CLOCK("Name of probe 1"); 75 | // 76 | // PROBE_WALL_CLOCK("Name of probe 2"); 77 | 78 | struct timespec wall_ticks_start; 79 | struct timespec wall_ticks_end; 80 | #define BEGIN_WALL_CLOCK {clock_gettime(CLOCK_MONOTONIC, &wall_ticks_start);} 81 | #define PROBE_WALL_CLOCK(str) {\ 82 | clock_gettime(CLOCK_MONOTONIC, &wall_ticks_end);\ 83 | print_time_elapsed(&wall_ticks_start, &wall_ticks_end, str);\ 84 | wall_ticks_start = wall_ticks_end;\ 85 | } 86 | 87 | #define SLO_TIMERS_H 88 | #endif 89 | -------------------------------------------------------------------------------- /timing_stats.txt: -------------------------------------------------------------------------------- 1 | ALL ICON NAMES TIMING 2 | ===================== 3 | 4 | These are the timing results of comparing trees to hash tables to balanced 5 | trees to store all the icon names. 6 | 7 | Changes of using a tree: 8 | 9 | - Even thought both memory pools that store actual names are identical, 10 | destroying the pool created for the hash table is 2x slower. +8us 11 | - Destroying a tree is more than 100x slower than destroying the hash table 12 | for the exact same keys. +300us 13 | - Creating the GtkListBox is about 30ms faster for trees. -20ms 14 | 15 | Destruction seems to be the least of the problems now, but using a tree does 16 | make it slower. GtkListBox creation is the slowest part, and using a tree makes 17 | it ~1.16% faster, which beats the slowness added on destruction. Still, this is 18 | unacceptably slow, I need to look further into this. 19 | 20 | TREE 21 | ---- 22 | name count: 6982 23 | [2.207614 s]: GtkListBox creation 24 | 25 | Allocated: 141480 bytes 26 | Available: 546 bytes 27 | Used: 136152 bytes (96.23%) 28 | Info: 3240 bytes (2.29%) 29 | Left empty: 1542 bytes (1.09%) 30 | Bins: 135 31 | 32 | [14.843000 us]: All names pool destruction 33 | [354.131012 us]: All names struct destruction 34 | 35 | 36 | HASH TABLE 37 | ---------- 38 | name count: 6982 39 | [2.233500 s]: GtkListBox creation 40 | 41 | Allocated: 141480 bytes 42 | Available: 546 bytes 43 | Used: 136152 bytes (96.23%) 44 | Info: 3240 bytes (2.29%) 45 | Left empty: 1542 bytes (1.09%) 46 | Bins: 135 47 | 48 | [7.034000 us]: All names pool destruction 49 | [28.572001 us]: All names struct destruction 50 | 51 | --------------------------------------------------------------------------------