From 54d7b7f20fc80460fb6160badb6d90e6505a4194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Mohari?= Date: Fri, 31 Jan 2014 14:17:52 +0100 Subject: Use a prefix key to execute the key handler The default prefix key is C-x, and can be changed in config.def.h. The first key pressed after the prefix key will be passed the external key handler, unless the key is Escape, which is used to cancel the prefix. --- README.md | 4 ++++ config.def.h | 6 ++++++ exec/key-handler | 6 +++--- main.c | 14 ++++++++++++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6ccf1e8..7c456bf 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,10 @@ of small previews is displayed, making it easy to choose an image to open. N Go [count] marked images forward P Go [count] marked images backward + Ctrl-x KEY Execute $XDG_CONFIG_HOME/sxiv/exec/key-handler with + KEY and the path of the current image as arguments. + If KEY is Escape, it cancels the effect of Ctrl-x. + *Thumbnail mode:* h,j,k,l Move selection left/down/up/right [count] times diff --git a/config.def.h b/config.def.h index 6c03bc1..1fa8de7 100644 --- a/config.def.h +++ b/config.def.h @@ -77,6 +77,12 @@ static const bool RENDER_WHITE_ALPHA = false; #endif #ifdef _MAPPINGS_CONFIG +/* the prefix key: when pressed, the next key combo is passed to the external + * key handler + */ +#define PREFIX_KEYMASK ControlMask +#define PREFIX_KEYSYM XK_x + /* keyboard mappings for image and thumbnail mode: */ static const keymap_t keys[] = { /* modifiers key function argument */ diff --git a/exec/key-handler b/exec/key-handler index f4de310..db1fe2f 100644 --- a/exec/key-handler +++ b/exec/key-handler @@ -1,9 +1,9 @@ #!/bin/sh # Example for $XDG_CONFIG_HOME/sxiv/exec/key-handler -# Called by sxiv(1) whenever an unbound key combo is used, -# with the key combo as its first argument and the path of the current image -# as its second argument. +# Called by sxiv(1) when you press the prefix key (C-x by default) followed by +# a key combo. The key combo is passed as its first argument and the path of +# the current image as its second argument. # sxiv(1) blocks until this script terminates. It then checks if the image # has been modified and reloads it. diff --git a/main.c b/main.c index be91d68..5d1ef41 100644 --- a/main.c +++ b/main.c @@ -504,6 +504,7 @@ void run_key_handler(const char *key, unsigned int mask) void on_keypress(XKeyEvent *kev) { + static bool seen_prefix_key = false; int i; unsigned int sh; KeySym ksym, shksym; @@ -523,6 +524,17 @@ void on_keypress(XKeyEvent *kev) if (IsModifierKey(ksym)) return; + if (seen_prefix_key) { + seen_prefix_key = false; + if (!(MODMASK(kev->state) == 0 && ksym == XK_Escape)) + run_key_handler(XKeysymToString(ksym), kev->state & ~sh); + return; + } else if (MODMASK(kev->state) == PREFIX_KEYMASK && ksym == PREFIX_KEYSYM) { + seen_prefix_key = true; + prefix = 0; + return; + } + if ((ksym == XK_Escape && MODMASK(kev->state) == 0) || (key >= '0' && key <= '9')) { @@ -545,8 +557,6 @@ void on_keypress(XKeyEvent *kev) break; } } - if (i == ARRLEN(keys)) - run_key_handler(XKeysymToString(ksym), kev->state & ~sh); prefix = 0; } -- cgit v1.2.3 From 2d703c30a2372c6b9955f5c08fb6b727cbd3cee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Mohari?= Date: Fri, 31 Jan 2014 14:28:35 +0100 Subject: Fix tabs and wording --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7c456bf..b30bb35 100644 --- a/README.md +++ b/README.md @@ -113,9 +113,9 @@ of small previews is displayed, making it easy to choose an image to open. N Go [count] marked images forward P Go [count] marked images backward - Ctrl-x KEY Execute $XDG_CONFIG_HOME/sxiv/exec/key-handler with - KEY and the path of the current image as arguments. - If KEY is Escape, it cancels the effect of Ctrl-x. + Ctrl-x KEY Execute $XDG_CONFIG_HOME/sxiv/exec/key-handler with + KEY and the path of the current image as arguments, + unless KEY is Escape, which cancels Ctrl-x. *Thumbnail mode:* -- cgit v1.2.3