Krolyxon
Commit a82c454

Branches

Refs →

nsxiva82c454

Use ctrl for ext cmds, disable them in config.h

Author
Bert
Date
2011-03-09 10:08 +0100
Parent
00d4b0f
Commit
a82c45431bd31bfedaad00d77cc2ab4c772774d0

+34 −20

4 files changed

  1. M Makefile +1 −1
  2. M commands.h +5 −5
  3. M config.h +4 −0
  4. M main.c +24 −14
M Makefile View
@@ -1,6 +1,6 @@
11 all: sxiv
22
3−VERSION=git-20110303
3+VERSION=git-20110309
44
55 CC?=gcc
66 PREFIX?=/usr/local
M commands.h View
@@ -5,9 +5,9 @@ typedef struct {
55 } command_t;
66
77 static command_t commands[] = {
8− /* key reload? command, '#' is replaced by filename */
9− { XK_a, True, "jpegtran -rotate 270 -copy all -outfile # #" },
10− { XK_s, True, "jpegtran -rotate 90 -copy all -outfile # #" },
11− { XK_A, True, "mogrify -rotate -90 #" },
12− { XK_S, True, "mogrify -rotate +90 #" }
8+ /* ctrl-... reload? command, '#' is replaced by filename */
9+ { XK_comma, True, "jpegtran -rotate 270 -copy all -outfile # #" },
10+ { XK_period, True, "jpegtran -rotate 90 -copy all -outfile # #" },
11+ { XK_less, True, "mogrify -rotate -90 #" },
12+ { XK_greater, True, "mogrify -rotate +90 #" }
1313 };
M config.h View
@@ -24,3 +24,7 @@ static const float zoom_levels[] = {
2424
2525 /* default dimension of thumbnails (width == height): */
2626 #define THUMB_SIZE 60
27+
28+/* remove this line to disable external commands: *
29+ * (otherwise have a look at commands.h to define them) */
30+#define EXT_COMMANDS
M main.c View
@@ -30,12 +30,16 @@
3030 #include <X11/Xutil.h>
3131 #include <X11/keysym.h>
3232
33+#include "config.h"
3334 #include "image.h"
3435 #include "options.h"
3536 #include "thumbs.h"
3637 #include "util.h"
3738 #include "window.h"
39+
40+#ifdef EXT_COMMANDS
3841 #include "commands.h"
42+#endif
3943
4044 typedef enum {
4145 MODE_NORMAL = 0,
@@ -273,6 +277,7 @@ void read_dir_rec(const char *dirname) {
273277 free(dirnames);
274278 }
275279
280+#ifdef EXT_COMMANDS
276281 int run_command(const char *cline, Bool reload) {
277282 int fncnt, fnlen;
278283 char *cn, *cmdline;
@@ -328,6 +333,7 @@ int run_command(const char *cline, Bool reload) {
328333 free(cmdline);
329334 return ret;
330335 }
336+#endif /* EXT_COMMANDS */
331337
332338
333339 /* event handling */
@@ -352,7 +358,7 @@ void redraw() {
352358 }
353359
354360 void on_keypress(XKeyEvent *kev) {
355− int i, x, y;
361+ int x, y;
356362 unsigned int w, h;
357363 char key;
358364 KeySym ksym;
@@ -364,24 +370,28 @@ void on_keypress(XKeyEvent *kev) {
364370 XLookupString(kev, &key, 1, &ksym, NULL);
365371 changed = 0;
366372
373+#ifdef EXT_COMMANDS
367374 /* external commands from commands.h */
368− for (i = 0; i < LEN(commands); ++i) {
369− if (commands[i].ksym == ksym) {
370− win_set_cursor(&win, CURSOR_WATCH);
371− if (run_command(commands[i].cmdline, commands[i].reload)) {
372− if (mode == MODE_NORMAL) {
373− img_close(&img, 1);
374− load_image(fileidx);
375− tns_load(&tns, &win, fileidx, filenames[fileidx]);
376− } else {
377− tns_load(&tns, &win, tns.sel, filenames[tns.sel]);
375+ if (CLEANMASK(kev->state) & ControlMask) {
376+ for (x = 0; x < LEN(commands); ++x) {
377+ if (commands[x].ksym == ksym) {
378+ win_set_cursor(&win, CURSOR_WATCH);
379+ if (run_command(commands[x].cmdline, commands[x].reload)) {
380+ if (mode == MODE_NORMAL) {
381+ img_close(&img, 1);
382+ load_image(fileidx);
383+ tns_load(&tns, &win, fileidx, filenames[fileidx]);
384+ } else {
385+ tns_load(&tns, &win, tns.sel, filenames[tns.sel]);
386+ }
387+ redraw();
378388 }
379− redraw();
389+ win_set_cursor(&win, mode == MODE_NORMAL ? CURSOR_NONE : CURSOR_ARROW);
390+ return;
380391 }
381− win_set_cursor(&win, mode == MODE_NORMAL ? CURSOR_NONE : CURSOR_ARROW);
382− return;
383392 }
384393 }
394+#endif
385395
386396 if (mode == MODE_NORMAL) {
387397 switch (ksym) {