From a82c45431bd31bfedaad00d77cc2ab4c772774d0 Mon Sep 17 00:00:00 2001 From: Bert Date: Wed, 9 Mar 2011 10:08:43 +0100 Subject: [PATCH] Use ctrl for ext cmds, disable them in config.h --- Makefile | 2 +- commands.h | 10 +++++----- config.h | 4 ++++ main.c | 38 ++++++++++++++++++++++++-------------- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index e3882bc..3bd788e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: sxiv -VERSION=git-20110303 +VERSION=git-20110309 CC?=gcc PREFIX?=/usr/local diff --git a/commands.h b/commands.h index cb14fe6..ce00858 100644 --- a/commands.h +++ b/commands.h @@ -5,9 +5,9 @@ typedef struct { } command_t; static command_t commands[] = { - /* key reload? command, '#' is replaced by filename */ - { XK_a, True, "jpegtran -rotate 270 -copy all -outfile # #" }, - { XK_s, True, "jpegtran -rotate 90 -copy all -outfile # #" }, - { XK_A, True, "mogrify -rotate -90 #" }, - { XK_S, True, "mogrify -rotate +90 #" } + /* ctrl-... reload? command, '#' is replaced by filename */ + { XK_comma, True, "jpegtran -rotate 270 -copy all -outfile # #" }, + { XK_period, True, "jpegtran -rotate 90 -copy all -outfile # #" }, + { XK_less, True, "mogrify -rotate -90 #" }, + { XK_greater, True, "mogrify -rotate +90 #" } }; diff --git a/config.h b/config.h index 0646787..bf48538 100644 --- a/config.h +++ b/config.h @@ -24,3 +24,7 @@ static const float zoom_levels[] = { /* default dimension of thumbnails (width == height): */ #define THUMB_SIZE 60 + +/* remove this line to disable external commands: * + * (otherwise have a look at commands.h to define them) */ +#define EXT_COMMANDS diff --git a/main.c b/main.c index d736d12..339eb95 100644 --- a/main.c +++ b/main.c @@ -30,12 +30,16 @@ #include #include +#include "config.h" #include "image.h" #include "options.h" #include "thumbs.h" #include "util.h" #include "window.h" + +#ifdef EXT_COMMANDS #include "commands.h" +#endif typedef enum { MODE_NORMAL = 0, @@ -273,6 +277,7 @@ void read_dir_rec(const char *dirname) { free(dirnames); } +#ifdef EXT_COMMANDS int run_command(const char *cline, Bool reload) { int fncnt, fnlen; char *cn, *cmdline; @@ -328,6 +333,7 @@ int run_command(const char *cline, Bool reload) { free(cmdline); return ret; } +#endif /* EXT_COMMANDS */ /* event handling */ @@ -352,7 +358,7 @@ void redraw() { } void on_keypress(XKeyEvent *kev) { - int i, x, y; + int x, y; unsigned int w, h; char key; KeySym ksym; @@ -364,24 +370,28 @@ void on_keypress(XKeyEvent *kev) { XLookupString(kev, &key, 1, &ksym, NULL); changed = 0; +#ifdef EXT_COMMANDS /* external commands from commands.h */ - for (i = 0; i < LEN(commands); ++i) { - if (commands[i].ksym == ksym) { - win_set_cursor(&win, CURSOR_WATCH); - if (run_command(commands[i].cmdline, commands[i].reload)) { - if (mode == MODE_NORMAL) { - img_close(&img, 1); - load_image(fileidx); - tns_load(&tns, &win, fileidx, filenames[fileidx]); - } else { - tns_load(&tns, &win, tns.sel, filenames[tns.sel]); + if (CLEANMASK(kev->state) & ControlMask) { + for (x = 0; x < LEN(commands); ++x) { + if (commands[x].ksym == ksym) { + win_set_cursor(&win, CURSOR_WATCH); + if (run_command(commands[x].cmdline, commands[x].reload)) { + if (mode == MODE_NORMAL) { + img_close(&img, 1); + load_image(fileidx); + tns_load(&tns, &win, fileidx, filenames[fileidx]); + } else { + tns_load(&tns, &win, tns.sel, filenames[tns.sel]); + } + redraw(); } - redraw(); + win_set_cursor(&win, mode == MODE_NORMAL ? CURSOR_NONE : CURSOR_ARROW); + return; } - win_set_cursor(&win, mode == MODE_NORMAL ? CURSOR_NONE : CURSOR_ARROW); - return; } } +#endif if (mode == MODE_NORMAL) { switch (ksym) {