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>
pull/365/head
explosion-mental 2 years ago committed by NRK
parent 6578e6eb65
commit 0f0c49a630

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

@ -753,56 +753,55 @@ static void run(void)
if (XEventsQueued(win.env.dpy, QueuedAlready) > 0) {
XPeekEvent(win.env.dpy, &nextev);
switch (ev.type) {
case ConfigureNotify:
case MotionNotify:
discard = ev.type == nextev.type;
break;
case KeyPress:
discard = (nextev.type == KeyPress || nextev.type == KeyRelease)
&& ev.xkey.keycode == nextev.xkey.keycode;
break;
case ConfigureNotify:
case MotionNotify:
discard = ev.type == nextev.type;
break;
case KeyPress:
discard = (nextev.type == KeyPress || nextev.type == KeyRelease)
&& ev.xkey.keycode == nextev.xkey.keycode;
break;
}
}
} while (discard);
switch (ev.type) {
/* handle events */
case ButtonPress:
on_buttonpress(&ev.xbutton);
break;
case ClientMessage:
if ((Atom) ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW])
cg_quit(EXIT_SUCCESS);
break;
case DestroyNotify:
cg_quit(EXIT_FAILURE);
break;
case ConfigureNotify:
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:
switch (ev.type) { /* handle events */
case ButtonPress:
on_buttonpress(&ev.xbutton);
break;
case ClientMessage:
if ((Atom) ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW])
cg_quit(EXIT_SUCCESS);
break;
case DestroyNotify:
cg_quit(EXIT_FAILURE);
break;
case ConfigureNotify:
if (win_configure(&win, &ev.xconfigure)) {
if (mode == MODE_IMAGE) {
set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
reset_cursor();
img.dirty = true;
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;
}
}
}

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

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

Loading…
Cancel
Save