nsxivd566ca8
Merge branch 'nsxiv-master'
+281 −261
19 files changed
- M .editorconfig +4 −2
- M README.md +2 −137
- M autoreload.c +13 −7
- M commands.c +15 −6
- M commands.h +2 −0
- M config.h +1 −0
- M config.mk +5 −2
- A etc/.clang-format +82 −0
- M etc/CHANGELOG.md +1 −1
- M etc/CONTRIBUTING.md +16 −1
- M etc/nsxiv.1 +7 −5
- M etc/woodpecker/clang-tidy-checks +1 −0
- M image.c +38 −28
- M main.c +40 −34
- M nsxiv.h +4 −0
- M options.c +3 −2
- M thumbs.c +15 −11
- M util.c +11 −10
- M window.c +21 −15
| @@ -1,7 +1,9 @@ | |||
| 1 | 1 | # EditorConfig | |
| 2 | + | # See this if your editor doesn't have built-in editorconfig support: | |
| 3 | + | # https://editorconfig.org/#download | |
| 2 | 4 | ||
| 3 | − | # apply to all files | |
| 4 | − | [*] | |
| 5 | + | # apply to all .c and .h files | |
| 6 | + | [*.{c,h}] | |
| 5 | 7 | ||
| 6 | 8 | # top-most EditorConfig file | |
| 7 | 9 | root = true | |
| @@ -1,137 +1,2 @@ | |||
| 1 | − | Dependencies | |
| 2 | − | ------------ | |
| 3 | − | ||
| 4 | − | nsxiv requires the following software to be installed: | |
| 5 | − | ||
| 6 | − | * Imlib2 | |
| 7 | − | * X11 | |
| 8 | − | ||
| 9 | − | The following dependencies are optional. | |
| 10 | − | ||
| 11 | − | * `inotify`<sup>\*</sup>: Used for auto-reloading images on change. | |
| 12 | − | Disabled via `HAVE_INOTIFY=0`. | |
| 13 | − | * `libXft`, `freetype2`, `fontconfig`: Used for the status bar. | |
| 14 | − | Disabled via `HAVE_LIBFONTS=0`. | |
| 15 | − | * `giflib`: Used for animated gif playback. | |
| 16 | − | Disabled via `HAVE_LIBGIF=0`. | |
| 17 | − | * `libexif`: Used for auto-orientation and exif thumbnails. | |
| 18 | − | Disable via `HAVE_LIBEXIF=0`. | |
| 19 | − | * `libwebp`: Used for animated webp playback. | |
| 20 | − | (***NOTE***: animated webp also requires Imlib2 v1.7.5 or above) | |
| 21 | − | Disabled via `HAVE_LIBWEBP=0`. | |
| 22 | − | ||
| 23 | − | Please make sure to install the corresponding development packages in case that | |
| 24 | − | you want to build nsxiv on a distribution with separate runtime and development | |
| 25 | − | packages (e.g. \*-dev on Debian). | |
| 26 | − | ||
| 27 | − | \* [inotify][] is a Linux-specific API for monitoring filesystem changes. | |
| 28 | − | It's not natively available on `*BSD` systems but can be enabed via installing | |
| 29 | − | and linking against [libinotify-kqueue][]. | |
| 30 | − | ||
| 31 | − | [inotify]: https://www.man7.org/linux/man-pages/man7/inotify.7.html | |
| 32 | − | [libinotify-kqueue]: https://github.com/libinotify-kqueue/libinotify-kqueue | |
| 33 | − | ||
| 34 | − | ||
| 35 | − | Building | |
| 36 | − | -------- | |
| 37 | − | ||
| 38 | − | nsxiv is built using the commands: | |
| 39 | − | ||
| 40 | − | $ make | |
| 41 | − | ||
| 42 | − | You can pass `HAVE_X=0` to `make` to disable an optional dependency. | |
| 43 | − | For example: | |
| 44 | − | ||
| 45 | − | $ make HAVE_LIBEXIF=0 | |
| 46 | − | ||
| 47 | − | will disable `libexif` support. Alternatively they can be disabled via editing | |
| 48 | − | `config.mk`. `OPT_DEP_DEFAULT=0` can be used to disable all optional | |
| 49 | − | dependencies. | |
| 50 | − | ||
| 51 | − | Installing nsxiv: | |
| 52 | − | ||
| 53 | − | # make install | |
| 54 | − | ||
| 55 | − | Installing desktop entry: | |
| 56 | − | ||
| 57 | − | # make install-desktop | |
| 58 | − | ||
| 59 | − | Installing icons: | |
| 60 | − | ||
| 61 | − | # make install-icon | |
| 62 | − | ||
| 63 | − | Installing all of the above: | |
| 64 | − | ||
| 65 | − | # make install-all | |
| 66 | − | ||
| 67 | − | Please note, that these requires root privileges. | |
| 68 | − | By default, nsxiv is installed using the prefix `/usr/local`, so the full path | |
| 69 | − | of the executable will be `/usr/local/bin/nsxiv`, the `.desktop` entry will be | |
| 70 | − | `/usr/local/share/applications/nsxiv.desktop` and the icon path will be | |
| 71 | − | `/usr/local/share/icons/hicolor/{size}/apps/nsxiv.png`. | |
| 72 | − | ||
| 73 | − | You can install nsxiv into a directory of your choice by changing this command to: | |
| 74 | − | ||
| 75 | − | $ make PREFIX="/your/dir" install | |
| 76 | − | ||
| 77 | − | Example scripts are installed using `EGPREFIX` which defaults to | |
| 78 | − | `/usr/local/share/doc/nsxiv/examples`. You can change `EGPREFIX` the same way | |
| 79 | − | you can change `PREFIX` shown above. | |
| 80 | − | ||
| 81 | − | The build-time specific settings of nsxiv can be found in the file *config.h*. | |
| 82 | − | Please check and change them, so that they fit your needs. | |
| 83 | − | If the file *config.h* does not already exist, then you have to create it with | |
| 84 | − | the following command: | |
| 85 | − | ||
| 86 | − | $ make config.h | |
| 87 | − | ||
| 88 | − | ||
| 89 | − | Usage | |
| 90 | − | ----- | |
| 91 | − | ||
| 92 | − | Refer to the man-page for the documentation: | |
| 93 | − | ||
| 94 | − | $ man nsxiv | |
| 95 | − | ||
| 96 | − | You may also view the man-page [online](https://nsxiv.codeberg.page/man/). | |
| 97 | − | However, note that the online man-page might not accurately represent your local | |
| 98 | − | copy. | |
| 99 | − | ||
| 100 | − | ||
| 101 | − | F.A.Q. | |
| 102 | − | ------ | |
| 103 | − | ||
| 104 | − | * Can I open remote urls with nsxiv? <br> | |
| 105 | − | Yes, see [nsxiv-url](https://codeberg.org/nsxiv/nsxiv-extra/src/branch/master/scripts/nsxiv-url) | |
| 106 | − | ||
| 107 | − | * Can I open all the images in a directory? <br> | |
| 108 | − | Yes, see [nsxiv-rifle](https://codeberg.org/nsxiv/nsxiv-extra/src/branch/master/scripts/nsxiv-rifle) | |
| 109 | − | ||
| 110 | − | * Can I set default arguments for nsxiv? <br> | |
| 111 | − | Yes, see [nsxiv-env](https://codeberg.org/nsxiv/nsxiv-extra/src/branch/master/scripts/nsxiv-env) | |
| 112 | − | ||
| 113 | − | * Can I pipe images into nsxiv? <br> | |
| 114 | − | Yes, see [nsxiv-pipe](https://codeberg.org/nsxiv/nsxiv-extra/src/branch/master/scripts/nsxiv-pipe) | |
| 115 | − | ||
| 116 | − | You may also wish to see the [known issues](https://codeberg.org/nsxiv/nsxiv/issues/242). | |
| 117 | − | ||
| 118 | − | ||
| 119 | − | Customization | |
| 120 | − | ------------- | |
| 121 | − | ||
| 122 | − | The main method of customizing nsxiv is by setting values for the variables in *config.h*, | |
| 123 | − | or by using Xresources as explained in the manual. If these options are not sufficient, | |
| 124 | − | you may implement your own features by following | |
| 125 | − | [this guide](https://codeberg.org/nsxiv/nsxiv-extra/src/branch/master/CUSTOMIZATION.md). | |
| 126 | − | ||
| 127 | − | Due to our limited [project scope](etc/CONTRIBUTING.md#project-scope), certain features or | |
| 128 | − | customization cannot be merged into nsxiv mainline. Following the spirit of suckless | |
| 129 | − | software, we host the [nsxiv-extra](https://codeberg.org/nsxiv/nsxiv-extra) repo where users | |
| 130 | − | are free to submit whatever patches or scripts they wish. | |
| 131 | − | ||
| 132 | − | If you think your custom features can be beneficial for the general user base and is within | |
| 133 | − | our project scope, please submit it as a pull request on this repository, then we *may* | |
| 134 | − | merge it to mainline. | |
| 135 | − | ||
| 136 | − | Description on how to use or submit patches can be found on | |
| 137 | − | nsxiv-extra's [README](https://codeberg.org/nsxiv/nsxiv-extra). | |
| 1 | + | ## Nsxiv | |
| 2 | + | This is my fork of Nsxiv | |
| @@ -28,7 +28,10 @@ | |||
| 28 | 28 | #include <sys/inotify.h> | |
| 29 | 29 | #include <unistd.h> | |
| 30 | 30 | ||
| 31 | − | static struct { char *buf; size_t len; } scratch; | |
| 31 | + | static struct { | |
| 32 | + | char *buf; | |
| 33 | + | size_t len; | |
| 34 | + | } scratch; | |
| 32 | 35 | ||
| 33 | 36 | void arl_init(arl_t *arl) | |
| 34 | 37 | { | |
| @@ -94,7 +97,10 @@ bool arl_handle(arl_t *arl) | |||
| 94 | 97 | char *ptr; | |
| 95 | 98 | const struct inotify_event *e; | |
| 96 | 99 | /* inotify_event aligned buffer */ | |
| 97 | − | static union { char d[4096]; struct inotify_event e; } buf; | |
| 100 | + | static union { | |
| 101 | + | char d[4096]; | |
| 102 | + | struct inotify_event e; | |
| 103 | + | } buf; | |
| 98 | 104 | ||
| 99 | 105 | while (true) { | |
| 100 | 106 | ssize_t len = read(arl->fd, buf.d, sizeof(buf.d)); | |
| @@ -105,7 +111,7 @@ bool arl_handle(arl_t *arl) | |||
| 105 | 111 | break; | |
| 106 | 112 | } | |
| 107 | 113 | for (ptr = buf.d; ptr < buf.d + len; ptr += sizeof(*e) + e->len) { | |
| 108 | − | e = (const struct inotify_event*) ptr; | |
| 114 | + | e = (const struct inotify_event *)ptr; | |
| 109 | 115 | if (e->wd == arl->wd_file && (e->mask & IN_CLOSE_WRITE)) { | |
| 110 | 116 | reload = true; | |
| 111 | 117 | } else if (e->wd == arl->wd_file && (e->mask & IN_DELETE_SELF)) { | |
| @@ -128,18 +134,18 @@ void arl_init(arl_t *arl) | |||
| 128 | 134 | ||
| 129 | 135 | void arl_cleanup(arl_t *arl) | |
| 130 | 136 | { | |
| 131 | − | (void) arl; | |
| 137 | + | (void)arl; | |
| 132 | 138 | } | |
| 133 | 139 | ||
| 134 | 140 | void arl_add(arl_t *arl, const char *filepath) | |
| 135 | 141 | { | |
| 136 | − | (void) arl; | |
| 137 | − | (void) filepath; | |
| 142 | + | (void)arl; | |
| 143 | + | (void)filepath; | |
| 138 | 144 | } | |
| 139 | 145 | ||
| 140 | 146 | bool arl_handle(arl_t *arl) | |
| 141 | 147 | { | |
| 142 | − | (void) arl; | |
| 148 | + | (void)arl; | |
| 143 | 149 | return false; | |
| 144 | 150 | } | |
| 145 | 151 | ||
| @@ -59,6 +59,13 @@ bool cg_quit(arg_t status) | |||
| 59 | 59 | return None; /* silence tcc warning */ | |
| 60 | 60 | } | |
| 61 | 61 | ||
| 62 | + | bool cg_pick_quit(arg_t status) | |
| 63 | + | { | |
| 64 | + | if (options->to_stdout && markcnt == 0) | |
| 65 | + | printf("%s%c", files[fileidx].name, options->using_null ? '\0' : '\n'); | |
| 66 | + | return cg_quit(status); | |
| 67 | + | } | |
| 68 | + | ||
| 62 | 69 | bool cg_switch_mode(arg_t _) | |
| 63 | 70 | { | |
| 64 | 71 | if (mode == MODE_IMAGE) { | |
| @@ -326,10 +333,10 @@ bool ci_drag(arg_t drag_mode) | |||
| 326 | 333 | ||
| 327 | 334 | while (true) { | |
| 328 | 335 | if (drag_mode == DRAG_ABSOLUTE) { | |
| 329 | − | px = MIN(MAX(0.0, x - win.w*0.1), win.w*0.8) / (win.w*0.8) | |
| 330 | − | * (win.w - img.w * img.zoom); | |
| 331 | − | py = MIN(MAX(0.0, y - win.h*0.1), win.h*0.8) / (win.h*0.8) | |
| 332 | − | * (win.h - img.h * img.zoom); | |
| 336 | + | px = MIN(MAX(0.0, x - win.w * 0.1), win.w * 0.8) / | |
| 337 | + | (win.w * 0.8) * (win.w - img.w * img.zoom); | |
| 338 | + | py = MIN(MAX(0.0, y - win.h * 0.1), win.h * 0.8) / | |
| 339 | + | (win.h * 0.8) * (win.h - img.h * img.zoom); | |
| 333 | 340 | } else { | |
| 334 | 341 | px = img.x + x - ox; | |
| 335 | 342 | py = img.y + y - oy; | |
| @@ -343,7 +350,8 @@ bool ci_drag(arg_t drag_mode) | |||
| 343 | 350 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e); | |
| 344 | 351 | if (e.type == ButtonPress || e.type == ButtonRelease) | |
| 345 | 352 | break; | |
| 346 | − | while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e)); | |
| 353 | + | while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e)) | |
| 354 | + | ; | |
| 347 | 355 | ox = x; | |
| 348 | 356 | oy = y; | |
| 349 | 357 | x = e.xmotion.x; | |
| @@ -443,7 +451,8 @@ bool ct_drag_mark_image(arg_t _) | |||
| 443 | 451 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e); | |
| 444 | 452 | if (e.type == ButtonPress || e.type == ButtonRelease) | |
| 445 | 453 | break; | |
| 446 | − | while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e)); | |
| 454 | + | while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e)) | |
| 455 | + | ; | |
| 447 | 456 | sel = tns_translate(&tns, e.xbutton.x, e.xbutton.y); | |
| 448 | 457 | } | |
| 449 | 458 | } | |
| @@ -12,6 +12,7 @@ bool cg_n_or_last(arg_t); | |||
| 12 | 12 | bool cg_navigate_marked(arg_t); | |
| 13 | 13 | bool cg_prefix_external(arg_t); | |
| 14 | 14 | bool cg_quit(arg_t); | |
| 15 | + | bool cg_pick_quit(arg_t); | |
| 15 | 16 | bool cg_reload_image(arg_t); | |
| 16 | 17 | bool cg_remove_image(arg_t); | |
| 17 | 18 | bool cg_reverse_marks(arg_t); | |
| @@ -57,6 +58,7 @@ bool ct_select(arg_t); | |||
| 57 | 58 | #define g_navigate_marked { cg_navigate_marked, MODE_ALL } | |
| 58 | 59 | #define g_prefix_external { cg_prefix_external, MODE_ALL } | |
| 59 | 60 | #define g_quit { cg_quit, MODE_ALL } | |
| 61 | + | #define g_pick_quit { cg_pick_quit, MODE_ALL } | |
| 60 | 62 | #define g_reload_image { cg_reload_image, MODE_ALL } | |
| 61 | 63 | #define g_remove_image { cg_remove_image, MODE_ALL } | |
| 62 | 64 | #define g_reverse_marks { cg_reverse_marks, MODE_ALL } | |
| @@ -92,6 +92,7 @@ static const KeySym KEYHANDLER_ABORT = XK_Escape; | |||
| 92 | 92 | static const keymap_t keys[] = { | |
| 93 | 93 | /* modifiers key function argument */ | |
| 94 | 94 | { 0, XK_q, g_quit, 0 }, | |
| 95 | + | { 0, XK_Q, g_pick_quit, 0 }, | |
| 95 | 96 | { 0, XK_Return, g_switch_mode, None }, | |
| 96 | 97 | { 0, XK_f, g_toggle_fullscreen, None }, | |
| 97 | 98 | { 0, XK_b, g_toggle_bar, None }, | |
| @@ -23,8 +23,11 @@ HAVE_LIBWEBP = $(OPT_DEP_DEFAULT) | |||
| 23 | 23 | ||
| 24 | 24 | # Compiler and linker | |
| 25 | 25 | CC = c99 | |
| 26 | − | # CFLAGS, any optimization flags goes here | |
| 27 | − | CFLAGS = -Wall -pedantic | |
| 26 | + | # CFLAGS, any additional compiler flags goes here | |
| 27 | + | CFLAGS = -Wall -pedantic -O2 -DNDEBUG | |
| 28 | + | # Uncomment for a debug build using gcc/clang | |
| 29 | + | # CFLAGS = -Wall -pedantic -DDEBUG -g3 -fsanitize=address,undefined | |
| 30 | + | # LDFLAGS = $(CFLAGS) | |
| 28 | 31 | ||
| 29 | 32 | # icons that will be installed via `make icon` | |
| 30 | 33 | ICONS = 16x16.png 32x32.png 48x48.png 64x64.png 128x128.png | |
| @@ -0,0 +1,82 @@ | |||
| 1 | + | # clang-format doesn't dictate the project's code style and can mess up a | |
| 2 | + | # couple edge cases. However it comes quite close and can be used for fixing | |
| 3 | + | # most style issues automatically on new changes via `git-clang-format`. | |
| 4 | + | --- | |
| 5 | + | ||
| 6 | + | Standard: c++03 | |
| 7 | + | ||
| 8 | + | ColumnLimit: 0 | |
| 9 | + | ||
| 10 | + | AccessModifierOffset: -8 | |
| 11 | + | ConstructorInitializerIndentWidth: 8 | |
| 12 | + | ContinuationIndentWidth: 8 | |
| 13 | + | IndentCaseLabels: false | |
| 14 | + | IndentGotoLabels: false | |
| 15 | + | IndentPPDirectives: None | |
| 16 | + | IndentWidth: 8 | |
| 17 | + | IndentWrappedFunctionNames: false | |
| 18 | + | NamespaceIndentation: None | |
| 19 | + | TabWidth: 8 | |
| 20 | + | UseTab: AlignWithSpaces | |
| 21 | + | ||
| 22 | + | AlignAfterOpenBracket: true | |
| 23 | + | AlignConsecutiveAssignments: false | |
| 24 | + | AlignConsecutiveDeclarations: false | |
| 25 | + | AlignEscapedNewlines: false | |
| 26 | + | AlignOperands: true | |
| 27 | + | AlignTrailingComments: false | |
| 28 | + | DerivePointerAlignment: true | |
| 29 | + | PointerAlignment: true | |
| 30 | + | ||
| 31 | + | AllowAllParametersOfDeclarationOnNextLine: false | |
| 32 | + | AllowShortBlocksOnASingleLine: true | |
| 33 | + | AllowShortCaseLabelsOnASingleLine: false | |
| 34 | + | AllowShortFunctionsOnASingleLine: None | |
| 35 | + | AllowShortIfStatementsOnASingleLine: false | |
| 36 | + | AllowShortLoopsOnASingleLine: false | |
| 37 | + | ||
| 38 | + | AlwaysBreakAfterDefinitionReturnType: None | |
| 39 | + | AlwaysBreakAfterReturnType: None | |
| 40 | + | AlwaysBreakBeforeMultilineStrings: false | |
| 41 | + | AlwaysBreakTemplateDeclarations: false | |
| 42 | + | ||
| 43 | + | BinPackArguments: true | |
| 44 | + | BinPackParameters: true | |
| 45 | + | ||
| 46 | + | BreakBeforeBraces: Custom | |
| 47 | + | BraceWrapping: | |
| 48 | + | AfterControlStatement: MultiLine | |
| 49 | + | AfterEnum: false | |
| 50 | + | AfterExternBlock: false | |
| 51 | + | AfterFunction: true | |
| 52 | + | AfterStruct: false | |
| 53 | + | AfterUnion: false | |
| 54 | + | BeforeElse: false | |
| 55 | + | IndentBraces: false | |
| 56 | + | SplitEmptyFunction: true | |
| 57 | + | ||
| 58 | + | BreakBeforeBinaryOperators: None | |
| 59 | + | BreakBeforeInheritanceComma: false | |
| 60 | + | BreakBeforeTernaryOperators: false | |
| 61 | + | BreakConstructorInitializers: BeforeComma | |
| 62 | + | BreakConstructorInitializersBeforeComma: false | |
| 63 | + | BreakStringLiterals: true | |
| 64 | + | ||
| 65 | + | Cpp11BracedListStyle: false | |
| 66 | + | MaxEmptyLinesToKeep: 1 | |
| 67 | + | ||
| 68 | + | ReflowComments: false | |
| 69 | + | ||
| 70 | + | SortIncludes: true | |
| 71 | + | ||
| 72 | + | SpaceAfterCStyleCast: false | |
| 73 | + | SpaceBeforeAssignmentOperators: true | |
| 74 | + | SpaceBeforeParens: ControlStatements | |
| 75 | + | SpaceInEmptyParentheses: false | |
| 76 | + | SpacesBeforeTrailingComments: 1 | |
| 77 | + | SpacesInAngles: false | |
| 78 | + | SpacesInCStyleCastParentheses: false | |
| 79 | + | SpacesInParentheses: false | |
| 80 | + | SpacesInSquareBrackets: false | |
| 81 | + | ||
| 82 | + | ... | |
| @@ -116,7 +116,7 @@ references *above* can be found on the new main nsxiv repository on CodeBerg. | |||
| 116 | 116 | ||
| 117 | 117 | * Changes: | |
| 118 | 118 | ||
| 119 | − | * Window title is now customizeable via `win-title`, cli flag `-T` and related | |
| 119 | + | * Window title is now customizable via `win-title`, cli flag `-T` and related | |
| 120 | 120 | config.h options are removed. See `WINDOW TITLE` section of the manpage for | |
| 121 | 121 | more info. [#213] | |
| 122 | 122 | * Imlib2 cache size is now set based on total memory percentage, by default | |
| @@ -23,7 +23,7 @@ Contribution Guideline | |||
| 23 | 23 | When contributing, make sure: | |
| 24 | 24 | ||
| 25 | 25 | * Your contribution falls under nsxiv's scope and aim | |
| 26 | − | * You follow the existing code style (see [.editorconfig](../.editorconfig)) | |
| 26 | + | * You follow the existing code style (see the "Code Style" section below) | |
| 27 | 27 | * You open the pull request from a new branch, not from master | |
| 28 | 28 | * To avoid using force pushes, especially for bigger patches. Only use them | |
| 29 | 29 | when there's merge conflicts. | |
| @@ -44,6 +44,21 @@ to work on. You can also filter the issues via label: | |||
| 44 | 44 | (Intermediate/Experienced) Issues where we require some help. | |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | + | Code Style | |
| 48 | + | ---------- | |
| 49 | + | ||
| 50 | + | `nsxiv` mostly follows the [suckless code-style][sl], with a few exceptions. | |
| 51 | + | If your editor supports [.editorconfig](../.editorconfig) then you'll already be | |
| 52 | + | off to a good start without needing much manual intervention. Additionally we | |
| 53 | + | provide a [clang-format](./.clang-format) configuration for reference, which you | |
| 54 | + | may use via [`git-clang-format`][cf] to format the changes you've made (please | |
| 55 | + | do not run it globally on the entire code-base since clang-format gets a decent | |
| 56 | + | amount of edge cases wrong). | |
| 57 | + | ||
| 58 | + | [sl]: https://suckless.org/coding_style/ | |
| 59 | + | [cf]: https://clang.llvm.org/docs/ClangFormat.html#git-integration | |
| 60 | + | ||
| 61 | + | ||
| 47 | 62 | Development workflow for maintainers | |
| 48 | 63 | ------------------------------------ | |
| 49 | 64 | ||
| @@ -135,6 +135,10 @@ Prefix the next command with a number (denoted via | |||
| 135 | 135 | .B q | |
| 136 | 136 | Quit nsxiv. | |
| 137 | 137 | .TP | |
| 138 | + | .B Q | |
| 139 | + | Quit nsxiv, but additionally print the current filename when \-o is active and | |
| 140 | + | no files have been marked. | |
| 141 | + | .TP | |
| 138 | 142 | .B Return | |
| 139 | 143 | Switch to thumbnail mode / open selected image in image mode. | |
| 140 | 144 | .TP | |
| @@ -457,6 +461,9 @@ Color of the bar foreground. Defaults to window.foreground | |||
| 457 | 461 | Color of the mark foreground. Defaults to window.foreground | |
| 458 | 462 | .TP | |
| 459 | 463 | Please see xrdb(1) on how to change them. | |
| 464 | + | .LP | |
| 465 | + | An X resources entry with an empty value means the default | |
| 466 | + | (defined in config.h) will be used. | |
| 460 | 467 | .SH WINDOW TITLE | |
| 461 | 468 | The window title can be replaced with the output of a user-provided script, | |
| 462 | 469 | which is called by nsxiv whenever any of the relevant information changes. | |
| @@ -562,11 +569,6 @@ TAAPArthur <taaparthur at gmail.com> | |||
| 562 | 569 | eylles <ed.ylles1997 at gmail.com> | |
| 563 | 570 | Stein Gunnar Bakkeby <bakkeby at gmail.com> | |
| 564 | 571 | explosion-mental <explosion0mental at gmail.com> | |
| 565 | − | mamg22 <marcomonizg at gmail.com> | |
| 566 | − | LuXu | |
| 567 | − | Guilherme Freire | |
| 568 | − | Sam Whitehead | |
| 569 | − | Kian Kasad <kian at kasad.com> | |
| 570 | 572 | .EE | |
| 571 | 573 | .SH CONTRIBUTORS | |
| 572 | 574 | .EX | |
| @@ -9,6 +9,7 @@ misc-*,android-cloexec-*,llvm-include-order | |||
| 9 | 9 | -bugprone-implicit-widening-of-multiplication-result,-bugprone-integer-division | |
| 10 | 10 | -android-cloexec-fopen,-android-cloexec-pipe,-cert-err33-c | |
| 11 | 11 | -bugprone-assignment-in-if-condition | |
| 12 | + | -bugprone-suspicious-realloc-usage | |
| 12 | 13 | ||
| 13 | 14 | # false positive warnings | |
| 14 | 15 | -clang-analyzer-valist.Uninitialized | |
| @@ -54,8 +54,12 @@ enum { DEF_GIF_DELAY = 75 }; | |||
| 54 | 54 | enum { DEF_WEBP_DELAY = 75 }; | |
| 55 | 55 | #endif | |
| 56 | 56 | ||
| 57 | + | #if HAVE_IMLIB2_MULTI_FRAME | |
| 58 | + | enum { DEF_ANIM_DELAY = 75 }; | |
| 59 | + | #endif | |
| 60 | + | ||
| 57 | 61 | #define ZOOM_MIN (zoom_levels[0] / 100) | |
| 58 | − | #define ZOOM_MAX (zoom_levels[ARRLEN(zoom_levels)-1] / 100) | |
| 62 | + | #define ZOOM_MAX (zoom_levels[ARRLEN(zoom_levels) - 1] / 100) | |
| 59 | 63 | ||
| 60 | 64 | static int calc_cache_size(void) | |
| 61 | 65 | { | |
| @@ -69,7 +73,7 @@ static int calc_cache_size(void) | |||
| 69 | 73 | #endif | |
| 70 | 74 | if (pages < 0 || page_size < 0) | |
| 71 | 75 | return CACHE_SIZE_FALLBACK; | |
| 72 | − | cache = (pages/100) * CACHE_SIZE_MEM_PERCENTAGE; | |
| 76 | + | cache = (pages / 100) * CACHE_SIZE_MEM_PERCENTAGE; | |
| 73 | 77 | cache *= page_size; | |
| 74 | 78 | ||
| 75 | 79 | return MIN(cache, CACHE_SIZE_LIMIT); | |
| @@ -234,12 +238,12 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) | |||
| 234 | 238 | while (ext) { | |
| 235 | 239 | if (ext_code == GRAPHICS_EXT_FUNC_CODE) { | |
| 236 | 240 | if (ext[1] & 1) | |
| 237 | − | transp = (int) ext[4]; | |
| 241 | + | transp = (int)ext[4]; | |
| 238 | 242 | else | |
| 239 | 243 | transp = -1; | |
| 240 | 244 | ||
| 241 | − | delay = 10 * ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]); | |
| 242 | − | disposal = (unsigned int) ext[1] >> 2 & 0x7; | |
| 245 | + | delay = 10 * ((unsigned int)ext[3] << 8 | (unsigned int)ext[2]); | |
| 246 | + | disposal = (unsigned int)ext[1] >> 2 & 0x7; | |
| 243 | 247 | } | |
| 244 | 248 | ext = NULL; | |
| 245 | 249 | DGifGetExtensionNext(gif, &ext); | |
| @@ -280,10 +284,11 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) | |||
| 280 | 284 | for (i = 0; i < sh; i++) { | |
| 281 | 285 | for (j = 0; j < sw; j++) { | |
| 282 | 286 | if (i < y || i >= y + h || j < x || j >= x + w || | |
| 283 | − | rows[i-y][j-x] == transp) | |
| 287 | + | rows[i - y][j - x] == transp) | |
| 284 | 288 | { | |
| 285 | − | if (prev_frame != NULL && (prev_disposal != 2 || | |
| 286 | − | i < py || i >= py + ph || j < px || j >= px + pw)) | |
| 289 | + | if (prev_frame != NULL && | |
| 290 | + | (prev_disposal != 2 || i < py || i >= py + ph || | |
| 291 | + | j < px || j >= px + pw)) | |
| 287 | 292 | { | |
| 288 | 293 | *ptr = prev_frame[i * sw + j]; | |
| 289 | 294 | } else { | |
| @@ -291,9 +296,9 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) | |||
| 291 | 296 | } | |
| 292 | 297 | } else { | |
| 293 | 298 | assert(cmap != NULL); | |
| 294 | − | r = cmap->Colors[rows[i-y][j-x]].Red; | |
| 295 | − | g = cmap->Colors[rows[i-y][j-x]].Green; | |
| 296 | − | b = cmap->Colors[rows[i-y][j-x]].Blue; | |
| 299 | + | r = cmap->Colors[rows[i - y][j - x]].Red; | |
| 300 | + | g = cmap->Colors[rows[i - y][j - x]].Green; | |
| 301 | + | b = cmap->Colors[rows[i - y][j - x]].Blue; | |
| 297 | 302 | *ptr = 0xffu << 24 | r << 16 | g << 8 | b; | |
| 298 | 303 | } | |
| 299 | 304 | ptr++; | |
| @@ -412,12 +417,12 @@ static bool img_load_webp(img_t *img, const fileinfo_t *file) | |||
| 412 | 417 | /* Load and decode frames (also works on images with only 1 frame) */ | |
| 413 | 418 | m->length = m->cnt = m->sel = 0; | |
| 414 | 419 | while (WebPAnimDecoderGetNext(dec, &buf, &ts)) { | |
| 415 | − | im = imlib_create_image_using_copied_data( | |
| 416 | − | info.canvas_width, info.canvas_height, (uint32_t *)buf); | |
| 420 | + | im = imlib_create_image_using_copied_data(info.canvas_width, info.canvas_height, | |
| 421 | + | (uint32_t *)buf); | |
| 417 | 422 | imlib_context_set_image(im); | |
| 418 | 423 | imlib_image_set_format("webp"); | |
| 419 | 424 | /* Get an iterator of this frame - used for frame info (duration, etc.) */ | |
| 420 | − | WebPDemuxGetFrame(demux, m->cnt+1, &iter); | |
| 425 | + | WebPDemuxGetFrame(demux, m->cnt + 1, &iter); | |
| 421 | 426 | imlib_image_set_has_alpha((flags & ALPHA_FLAG) == ALPHA_FLAG); | |
| 422 | 427 | /* Store info for this frame */ | |
| 423 | 428 | m->frames[m->cnt].im = im; | |
| @@ -469,11 +474,6 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file) | |||
| 469 | 474 | m->frames = erealloc(m->frames, m->cap * sizeof(*m->frames)); | |
| 470 | 475 | } | |
| 471 | 476 | ||
| 472 | − | imlib_context_set_dither(0); | |
| 473 | − | imlib_context_set_anti_alias(0); | |
| 474 | − | imlib_context_set_color_modifier(NULL); | |
| 475 | − | imlib_context_set_operation(IMLIB_OP_COPY); | |
| 476 | − | ||
| 477 | 477 | if ((blank = imlib_create_image(img->w, img->h)) == NULL) { | |
| 478 | 478 | error(0, 0, "%s: couldn't create image", file->name); | |
| 479 | 479 | return false; | |
| @@ -481,6 +481,11 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file) | |||
| 481 | 481 | imlib_context_set_image(blank); | |
| 482 | 482 | img_area_clear(0, 0, img->w, img->h); | |
| 483 | 483 | ||
| 484 | + | imlib_context_set_dither(0); | |
| 485 | + | imlib_context_set_anti_alias(0); | |
| 486 | + | imlib_context_set_color_modifier(NULL); | |
| 487 | + | imlib_context_set_operation(IMLIB_OP_COPY); | |
| 488 | + | ||
| 484 | 489 | /* | |
| 485 | 490 | * Imlib2 gives back a "raw frame", we need to blend it on top of the | |
| 486 | 491 | * previous frame ourselves if necessary to get the fully decoded frame. | |
| @@ -505,6 +510,7 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file) | |||
| 505 | 510 | } | |
| 506 | 511 | ||
| 507 | 512 | imlib_context_set_image(frame); | |
| 513 | + | imlib_image_set_changes_on_disk(); /* see img_load() for rationale */ | |
| 508 | 514 | imlib_image_get_frame_info(&finfo); | |
| 509 | 515 | assert(finfo.frame_count == (int)fcnt); | |
| 510 | 516 | assert(finfo.canvas_w == img->w && finfo.canvas_h == img->h); | |
| @@ -537,7 +543,7 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file) | |||
| 537 | 543 | imlib_context_set_blend(!!(finfo.frame_flags & IMLIB_FRAME_BLEND)); | |
| 538 | 544 | imlib_blend_image_onto_image(frame, has_alpha, 0, 0, sw, sh, sx, sy, sw, sh); | |
| 539 | 545 | m->frames[m->cnt].im = canvas; | |
| 540 | − | m->frames[m->cnt].delay = finfo.frame_delay; | |
| 546 | + | m->frames[m->cnt].delay = finfo.frame_delay ? finfo.frame_delay : DEF_ANIM_DELAY; | |
| 541 | 547 | m->length += m->frames[m->cnt].delay; | |
| 542 | 548 | m->cnt++; | |
| 543 | 549 | imlib_context_set_image(frame); | |
| @@ -546,6 +552,7 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file) | |||
| 546 | 552 | imlib_context_set_image(blank); | |
| 547 | 553 | imlib_free_image(); | |
| 548 | 554 | img_multiframe_context_set(img); | |
| 555 | + | imlib_context_set_color_modifier(img->cmod); /* restore cmod */ | |
| 549 | 556 | return m->cnt > 0; | |
| 550 | 557 | } | |
| 551 | 558 | #endif /* HAVE_IMLIB2_MULTI_FRAME */ | |
| @@ -578,6 +585,9 @@ bool img_load(img_t *img, const fileinfo_t *file) | |||
| 578 | 585 | if ((img->im = img_open(file)) == NULL) | |
| 579 | 586 | return false; | |
| 580 | 587 | ||
| 588 | + | /* ensure that the image's timestamp is checked when loading from cache | |
| 589 | + | * to avoid issues like: https://codeberg.org/nsxiv/nsxiv/issues/436 | |
| 590 | + | */ | |
| 581 | 591 | imlib_image_set_changes_on_disk(); | |
| 582 | 592 | ||
| 583 | 593 | /* since v1.7.5, Imlib2 can parse exif orientation from jpeg files. | |
| @@ -673,8 +683,8 @@ static bool img_fit(img_t *img) | |||
| 673 | 683 | if (img->scalemode == SCALE_ZOOM) | |
| 674 | 684 | return false; | |
| 675 | 685 | ||
| 676 | − | zw = (float) img->win->w / (float) img->w; | |
| 677 | − | zh = (float) img->win->h / (float) img->h; | |
| 686 | + | zw = (float)img->win->w / (float)img->w; | |
| 687 | + | zh = (float)img->win->h / (float)img->h; | |
| 678 | 688 | ||
| 679 | 689 | switch (img->scalemode) { | |
| 680 | 690 | case SCALE_FILL: | |
| @@ -692,7 +702,7 @@ static bool img_fit(img_t *img) | |||
| 692 | 702 | } | |
| 693 | 703 | z = MIN(z, img->scalemode == SCALE_DOWN ? 1.0 : ZOOM_MAX); | |
| 694 | 704 | ||
| 695 | − | if (ABS(img->zoom - z) > 1.0/MAX(img->w, img->h)) { | |
| 705 | + | if (ABS(img->zoom - z) > 1.0 / MAX(img->w, img->h)) { | |
| 696 | 706 | img->zoom = z; | |
| 697 | 707 | img->dirty = title_dirty = true; | |
| 698 | 708 | return true; | |
| @@ -838,14 +848,14 @@ bool img_zoom_to(img_t *img, float z) | |||
| 838 | 848 | ||
| 839 | 849 | bool img_zoom(img_t *img, int d) | |
| 840 | 850 | { | |
| 841 | − | int i = d > 0 ? 0 : (int)ARRLEN(zoom_levels)-1; | |
| 851 | + | int i = d > 0 ? 0 : (int)ARRLEN(zoom_levels) - 1; | |
| 842 | 852 | while (i >= 0 && i < (int)ARRLEN(zoom_levels) && | |
| 843 | − | (d > 0 ? zoom_levels[i]/100 <= img->zoom : zoom_levels[i]/100 >= img->zoom)) | |
| 853 | + | (d > 0 ? zoom_levels[i] / 100 <= img->zoom : zoom_levels[i] / 100 >= img->zoom)) | |
| 844 | 854 | { | |
| 845 | 855 | i += d; | |
| 846 | 856 | } | |
| 847 | − | i = MIN(MAX(i, 0), (int)ARRLEN(zoom_levels)-1); | |
| 848 | − | return img_zoom_to(img, zoom_levels[i]/100); | |
| 857 | + | i = MIN(MAX(i, 0), (int)ARRLEN(zoom_levels) - 1); | |
| 858 | + | return img_zoom_to(img, zoom_levels[i] / 100); | |
| 849 | 859 | } | |
| 850 | 860 | ||
| 851 | 861 | bool img_pos(img_t *img, float x, float y) | |
| @@ -882,7 +892,7 @@ bool img_pan(img_t *img, direction_t dir, int d) | |||
| 882 | 892 | float x, y; | |
| 883 | 893 | ||
| 884 | 894 | if (d > 0) { | |
| 885 | − | x = y = MAX(1, (float) d * img->zoom); | |
| 895 | + | x = y = MAX(1, (float)d * img->zoom); | |
| 886 | 896 | } else { | |
| 887 | 897 | x = img->win->w / (d < 0 ? 1 : PAN_FRACTION); | |
| 888 | 898 | y = img->win->h / (d < 0 ? 1 : PAN_FRACTION); | |
| @@ -40,15 +40,16 @@ | |||
| 40 | 40 | #include <X11/XF86keysym.h> | |
| 41 | 41 | #include <X11/keysym.h> | |
| 42 | 42 | ||
| 43 | − | #define MODMASK(mask) ((mask) & USED_MODMASK) | |
| 43 | + | #define MODMASK(mask) (USED_MODMASK & (mask)) | |
| 44 | 44 | #define BAR_SEP " " | |
| 45 | 45 | ||
| 46 | 46 | #define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \ | |
| 47 | 47 | ((t1)->tv_usec - (t2)->tv_usec) / 1000) | |
| 48 | − | #define TV_ADD_MSEC(tv,t) { \ | |
| 49 | − | (tv)->tv_sec += (t) / 1000; \ | |
| 50 | − | (tv)->tv_usec += (t) % 1000 * 1000; \ | |
| 51 | − | } | |
| 48 | + | #define TV_ADD_MSEC(tv, t) \ | |
| 49 | + | do { \ | |
| 50 | + | (tv)->tv_sec += (t) / 1000; \ | |
| 51 | + | (tv)->tv_usec += (t) % 1000 * 1000; \ | |
| 52 | + | } while (0) | |
| 52 | 53 | ||
| 53 | 54 | typedef struct { | |
| 54 | 55 | int err; | |
| @@ -112,8 +113,8 @@ static void cleanup(void) | |||
| 112 | 113 | static bool xgetline(char **lineptr, size_t *n) | |
| 113 | 114 | { | |
| 114 | 115 | ssize_t len = getdelim(lineptr, n, options->using_null ? '\0' : '\n', stdin); | |
| 115 | − | if (!options->using_null && len > 0 && (*lineptr)[len-1] == '\n') | |
| 116 | − | (*lineptr)[len-1] = '\0'; | |
| 116 | + | if (!options->using_null && len > 0 && (*lineptr)[len - 1] == '\n') | |
| 117 | + | (*lineptr)[len - 1] = '\0'; | |
| 117 | 118 | return len > 0; | |
| 118 | 119 | } | |
| 119 | 120 | ||
| @@ -140,7 +141,7 @@ static void check_add_file(const char *filename, bool given) | |||
| 140 | 141 | if (fileidx == filecnt) { | |
| 141 | 142 | filecnt *= 2; | |
| 142 | 143 | files = erealloc(files, filecnt * sizeof(*files)); | |
| 143 | − | memset(&files[filecnt/2], 0, filecnt/2 * sizeof(*files)); | |
| 144 | + | memset(&files[filecnt / 2], 0, filecnt / 2 * sizeof(*files)); | |
| 144 | 145 | } | |
| 145 | 146 | ||
| 146 | 147 | files[fileidx].name = estrdup(filename); | |
| @@ -193,15 +194,15 @@ void remove_file(int n, bool manual) | |||
| 193 | 194 | markcnt--; | |
| 194 | 195 | ||
| 195 | 196 | if (files[n].path != files[n].name) | |
| 196 | − | free((void*) files[n].path); | |
| 197 | − | free((void*) files[n].name); | |
| 197 | + | free((void *)files[n].path); | |
| 198 | + | free((void *)files[n].name); | |
| 198 | 199 | if (tns.thumbs != NULL) | |
| 199 | 200 | tns_unload(&tns, n); | |
| 200 | 201 | ||
| 201 | 202 | if (n + 1 < filecnt) { | |
| 202 | 203 | if (tns.thumbs != NULL) { | |
| 203 | − | memmove(tns.thumbs + n, tns.thumbs + n + 1, (filecnt - n - 1) * | |
| 204 | − | sizeof(*tns.thumbs)); | |
| 204 | + | memmove(tns.thumbs + n, tns.thumbs + n + 1, | |
| 205 | + | (filecnt - n - 1) * sizeof(*tns.thumbs)); | |
| 205 | 206 | memset(tns.thumbs + filecnt - 1, 0, sizeof(*tns.thumbs)); | |
| 206 | 207 | } | |
| 207 | 208 | memmove(files + n, files + n + 1, (filecnt - n - 1) * sizeof(*files)); | |
| @@ -287,7 +288,7 @@ static void read_title(void) | |||
| 287 | 288 | ssize_t n; | |
| 288 | 289 | char buf[512]; | |
| 289 | 290 | ||
| 290 | − | if ((n = read(wintitle.fd, buf, sizeof(buf)-1)) > 0) { | |
| 291 | + | if ((n = read(wintitle.fd, buf, sizeof(buf) - 1)) > 0) { | |
| 291 | 292 | buf[n] = '\0'; | |
| 292 | 293 | win_set_title(&win, buf, n); | |
| 293 | 294 | } | |
| @@ -308,7 +309,7 @@ static void open_title(void) | |||
| 308 | 309 | snprintf(h, ARRLEN(h), "%d", img.h); | |
| 309 | 310 | snprintf(z, ARRLEN(z), "%d", (int)(img.zoom * 100)); | |
| 310 | 311 | } | |
| 311 | − | snprintf(fidx, ARRLEN(fidx), "%d", fileidx+1); | |
| 312 | + | snprintf(fidx, ARRLEN(fidx), "%d", fileidx + 1); | |
| 312 | 313 | snprintf(fcnt, ARRLEN(fcnt), "%d", filecnt); | |
| 313 | 314 | construct_argv(argv, ARRLEN(argv), wintitle.f.cmd, files[fileidx].path, | |
| 314 | 315 | fidx, fcnt, w, h, z, NULL); | |
| @@ -377,7 +378,7 @@ void load_image(int new) | |||
| 377 | 378 | if (new >= filecnt) | |
| 378 | 379 | new = filecnt - 1; | |
| 379 | 380 | else if (new > 0 && prev) | |
| 380 | − | new--; | |
| 381 | + | new -= 1; | |
| 381 | 382 | } | |
| 382 | 383 | files[new].flags &= ~FF_WARN; | |
| 383 | 384 | fileidx = current = new; | |
| @@ -426,18 +427,19 @@ static void update_info(void) | |||
| 426 | 427 | /* update bar contents */ | |
| 427 | 428 | if (win.bar.h == 0 || extprefix) | |
| 428 | 429 | return; | |
| 429 | − | for (fw = 0, i = filecnt; i > 0; fw++, i /= 10); | |
| 430 | + | for (fw = 0, i = filecnt; i > 0; fw++, i /= 10) | |
| 431 | + | ; | |
| 430 | 432 | mark = files[fileidx].flags & FF_MARK ? "* " : ""; | |
| 431 | 433 | l->p = l->buf; | |
| 432 | 434 | r->p = r->buf; | |
| 433 | 435 | if (mode == MODE_THUMB) { | |
| 434 | 436 | if (tns.loadnext < tns.end) | |
| 435 | − | bar_put(l, "Loading... %0*d", fw, tns.loadnext + 1); | |
| 437 | + | bar_put(r, "Loading... %0*d | ", fw, tns.loadnext + 1); | |
| 436 | 438 | else if (tns.initnext < filecnt) | |
| 437 | − | bar_put(l, "Caching... %0*d", fw, tns.initnext + 1); | |
| 438 | − | else if (info.ft.err) | |
| 439 | − | strncpy(l->buf, files[fileidx].name, l->size); | |
| 439 | + | bar_put(r, "Caching... %0*d | ", fw, tns.initnext + 1); | |
| 440 | 440 | bar_put(r, "%s%0*d/%d", mark, fw, fileidx + 1, filecnt); | |
| 441 | + | if (info.ft.err) | |
| 442 | + | strncpy(l->buf, files[fileidx].name, l->size); | |
| 441 | 443 | } else { | |
| 442 | 444 | bar_put(r, "%s", mark); | |
| 443 | 445 | if (img.ss.on) { | |
| @@ -452,9 +454,10 @@ static void update_info(void) | |||
| 452 | 454 | bar_put(r, "B%+d" BAR_SEP, img.brightness); | |
| 453 | 455 | if (img.contrast) | |
| 454 | 456 | bar_put(r, "C%+d" BAR_SEP, img.contrast); | |
| 455 | − | bar_put(r, "%3d%%" BAR_SEP, (int) (img.zoom * 100.0)); | |
| 457 | + | bar_put(r, "%3d%%" BAR_SEP, (int)(img.zoom * 100.0)); | |
| 456 | 458 | if (img.multi.cnt > 0) { | |
| 457 | − | for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10); | |
| 459 | + | for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10) | |
| 460 | + | ; | |
| 458 | 461 | bar_put(r, "%0*d/%d" BAR_SEP, fn, img.multi.sel + 1, img.multi.cnt); | |
| 459 | 462 | } | |
| 460 | 463 | bar_put(r, "%0*d/%d", fw, fileidx + 1, filecnt); | |
| @@ -562,8 +565,9 @@ void handle_key_handler(bool init) | |||
| 562 | 565 | return; | |
| 563 | 566 | if (init) { | |
| 564 | 567 | close_info(); | |
| 565 | − | snprintf(win.bar.l.buf, win.bar.l.size, "Getting key handler input " | |
| 566 | − | "(%s to abort)...", XKeysymToString(KEYHANDLER_ABORT)); | |
| 568 | + | snprintf(win.bar.l.buf, win.bar.l.size, | |
| 569 | + | "Getting key handler input (%s to abort)...", | |
| 570 | + | XKeysymToString(KEYHANDLER_ABORT)); | |
| 567 | 571 | } else { /* abort */ | |
| 568 | 572 | open_info(); | |
| 569 | 573 | update_info(); | |
| @@ -622,7 +626,8 @@ static bool run_key_handler(const char *key, unsigned int mask) | |||
| 622 | 626 | } | |
| 623 | 627 | } | |
| 624 | 628 | fclose(pfs); | |
| 625 | − | while (waitpid(pid, NULL, 0) == -1 && errno == EINTR); | |
| 629 | + | while (waitpid(pid, NULL, 0) == -1 && errno == EINTR) | |
| 630 | + | ; | |
| 626 | 631 | ||
| 627 | 632 | for (f = i = 0; f < fcnt; i++) { | |
| 628 | 633 | if ((marked && (files[i].flags & FF_MARK)) || (!marked && i == fileidx)) { | |
| @@ -639,7 +644,8 @@ static bool run_key_handler(const char *key, unsigned int mask) | |||
| 639 | 644 | } | |
| 640 | 645 | } | |
| 641 | 646 | /* drop user input events that occurred while running the key handler */ | |
| 642 | − | while (XCheckIfEvent(win.env.dpy, &dump, is_input_ev, NULL)); | |
| 647 | + | while (XCheckIfEvent(win.env.dpy, &dump, is_input_ev, NULL)) | |
| 648 | + | ; | |
| 643 | 649 | ||
| 644 | 650 | if (mode == MODE_IMAGE && changed) { | |
| 645 | 651 | img_close(&img, true); | |
| @@ -698,7 +704,7 @@ static void on_keypress(XKeyEvent *kev) | |||
| 698 | 704 | handle_key_handler(false); | |
| 699 | 705 | } else if (key >= '0' && key <= '9') { | |
| 700 | 706 | /* number prefix for commands */ | |
| 701 | − | prefix = prefix * 10 + (int) (key - '0'); | |
| 707 | + | prefix = prefix * 10 + (int)(key - '0'); | |
| 702 | 708 | return; | |
| 703 | 709 | } else { | |
| 704 | 710 | dirty = process_bindings(keys, ARRLEN(keys), ksym, kev->state, sh); | |
| @@ -729,7 +735,7 @@ static void run(void) | |||
| 729 | 735 | enum { FD_X, FD_INFO, FD_TITLE, FD_ARL, FD_CNT }; | |
| 730 | 736 | struct pollfd pfd[FD_CNT]; | |
| 731 | 737 | int timeout = 0; | |
| 732 | − | const struct timespec ten_ms = {0, 10000000}; | |
| 738 | + | const struct timespec ten_ms = { 0, 10000000 }; | |
| 733 | 739 | bool discard, init_thumb, load_thumb, to_set; | |
| 734 | 740 | XEvent ev, nextev; | |
| 735 | 741 | ||
| @@ -739,8 +745,8 @@ static void run(void) | |||
| 739 | 745 | init_thumb = mode == MODE_THUMB && tns.initnext < filecnt; | |
| 740 | 746 | load_thumb = mode == MODE_THUMB && tns.loadnext < tns.end; | |
| 741 | 747 | ||
| 742 | − | if ((init_thumb || load_thumb || to_set || info.fd != -1 || | |
| 743 | − | arl.fd != -1) && XPending(win.env.dpy) == 0) | |
| 748 | + | if ((init_thumb || load_thumb || to_set || info.fd != -1 || arl.fd != -1) && | |
| 749 | + | XPending(win.env.dpy) == 0) | |
| 744 | 750 | { | |
| 745 | 751 | if (load_thumb) { | |
| 746 | 752 | set_timeout(redraw, TO_REDRAW_THUMBS, false); | |
| @@ -793,8 +799,8 @@ static void run(void) | |||
| 793 | 799 | discard = ev.type == nextev.type; | |
| 794 | 800 | break; | |
| 795 | 801 | case KeyPress: | |
| 796 | − | discard = (nextev.type == KeyPress || nextev.type == KeyRelease) | |
| 797 | − | && ev.xkey.keycode == nextev.xkey.keycode; | |
| 802 | + | discard = (nextev.type == KeyPress || nextev.type == KeyRelease) && | |
| 803 | + | ev.xkey.keycode == nextev.xkey.keycode; | |
| 798 | 804 | break; | |
| 799 | 805 | } | |
| 800 | 806 | } | |
| @@ -805,7 +811,7 @@ static void run(void) | |||
| 805 | 811 | on_buttonpress(&ev.xbutton); | |
| 806 | 812 | break; | |
| 807 | 813 | case ClientMessage: | |
| 808 | − | if ((Atom) ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW]) | |
| 814 | + | if ((Atom)ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW]) | |
| 809 | 815 | cg_quit(EXIT_SUCCESS); | |
| 810 | 816 | break; | |
| 811 | 817 | case DestroyNotify: | |
| @@ -858,7 +864,7 @@ int main(int argc, char *argv[]) | |||
| 858 | 864 | size_t n; | |
| 859 | 865 | const char *homedir, *dsuffix = ""; | |
| 860 | 866 | ||
| 861 | − | setup_signal(SIGCHLD, SIG_DFL, SA_RESTART|SA_NOCLDSTOP|SA_NOCLDWAIT); | |
| 867 | + | setup_signal(SIGCHLD, SIG_DFL, SA_RESTART | SA_NOCLDSTOP | SA_NOCLDWAIT); | |
| 862 | 868 | setup_signal(SIGPIPE, SIG_IGN, 0); | |
| 863 | 869 | ||
| 864 | 870 | setlocale(LC_COLLATE, ""); | |
| @@ -20,6 +20,10 @@ | |||
| 20 | 20 | #ifndef NSXIV_H | |
| 21 | 21 | #define NSXIV_H | |
| 22 | 22 | ||
| 23 | + | #if !defined(DEBUG) && !defined(NDEBUG) | |
| 24 | + | #define NDEBUG | |
| 25 | + | #endif | |
| 26 | + | ||
| 23 | 27 | #include <stdbool.h> | |
| 24 | 28 | #include <stddef.h> | |
| 25 | 29 | ||
| @@ -43,7 +43,8 @@ void print_usage(void) | |||
| 43 | 43 | { | |
| 44 | 44 | printf("usage: %s [-abcfhiopqrtvZ0] [-A FRAMERATE] [-e WID] [-G GAMMA] " | |
| 45 | 45 | "[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] " | |
| 46 | − | "[-z ZOOM] FILES...\n", progname); | |
| 46 | + | "[-z ZOOM] FILES...\n", | |
| 47 | + | progname); | |
| 47 | 48 | } | |
| 48 | 49 | ||
| 49 | 50 | static void print_version(void) | |
| @@ -227,7 +228,7 @@ void parse_options(int argc, char **argv) | |||
| 227 | 228 | if (*end != '\0' || n <= 0) | |
| 228 | 229 | error(EXIT_FAILURE, 0, "Invalid zoom level: %s", op.optarg); | |
| 229 | 230 | _options.scalemode = SCALE_ZOOM; | |
| 230 | − | _options.zoom = (float) n / 100.0f; | |
| 231 | + | _options.zoom = (float)n / 100.0f; | |
| 231 | 232 | break; | |
| 232 | 233 | case '0': | |
| 233 | 234 | _options.using_null = true; | |
| @@ -36,7 +36,7 @@ | |||
| 36 | 36 | ||
| 37 | 37 | static char *cache_dir; | |
| 38 | 38 | ||
| 39 | − | static char* tns_cache_filepath(const char *filepath) | |
| 39 | + | static char *tns_cache_filepath(const char *filepath) | |
| 40 | 40 | { | |
| 41 | 41 | size_t len; | |
| 42 | 42 | char *cfile = NULL; | |
| @@ -201,8 +201,8 @@ static Imlib_Image tns_scale_down(Imlib_Image im, int dim) | |||
| 201 | 201 | imlib_context_set_image(im); | |
| 202 | 202 | w = imlib_image_get_width(); | |
| 203 | 203 | h = imlib_image_get_height(); | |
| 204 | − | zw = (float) dim / (float) w; | |
| 205 | − | zh = (float) dim / (float) h; | |
| 204 | + | zw = (float)dim / (float)w; | |
| 205 | + | zh = (float)dim / (float)h; | |
| 206 | 206 | z = MIN(zw, zh); | |
| 207 | 207 | z = MIN(z, 1.0); | |
| 208 | 208 | ||
| @@ -219,7 +219,7 @@ static Imlib_Image tns_scale_down(Imlib_Image im, int dim) | |||
| 219 | 219 | ||
| 220 | 220 | bool tns_load(tns_t *tns, int n, bool force, bool cache_only) | |
| 221 | 221 | { | |
| 222 | − | int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1]; | |
| 222 | + | int maxwh = thumb_sizes[ARRLEN(thumb_sizes) - 1]; | |
| 223 | 223 | bool cache_hit = false; | |
| 224 | 224 | char *cfile; | |
| 225 | 225 | thumb_t *t; | |
| @@ -290,8 +290,8 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only) | |||
| 290 | 290 | h = imlib_image_get_height(); | |
| 291 | 291 | ||
| 292 | 292 | if (pw > w && ph > h && (pw - ph >= 0) == (w - h >= 0)) { | |
| 293 | − | zw = (float) pw / (float) w; | |
| 294 | − | zh = (float) ph / (float) h; | |
| 293 | + | zw = (float)pw / (float)w; | |
| 294 | + | zh = (float)ph / (float)h; | |
| 295 | 295 | if (zw < zh) { | |
| 296 | 296 | pw /= zh; | |
| 297 | 297 | x = (w - pw) / 2; | |
| @@ -343,10 +343,14 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only) | |||
| 343 | 343 | } | |
| 344 | 344 | file->flags |= FF_TN_INIT; | |
| 345 | 345 | ||
| 346 | − | if (n == tns->initnext) | |
| 347 | − | while (++tns->initnext < *tns->cnt && ((++file)->flags & FF_TN_INIT)); | |
| 348 | − | if (n == tns->loadnext && !cache_only) | |
| 349 | − | while (++tns->loadnext < tns->end && (++t)->im != NULL); | |
| 346 | + | if (n == tns->initnext) { | |
| 347 | + | while (++tns->initnext < *tns->cnt && ((++file)->flags & FF_TN_INIT)) | |
| 348 | + | ; | |
| 349 | + | } | |
| 350 | + | if (n == tns->loadnext && !cache_only) { | |
| 351 | + | while (++tns->loadnext < tns->end && (++t)->im != NULL) | |
| 352 | + | ; | |
| 353 | + | } | |
| 350 | 354 | ||
| 351 | 355 | return true; | |
| 352 | 356 | } | |
| @@ -557,7 +561,7 @@ bool tns_zoom(tns_t *tns, int d) | |||
| 557 | 561 | oldzl = tns->zl; | |
| 558 | 562 | tns->zl += -(d < 0) + (d > 0); | |
| 559 | 563 | tns->zl = MAX(tns->zl, 0); | |
| 560 | − | tns->zl = MIN(tns->zl, (int)ARRLEN(thumb_sizes)-1); | |
| 564 | + | tns->zl = MIN(tns->zl, (int)ARRLEN(thumb_sizes) - 1); | |
| 561 | 565 | ||
| 562 | 566 | tns->bw = ((thumb_sizes[tns->zl] - 1) >> 5) + 1; | |
| 563 | 567 | tns->bw = MIN(tns->bw, 4); | |
| @@ -32,7 +32,7 @@ | |||
| 32 | 32 | extern char **environ; | |
| 33 | 33 | const char *progname = "nsxiv"; | |
| 34 | 34 | ||
| 35 | − | void* emalloc(size_t size) | |
| 35 | + | void *emalloc(size_t size) | |
| 36 | 36 | { | |
| 37 | 37 | void *ptr; | |
| 38 | 38 | ||
| @@ -42,7 +42,7 @@ void* emalloc(size_t size) | |||
| 42 | 42 | return ptr; | |
| 43 | 43 | } | |
| 44 | 44 | ||
| 45 | − | void* ecalloc(size_t nmemb, size_t size) | |
| 45 | + | void *ecalloc(size_t nmemb, size_t size) | |
| 46 | 46 | { | |
| 47 | 47 | void *ptr; | |
| 48 | 48 | ||
| @@ -52,7 +52,7 @@ void* ecalloc(size_t nmemb, size_t size) | |||
| 52 | 52 | return ptr; | |
| 53 | 53 | } | |
| 54 | 54 | ||
| 55 | − | void* erealloc(void *ptr, size_t size) | |
| 55 | + | void *erealloc(void *ptr, size_t size) | |
| 56 | 56 | { | |
| 57 | 57 | ptr = realloc(ptr, size); | |
| 58 | 58 | if (ptr == NULL) | |
| @@ -60,13 +60,13 @@ void* erealloc(void *ptr, size_t size) | |||
| 60 | 60 | return ptr; | |
| 61 | 61 | } | |
| 62 | 62 | ||
| 63 | − | char* estrdup(const char *s) | |
| 63 | + | char *estrdup(const char *s) | |
| 64 | 64 | { | |
| 65 | 65 | size_t n = strlen(s) + 1; | |
| 66 | 66 | return memcpy(emalloc(n), s, n); | |
| 67 | 67 | } | |
| 68 | 68 | ||
| 69 | − | void error(int eval, int err, const char* fmt, ...) | |
| 69 | + | void error(int eval, int err, const char *fmt, ...) | |
| 70 | 70 | { | |
| 71 | 71 | va_list ap; | |
| 72 | 72 | ||
| @@ -102,7 +102,7 @@ int r_opendir(r_dir_t *rdir, const char *dirname, bool recursive) | |||
| 102 | 102 | rdir->stack = emalloc(rdir->stcap * sizeof(*rdir->stack)); | |
| 103 | 103 | rdir->stlen = 0; | |
| 104 | 104 | ||
| 105 | − | rdir->name = (char*) dirname; | |
| 105 | + | rdir->name = (char *)dirname; | |
| 106 | 106 | rdir->d = 0; | |
| 107 | 107 | rdir->recursive = recursive; | |
| 108 | 108 | ||
| @@ -133,7 +133,7 @@ int r_closedir(r_dir_t *rdir) | |||
| 133 | 133 | return ret; | |
| 134 | 134 | } | |
| 135 | 135 | ||
| 136 | − | char* r_readdir(r_dir_t *rdir, bool skip_dotfiles) | |
| 136 | + | char *r_readdir(r_dir_t *rdir, bool skip_dotfiles) | |
| 137 | 137 | { | |
| 138 | 138 | size_t len; | |
| 139 | 139 | char *filename; | |
| @@ -154,7 +154,7 @@ char* r_readdir(r_dir_t *rdir, bool skip_dotfiles) | |||
| 154 | 154 | len = strlen(rdir->name) + strlen(dentry->d_name) + 2; | |
| 155 | 155 | filename = emalloc(len); | |
| 156 | 156 | snprintf(filename, len, "%s%s%s", rdir->name, | |
| 157 | − | rdir->name[strlen(rdir->name)-1] == '/' ? "" : "/", | |
| 157 | + | rdir->name[strlen(rdir->name) - 1] == '/' ? "" : "/", | |
| 158 | 158 | dentry->d_name); | |
| 159 | 159 | ||
| 160 | 160 | if (stat(filename, &fstats) < 0) { | |
| @@ -203,7 +203,8 @@ int r_mkdir(char *path) | |||
| 203 | 203 | s++; | |
| 204 | 204 | continue; | |
| 205 | 205 | } | |
| 206 | − | for (; *s != '\0' && *s != '/'; s++); | |
| 206 | + | for (; *s != '\0' && *s != '/'; s++) | |
| 207 | + | ; | |
| 207 | 208 | c = *s; | |
| 208 | 209 | *s = '\0'; | |
| 209 | 210 | if (mkdir(path, 0755) == -1) { | |
| @@ -226,7 +227,7 @@ void construct_argv(char **argv, unsigned int len, ...) | |||
| 226 | 227 | for (i = 0; i < len; ++i) | |
| 227 | 228 | argv[i] = va_arg(args, char *); | |
| 228 | 229 | va_end(args); | |
| 229 | − | assert(argv[len-1] == NULL && "argv should be NULL terminated"); | |
| 230 | + | assert(argv[len - 1] == NULL && "argv should be NULL terminated"); | |
| 230 | 231 | } | |
| 231 | 232 | ||
| 232 | 233 | static int mkspawn_pipe(posix_spawn_file_actions_t *fa, const char *cmd, int *pfd, int dupidx) | |
| @@ -34,7 +34,7 @@ | |||
| 34 | 34 | ||
| 35 | 35 | #if HAVE_LIBFONTS | |
| 36 | 36 | #include "utf8.h" | |
| 37 | − | #define UTF8_PADDING 4 /* utf8_decode requires 4 bytes of zero padding */ | |
| 37 | + | #define UTF8_PADDING 4 /* utf8_decode requires 4 bytes of zero padding */ | |
| 38 | 38 | #define TEXTWIDTH(win, text, len) \ | |
| 39 | 39 | win_draw_text(win, NULL, NULL, 0, 0, text, len, 0) | |
| 40 | 40 | #endif | |
| @@ -56,8 +56,12 @@ static struct { | |||
| 56 | 56 | int name; | |
| 57 | 57 | Cursor icon; | |
| 58 | 58 | } cursors[CURSOR_COUNT] = { | |
| 59 | − | { XC_left_ptr }, { XC_dotbox }, { XC_fleur }, { XC_watch }, | |
| 60 | − | { XC_sb_left_arrow }, { XC_sb_right_arrow } | |
| 59 | + | { XC_left_ptr }, | |
| 60 | + | { XC_dotbox }, | |
| 61 | + | { XC_fleur }, | |
| 62 | + | { XC_watch }, | |
| 63 | + | { XC_sb_left_arrow }, | |
| 64 | + | { XC_sb_right_arrow } | |
| 61 | 65 | }; | |
| 62 | 66 | ||
| 63 | 67 | #if HAVE_LIBFONTS | |
| @@ -90,7 +94,7 @@ static void win_alloc_color(const win_env_t *e, const char *name, XColor *col) | |||
| 90 | 94 | error(EXIT_FAILURE, 0, "Error allocating color '%s'", name); | |
| 91 | 95 | } | |
| 92 | 96 | ||
| 93 | − | static const char* win_res(XrmDatabase db, const char *name, const char *def) | |
| 97 | + | static const char *win_res(XrmDatabase db, const char *name, const char *def) | |
| 94 | 98 | { | |
| 95 | 99 | char *type; | |
| 96 | 100 | XrmValue ret; | |
| @@ -226,8 +230,8 @@ void win_open(win_t *win) | |||
| 226 | 230 | if (gmask & YValue) { | |
| 227 | 231 | if (gmask & YNegative) { | |
| 228 | 232 | win->y += e->scrh - win->h; | |
| 229 | − | sizehints.win_gravity = sizehints.win_gravity == NorthEastGravity | |
| 230 | − | ? SouthEastGravity : SouthWestGravity; | |
| 233 | + | sizehints.win_gravity = sizehints.win_gravity == NorthEastGravity ? | |
| 234 | + | SouthEastGravity : SouthWestGravity; | |
| 231 | 235 | } | |
| 232 | 236 | sizehints.flags |= USPosition; | |
| 233 | 237 | } else { | |
| @@ -246,7 +250,7 @@ void win_open(win_t *win) | |||
| 246 | 250 | /* set the _NET_WM_PID */ | |
| 247 | 251 | pid = getpid(); | |
| 248 | 252 | XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_PID], XA_CARDINAL, | |
| 249 | − | 32, PropModeReplace, (unsigned char *) &pid, 1); | |
| 253 | + | 32, PropModeReplace, (unsigned char *)&pid, 1); | |
| 250 | 254 | if (gethostname(hostname, ARRLEN(hostname)) == 0) { | |
| 251 | 255 | XTextProperty tp; | |
| 252 | 256 | tp.value = (unsigned char *)hostname; | |
| @@ -272,7 +276,7 @@ void win_open(win_t *win) | |||
| 272 | 276 | ||
| 273 | 277 | gc = XCreateGC(e->dpy, win->xwin, 0, None); | |
| 274 | 278 | ||
| 275 | − | n = icons[ARRLEN(icons)-1].size; | |
| 279 | + | n = icons[ARRLEN(icons) - 1].size; | |
| 276 | 280 | icon_data = emalloc((n * n + 2) * sizeof(*icon_data)); | |
| 277 | 281 | ||
| 278 | 282 | for (i = 0; i < (int)ARRLEN(icons); i++) { | |
| @@ -286,7 +290,7 @@ void win_open(win_t *win) | |||
| 286 | 290 | } | |
| 287 | 291 | XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32, | |
| 288 | 292 | i == 0 ? PropModeReplace : PropModeAppend, | |
| 289 | − | (unsigned char *) icon_data, n); | |
| 293 | + | (unsigned char *)icon_data, n); | |
| 290 | 294 | } | |
| 291 | 295 | free(icon_data); | |
| 292 | 296 | ||
| @@ -311,7 +315,7 @@ void win_open(win_t *win) | |||
| 311 | 315 | if (options->fullscreen) { | |
| 312 | 316 | XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_STATE], | |
| 313 | 317 | XA_ATOM, 32, PropModeReplace, | |
| 314 | − | (unsigned char *) &atoms[ATOM__NET_WM_STATE_FULLSCREEN], 1); | |
| 318 | + | (unsigned char *)&atoms[ATOM__NET_WM_STATE_FULLSCREEN], 1); | |
| 315 | 319 | } | |
| 316 | 320 | ||
| 317 | 321 | win->h -= win->bar.h; | |
| @@ -432,10 +436,10 @@ static int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, | |||
| 432 | 436 | FC_SIZE, FcTypeDouble, fontsize, NULL); | |
| 433 | 437 | FcCharSetDestroy(fccharset); | |
| 434 | 438 | } | |
| 435 | − | XftTextExtentsUtf8(win->env.dpy, f, (XftChar8*)t, next - t, &ext); | |
| 439 | + | XftTextExtentsUtf8(win->env.dpy, f, (XftChar8 *)t, next - t, &ext); | |
| 436 | 440 | tw += ext.xOff; | |
| 437 | 441 | if (tw <= w) { | |
| 438 | − | XftDrawStringUtf8(d, color, f, x, y, (XftChar8*)t, next - t); | |
| 442 | + | XftDrawStringUtf8(d, color, f, x, y, (XftChar8 *)t, next - t); | |
| 439 | 443 | x += ext.xOff; | |
| 440 | 444 | } | |
| 441 | 445 | if (f != font) | |
| @@ -456,7 +460,7 @@ static void win_draw_bar(win_t *win) | |||
| 456 | 460 | r = &win->bar.r; | |
| 457 | 461 | assert(l->buf != NULL && r->buf != NULL); | |
| 458 | 462 | y = (win->bar.top ? 0 : win->h) + font->ascent + V_TEXT_PAD; | |
| 459 | − | w = win->w - 2*H_TEXT_PAD; | |
| 463 | + | w = win->w - 2 * H_TEXT_PAD; | |
| 460 | 464 | d = XftDrawCreate(e->dpy, win->buf.pm, e->vis, e->cmap); | |
| 461 | 465 | ||
| 462 | 466 | XSetForeground(e->dpy, gc, win->bar_bg.pixel); | |
| @@ -466,8 +470,10 @@ static void win_draw_bar(win_t *win) | |||
| 466 | 470 | XSetBackground(e->dpy, gc, win->bar_bg.pixel); | |
| 467 | 471 | ||
| 468 | 472 | if ((len = strlen(r->buf)) > 0) { | |
| 469 | − | if ((tw = TEXTWIDTH(win, r->buf, len)) > w) | |
| 473 | + | if ((tw = TEXTWIDTH(win, r->buf, len)) > w) { | |
| 474 | + | XftDrawDestroy(d); | |
| 470 | 475 | return; | |
| 476 | + | } | |
| 471 | 477 | x = win->w - tw - H_TEXT_PAD; | |
| 472 | 478 | w -= tw; | |
| 473 | 479 | win_draw_text(win, d, &win->bar_fg, x, y, r->buf, len, tw); | |
| @@ -482,7 +488,7 @@ static void win_draw_bar(win_t *win) | |||
| 482 | 488 | #else | |
| 483 | 489 | static void win_draw_bar(win_t *win) | |
| 484 | 490 | { | |
| 485 | − | (void) win; | |
| 491 | + | (void)win; | |
| 486 | 492 | } | |
| 487 | 493 | #endif /* HAVE_LIBFONTS */ | |
| 488 | 494 | ||