code-style: don't indent switch cases (#358)

The suckless coding style [^0] and the linux coding style [^1] both
recommends not indenting switch cases. And it helps out people with
lower resolution monitors.

[^0]: https://suckless.org/coding_style/
[^1]: https://www.kernel.org/doc/html/v5.10/process/coding-style.html#indentation

Co-authored-by: explosion-mental <explosion0mental@gmail.com>
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/358
Reviewed-by: NRK <nrk@disroot.org>
Co-authored-by: explosion-mental <explosion-mental@noreply.codeberg.org>
Co-committed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
This commit is contained in:
explosion-mental 2022-08-16 10:54:31 +02:00 committed by NRK
parent 6578e6eb65
commit 0f0c49a630
4 changed files with 197 additions and 198 deletions

82
image.c
View File

@ -111,27 +111,27 @@ void exif_auto_orientate(const fileinfo_t *file)
exif_data_unref(ed); exif_data_unref(ed);
switch (orientation) { switch (orientation) {
case 5: case 5:
imlib_image_orientate(1); imlib_image_orientate(1);
/* fall through */ /* fall through */
case 2: case 2:
imlib_image_flip_vertical(); imlib_image_flip_vertical();
break; break;
case 3: case 3:
imlib_image_orientate(2); imlib_image_orientate(2);
break; break;
case 7: case 7:
imlib_image_orientate(1); imlib_image_orientate(1);
/* fall through */ /* fall through */
case 4: case 4:
imlib_image_flip_horizontal(); imlib_image_flip_horizontal();
break; break;
case 6: case 6:
imlib_image_orientate(1); imlib_image_orientate(1);
break; break;
case 8: case 8:
imlib_image_orientate(3); imlib_image_orientate(3);
break; break;
} }
} }
#endif #endif
@ -531,18 +531,18 @@ static bool img_fit(img_t *img)
zh = (float) img->win->h / (float) img->h; zh = (float) img->win->h / (float) img->h;
switch (img->scalemode) { switch (img->scalemode) {
case SCALE_FILL: case SCALE_FILL:
z = MAX(zw, zh); z = MAX(zw, zh);
break; break;
case SCALE_WIDTH: case SCALE_WIDTH:
z = zw; z = zw;
break; break;
case SCALE_HEIGHT: case SCALE_HEIGHT:
z = zh; z = zh;
break; break;
default: default:
z = MIN(zw, zh); z = MIN(zw, zh);
break; break;
} }
z = MIN(z, img->scalemode == SCALE_DOWN ? 1.0 : ZOOM_MAX); z = MIN(z, img->scalemode == SCALE_DOWN ? 1.0 : ZOOM_MAX);
@ -741,14 +741,14 @@ bool img_pan(img_t *img, direction_t dir, int d)
} }
switch (dir) { switch (dir) {
case DIR_LEFT: case DIR_LEFT:
return img_move(img, x, 0.0); return img_move(img, x, 0.0);
case DIR_RIGHT: case DIR_RIGHT:
return img_move(img, -x, 0.0); return img_move(img, -x, 0.0);
case DIR_UP: case DIR_UP:
return img_move(img, 0.0, y); return img_move(img, 0.0, y);
case DIR_DOWN: case DIR_DOWN:
return img_move(img, 0.0, -y); return img_move(img, 0.0, -y);
} }
return false; return false;
} }

87
main.c
View File

