Krolyxon
Commit 723e140

Branches

Refs →

nsxiv723e140

what the actual fuck?

Author
krolyxon
Date
2023-06-11 21:35 +0530
Parents
e438009 c03ec39
Commit
723e140d5525cdc4572f5b859ec7b66433b5e32b

+281 −261

19 files changed

  1. M .editorconfig +4 −2
  2. M README.md +2 −137
  3. M autoreload.c +13 −7
  4. M commands.c +15 −6
  5. M commands.h +2 −0
  6. M config.h +1 −0
  7. M config.mk +5 −2
  8. A etc/.clang-format +82 −0
  9. M etc/CHANGELOG.md +1 −1
  10. M etc/CONTRIBUTING.md +16 −1
  11. M etc/nsxiv.1 +7 −5
  12. M etc/woodpecker/clang-tidy-checks +1 −0
  13. M image.c +38 −28
  14. M main.c +40 −34
  15. M nsxiv.h +4 −0
  16. M options.c +3 −2
  17. M thumbs.c +15 −11
  18. M util.c +11 −10
  19. M window.c +21 −15
M .editorconfig View
@@ -1,7 +1,9 @@
11 # EditorConfig
2+# See this if your editor doesn't have built-in editorconfig support:
3+# https://editorconfig.org/#download
24
3−# apply to all files
4−[*]
5+# apply to all .c and .h files
6+[*.{c,h}]
57
68 # top-most EditorConfig file
79 root = true
M README.md View
@@ -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
M autoreload.c View
@@ -28,7 +28,10 @@
2828 #include <sys/inotify.h>
2929 #include <unistd.h>
3030
31−static struct { char *buf; size_t len; } scratch;
31+static struct {
32+ char *buf;
33+ size_t len;
34+} scratch;
3235
3336 void arl_init(arl_t *arl)
3437 {
@@ -94,7 +97,10 @@ bool arl_handle(arl_t *arl)
9497 char *ptr;
9598 const struct inotify_event *e;
9699 /* 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;
98104
99105 while (true) {
100106 ssize_t len = read(arl->fd, buf.d, sizeof(buf.d));
@@ -105,7 +111,7 @@ bool arl_handle(arl_t *arl)
105111 break;
106112 }
107113 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;
109115 if (e->wd == arl->wd_file && (e->mask & IN_CLOSE_WRITE)) {
110116 reload = true;
111117 } else if (e->wd == arl->wd_file && (e->mask & IN_DELETE_SELF)) {
@@ -128,18 +134,18 @@ void arl_init(arl_t *arl)
128134
129135 void arl_cleanup(arl_t *arl)
130136 {
131− (void) arl;
137+ (void)arl;
132138 }
133139
134140 void arl_add(arl_t *arl, const char *filepath)
135141 {
136− (void) arl;
137− (void) filepath;
142+ (void)arl;
143+ (void)filepath;
138144 }
139145
140146 bool arl_handle(arl_t *arl)
141147 {
142− (void) arl;
148+ (void)arl;
143149 return false;
144150 }
145151
M commands.c View
@@ -59,6 +59,13 @@ bool cg_quit(arg_t status)
5959 return None; /* silence tcc warning */
6060 }
6161
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+
6269 bool cg_switch_mode(arg_t _)
6370 {
6471 if (mode == MODE_IMAGE) {
@@ -326,10 +333,10 @@ bool ci_drag(arg_t drag_mode)
326333
327334 while (true) {
328335 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);
333340 } else {
334341 px = img.x + x - ox;
335342 py = img.y + y - oy;
@@ -343,7 +350,8 @@ bool ci_drag(arg_t drag_mode)
343350 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e);
344351 if (e.type == ButtonPress || e.type == ButtonRelease)
345352 break;
346− while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e));
353+ while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e))
354+ ;
347355 ox = x;
348356 oy = y;
349357 x = e.xmotion.x;
@@ -443,7 +451,8 @@ bool ct_drag_mark_image(arg_t _)
443451 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e);
444452 if (e.type == ButtonPress || e.type == ButtonRelease)
445453 break;
446− while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e));
454+ while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e))
455+ ;
447456 sel = tns_translate(&tns, e.xbutton.x, e.xbutton.y);
448457 }
449458 }
M commands.h View
@@ -12,6 +12,7 @@ bool cg_n_or_last(arg_t);
1212 bool cg_navigate_marked(arg_t);
1313 bool cg_prefix_external(arg_t);
1414 bool cg_quit(arg_t);
15+bool cg_pick_quit(arg_t);
1516 bool cg_reload_image(arg_t);
1617 bool cg_remove_image(arg_t);
1718 bool cg_reverse_marks(arg_t);
@@ -57,6 +58,7 @@ bool ct_select(arg_t);
5758 #define g_navigate_marked { cg_navigate_marked, MODE_ALL }
5859 #define g_prefix_external { cg_prefix_external, MODE_ALL }
5960 #define g_quit { cg_quit, MODE_ALL }
61+#define g_pick_quit { cg_pick_quit, MODE_ALL }
6062 #define g_reload_image { cg_reload_image, MODE_ALL }
6163 #define g_remove_image { cg_remove_image, MODE_ALL }
6264 #define g_reverse_marks { cg_reverse_marks, MODE_ALL }
M config.h View
@@ -92,6 +92,7 @@ static const KeySym KEYHANDLER_ABORT = XK_Escape;
9292 static const keymap_t keys[] = {
9393 /* modifiers key function argument */
9494 { 0, XK_q, g_quit, 0 },
95+ { 0, XK_Q, g_pick_quit, 0 },
9596 { 0, XK_Return, g_switch_mode, None },
9697 { 0, XK_f, g_toggle_fullscreen, None },
9798 { 0, XK_b, g_toggle_bar, None },
M config.mk View
@@ -23,8 +23,11 @@ HAVE_LIBWEBP = $(OPT_DEP_DEFAULT)
2323
2424 # Compiler and linker
2525 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)
2831
2932 # icons that will be installed via `make icon`
3033 ICONS = 16x16.png 32x32.png 48x48.png 64x64.png 128x128.png
A etc/.clang-format View
@@ -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+...
M etc/CHANGELOG.md View
@@ -116,7 +116,7 @@ references *above* can be found on the new main nsxiv repository on CodeBerg.
116116
117117 * Changes:
118118
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
120120 config.h options are removed. See `WINDOW TITLE` section of the manpage for
121121 more info. [#213]
122122 * Imlib2 cache size is now set based on total memory percentage, by default
M etc/CONTRIBUTING.md View
@@ -23,7 +23,7 @@ Contribution Guideline
2323 When contributing, make sure:
2424
2525 * 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)
2727 * You open the pull request from a new branch, not from master
2828 * To avoid using force pushes, especially for bigger patches. Only use them
2929 when there's merge conflicts.
@@ -44,6 +44,21 @@ to work on. You can also filter the issues via label:
4444 (Intermediate/Experienced) Issues where we require some help.
4545
4646
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+
4762 Development workflow for maintainers
4863 ------------------------------------
4964
M etc/nsxiv.1 View
@@ -135,6 +135,10 @@ Prefix the next command with a number (denoted via
135135 .B q
136136 Quit nsxiv.
137137 .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
138142 .B Return
139143 Switch to thumbnail mode / open selected image in image mode.
140144 .TP
@@ -457,6 +461,9 @@ Color of the bar foreground. Defaults to window.foreground
457461 Color of the mark foreground. Defaults to window.foreground
458462 .TP
459463 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.
460467 .SH WINDOW TITLE
461468 The window title can be replaced with the output of a user-provided script,
462469 which is called by nsxiv whenever any of the relevant information changes.
@@ -562,11 +569,6 @@ TAAPArthur <taaparthur at gmail.com>
562569 eylles <ed.ylles1997 at gmail.com>
563570 Stein Gunnar Bakkeby <bakkeby at gmail.com>
564571 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>
570572 .EE
571573 .SH CONTRIBUTORS
572574 .EX
M etc/woodpecker/clang-tidy-checks View
@@ -9,6 +9,7 @@ misc-*,android-cloexec-*,llvm-include-order
99 -bugprone-implicit-widening-of-multiplication-result,-bugprone-integer-division
1010 -android-cloexec-fopen,-android-cloexec-pipe,-cert-err33-c
1111 -bugprone-assignment-in-if-condition
12+-bugprone-suspicious-realloc-usage
1213
1314 # false positive warnings
1415 -clang-analyzer-valist.Uninitialized
M image.c View
@@ -54,8 +54,12 @@ enum { DEF_GIF_DELAY = 75 };
5454 enum { DEF_WEBP_DELAY = 75 };
5555 #endif
5656
57+#if HAVE_IMLIB2_MULTI_FRAME
58+enum { DEF_ANIM_DELAY = 75 };
59+#endif
60+
5761 #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)
5963
6064 static int calc_cache_size(void)
6165 {
@@ -69,7 +73,7 @@ static int calc_cache_size(void)
6973 #endif
7074 if (pages < 0 || page_size < 0)
7175 return CACHE_SIZE_FALLBACK;
72− cache = (pages/100) * CACHE_SIZE_MEM_PERCENTAGE;
76+ cache = (pages / 100) * CACHE_SIZE_MEM_PERCENTAGE;
7377 cache *= page_size;
7478
7579 return MIN(cache, CACHE_SIZE_LIMIT);
@@ -234,12 +238,12 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file)
234238 while (ext) {
235239 if (ext_code == GRAPHICS_EXT_FUNC_CODE) {
236240 if (ext[1] & 1)
237− transp = (int) ext[4];
241+ transp = (int)ext[4];
238242 else
239243 transp = -1;
240244
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;
243247 }
244248 ext = NULL;
245249 DGifGetExtensionNext(gif, &ext);
@@ -280,10 +284,11 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file)
280284 for (i = 0; i < sh; i++) {
281285 for (j = 0; j < sw; j++) {
282286 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)
284288 {
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))
287292 {
288293 *ptr = prev_frame[i * sw + j];
289294 } else {
@@ -291,9 +296,9 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file)
291296 }
292297 } else {
293298 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;
297302 *ptr = 0xffu << 24 | r << 16 | g << 8 | b;
298303 }
299304 ptr++;
@@ -412,12 +417,12 @@ static bool img_load_webp(img_t *img, const fileinfo_t *file)
412417 /* Load and decode frames (also works on images with only 1 frame) */
413418 m->length = m->cnt = m->sel = 0;
414419 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);
417422 imlib_context_set_image(im);
418423 imlib_image_set_format("webp");
419424 /* 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);
421426 imlib_image_set_has_alpha((flags & ALPHA_FLAG) == ALPHA_FLAG);
422427 /* Store info for this frame */
423428 m->frames[m->cnt].im = im;
@@ -469,11 +474,6 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file)
469474 m->frames = erealloc(m->frames, m->cap * sizeof(*m->frames));
470475 }
471476
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−
477477 if ((blank = imlib_create_image(img->w, img->h)) == NULL) {
478478 error(0, 0, "%s: couldn't create image", file->name);
479479 return false;
@@ -481,6 +481,11 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file)
481481 imlib_context_set_image(blank);
482482 img_area_clear(0, 0, img->w, img->h);
483483
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+
484489 /*
485490 * Imlib2 gives back a "raw frame", we need to blend it on top of the
486491 * 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)
505510 }
506511
507512 imlib_context_set_image(frame);
513+ imlib_image_set_changes_on_disk(); /* see img_load() for rationale */
508514 imlib_image_get_frame_info(&finfo);
509515 assert(finfo.frame_count == (int)fcnt);
510516 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)
537543 imlib_context_set_blend(!!(finfo.frame_flags & IMLIB_FRAME_BLEND));
538544 imlib_blend_image_onto_image(frame, has_alpha, 0, 0, sw, sh, sx, sy, sw, sh);
539545 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;
541547 m->length += m->frames[m->cnt].delay;
542548 m->cnt++;
543549 imlib_context_set_image(frame);
@@ -546,6 +552,7 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file)
546552 imlib_context_set_image(blank);
547553 imlib_free_image();
548554 img_multiframe_context_set(img);
555+ imlib_context_set_color_modifier(img->cmod); /* restore cmod */
549556 return m->cnt > 0;
550557 }
551558 #endif /* HAVE_IMLIB2_MULTI_FRAME */
@@ -578,6 +585,9 @@ bool img_load(img_t *img, const fileinfo_t *file)
578585 if ((img->im = img_open(file)) == NULL)
579586 return false;
580587
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+ */
581591 imlib_image_set_changes_on_disk();
582592
583593 /* since v1.7.5, Imlib2 can parse exif orientation from jpeg files.
@@ -673,8 +683,8 @@ static bool img_fit(img_t *img)
673683 if (img->scalemode == SCALE_ZOOM)
674684 return false;
675685
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;
678688
679689 switch (img->scalemode) {
680690 case SCALE_FILL:
@@ -692,7 +702,7 @@ static bool img_fit(img_t *img)
692702 }
693703 z = MIN(z, img->scalemode == SCALE_DOWN ? 1.0 : ZOOM_MAX);
694704
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)) {
696706 img->zoom = z;
697707 img->dirty = title_dirty = true;
698708 return true;
@@ -838,14 +848,14 @@ bool img_zoom_to(img_t *img, float z)
838848
839849 bool img_zoom(img_t *img, int d)
840850 {
841− int i = d > 0 ? 0 : (int)ARRLEN(zoom_levels)-1;
851+ int i = d > 0 ? 0 : (int)ARRLEN(zoom_levels) - 1;
842852 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))
844854 {
845855 i += d;
846856 }
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);
849859 }
850860
851861 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)
882892 float x, y;
883893
884894 if (d > 0) {
885− x = y = MAX(1, (float) d * img->zoom);
895+ x = y = MAX(1, (float)d * img->zoom);
886896 } else {
887897 x = img->win->w / (d < 0 ? 1 : PAN_FRACTION);
888898 y = img->win->h / (d < 0 ? 1 : PAN_FRACTION);
M main.c View
@@ -40,15 +40,16 @@
4040 #include <X11/XF86keysym.h>
4141 #include <X11/keysym.h>
4242
43−#define MODMASK(mask) ((mask) & USED_MODMASK)
43+#define MODMASK(mask) (USED_MODMASK & (mask))
4444 #define BAR_SEP " "
4545
4646 #define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
4747 ((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)
5253
5354 typedef struct {
5455 int err;
@@ -112,8 +113,8 @@ static void cleanup(void)
112113 static bool xgetline(char **lineptr, size_t *n)
113114 {
114115 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';
117118 return len > 0;
118119 }
119120
@@ -140,7 +141,7 @@ static void check_add_file(const char *filename, bool given)
140141 if (fileidx == filecnt) {
141142 filecnt *= 2;
142143 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));
144145 }
145146
146147 files[fileidx].name = estrdup(filename);
@@ -193,15 +194,15 @@ void remove_file(int n, bool manual)
193194 markcnt--;
194195
195196 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);
198199 if (tns.thumbs != NULL)
199200 tns_unload(&tns, n);
200201
201202 if (n + 1 < filecnt) {
202203 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));
205206 memset(tns.thumbs + filecnt - 1, 0, sizeof(*tns.thumbs));
206207 }
207208 memmove(files + n, files + n + 1, (filecnt - n - 1) * sizeof(*files));
@@ -287,7 +288,7 @@ static void read_title(void)
287288 ssize_t n;
288289 char buf[512];
289290
290− if ((n = read(wintitle.fd, buf, sizeof(buf)-1)) > 0) {
291+ if ((n = read(wintitle.fd, buf, sizeof(buf) - 1)) > 0) {
291292 buf[n] = '\0';
292293 win_set_title(&win, buf, n);
293294 }
@@ -308,7 +309,7 @@ static void open_title(void)
308309 snprintf(h, ARRLEN(h), "%d", img.h);
309310 snprintf(z, ARRLEN(z), "%d", (int)(img.zoom * 100));
310311 }
311− snprintf(fidx, ARRLEN(fidx), "%d", fileidx+1);
312+ snprintf(fidx, ARRLEN(fidx), "%d", fileidx + 1);
312313 snprintf(fcnt, ARRLEN(fcnt), "%d", filecnt);
313314 construct_argv(argv, ARRLEN(argv), wintitle.f.cmd, files[fileidx].path,
314315 fidx, fcnt, w, h, z, NULL);
@@ -377,7 +378,7 @@ void load_image(int new)
377378 if (new >= filecnt)
378379 new = filecnt - 1;
379380 else if (new > 0 && prev)
380− new--;
381+ new -= 1;
381382 }
382383 files[new].flags &= ~FF_WARN;
383384 fileidx = current = new;
@@ -426,18 +427,19 @@ static void update_info(void)
426427 /* update bar contents */
427428 if (win.bar.h == 0 || extprefix)
428429 return;
429− for (fw = 0, i = filecnt; i > 0; fw++, i /= 10);
430+ for (fw = 0, i = filecnt; i > 0; fw++, i /= 10)
431+ ;
430432 mark = files[fileidx].flags & FF_MARK ? "* " : "";
431433 l->p = l->buf;
432434 r->p = r->buf;
433435 if (mode == MODE_THUMB) {
434436 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);
436438 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);
440440 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);
441443 } else {
442444 bar_put(r, "%s", mark);
443445 if (img.ss.on) {
@@ -452,9 +454,10 @@ static void update_info(void)
452454 bar_put(r, "B%+d" BAR_SEP, img.brightness);
453455 if (img.contrast)
454456 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));
456458 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+ ;
458461 bar_put(r, "%0*d/%d" BAR_SEP, fn, img.multi.sel + 1, img.multi.cnt);
459462 }
460463 bar_put(r, "%0*d/%d", fw, fileidx + 1, filecnt);
@@ -562,8 +565,9 @@ void handle_key_handler(bool init)
562565 return;
563566 if (init) {
564567 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));
567571 } else { /* abort */
568572 open_info();
569573 update_info();
@@ -622,7 +626,8 @@ static bool run_key_handler(const char *key, unsigned int mask)
622626 }
623627 }
624628 fclose(pfs);
625− while (waitpid(pid, NULL, 0) == -1 && errno == EINTR);
629+ while (waitpid(pid, NULL, 0) == -1 && errno == EINTR)
630+ ;
626631
627632 for (f = i = 0; f < fcnt; i++) {
628633 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)
639644 }
640645 }
641646 /* 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+ ;
643649
644650 if (mode == MODE_IMAGE && changed) {
645651 img_close(&img, true);
@@ -698,7 +704,7 @@ static void on_keypress(XKeyEvent *kev)
698704 handle_key_handler(false);
699705 } else if (key >= '0' && key <= '9') {
700706 /* number prefix for commands */
701− prefix = prefix * 10 + (int) (key - '0');
707+ prefix = prefix * 10 + (int)(key - '0');
702708 return;
703709 } else {
704710 dirty = process_bindings(keys, ARRLEN(keys), ksym, kev->state, sh);
@@ -729,7 +735,7 @@ static void run(void)
729735 enum { FD_X, FD_INFO, FD_TITLE, FD_ARL, FD_CNT };
730736 struct pollfd pfd[FD_CNT];
731737 int timeout = 0;
732− const struct timespec ten_ms = {0, 10000000};
738+ const struct timespec ten_ms = { 0, 10000000 };
733739 bool discard, init_thumb, load_thumb, to_set;
734740 XEvent ev, nextev;
735741
@@ -739,8 +745,8 @@ static void run(void)
739745 init_thumb = mode == MODE_THUMB && tns.initnext < filecnt;
740746 load_thumb = mode == MODE_THUMB && tns.loadnext < tns.end;
741747
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)
744750 {
745751 if (load_thumb) {
746752 set_timeout(redraw, TO_REDRAW_THUMBS, false);
@@ -793,8 +799,8 @@ static void run(void)
793799 discard = ev.type == nextev.type;
794800 break;
795801 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;
798804 break;
799805 }
800806 }
@@ -805,7 +811,7 @@ static void run(void)
805811 on_buttonpress(&ev.xbutton);
806812 break;
807813 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])
809815 cg_quit(EXIT_SUCCESS);
810816 break;
811817 case DestroyNotify:
@@ -858,7 +864,7 @@ int main(int argc, char *argv[])
858864 size_t n;
859865 const char *homedir, *dsuffix = "";
860866
861− setup_signal(SIGCHLD, SIG_DFL, SA_RESTART|SA_NOCLDSTOP|SA_NOCLDWAIT);
867+ setup_signal(SIGCHLD, SIG_DFL, SA_RESTART | SA_NOCLDSTOP | SA_NOCLDWAIT);
862868 setup_signal(SIGPIPE, SIG_IGN, 0);
863869
864870 setlocale(LC_COLLATE, "");
M nsxiv.h View
@@ -20,6 +20,10 @@
2020 #ifndef NSXIV_H
2121 #define NSXIV_H
2222
23+#if !defined(DEBUG) && !defined(NDEBUG)
24+ #define NDEBUG
25+#endif
26+
2327 #include <stdbool.h>
2428 #include <stddef.h>
2529
M options.c View
@@ -43,7 +43,8 @@ void print_usage(void)
4343 {
4444 printf("usage: %s [-abcfhiopqrtvZ0] [-A FRAMERATE] [-e WID] [-G GAMMA] "
4545 "[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] "
46− "[-z ZOOM] FILES...\n", progname);
46+ "[-z ZOOM] FILES...\n",
47+ progname);
4748 }
4849
4950 static void print_version(void)
@@ -227,7 +228,7 @@ void parse_options(int argc, char **argv)
227228 if (*end != '\0' || n <= 0)
228229 error(EXIT_FAILURE, 0, "Invalid zoom level: %s", op.optarg);
229230 _options.scalemode = SCALE_ZOOM;
230− _options.zoom = (float) n / 100.0f;
231+ _options.zoom = (float)n / 100.0f;
231232 break;
232233 case '0':
233234 _options.using_null = true;
M thumbs.c View
@@ -36,7 +36,7 @@
3636
3737 static char *cache_dir;
3838
39−static char* tns_cache_filepath(const char *filepath)
39+static char *tns_cache_filepath(const char *filepath)
4040 {
4141 size_t len;
4242 char *cfile = NULL;
@@ -201,8 +201,8 @@ static Imlib_Image tns_scale_down(Imlib_Image im, int dim)
201201 imlib_context_set_image(im);
202202 w = imlib_image_get_width();
203203 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;
206206 z = MIN(zw, zh);
207207 z = MIN(z, 1.0);
208208
@@ -219,7 +219,7 @@ static Imlib_Image tns_scale_down(Imlib_Image im, int dim)
219219
220220 bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
221221 {
222− int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1];
222+ int maxwh = thumb_sizes[ARRLEN(thumb_sizes) - 1];
223223 bool cache_hit = false;
224224 char *cfile;
225225 thumb_t *t;
@@ -290,8 +290,8 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
290290 h = imlib_image_get_height();
291291
292292 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;
295295 if (zw < zh) {
296296 pw /= zh;
297297 x = (w - pw) / 2;
@@ -343,10 +343,14 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
343343 }
344344 file->flags |= FF_TN_INIT;
345345
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+ }
350354
351355 return true;
352356 }
@@ -557,7 +561,7 @@ bool tns_zoom(tns_t *tns, int d)
557561 oldzl = tns->zl;
558562 tns->zl += -(d < 0) + (d > 0);
559563 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);
561565
562566 tns->bw = ((thumb_sizes[tns->zl] - 1) >> 5) + 1;
563567 tns->bw = MIN(tns->bw, 4);
M util.c View
@@ -32,7 +32,7 @@
3232 extern char **environ;
3333 const char *progname = "nsxiv";
3434
35−void* emalloc(size_t size)
35+void *emalloc(size_t size)
3636 {
3737 void *ptr;
3838
@@ -42,7 +42,7 @@ void* emalloc(size_t size)
4242 return ptr;
4343 }
4444
45−void* ecalloc(size_t nmemb, size_t size)
45+void *ecalloc(size_t nmemb, size_t size)
4646 {
4747 void *ptr;
4848
@@ -52,7 +52,7 @@ void* ecalloc(size_t nmemb, size_t size)
5252 return ptr;
5353 }
5454
55−void* erealloc(void *ptr, size_t size)
55+void *erealloc(void *ptr, size_t size)
5656 {
5757 ptr = realloc(ptr, size);
5858 if (ptr == NULL)
@@ -60,13 +60,13 @@ void* erealloc(void *ptr, size_t size)
6060 return ptr;
6161 }
6262
63−char* estrdup(const char *s)
63+char *estrdup(const char *s)
6464 {
6565 size_t n = strlen(s) + 1;
6666 return memcpy(emalloc(n), s, n);
6767 }
6868
69−void error(int eval, int err, const char* fmt, ...)
69+void error(int eval, int err, const char *fmt, ...)
7070 {
7171 va_list ap;
7272
@@ -102,7 +102,7 @@ int r_opendir(r_dir_t *rdir, const char *dirname, bool recursive)
102102 rdir->stack = emalloc(rdir->stcap * sizeof(*rdir->stack));
103103 rdir->stlen = 0;
104104
105− rdir->name = (char*) dirname;
105+ rdir->name = (char *)dirname;
106106 rdir->d = 0;
107107 rdir->recursive = recursive;
108108
@@ -133,7 +133,7 @@ int r_closedir(r_dir_t *rdir)
133133 return ret;
134134 }
135135
136−char* r_readdir(r_dir_t *rdir, bool skip_dotfiles)
136+char *r_readdir(r_dir_t *rdir, bool skip_dotfiles)
137137 {
138138 size_t len;
139139 char *filename;
@@ -154,7 +154,7 @@ char* r_readdir(r_dir_t *rdir, bool skip_dotfiles)
154154 len = strlen(rdir->name) + strlen(dentry->d_name) + 2;
155155 filename = emalloc(len);
156156 snprintf(filename, len, "%s%s%s", rdir->name,
157− rdir->name[strlen(rdir->name)-1] == '/' ? "" : "/",
157+ rdir->name[strlen(rdir->name) - 1] == '/' ? "" : "/",
158158 dentry->d_name);
159159
160160 if (stat(filename, &fstats) < 0) {
@@ -203,7 +203,8 @@ int r_mkdir(char *path)
203203 s++;
204204 continue;
205205 }
206− for (; *s != '\0' && *s != '/'; s++);
206+ for (; *s != '\0' && *s != '/'; s++)
207+ ;
207208 c = *s;
208209 *s = '\0';
209210 if (mkdir(path, 0755) == -1) {
@@ -226,7 +227,7 @@ void construct_argv(char **argv, unsigned int len, ...)
226227 for (i = 0; i < len; ++i)
227228 argv[i] = va_arg(args, char *);
228229 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");
230231 }
231232
232233 static int mkspawn_pipe(posix_spawn_file_actions_t *fa, const char *cmd, int *pfd, int dupidx)
M window.c View
@@ -34,7 +34,7 @@
3434
3535 #if HAVE_LIBFONTS
3636 #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 */
3838 #define TEXTWIDTH(win, text, len) \
3939 win_draw_text(win, NULL, NULL, 0, 0, text, len, 0)
4040 #endif
@@ -56,8 +56,12 @@ static struct {
5656 int name;
5757 Cursor icon;
5858 } 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 }
6165 };
6266
6367 #if HAVE_LIBFONTS
@@ -90,7 +94,7 @@ static void win_alloc_color(const win_env_t *e, const char *name, XColor *col)
9094 error(EXIT_FAILURE, 0, "Error allocating color '%s'", name);
9195 }
9296
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)
9498 {
9599 char *type;
96100 XrmValue ret;
@@ -226,8 +230,8 @@ void win_open(win_t *win)
226230 if (gmask & YValue) {
227231 if (gmask & YNegative) {
228232 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;
231235 }
232236 sizehints.flags |= USPosition;
233237 } else {
@@ -246,7 +250,7 @@ void win_open(win_t *win)
246250 /* set the _NET_WM_PID */
247251 pid = getpid();
248252 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);
250254 if (gethostname(hostname, ARRLEN(hostname)) == 0) {
251255 XTextProperty tp;
252256 tp.value = (unsigned char *)hostname;
@@ -272,7 +276,7 @@ void win_open(win_t *win)
272276
273277 gc = XCreateGC(e->dpy, win->xwin, 0, None);
274278
275− n = icons[ARRLEN(icons)-1].size;
279+ n = icons[ARRLEN(icons) - 1].size;
276280 icon_data = emalloc((n * n + 2) * sizeof(*icon_data));
277281
278282 for (i = 0; i < (int)ARRLEN(icons); i++) {
@@ -286,7 +290,7 @@ void win_open(win_t *win)
286290 }
287291 XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32,
288292 i == 0 ? PropModeReplace : PropModeAppend,
289− (unsigned char *) icon_data, n);
293+ (unsigned char *)icon_data, n);
290294 }
291295 free(icon_data);
292296
@@ -311,7 +315,7 @@ void win_open(win_t *win)
311315 if (options->fullscreen) {
312316 XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_STATE],
313317 XA_ATOM, 32, PropModeReplace,
314− (unsigned char *) &atoms[ATOM__NET_WM_STATE_FULLSCREEN], 1);
318+ (unsigned char *)&atoms[ATOM__NET_WM_STATE_FULLSCREEN], 1);
315319 }
316320
317321 win->h -= win->bar.h;
@@ -432,10 +436,10 @@ static int win_draw_text(win_t *win, XftDraw *d, const XftColor *color,
432436 FC_SIZE, FcTypeDouble, fontsize, NULL);
433437 FcCharSetDestroy(fccharset);
434438 }
435− XftTextExtentsUtf8(win->env.dpy, f, (XftChar8*)t, next - t, &ext);
439+ XftTextExtentsUtf8(win->env.dpy, f, (XftChar8 *)t, next - t, &ext);
436440 tw += ext.xOff;
437441 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);
439443 x += ext.xOff;
440444 }
441445 if (f != font)
@@ -456,7 +460,7 @@ static void win_draw_bar(win_t *win)
456460 r = &win->bar.r;
457461 assert(l->buf != NULL && r->buf != NULL);
458462 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;
460464 d = XftDrawCreate(e->dpy, win->buf.pm, e->vis, e->cmap);
461465
462466 XSetForeground(e->dpy, gc, win->bar_bg.pixel);
@@ -466,8 +470,10 @@ static void win_draw_bar(win_t *win)
466470 XSetBackground(e->dpy, gc, win->bar_bg.pixel);
467471
468472 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);
470475 return;
476+ }
471477 x = win->w - tw - H_TEXT_PAD;
472478 w -= tw;
473479 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)
482488 #else
483489 static void win_draw_bar(win_t *win)
484490 {
485− (void) win;
491+ (void)win;
486492 }
487493 #endif /* HAVE_LIBFONTS */
488494