Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

removed unnecessary explicit case for escape key being pressed and... #428

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,11 @@ static const button_t buttons[] = {
{ 0, 5, g_zoom, -1 },
};


/* if false, sxiv will send all key combos to the external keyhandler until the
* keyhandler returns 1 as its exit status.
* the example external keyhandler uses the escape key for this.
*/
static const bool one_extkeyhandler_cmd = true;

#endif
1 change: 1 addition & 0 deletions exec/key-handler
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ case "$1" in
"C-comma") rotate 270 ;;
"C-period") rotate 90 ;;
"C-slash") rotate 180 ;;
"Escape") exit 1 ;;
esac

26 changes: 15 additions & 11 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ Bool is_input_ev(Display *dpy, XEvent *ev, XPointer arg)
return ev->type == ButtonPress || ev->type == KeyPress;
}

void run_key_handler(const char *key, unsigned int mask)
int run_key_handler(const char *key, unsigned int mask)
{
pid_t pid;
FILE *pfs;
Expand All @@ -479,25 +479,26 @@ void run_key_handler(const char *key, unsigned int mask)
char kstr[32];
struct stat *oldst, st;
XEvent dump;
int status;

if (keyhandler.f.err != 0) {
if (!keyhandler.warned) {
error(0, keyhandler.f.err, "%s", keyhandler.f.cmd);
keyhandler.warned = true;
}
return;
return 1;
}
if (key == NULL)
return;
return 1;

if (pipe(pfd) < 0) {
error(0, errno, "pipe");
return;
return 1;
}
if ((pfs = fdopen(pfd[1], "w")) == NULL) {
error(0, errno, "open pipe");
close(pfd[0]), close(pfd[1]);
return;
return 1;
}
oldst = emalloc(fcnt * sizeof(*oldst));

Expand Down Expand Up @@ -532,7 +533,7 @@ void run_key_handler(const char *key, unsigned int mask)
}
}
fclose(pfs);
while (waitpid(pid, NULL, 0) == -1 && errno == EINTR);
while (waitpid(pid, &status, 0) == -1 && errno == EINTR);

for (f = i = 0; f < fcnt; i++) {
if ((marked && (files[i].flags & FF_MARK)) || (!marked && i == fileidx)) {
Expand Down Expand Up @@ -563,6 +564,9 @@ void run_key_handler(const char *key, unsigned int mask)
free(oldst);
reset_cursor();
redraw();
if (WIFEXITED(status))
return WEXITSTATUS(status);
return 1;
}

#define MODMASK(mask) ((mask) & (ShiftMask|ControlMask|Mod1Mask))
Expand All @@ -586,11 +590,11 @@ void on_keypress(XKeyEvent *kev)
}
if (IsModifierKey(ksym))
return;
if (ksym == XK_Escape && MODMASK(kev->state) == 0) {
extprefix = False;
} else if (extprefix) {
run_key_handler(XKeysymToString(ksym), kev->state & ~sh);
extprefix = False;
if (extprefix) {
if (run_key_handler(XKeysymToString(ksym), kev->state & ~sh))
extprefix = False;
if (one_extkeyhandler_cmd)
extprefix = False;
} else if (key >= '0' && key <= '9') {
/* number prefix for commands */
prefix = prefix * 10 + (int) (key - '0');
Expand Down