diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 74 |
1 files changed, 40 insertions, 34 deletions
@@ -40,15 +40,16 @@ #include <X11/XF86keysym.h> #include <X11/keysym.h> -#define MODMASK(mask) ((mask) & USED_MODMASK) +#define MODMASK(mask) (USED_MODMASK & (mask)) #define BAR_SEP " " #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) { \ - (tv)->tv_sec += (t) / 1000; \ - (tv)->tv_usec += (t) % 1000 * 1000; \ -} +#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,15 +194,15 @@ 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); if (n + 1 < filecnt) { if (tns.thumbs != NULL) { - memmove(tns.thumbs + n, tns.thumbs + n + 1, (filecnt - n - 1) * - sizeof(*tns.thumbs)); + memmove(tns.thumbs + n, tns.thumbs + n + 1, + (filecnt - n - 1) * sizeof(*tns.thumbs)); memset(tns.thumbs + filecnt - 1, 0, sizeof(*tns.thumbs)); } memmove(files + n, files + n + 1, (filecnt - n - 1) * sizeof(*files)); @@ -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); @@ -377,7 +378,7 @@ void load_image(int new) if (new >= filecnt) new = filecnt - 1; else if (new > 0 && prev) - new--; + new -= 1; } files[new].flags &= ~FF_WARN; fileidx = current = new; @@ -426,18 +427,19 @@ 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; if (mode == MODE_THUMB) { if (tns.loadnext < tns.end) - bar_put(l, "Loading... %0*d", fw, tns.loadnext + 1); + bar_put(r, "Loading... %0*d | ", fw, tns.loadnext + 1); else if (tns.initnext < filecnt) - bar_put(l, "Caching... %0*d", fw, tns.initnext + 1); - else if (info.ft.err) - strncpy(l->buf, files[fileidx].name, l->size); + bar_put(r, "Caching... %0*d | ", fw, tns.initnext + 1); bar_put(r, "%s%0*d/%d", mark, fw, fileidx + 1, filecnt); + if (info.ft.err) + strncpy(l->buf, files[fileidx].name, l->size); } else { bar_put(r, "%s", mark); if (img.ss.on) { @@ -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); @@ -562,8 +565,9 @@ void handle_key_handler(bool init) return; if (init) { close_info(); - snprintf(win.bar.l.buf, win.bar.l.size, "Getting key handler input " - "(%s to abort)...", XKeysymToString(KEYHANDLER_ABORT)); + snprintf(win.bar.l.buf, win.bar.l.size, + "Getting key handler input (%s to abort)...", + XKeysymToString(KEYHANDLER_ABORT)); } else { /* abort */ open_info(); update_info(); @@ -622,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)) { @@ -639,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); @@ -698,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); @@ -729,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; @@ -739,8 +745,8 @@ static void run(void) init_thumb = mode == MODE_THUMB && tns.initnext < filecnt; load_thumb = mode == MODE_THUMB && tns.loadnext < tns.end; - if ((init_thumb || load_thumb || to_set || info.fd != -1 || - arl.fd != -1) && XPending(win.env.dpy) == 0) + if ((init_thumb || load_thumb || to_set || info.fd != -1 || arl.fd != -1) && + XPending(win.env.dpy) == 0) { if (load_thumb) { set_timeout(redraw, TO_REDRAW_THUMBS, false); @@ -793,8 +799,8 @@ static void run(void) discard = ev.type == nextev.type; break; case KeyPress: - discard = (nextev.type == KeyPress || nextev.type == KeyRelease) - && ev.xkey.keycode == nextev.xkey.keycode; + discard = (nextev.type == KeyPress || nextev.type == KeyRelease) && + ev.xkey.keycode == nextev.xkey.keycode; break; } } @@ -805,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: @@ -858,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, ""); |
