Show key handler status in bar while it is running

master
Bert Münnich 2014-06-15 14:15:48 +02:00
parent 5cfae63620
commit 5d0679b855
3 changed files with 20 additions and 8 deletions

View File

@ -1,4 +1,4 @@
VERSION = git-20140610
VERSION = git-20140615
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man

24
main.c
View File

@ -465,7 +465,8 @@ void run_key_handler(const char *key, unsigned int mask)
{
pid_t pid;
int retval, status, n = mode == MODE_IMAGE ? fileidx : tns.sel;
char kstr[32];
char kstr[32], oldbar[sizeof(win.bar.l)];
bool restore_bar = mode == MODE_IMAGE && info.cmd != NULL;
struct stat oldst, newst;
if (keyhandler.cmd == NULL) {
@ -483,6 +484,11 @@ void run_key_handler(const char *key, unsigned int mask)
mask & Mod1Mask ? "M-" : "",
mask & ShiftMask ? "S-" : "", key);
if (restore_bar)
memcpy(oldbar, win.bar.l, sizeof(win.bar.l));
strncpy(win.bar.l, "Running key handler...", sizeof(win.bar.l));
win_update_bar(&win);
win_set_cursor(&win, CURSOR_WATCH);
stat(files[n].path, &oldst);
if ((pid = fork()) == 0) {
@ -491,10 +497,8 @@ void run_key_handler(const char *key, unsigned int mask)
exit(EXIT_FAILURE);
} else if (pid < 0) {
warn("could not fork key handler");
return;
goto end;
}
win_set_cursor(&win, CURSOR_WATCH);
waitpid(pid, &status, 0);
retval = WEXITSTATUS(status);
if (WIFEXITED(status) == 0 || retval != 0)
@ -504,10 +508,12 @@ void run_key_handler(const char *key, unsigned int mask)
memcmp(&oldst.st_mtime, &newst.st_mtime, sizeof(oldst.st_mtime)) == 0)
{
/* file has not changed */
win_set_cursor(&win, CURSOR_ARROW);
set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
return;
goto end;
}
restore_bar = false;
strncpy(win.bar.l, "Reloading image...", sizeof(win.bar.l));
win_update_bar(&win);
if (mode == MODE_IMAGE) {
img_close(&img, true);
load_image(fileidx);
@ -520,6 +526,10 @@ void run_key_handler(const char *key, unsigned int mask)
if (tns.sel >= tns.cnt)
tns.sel = tns.cnt - 1;
}
end:
if (restore_bar)
memcpy(win.bar.l, oldbar, sizeof(win.bar.l));
set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
redraw();
}

View File

@ -481,6 +481,7 @@ void win_draw(win_t *win)
XCopyArea(win->env.dpy, win->pm, win->xwin, gc,
0, 0, win->w, win->h + win->bar.h, 0, 0);
XFlush(win->env.dpy);
}
void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h,
@ -510,6 +511,7 @@ void win_update_bar(win_t *win)
win_draw_bar(win);
XCopyArea(win->env.dpy, win->pm, win->xwin, gc,
0, win->h, win->w, win->bar.h, 0, win->h);
XFlush(win->env.dpy);
}
}