@ -753,56 +753,55 @@ static void run(void)
if (XEventsQueued(win.env.dpy, QueuedAlready) > 0) { if (XEventsQueued(win.env.dpy, QueuedAlready) > 0) {
XPeekEvent(win.env.dpy, &nextev); XPeekEvent(win.env.dpy, &nextev);
switch (ev.type) { switch (ev.type) {
case ConfigureNotify: case ConfigureNotify:
case MotionNotify: case MotionNotify:
discard = ev.type == nextev.type; discard = ev.type == nextev.type;
break; break;
case KeyPress: case KeyPress:
discard = (nextev.type == KeyPress || nextev.type == KeyRelease) discard = (nextev.type == KeyPress || nextev.type == KeyRelease)
&& ev.xkey.keycode == nextev.xkey.keycode; && ev.xkey.keycode == nextev.xkey.keycode;
break; break;
} }
} }
} while (discard); } while (discard);
switch (ev.type) { switch (ev.type) { /* handle events */
/* handle events */ case ButtonPress:
case ButtonPress: on_buttonpress(&ev.xbutton);
on_buttonpress(&ev.xbutton); break;
break; case ClientMessage:
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);
cg_quit(EXIT_SUCCESS); break;
break; case DestroyNotify:
case DestroyNotify: cg_quit(EXIT_FAILURE);
cg_quit(EXIT_FAILURE); break;
break; case ConfigureNotify:
case ConfigureNotify: if (win_configure(&win, &ev.xconfigure)) {
if (win_configure(&win, &ev.xconfigure)) {
if (mode == MODE_IMAGE) {
img.dirty = true;
img.checkpan = true;
} else {
tns.dirty = true;
}
if (!resized) {
redraw();
set_timeout(clear_resize, TO_REDRAW_RESIZE, false);
resized = true;
} else {
set_timeout(redraw, TO_REDRAW_RESIZE, false);
}
}
break;
case KeyPress:
on_keypress(&ev.xkey);
break;
case MotionNotify:
if (mode == MODE_IMAGE) { if (mode == MODE_IMAGE) {
set_timeout(reset_cursor, TO_CURSOR_HIDE, true); img.dirty = true;
reset_cursor(); img.checkpan = true;
} else {
tns.dirty = true;
} }
break; if (!resized) {
redraw();
set_timeout(clear_resize, TO_REDRAW_RESIZE, false);
resized = true;
} else {
set_timeout(redraw, TO_REDRAW_RESIZE, false);
}
}
break;
case KeyPress:
on_keypress(&ev.xkey);
break;
case MotionNotify:
if (mode == MODE_IMAGE) {
set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
reset_cursor();
}
break;
} }
} }
} }

198
options.c
View File

