diff options
author | NRK <nrk@disroot.org> | 2022-08-16 10:53:05 +0200 |
---|---|---|
committer | NRK <nrk@disroot.org> | 2022-08-16 10:53:05 +0200 |
commit | 6578e6eb6533a6651bd88ecae7720aced88c8c2f (patch) | |
tree | 4aed4b6f10e012527c3aaf484826dba9a81b39a5 /window.c | |
parent | 216f312578be5c959527c03ccc70d27eebcc76aa (diff) | |
download | nsxiv-6578e6eb6533a6651bd88ecae7720aced88c8c2f.tar.zst |
code-style: various cleanups (#356)
* run_key_handler: make the logic easier to follow
* remove timeout_t
the typedef is not needed. inline the declaration similar to the other
static structs.
* simplify estrdup
reuse emalloc, instead of calling malloc and null-checking.
* win_clear: initialize `e` right away
* process_bindings: explicitly check against NULL
most pointer checks in the codebase do explicit check.
* use a named constant instead of magic number
also changes the padding from 3 to 4 bytes according to [0]. but i
couldn't find any situtation where this mattered, so perhaps the current
padding is enough. but doesn't hurt adding one more byte.
[0]: https://nullprogram.com/blog/2017/10/06/
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/356
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
Diffstat (limited to 'window.c')
-rw-r--r-- | window.c | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -33,6 +33,7 @@ #if HAVE_LIBFONTS #include "utf8.h" +#define UTF8_PADDING 4 /* utf8_decode requires 4 bytes of zero padding */ static XftFont *font; static double fontsize; #define TEXTWIDTH(win, text, len) \ @@ -112,7 +113,7 @@ void win_init(win_t *win) #if HAVE_LIBFONTS const char *bar_fg, *bar_bg, *f; - static char lbuf[512 + 3], rbuf[64 + 3]; + static char lbuf[512 + UTF8_PADDING], rbuf[64 + UTF8_PADDING]; #endif memset(win, 0, sizeof(win_t)); @@ -153,9 +154,8 @@ void win_init(win_t *win) win->bar.l.buf = lbuf; win->bar.r.buf = rbuf; - /* 3 padding bytes needed by utf8_decode */ - win->bar.l.size = sizeof(lbuf) - 3; - win->bar.r.size = sizeof(rbuf) - 3; + win->bar.l.size = sizeof(lbuf) - UTF8_PADDING; + win->bar.r.size = sizeof(rbuf) - UTF8_PADDING; win->bar.h = options->hide_bar ? 0 : barheight; win->bar.top = TOP_STATUSBAR; #endif /* HAVE_LIBFONTS */ @@ -388,9 +388,7 @@ void win_toggle_bar(win_t *win) void win_clear(win_t *win) { - win_env_t *e; - - e = &win->env; + win_env_t *e = &win->env; if (win->w > win->buf.w || win->h + win->bar.h > win->buf.h) { XFreePixmap(e->dpy, win->buf.pm); |