Krolyxon
Commit 0f0c49a

Branches

Refs →

nsxiv0f0c49a

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
Author
explosion-mental
Date
2022-08-16 10:54 +0200
Committer
NRK · 2022-08-16 10:54 +0200
Parent
6578e6e
Commit
0f0c49a630285af10c765e0b724896ff281e7b66

+197 −198

4 files changed

  1. M image.c +41 −41
  2. M main.c +43 −44
  3. M options.c +99 −99
  4. M thumbs.c +14 −14
M image.c View
@@ -111,27 +111,27 @@ void exif_auto_orientate(const fileinfo_t *file)
111111 exif_data_unref(ed);
112112
113113 switch (orientation) {
114− case 5:
115− imlib_image_orientate(1);
116− /* fall through */
117− case 2:
118− imlib_image_flip_vertical();
119− break;
120− case 3:
121− imlib_image_orientate(2);
122− break;
123− case 7:
124− imlib_image_orientate(1);
125− /* fall through */
126− case 4:
127− imlib_image_flip_horizontal();
128− break;
129− case 6:
130− imlib_image_orientate(1);
131− break;
132− case 8:
133− imlib_image_orientate(3);
134− break;
114+ case 5:
115+ imlib_image_orientate(1);
116+ /* fall through */
117+ case 2:
118+ imlib_image_flip_vertical();
119+ break;
120+ case 3:
121+ imlib_image_orientate(2);
122+ break;
123+ case 7:
124+ imlib_image_orientate(1);
125+ /* fall through */
126+ case 4:
127+ imlib_image_flip_horizontal();
128+ break;
129+ case 6:
130+ imlib_image_orientate(1);
131+ break;
132+ case 8:
133+ imlib_image_orientate(3);
134+ break;
135135 }
136136 }
137137 #endif
@@ -531,18 +531,18 @@ static bool img_fit(img_t *img)
531531 zh = (float) img->win->h / (float) img->h;
532532
533533 switch (img->scalemode) {
534− case SCALE_FILL:
535− z = MAX(zw, zh);
536− break;
537− case SCALE_WIDTH:
538− z = zw;
539− break;
540− case SCALE_HEIGHT:
541− z = zh;
542− break;
543− default:
544− z = MIN(zw, zh);
545− break;
534+ case SCALE_FILL:
535+ z = MAX(zw, zh);
536+ break;
537+ case SCALE_WIDTH:
538+ z = zw;
539+ break;
540+ case SCALE_HEIGHT:
541+ z = zh;
542+ break;
543+ default:
544+ z = MIN(zw, zh);
545+ break;
546546 }
547547 z = MIN(z, img->scalemode == SCALE_DOWN ? 1.0 : ZOOM_MAX);
548548
@@ -741,14 +741,14 @@ bool img_pan(img_t *img, direction_t dir, int d)
741741 }
742742
743743 switch (dir) {
744− case DIR_LEFT:
745− return img_move(img, x, 0.0);
746− case DIR_RIGHT:
747− return img_move(img, -x, 0.0);
748− case DIR_UP:
749− return img_move(img, 0.0, y);
750− case DIR_DOWN:
751− return img_move(img, 0.0, -y);
744+ case DIR_LEFT:
745+ return img_move(img, x, 0.0);
746+ case DIR_RIGHT:
747+ return img_move(img, -x, 0.0);
748+ case DIR_UP:
749+ return img_move(img, 0.0, y);
750+ case DIR_DOWN:
751+ return img_move(img, 0.0, -y);
752752 }
753753 return false;
754754 }
M main.c View
@@ -753,56 +753,55 @@ static void run(void)
753753 if (XEventsQueued(win.env.dpy, QueuedAlready) > 0) {
754754 XPeekEvent(win.env.dpy, &nextev);
755755 switch (ev.type) {
756− case ConfigureNotify:
757− case MotionNotify:
758− discard = ev.type == nextev.type;
759− break;
760− case KeyPress:
761− discard = (nextev.type == KeyPress || nextev.type == KeyRelease)
762− && ev.xkey.keycode == nextev.xkey.keycode;
763− break;
756+ case ConfigureNotify:
757+ case MotionNotify:
758+ discard = ev.type == nextev.type;
759+ break;
760+ case KeyPress:
761+ discard = (nextev.type == KeyPress || nextev.type == KeyRelease)
762+ && ev.xkey.keycode == nextev.xkey.keycode;
763+ break;
764764 }
765765 }
766766 } while (discard);
767767
768− switch (ev.type) {
769− /* handle events */
770− case ButtonPress:
771− on_buttonpress(&ev.xbutton);
772− break;
773− case ClientMessage:
774− if ((Atom) ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW])
775− cg_quit(EXIT_SUCCESS);
776− break;
777− case DestroyNotify:
778− cg_quit(EXIT_FAILURE);
779− break;
780− case ConfigureNotify:
781− if (win_configure(&win, &ev.xconfigure)) {
782− if (mode == MODE_IMAGE) {
783− img.dirty = true;
784− img.checkpan = true;
785− } else {
786− tns.dirty = true;
787− }
788− if (!resized) {
789− redraw();
790− set_timeout(clear_resize, TO_REDRAW_RESIZE, false);
791− resized = true;
792− } else {
793− set_timeout(redraw, TO_REDRAW_RESIZE, false);
794− }
795− }
796− break;
797− case KeyPress:
798− on_keypress(&ev.xkey);
799− break;
800− case MotionNotify:
768+ switch (ev.type) { /* handle events */
769+ case ButtonPress:
770+ on_buttonpress(&ev.xbutton);
771+ break;
772+ case ClientMessage:
773+ if ((Atom) ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW])
774+ cg_quit(EXIT_SUCCESS);
775+ break;
776+ case DestroyNotify:
777+ cg_quit(EXIT_FAILURE);
778+ break;
779+ case ConfigureNotify:
780+ if (win_configure(&win, &ev.xconfigure)) {
801781 if (mode == MODE_IMAGE) {
802− set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
803− reset_cursor();
782+ img.dirty = true;
783+ img.checkpan = true;
784+ } else {
785+ tns.dirty = true;
804786 }
805− break;
787+ if (!resized) {
788+ redraw();
789+ set_timeout(clear_resize, TO_REDRAW_RESIZE, false);
790+ resized = true;
791+ } else {
792+ set_timeout(redraw, TO_REDRAW_RESIZE, false);
793+ }
794+ }
795+ break;
796+ case KeyPress:
797+ on_keypress(&ev.xkey);
798+ break;
799+ case MotionNotify:
800+ if (mode == MODE_IMAGE) {
801+ set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
802+ reset_cursor();
803+ }
804+ break;
806805 }
807806 }
808807 }
M options.c View
@@ -132,105 +132,105 @@ void parse_options(int argc, char **argv)
132132 assert(op.optarg != NULL);
133133 }
134134 switch (opt) {
135− case '?':
136− fprintf(stderr, "%s\n", op.errmsg);
137− print_usage();
138− exit(EXIT_FAILURE);
139− case 'A':
140− n = strtol(op.optarg, &end, 0);
141− if (*end != '\0' || n <= 0)
142− error(EXIT_FAILURE, 0, "Invalid argument for option -A: %s", op.optarg);
143− _options.framerate = n;
144− /* fall through */
145− case 'a':
146− _options.animate = true;
147− break;
148− case 'b':
149− _options.hide_bar = true;
150− break;
151− case 'c':
152− _options.clean_cache = true;
153− break;
154− case 'e':
155− n = strtol(op.optarg, &end, 0);
156− if (*end != '\0')
157− error(EXIT_FAILURE, 0, "Invalid argument for option -e: %s", op.optarg);
158− _options.embed = n;
159− break;
160− case 'f':
161− _options.fullscreen = true;
162− break;
163− case 'G':
164− n = strtol(op.optarg, &end, 0);
165− if (*end != '\0')
166− error(EXIT_FAILURE, 0, "Invalid argument for option -G: %s", op.optarg);
167− _options.gamma = n;
168− break;
169− case 'g':
170− _options.geometry = op.optarg;
171− break;
172− case 'h':
173− print_usage();
174− exit(EXIT_SUCCESS);
175− case 'i':
176− _options.from_stdin = true;
177− break;
178− case 'n':
179− n = strtol(op.optarg, &end, 0);
180− if (*end != '\0' || n <= 0)
181− error(EXIT_FAILURE, 0, "Invalid argument for option -n: %s", op.optarg);
182− _options.startnum = n - 1;
183− break;
184− case 'N':
185− _options.res_name = op.optarg;
186− break;
187− case 'o':
188− _options.to_stdout = true;
189− break;
190− case 'p':
191− _options.private_mode = true;
192− break;
193− case 'q':
194− _options.quiet = true;
195− break;
196− case 'r':
197− _options.recursive = true;
198− break;
199− case 'S':
200− n = strtof(op.optarg, &end) * 10;
201− if (*end != '\0' || n <= 0)
202− error(EXIT_FAILURE, 0, "Invalid argument for option -S: %s", op.optarg);
203− _options.slideshow = n;
204− break;
205− case 's':
206− s = strchr(scalemodes, op.optarg[0]);
207− if (s == NULL || *s == '\0' || strlen(op.optarg) != 1)
208− error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", op.optarg);
209− _options.scalemode = s - scalemodes;
210− break;
211− case 'T':
212− title_deprecation_notice(); /* TODO(v31): remove this option */
213− break;
214− case 't':
215− _options.thumb_mode = true;
216− break;
217− case 'v':
218− print_version();
219− exit(EXIT_SUCCESS);
220− case 'Z':
221− _options.scalemode = SCALE_ZOOM;
222− _options.zoom = 1.0f;
223− break;
224− case 'z':
225− n = strtol(op.optarg, &end, 0);
226− if (*end != '\0' || n <= 0)
227− error(EXIT_FAILURE, 0, "Invalid argument for option -z: %s", op.optarg);
228− _options.scalemode = SCALE_ZOOM;
229− _options.zoom = (float) n / 100.0f;
230− break;
231− case '0':
232− _options.using_null = true;
233− break;
135+ case '?':
136+ fprintf(stderr, "%s\n", op.errmsg);
137+ print_usage();
138+ exit(EXIT_FAILURE);
139+ case 'A':
140+ n = strtol(op.optarg, &end, 0);
141+ if (*end != '\0' || n <= 0)
142+ error(EXIT_FAILURE, 0, "Invalid argument for option -A: %s", op.optarg);
143+ _options.framerate = n;
144+ /* fall through */
145+ case 'a':
146+ _options.animate = true;
147+ break;
148+ case 'b':
149+ _options.hide_bar = true;
150+ break;
151+ case 'c':
152+ _options.clean_cache = true;
153+ break;
154+ case 'e':
155+ n = strtol(op.optarg, &end, 0);
156+ if (*end != '\0')
157+ error(EXIT_FAILURE, 0, "Invalid argument for option -e: %s", op.optarg);
158+ _options.embed = n;
159+ break;
160+ case 'f':
161+ _options.fullscreen = true;
162+ break;
163+ case 'G':
164+ n = strtol(op.optarg, &end, 0);
165+ if (*end != '\0')
166+ error(EXIT_FAILURE, 0, "Invalid argument for option -G: %s", op.optarg);
167+ _options.gamma = n;
168+ break;
169+ case 'g':
170+ _options.geometry = op.optarg;
171+ break;
172+ case 'h':
173+ print_usage();
174+ exit(EXIT_SUCCESS);
175+ case 'i':
176+ _options.from_stdin = true;
177+ break;
178+ case 'n':
179+ n = strtol(op.optarg, &end, 0);
180+ if (*end != '\0' || n <= 0)
181+ error(EXIT_FAILURE, 0, "Invalid argument for option -n: %s", op.optarg);
182+ _options.startnum = n - 1;
183+ break;
184+ case 'N':
185+ _options.res_name = op.optarg;
186+ break;
187+ case 'o':
188+ _options.to_stdout = true;
189+ break;
190+ case 'p':
191+ _options.private_mode = true;
192+ break;
193+ case 'q':
194+ _options.quiet = true;
195+ break;
196+ case 'r':
197+ _options.recursive = true;
198+ break;
199+ case 'S':
200+ n = strtof(op.optarg, &end) * 10;
201+ if (*end != '\0' || n <= 0)
202+ error(EXIT_FAILURE, 0, "Invalid argument for option -S: %s", op.optarg);
203+ _options.slideshow = n;
204+ break;
205+ case 's':
206+ s = strchr(scalemodes, op.optarg[0]);
207+ if (s == NULL || *s == '\0' || strlen(op.optarg) != 1)
208+ error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", op.optarg);
209+ _options.scalemode = s - scalemodes;
210+ break;
211+ case 'T':
212+ title_deprecation_notice(); /* TODO(v31): remove this option */
213+ break;
214+ case 't':
215+ _options.thumb_mode = true;
216+ break;
217+ case 'v':
218+ print_version();
219+ exit(EXIT_SUCCESS);
220+ case 'Z':
221+ _options.scalemode = SCALE_ZOOM;
222+ _options.zoom = 1.0f;
223+ break;
224+ case 'z':
225+ n = strtol(op.optarg, &end, 0);
226+ if (*end != '\0' || n <= 0)
227+ error(EXIT_FAILURE, 0, "Invalid argument for option -z: %s", op.optarg);
228+ _options.scalemode = SCALE_ZOOM;
229+ _options.zoom = (float) n / 100.0f;
230+ break;
231+ case '0':
232+ _options.using_null = true;
233+ break;
234234 }
235235 }
236236
M thumbs.c View
@@ -505,20 +505,20 @@ bool tns_move_selection(tns_t *tns, direction_t dir, int cnt)
505505 cnt = cnt > 1 ? cnt : 1;
506506
507507 switch (dir) {
508− case DIR_UP:
509− *tns->sel = MAX(*tns->sel - cnt * tns->cols, *tns->sel % tns->cols);
510− break;
511− case DIR_DOWN:
512− max = tns->cols * ((*tns->cnt - 1) / tns->cols) +
513− MIN((*tns->cnt - 1) % tns->cols, *tns->sel % tns->cols);
514− *tns->sel = MIN(*tns->sel + cnt * tns->cols, max);
515− break;
516− case DIR_LEFT:
517− *tns->sel = MAX(*tns->sel - cnt, 0);
518− break;
519− case DIR_RIGHT:
520− *tns->sel = MIN(*tns->sel + cnt, *tns->cnt - 1);
521− break;
508+ case DIR_UP:
509+ *tns->sel = MAX(*tns->sel - cnt * tns->cols, *tns->sel % tns->cols);
510+ break;
511+ case DIR_DOWN:
512+ max = tns->cols * ((*tns->cnt - 1) / tns->cols) +
513+ MIN((*tns->cnt - 1) % tns->cols, *tns->sel % tns->cols);
514+ *tns->sel = MIN(*tns->sel + cnt * tns->cols, max);
515+ break;
516+ case DIR_LEFT:
517+ *tns->sel = MAX(*tns->sel - cnt, 0);
518+ break;
519+ case DIR_RIGHT:
520+ *tns->sel = MIN(*tns->sel + cnt, *tns->cnt - 1);
521+ break;
522522 }
523523
524524 if (*tns->sel != old) {