From 2434e83807360bfe43e3c404be12438f00a894ab Mon Sep 17 00:00:00 2001 From: NRK Date: Sat, 2 Jul 2022 21:06:24 +0600 Subject: make some changes prepping for clang-format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Berke Kocaoğlu --- image.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'image.c') diff --git a/image.c b/image.c index cded0fe..2f5d697 100644 --- a/image.c +++ b/image.c @@ -282,8 +282,9 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) if (i < y || i >= y + h || j < x || j >= x + w || rows[i-y][j-x] == transp) { - if (prev_frame != NULL && (prev_disposal != 2 || - i < py || i >= py + ph || j < px || j >= px + pw)) + if (prev_frame != NULL && + (prev_disposal != 2 || i < py || i >= py + ph || + j < px || j >= px + pw)) { *ptr = prev_frame[i * sw + j]; } else { @@ -412,8 +413,8 @@ static bool img_load_webp(img_t *img, const fileinfo_t *file) /* Load and decode frames (also works on images with only 1 frame) */ m->length = m->cnt = m->sel = 0; while (WebPAnimDecoderGetNext(dec, &buf, &ts)) { - im = imlib_create_image_using_copied_data( - info.canvas_width, info.canvas_height, (uint32_t *)buf); + im = imlib_create_image_using_copied_data(info.canvas_width, info.canvas_height, + (uint32_t *)buf); imlib_context_set_image(im); imlib_image_set_format("webp"); /* Get an iterator of this frame - used for frame info (duration, etc.) */ -- cgit v1.2.3 From f2f4903de4bd3ce06c03dd66f0c9a7dda97a3550 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 10 Feb 2023 11:35:53 +0600 Subject: apply clang-format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit minus the bogus changes Co-authored-by: Berke Kocaoğlu --- autoreload.c | 20 +++++++++++++------- commands.c | 14 ++++++++------ image.c | 36 ++++++++++++++++++------------------ main.c | 47 ++++++++++++++++++++++++++--------------------- options.c | 5 +++-- thumbs.c | 26 +++++++++++++++----------- util.c | 21 +++++++++++---------- window.c | 28 ++++++++++++++++------------ 8 files changed, 110 insertions(+), 87 deletions(-) (limited to 'image.c') diff --git a/autoreload.c b/autoreload.c index 1c2fbf7..8b3f6da 100644 --- a/autoreload.c +++ b/autoreload.c @@ -28,7 +28,10 @@ #include #include -static struct { char *buf; size_t len; } scratch; +static struct { + char *buf; + size_t len; +} scratch; void arl_init(arl_t *arl) { @@ -94,7 +97,10 @@ bool arl_handle(arl_t *arl) char *ptr; const struct inotify_event *e; /* inotify_event aligned buffer */ - static union { char d[4096]; struct inotify_event e; } buf; + static union { + char d[4096]; + struct inotify_event e; + } buf; while (true) { ssize_t len = read(arl->fd, buf.d, sizeof(buf.d)); @@ -105,7 +111,7 @@ bool arl_handle(arl_t *arl) break; } for (ptr = buf.d; ptr < buf.d + len; ptr += sizeof(*e) + e->len) { - e = (const struct inotify_event*) ptr; + e = (const struct inotify_event *)ptr; if (e->wd == arl->wd_file && (e->mask & IN_CLOSE_WRITE)) { reload = true; } else if (e->wd == arl->wd_file && (e->mask & IN_DELETE_SELF)) { @@ -128,18 +134,18 @@ void arl_init(arl_t *arl) void arl_cleanup(arl_t *arl) { - (void) arl; + (void)arl; } void arl_add(arl_t *arl, const char *filepath) { - (void) arl; - (void) filepath; + (void)arl; + (void)filepath; } bool arl_handle(arl_t *arl) { - (void) arl; + (void)arl; return false; } diff --git a/commands.c b/commands.c index db1cb09..7c44ace 100644 --- a/commands.c +++ b/commands.c @@ -326,10 +326,10 @@ bool ci_drag(arg_t drag_mode) while (true) { if (drag_mode == DRAG_ABSOLUTE) { - px = MIN(MAX(0.0, x - win.w*0.1), win.w*0.8) / - (win.w*0.8) * (win.w - img.w * img.zoom); - py = MIN(MAX(0.0, y - win.h*0.1), win.h*0.8) / - (win.h*0.8) * (win.h - img.h * img.zoom); + px = MIN(MAX(0.0, x - win.w * 0.1), win.w * 0.8) / + (win.w * 0.8) * (win.w - img.w * img.zoom); + py = MIN(MAX(0.0, y - win.h * 0.1), win.h * 0.8) / + (win.h * 0.8) * (win.h - img.h * img.zoom); } else { px = img.x + x - ox; py = img.y + y - oy; @@ -343,7 +343,8 @@ bool ci_drag(arg_t drag_mode) ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e); if (e.type == ButtonPress || e.type == ButtonRelease) break; - while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e)); + while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e)) + ; ox = x; oy = y; x = e.xmotion.x; @@ -443,7 +444,8 @@ bool ct_drag_mark_image(arg_t _) ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e); if (e.type == ButtonPress || e.type == ButtonRelease) break; - while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e)); + while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e)) + ; sel = tns_translate(&tns, e.xbutton.x, e.xbutton.y); } } diff --git a/image.c b/image.c index 2f5d697..42979c7 100644 --- a/image.c +++ b/image.c @@ -55,7 +55,7 @@ enum { DEF_WEBP_DELAY = 75 }; #endif #define ZOOM_MIN (zoom_levels[0] / 100) -#define ZOOM_MAX (zoom_levels[ARRLEN(zoom_levels)-1] / 100) +#define ZOOM_MAX (zoom_levels[ARRLEN(zoom_levels) - 1] / 100) static int calc_cache_size(void) { @@ -69,7 +69,7 @@ static int calc_cache_size(void) #endif if (pages < 0 || page_size < 0) return CACHE_SIZE_FALLBACK; - cache = (pages/100) * CACHE_SIZE_MEM_PERCENTAGE; + cache = (pages / 100) * CACHE_SIZE_MEM_PERCENTAGE; cache *= page_size; return MIN(cache, CACHE_SIZE_LIMIT); @@ -234,12 +234,12 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) while (ext) { if (ext_code == GRAPHICS_EXT_FUNC_CODE) { if (ext[1] & 1) - transp = (int) ext[4]; + transp = (int)ext[4]; else transp = -1; - delay = 10 * ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]); - disposal = (unsigned int) ext[1] >> 2 & 0x7; + delay = 10 * ((unsigned int)ext[3] << 8 | (unsigned int)ext[2]); + disposal = (unsigned int)ext[1] >> 2 & 0x7; } ext = NULL; DGifGetExtensionNext(gif, &ext); @@ -280,7 +280,7 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) for (i = 0; i < sh; i++) { for (j = 0; j < sw; j++) { if (i < y || i >= y + h || j < x || j >= x + w || - rows[i-y][j-x] == transp) + rows[i - y][j - x] == transp) { if (prev_frame != NULL && (prev_disposal != 2 || i < py || i >= py + ph || @@ -292,9 +292,9 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file) } } else { assert(cmap != NULL); - r = cmap->Colors[rows[i-y][j-x]].Red; - g = cmap->Colors[rows[i-y][j-x]].Green; - b = cmap->Colors[rows[i-y][j-x]].Blue; + r = cmap->Colors[rows[i - y][j - x]].Red; + g = cmap->Colors[rows[i - y][j - x]].Green; + b = cmap->Colors[rows[i - y][j - x]].Blue; *ptr = 0xffu << 24 | r << 16 | g << 8 | b; } ptr++; @@ -418,7 +418,7 @@ static bool img_load_webp(img_t *img, const fileinfo_t *file) imlib_context_set_image(im); imlib_image_set_format("webp"); /* Get an iterator of this frame - used for frame info (duration, etc.) */ - WebPDemuxGetFrame(demux, m->cnt+1, &iter); + WebPDemuxGetFrame(demux, m->cnt + 1, &iter); imlib_image_set_has_alpha((flags & ALPHA_FLAG) == ALPHA_FLAG); /* Store info for this frame */ m->frames[m->cnt].im = im; @@ -674,8 +674,8 @@ static bool img_fit(img_t *img) if (img->scalemode == SCALE_ZOOM) return false; - zw = (float) img->win->w / (float) img->w; - zh = (float) img->win->h / (float) img->h; + zw = (float)img->win->w / (float)img->w; + zh = (float)img->win->h / (float)img->h; switch (img->scalemode) { case SCALE_FILL: @@ -693,7 +693,7 @@ static bool img_fit(img_t *img) } z = MIN(z, img->scalemode == SCALE_DOWN ? 1.0 : ZOOM_MAX); - if (ABS(img->zoom - z) > 1.0/MAX(img->w, img->h)) { + if (ABS(img->zoom - z) > 1.0 / MAX(img->w, img->h)) { img->zoom = z; img->dirty = title_dirty = true; return true; @@ -839,14 +839,14 @@ bool img_zoom_to(img_t *img, float z) bool img_zoom(img_t *img, int d) { - int i = d > 0 ? 0 : (int)ARRLEN(zoom_levels)-1; + int i = d > 0 ? 0 : (int)ARRLEN(zoom_levels) - 1; while (i >= 0 && i < (int)ARRLEN(zoom_levels) && - (d > 0 ? zoom_levels[i]/100 <= img->zoom : zoom_levels[i]/100 >= img->zoom)) + (d > 0 ? zoom_levels[i] / 100 <= img->zoom : zoom_levels[i] / 100 >= img->zoom)) { i += d; } - i = MIN(MAX(i, 0), (int)ARRLEN(zoom_levels)-1); - return img_zoom_to(img, zoom_levels[i]/100); + i = MIN(MAX(i, 0), (int)ARRLEN(zoom_levels) - 1); + return img_zoom_to(img, zoom_levels[i] / 100); } bool img_pos(img_t *img, float x, float y) @@ -883,7 +883,7 @@ bool img_pan(img_t *img, direction_t dir, int d) float x, y; if (d > 0) { - x = y = MAX(1, (float) d * img->zoom); + x = y = MAX(1, (float)d * img->zoom); } else { x = img->win->w / (d < 0 ? 1 : PAN_FRACTION); y = img->win->h / (d < 0 ? 1 : PAN_FRACTION); diff --git a/main.c b/main.c index 322fd74..3868e8e 100644 --- a/main.c +++ b/main.c @@ -45,10 +45,11 @@ #define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \ ((t1)->tv_usec - (t2)->tv_usec) / 1000) -#define TV_ADD_MSEC(tv,t) do { \ - (tv)->tv_sec += (t) / 1000; \ - (tv)->tv_usec += (t) % 1000 * 1000; \ -} while (0) +#define TV_ADD_MSEC(tv, t) \ + do { \ + (tv)->tv_sec += (t) / 1000; \ + (tv)->tv_usec += (t) % 1000 * 1000; \ + } while (0) typedef struct { int err; @@ -112,8 +113,8 @@ static void cleanup(void) static bool xgetline(char **lineptr, size_t *n) { ssize_t len = getdelim(lineptr, n, options->using_null ? '\0' : '\n', stdin); - if (!options->using_null && len > 0 && (*lineptr)[len-1] == '\n') - (*lineptr)[len-1] = '\0'; + if (!options->using_null && len > 0 && (*lineptr)[len - 1] == '\n') + (*lineptr)[len - 1] = '\0'; return len > 0; } @@ -140,7 +141,7 @@ static void check_add_file(const char *filename, bool given) if (fileidx == filecnt) { filecnt *= 2; files = erealloc(files, filecnt * sizeof(*files)); - memset(&files[filecnt/2], 0, filecnt/2 * sizeof(*files)); + memset(&files[filecnt / 2], 0, filecnt / 2 * sizeof(*files)); } files[fileidx].name = estrdup(filename); @@ -193,8 +194,8 @@ void remove_file(int n, bool manual) markcnt--; if (files[n].path != files[n].name) - free((void*) files[n].path); - free((void*) files[n].name); + free((void *)files[n].path); + free((void *)files[n].name); if (tns.thumbs != NULL) tns_unload(&tns, n); @@ -287,7 +288,7 @@ static void read_title(void) ssize_t n; char buf[512]; - if ((n = read(wintitle.fd, buf, sizeof(buf)-1)) > 0) { + if ((n = read(wintitle.fd, buf, sizeof(buf) - 1)) > 0) { buf[n] = '\0'; win_set_title(&win, buf, n); } @@ -308,7 +309,7 @@ static void open_title(void) snprintf(h, ARRLEN(h), "%d", img.h); snprintf(z, ARRLEN(z), "%d", (int)(img.zoom * 100)); } - snprintf(fidx, ARRLEN(fidx), "%d", fileidx+1); + snprintf(fidx, ARRLEN(fidx), "%d", fileidx + 1); snprintf(fcnt, ARRLEN(fcnt), "%d", filecnt); construct_argv(argv, ARRLEN(argv), wintitle.f.cmd, files[fileidx].path, fidx, fcnt, w, h, z, NULL); @@ -426,7 +427,8 @@ static void update_info(void) /* update bar contents */ if (win.bar.h == 0 || extprefix) return; - for (fw = 0, i = filecnt; i > 0; fw++, i /= 10); + for (fw = 0, i = filecnt; i > 0; fw++, i /= 10) + ; mark = files[fileidx].flags & FF_MARK ? "* " : ""; l->p = l->buf; r->p = r->buf; @@ -452,9 +454,10 @@ static void update_info(void) bar_put(r, "B%+d" BAR_SEP, img.brightness); if (img.contrast) bar_put(r, "C%+d" BAR_SEP, img.contrast); - bar_put(r, "%3d%%" BAR_SEP, (int) (img.zoom * 100.0)); + bar_put(r, "%3d%%" BAR_SEP, (int)(img.zoom * 100.0)); if (img.multi.cnt > 0) { - for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10); + for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10) + ; bar_put(r, "%0*d/%d" BAR_SEP, fn, img.multi.sel + 1, img.multi.cnt); } bar_put(r, "%0*d/%d", fw, fileidx + 1, filecnt); @@ -623,7 +626,8 @@ static bool run_key_handler(const char *key, unsigned int mask) } } fclose(pfs); - while (waitpid(pid, NULL, 0) == -1 && errno == EINTR); + while (waitpid(pid, NULL, 0) == -1 && errno == EINTR) + ; for (f = i = 0; f < fcnt; i++) { if ((marked && (files[i].flags & FF_MARK)) || (!marked && i == fileidx)) { @@ -640,7 +644,8 @@ static bool run_key_handler(const char *key, unsigned int mask) } } /* drop user input events that occurred while running the key handler */ - while (XCheckIfEvent(win.env.dpy, &dump, is_input_ev, NULL)); + while (XCheckIfEvent(win.env.dpy, &dump, is_input_ev, NULL)) + ; if (mode == MODE_IMAGE && changed) { img_close(&img, true); @@ -699,7 +704,7 @@ static void on_keypress(XKeyEvent *kev) handle_key_handler(false); } else if (key >= '0' && key <= '9') { /* number prefix for commands */ - prefix = prefix * 10 + (int) (key - '0'); + prefix = prefix * 10 + (int)(key - '0'); return; } else { dirty = process_bindings(keys, ARRLEN(keys), ksym, kev->state, sh); @@ -730,7 +735,7 @@ static void run(void) enum { FD_X, FD_INFO, FD_TITLE, FD_ARL, FD_CNT }; struct pollfd pfd[FD_CNT]; int timeout = 0; - const struct timespec ten_ms = {0, 10000000}; + const struct timespec ten_ms = { 0, 10000000 }; bool discard, init_thumb, load_thumb, to_set; XEvent ev, nextev; @@ -795,7 +800,7 @@ static void run(void) break; case KeyPress: discard = (nextev.type == KeyPress || nextev.type == KeyRelease) && - ev.xkey.keycode == nextev.xkey.keycode; + ev.xkey.keycode == nextev.xkey.keycode; break; } } @@ -806,7 +811,7 @@ static void run(void) on_buttonpress(&ev.xbutton); break; case ClientMessage: - if ((Atom) ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW]) + if ((Atom)ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW]) cg_quit(EXIT_SUCCESS); break; case DestroyNotify: @@ -859,7 +864,7 @@ int main(int argc, char *argv[]) size_t n; const char *homedir, *dsuffix = ""; - setup_signal(SIGCHLD, SIG_DFL, SA_RESTART|SA_NOCLDSTOP|SA_NOCLDWAIT); + setup_signal(SIGCHLD, SIG_DFL, SA_RESTART | SA_NOCLDSTOP | SA_NOCLDWAIT); setup_signal(SIGPIPE, SIG_IGN, 0); setlocale(LC_COLLATE, ""); diff --git a/options.c b/options.c index 6231d03..ef874ac 100644 --- a/options.c +++ b/options.c @@ -43,7 +43,8 @@ void print_usage(void) { printf("usage: %s [-abcfhiopqrtvZ0] [-A FRAMERATE] [-e WID] [-G GAMMA] " "[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] " - "[-z ZOOM] FILES...\n", progname); + "[-z ZOOM] FILES...\n", + progname); } static void print_version(void) @@ -227,7 +228,7 @@ void parse_options(int argc, char **argv) if (*end != '\0' || n <= 0) error(EXIT_FAILURE, 0, "Invalid zoom level: %s", op.optarg); _options.scalemode = SCALE_ZOOM; - _options.zoom = (float) n / 100.0f; + _options.zoom = (float)n / 100.0f; break; case '0': _options.using_null = true; diff --git a/thumbs.c b/thumbs.c index b5da098..c1778b5 100644 --- a/thumbs.c +++ b/thumbs.c @@ -36,7 +36,7 @@ static char *cache_dir; -static char* tns_cache_filepath(const char *filepath) +static char *tns_cache_filepath(const char *filepath) { size_t len; char *cfile = NULL; @@ -201,8 +201,8 @@ static Imlib_Image tns_scale_down(Imlib_Image im, int dim) imlib_context_set_image(im); w = imlib_image_get_width(); h = imlib_image_get_height(); - zw = (float) dim / (float) w; - zh = (float) dim / (float) h; + zw = (float)dim / (float)w; + zh = (float)dim / (float)h; z = MIN(zw, zh); z = MIN(z, 1.0); @@ -219,7 +219,7 @@ static Imlib_Image tns_scale_down(Imlib_Image im, int dim) bool tns_load(tns_t *tns, int n, bool force, bool cache_only) { - int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1]; + int maxwh = thumb_sizes[ARRLEN(thumb_sizes) - 1]; bool cache_hit = false; char *cfile; thumb_t *t; @@ -290,8 +290,8 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only) h = imlib_image_get_height(); if (pw > w && ph > h && (pw - ph >= 0) == (w - h >= 0)) { - zw = (float) pw / (float) w; - zh = (float) ph / (float) h; + zw = (float)pw / (float)w; + zh = (float)ph / (float)h; if (zw < zh) { pw /= zh; x = (w - pw) / 2; @@ -343,10 +343,14 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only) } file->flags |= FF_TN_INIT; - if (n == tns->initnext) - while (++tns->initnext < *tns->cnt && ((++file)->flags & FF_TN_INIT)); - if (n == tns->loadnext && !cache_only) - while (++tns->loadnext < tns->end && (++t)->im != NULL); + if (n == tns->initnext) { + while (++tns->initnext < *tns->cnt && ((++file)->flags & FF_TN_INIT)) + ; + } + if (n == tns->loadnext && !cache_only) { + while (++tns->loadnext < tns->end && (++t)->im != NULL) + ; + } return true; } @@ -557,7 +561,7 @@ bool tns_zoom(tns_t *tns, int d) oldzl = tns->zl; tns->zl += -(d < 0) + (d > 0); tns->zl = MAX(tns->zl, 0); - tns->zl = MIN(tns->zl, (int)ARRLEN(thumb_sizes)-1); + tns->zl = MIN(tns->zl, (int)ARRLEN(thumb_sizes) - 1); tns->bw = ((thumb_sizes[tns->zl] - 1) >> 5) + 1; tns->bw = MIN(tns->bw, 4); diff --git a/util.c b/util.c index 1e6bc70..c7fb210 100644 --- a/util.c +++ b/util.c @@ -32,7 +32,7 @@ extern char **environ; const char *progname = "nsxiv"; -void* emalloc(size_t size) +void *emalloc(size_t size) { void *ptr; @@ -42,7 +42,7 @@ void* emalloc(size_t size) return ptr; } -void* ecalloc(size_t nmemb, size_t size) +void *ecalloc(size_t nmemb, size_t size) { void *ptr; @@ -52,7 +52,7 @@ void* ecalloc(size_t nmemb, size_t size) return ptr; } -void* erealloc(void *ptr, size_t size) +void *erealloc(void *ptr, size_t size) { ptr = realloc(ptr, size); if (ptr == NULL) @@ -60,13 +60,13 @@ void* erealloc(void *ptr, size_t size) return ptr; } -char* estrdup(const char *s) +char *estrdup(const char *s) { size_t n = strlen(s) + 1; return memcpy(emalloc(n), s, n); } -void error(int eval, int err, const char* fmt, ...) +void error(int eval, int err, const char *fmt, ...) { va_list ap; @@ -102,7 +102,7 @@ int r_opendir(r_dir_t *rdir, const char *dirname, bool recursive) rdir->stack = emalloc(rdir->stcap * sizeof(*rdir->stack)); rdir->stlen = 0; - rdir->name = (char*) dirname; + rdir->name = (char *)dirname; rdir->d = 0; rdir->recursive = recursive; @@ -133,7 +133,7 @@ int r_closedir(r_dir_t *rdir) return ret; } -char* r_readdir(r_dir_t *rdir, bool skip_dotfiles) +char *r_readdir(r_dir_t *rdir, bool skip_dotfiles) { size_t len; char *filename; @@ -154,7 +154,7 @@ char* r_readdir(r_dir_t *rdir, bool skip_dotfiles) len = strlen(rdir->name) + strlen(dentry->d_name) + 2; filename = emalloc(len); snprintf(filename, len, "%s%s%s", rdir->name, - rdir->name[strlen(rdir->name)-1] == '/' ? "" : "/", + rdir->name[strlen(rdir->name) - 1] == '/' ? "" : "/", dentry->d_name); if (stat(filename, &fstats) < 0) { @@ -203,7 +203,8 @@ int r_mkdir(char *path) s++; continue; } - for (; *s != '\0' && *s != '/'; s++); + for (; *s != '\0' && *s != '/'; s++) + ; c = *s; *s = '\0'; if (mkdir(path, 0755) == -1) { @@ -226,7 +227,7 @@ void construct_argv(char **argv, unsigned int len, ...) for (i = 0; i < len; ++i) argv[i] = va_arg(args, char *); va_end(args); - assert(argv[len-1] == NULL && "argv should be NULL terminated"); + assert(argv[len - 1] == NULL && "argv should be NULL terminated"); } static int mkspawn_pipe(posix_spawn_file_actions_t *fa, const char *cmd, int *pfd, int dupidx) diff --git a/window.c b/window.c index 765f67d..3857871 100644 --- a/window.c +++ b/window.c @@ -34,7 +34,7 @@ #if HAVE_LIBFONTS #include "utf8.h" -#define UTF8_PADDING 4 /* utf8_decode requires 4 bytes of zero padding */ +#define UTF8_PADDING 4 /* utf8_decode requires 4 bytes of zero padding */ #define TEXTWIDTH(win, text, len) \ win_draw_text(win, NULL, NULL, 0, 0, text, len, 0) #endif @@ -56,8 +56,12 @@ static struct { int name; Cursor icon; } cursors[CURSOR_COUNT] = { - { XC_left_ptr }, { XC_dotbox }, { XC_fleur }, { XC_watch }, - { XC_sb_left_arrow }, { XC_sb_right_arrow } + { XC_left_ptr }, + { XC_dotbox }, + { XC_fleur }, + { XC_watch }, + { XC_sb_left_arrow }, + { XC_sb_right_arrow } }; #if HAVE_LIBFONTS @@ -90,7 +94,7 @@ static void win_alloc_color(const win_env_t *e, const char *name, XColor *col) error(EXIT_FAILURE, 0, "Error allocating color '%s'", name); } -static const char* win_res(XrmDatabase db, const char *name, const char *def) +static const char *win_res(XrmDatabase db, const char *name, const char *def) { char *type; XrmValue ret; @@ -246,7 +250,7 @@ void win_open(win_t *win) /* set the _NET_WM_PID */ pid = getpid(); XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_PID], XA_CARDINAL, - 32, PropModeReplace, (unsigned char *) &pid, 1); + 32, PropModeReplace, (unsigned char *)&pid, 1); if (gethostname(hostname, ARRLEN(hostname)) == 0) { XTextProperty tp; tp.value = (unsigned char *)hostname; @@ -272,7 +276,7 @@ void win_open(win_t *win) gc = XCreateGC(e->dpy, win->xwin, 0, None); - n = icons[ARRLEN(icons)-1].size; + n = icons[ARRLEN(icons) - 1].size; icon_data = emalloc((n * n + 2) * sizeof(*icon_data)); for (i = 0; i < (int)ARRLEN(icons); i++) { @@ -286,7 +290,7 @@ void win_open(win_t *win) } XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32, i == 0 ? PropModeReplace : PropModeAppend, - (unsigned char *) icon_data, n); + (unsigned char *)icon_data, n); } free(icon_data); @@ -311,7 +315,7 @@ void win_open(win_t *win) if (options->fullscreen) { XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_STATE], XA_ATOM, 32, PropModeReplace, - (unsigned char *) &atoms[ATOM__NET_WM_STATE_FULLSCREEN], 1); + (unsigned char *)&atoms[ATOM__NET_WM_STATE_FULLSCREEN], 1); } win->h -= win->bar.h; @@ -432,10 +436,10 @@ static int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, FC_SIZE, FcTypeDouble, fontsize, NULL); FcCharSetDestroy(fccharset); } - XftTextExtentsUtf8(win->env.dpy, f, (XftChar8*)t, next - t, &ext); + XftTextExtentsUtf8(win->env.dpy, f, (XftChar8 *)t, next - t, &ext); tw += ext.xOff; if (tw <= w) { - XftDrawStringUtf8(d, color, f, x, y, (XftChar8*)t, next - t); + XftDrawStringUtf8(d, color, f, x, y, (XftChar8 *)t, next - t); x += ext.xOff; } if (f != font) @@ -456,7 +460,7 @@ static void win_draw_bar(win_t *win) r = &win->bar.r; assert(l->buf != NULL && r->buf != NULL); y = (win->bar.top ? 0 : win->h) + font->ascent + V_TEXT_PAD; - w = win->w - 2*H_TEXT_PAD; + w = win->w - 2 * H_TEXT_PAD; d = XftDrawCreate(e->dpy, win->buf.pm, e->vis, e->cmap); XSetForeground(e->dpy, gc, win->bar_bg.pixel); @@ -482,7 +486,7 @@ static void win_draw_bar(win_t *win) #else static void win_draw_bar(win_t *win) { - (void) win; + (void)win; } #endif /* HAVE_LIBFONTS */ -- cgit v1.2.3 From 4b67816eae77db28db64e5e80d0d99c60e74973f Mon Sep 17 00:00:00 2001 From: NRK Date: Thu, 18 May 2023 15:05:45 +0000 Subject: fix: loading old frames due to multi-frame cache (#437) by default imlib2 doesn't check the file's timestamp to avoid disk activity when loading from cache. however, this ends up breaking our autoreload functionality on multi-frame images. the reason why single frame images weren't broken was because `img_load()` calls `imlib_image_set_changes_on_disk()`, which tells imlib2 to check the timestamp before loading from cache. do the same thing for the multi-frame loader as well. additionally add a comment to img_load() explaining what's going on. Closes: https://codeberg.org/nsxiv/nsxiv/issues/436 Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/437 Reviewed-by: eylles --- image.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'image.c') diff --git a/image.c b/image.c index 42979c7..49dc72f 100644 --- a/image.c +++ b/image.c @@ -506,6 +506,7 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file) } imlib_context_set_image(frame); + imlib_image_set_changes_on_disk(); /* see img_load() for rationale */ imlib_image_get_frame_info(&finfo); assert(finfo.frame_count == (int)fcnt); assert(finfo.canvas_w == img->w && finfo.canvas_h == img->h); @@ -579,6 +580,9 @@ bool img_load(img_t *img, const fileinfo_t *file) if ((img->im = img_open(file)) == NULL) return false; + /* ensure that the image's timestamp is checked when loading from cache + * to avoid issues like: https://codeberg.org/nsxiv/nsxiv/issues/436 + */ imlib_image_set_changes_on_disk(); /* since v1.7.5, Imlib2 can parse exif orientation from jpeg files. -- cgit v1.2.3 From d0ec8716d7d4d0cfb0067290cac51b59b7fd4e42 Mon Sep 17 00:00:00 2001 From: NRK Date: Thu, 18 May 2023 15:06:44 +0000 Subject: fix: calling imlib2 with color modifier being NULL (#440) the multiframe loaders sets the color modifier to NULL but doesn't restore it before returning. this results in a imlib2 developer warning if you try to change brightness/contrast on a multiframe image (which doesn't have alpha). ensure that the color modifier is restored before returning under all paths. Reported-by: Madhu Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/440 Reviewed-by: eylles --- image.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'image.c') diff --git a/image.c b/image.c index 49dc72f..4f9015d 100644 --- a/image.c +++ b/image.c @@ -470,11 +470,6 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file) m->frames = erealloc(m->frames, m->cap * sizeof(*m->frames)); } - imlib_context_set_dither(0); - imlib_context_set_anti_alias(0); - imlib_context_set_color_modifier(NULL); - imlib_context_set_operation(IMLIB_OP_COPY); - if ((blank = imlib_create_image(img->w, img->h)) == NULL) { error(0, 0, "%s: couldn't create image", file->name); return false; @@ -482,6 +477,11 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file) imlib_context_set_image(blank); img_area_clear(0, 0, img->w, img->h); + imlib_context_set_dither(0); + imlib_context_set_anti_alias(0); + imlib_context_set_color_modifier(NULL); + imlib_context_set_operation(IMLIB_OP_COPY); + /* * Imlib2 gives back a "raw frame", we need to blend it on top of the * previous frame ourselves if necessary to get the fully decoded frame. @@ -548,6 +548,7 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file) imlib_context_set_image(blank); imlib_free_image(); img_multiframe_context_set(img); + imlib_context_set_color_modifier(img->cmod); /* restore cmod */ return m->cnt > 0; } #endif /* HAVE_IMLIB2_MULTI_FRAME */ -- cgit v1.2.3 From 0e1bc3c045384bca18922accbc50fa6914a67bd0 Mon Sep 17 00:00:00 2001 From: NRK Date: Tue, 23 May 2023 11:36:41 +0000 Subject: set a default delay if delay is 0 (#445) gif spec [0] doesn't mention what to do when "Delay Time" is 0. apng spec [1] states: | If the the value of the numerator is 0 the decoder should render the | next frame as quickly as possible, though viewers may impose a | reasonable lower bound. webp spec [2]: | the interpretation of frame duration of 0 (and often <= 10) is | implementation defined. so it seems that it's safe to set a default delay for 0 delay frames, which is what the older gif and webp loaders were already doing. do the same for the imlib2 multi-frame loader as well. [0]: https://www.w3.org/Graphics/GIF/spec-gif89a.txt [1]: https://wiki.mozilla.org/APNG_Specification [2]: https://developers.google.com/speed/webp/docs/riff_container#animation Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/445 Reviewed-by: eylles --- image.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'image.c') diff --git a/image.c b/image.c index 4f9015d..426a05a 100644 --- a/image.c +++ b/image.c @@ -54,6 +54,10 @@ enum { DEF_GIF_DELAY = 75 }; enum { DEF_WEBP_DELAY = 75 }; #endif +#if HAVE_IMLIB2_MULTI_FRAME +enum { DEF_ANIM_DELAY = 75 }; +#endif + #define ZOOM_MIN (zoom_levels[0] / 100) #define ZOOM_MAX (zoom_levels[ARRLEN(zoom_levels) - 1] / 100) @@ -539,7 +543,7 @@ static bool img_load_multiframe(img_t *img, const fileinfo_t *file) imlib_context_set_blend(!!(finfo.frame_flags & IMLIB_FRAME_BLEND)); imlib_blend_image_onto_image(frame, has_alpha, 0, 0, sw, sh, sx, sy, sw, sh); m->frames[m->cnt].im = canvas; - m->frames[m->cnt].delay = finfo.frame_delay; + m->frames[m->cnt].delay = finfo.frame_delay ? finfo.frame_delay : DEF_ANIM_DELAY; m->length += m->frames[m->cnt].delay; m->cnt++; imlib_context_set_image(frame); -- cgit v1.2.3