@ -132,105 +132,105 @@ void parse_options(int argc, char **argv)
assert(op.optarg != NULL); assert(op.optarg != NULL);
} }
switch (opt) { switch (opt) {
case '?': case '?':
fprintf(stderr, "%s\n", op.errmsg); fprintf(stderr, "%s\n", op.errmsg);
print_usage(); print_usage();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
case 'A': case 'A':
n = strtol(op.optarg, &end, 0); n = strtol(op.optarg, &end, 0);
if (*end != '\0' || n <= 0) if (*end != '\0' || n <= 0)
error(EXIT_FAILURE, 0, "Invalid argument for option -A: %s", op.optarg); error(EXIT_FAILURE, 0, "Invalid argument for option -A: %s", op.optarg);
_options.framerate = n; _options.framerate = n;
/* fall through */ /* fall through */
case 'a': case 'a':
_options.animate = true; _options.animate = true;
break; break;
case 'b': case 'b':
_options.hide_bar = true; _options.hide_bar = true;
break; break;
case 'c': case 'c':
_options.clean_cache = true; _options.clean_cache = true;
break; break;
case 'e': case 'e':
n = strtol(op.optarg, &end, 0); n = strtol(op.optarg, &end, 0);
if (*end != '\0') if (*end != '\0')
error(EXIT_FAILURE, 0, "Invalid argument for option -e: %s", op.optarg); error(EXIT_FAILURE, 0, "Invalid argument for option -e: %s", op.optarg);
_options.embed = n; _options.embed = n;
break; break;
case 'f': case 'f':
_options.fullscreen = true; _options.fullscreen = true;
break; break;
case 'G': case 'G':
n = strtol(op.optarg, &end, 0); n = strtol(op.optarg, &end, 0);
if (*end != '\0') if (*end != '\0')
error(EXIT_FAILURE, 0, "Invalid argument for option -G: %s", op.optarg); error(EXIT_FAILURE, 0, "Invalid argument for option -G: %s", op.optarg);
_options.gamma = n; _options.gamma = n;
break; break;
case 'g': case 'g':
_options.geometry = op.optarg; _options.geometry = op.optarg;
break; break;
case 'h': case 'h':
print_usage(); print_usage();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'i': case 'i':
_options.from_stdin = true; _options.from_stdin = true;
break; break;
case 'n': case 'n':
n = strtol(op.optarg, &end, 0); n = strtol(op.optarg, &end, 0);
if (*end != '\0' || n <= 0) if (*end != '\0' || n <= 0)
error(EXIT_FAILURE, 0, "Invalid argument for option -n: %s", op.optarg); error(EXIT_FAILURE, 0, "Invalid argument for option -n: %s", op.optarg);
_options.startnum = n - 1; _options.startnum = n - 1;
break; break;
case 'N': case 'N':
_options.res_name = op.optarg; _options.res_name = op.optarg;
break; break;
case 'o': case 'o':
_options.to_stdout = true; _options.to_stdout = true;
break; break;
case 'p': case 'p':
_options.private_mode = true; _options.private_mode = true;
break; break;
case 'q': case 'q':
_options.quiet = true; _options.quiet = true;
break; break;
case 'r': case 'r':
_options.recursive = true; _options.recursive = true;
break; break;
case 'S': case 'S':
n = strtof(op.optarg, &end) * 10; n = strtof(op.optarg, &end) * 10;
if (*end != '\0' || n <= 0) if (*end != '\0' || n <= 0)
error(EXIT_FAILURE, 0, "Invalid argument for option -S: %s", op.optarg); error(EXIT_FAILURE, 0, "Invalid argument for option -S: %s", op.optarg);
_options.slideshow = n; _options.slideshow = n;
break; break;
case 's': case 's':
s = strchr(scalemodes, op.optarg[0]); s = strchr(scalemodes, op.optarg[0]);
if (s == NULL || *s == '\0' || strlen(op.optarg) != 1) if (s == NULL || *s == '\0' || strlen(op.optarg) != 1)
error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", op.optarg); error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", op.optarg);
_options.scalemode = s - scalemodes; _options.scalemode = s - scalemodes;
break; break;
case 'T': case 'T':
title_deprecation_notice(); /* TODO(v31): remove this option */ title_deprecation_notice(); /* TODO(v31): remove this option */
break; break;
case 't': case 't':
_options.thumb_mode = true; _options.thumb_mode = true;
break; break;
case 'v': case 'v':
print_version(); print_version();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'Z': case 'Z':
_options.scalemode = SCALE_ZOOM; _options.scalemode = SCALE_ZOOM;
_options.zoom = 1.0f; _options.zoom = 1.0f;
break; break;
case 'z': case 'z':
n = strtol(op.optarg, &end, 0); n = strtol(op.optarg, &end, 0);
if (*end != '\0' || n <= 0) if (*end != '\0' || n <= 0)
error(EXIT_FAILURE, 0, "Invalid argument for option -z: %s", op.optarg); error(EXIT_FAILURE, 0, "Invalid argument for option -z: %s", op.optarg);
_options.scalemode = SCALE_ZOOM; _options.scalemode = SCALE_ZOOM;
_options.zoom = (float) n / 100.0f; _options.zoom = (float) n / 100.0f;
break; break;
case '0': case '0':
_options.using_null = true; _options.using_null = true;
break; break;
} }
} }

View File

@ -505,20 +505,20 @@ bool tns_move_selection(tns_t *tns, direction_t dir, int cnt)
cnt = cnt > 1 ? cnt : 1; cnt = cnt > 1 ? cnt : 1;
switch (dir) { switch (dir) {
case DIR_UP: case DIR_UP:
*tns->sel = MAX(*tns->sel - cnt * tns->cols, *tns->sel % tns->cols); *tns->sel = MAX(*tns->sel - cnt * tns->cols, *tns->sel % tns->cols);
break; break;
case DIR_DOWN: case DIR_DOWN:
max = tns->cols * ((*tns->cnt - 1) / tns->cols) + max = tns->cols * ((*tns->cnt - 1) / tns->cols) +
MIN((*tns->cnt - 1) % tns->cols, *tns->sel % tns->cols); MIN((*tns->cnt - 1) % tns->cols, *tns->sel % tns->cols);
*tns->sel = MIN(*tns->sel + cnt * tns->cols, max); *tns->sel = MIN(*tns->sel + cnt * tns->cols, max);
break; break;
case DIR_LEFT: case DIR_LEFT:
*tns->sel = MAX(*tns->sel - cnt, 0); *tns->sel = MAX(*tns->sel - cnt, 0);
break; break;
case DIR_RIGHT: case DIR_RIGHT:
*tns->sel = MIN(*tns->sel + cnt, *tns->cnt - 1); *tns->sel = MIN(*tns->sel + cnt, *tns->cnt - 1);
break; break;
} }
if (*tns->sel != old) { if (*tns->sel != old) {