Show key handler status in bar while it is running
This commit is contained in:
parent
5cfae63620
commit
5d0679b855
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
VERSION = git-20140610
|
VERSION = git-20140615
|
||||||
|
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
MANPREFIX = $(PREFIX)/share/man
|
MANPREFIX = $(PREFIX)/share/man
|
||||||
|
|
24
main.c
24
main.c
|
@ -465,7 +465,8 @@ void run_key_handler(const char *key, unsigned int mask)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int retval, status, n = mode == MODE_IMAGE ? fileidx : tns.sel;
|
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;
|
struct stat oldst, newst;
|
||||||
|
|
||||||
if (keyhandler.cmd == NULL) {
|
if (keyhandler.cmd == NULL) {
|
||||||
|
@ -483,6 +484,11 @@ void run_key_handler(const char *key, unsigned int mask)
|
||||||
mask & Mod1Mask ? "M-" : "",
|
mask & Mod1Mask ? "M-" : "",
|
||||||
mask & ShiftMask ? "S-" : "", key);
|
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);
|
stat(files[n].path, &oldst);
|
||||||
|
|
||||||
if ((pid = fork()) == 0) {
|
if ((pid = fork()) == 0) {
|
||||||
|
@ -491,10 +497,8 @@ void run_key_handler(const char *key, unsigned int mask)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
} else if (pid < 0) {
|
} else if (pid < 0) {
|
||||||
warn("could not fork key handler");
|
warn("could not fork key handler");
|
||||||
return;
|
goto end;
|
||||||
}
|
}
|
||||||
win_set_cursor(&win, CURSOR_WATCH);
|
|
||||||
|
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
retval = WEXITSTATUS(status);
|
retval = WEXITSTATUS(status);
|
||||||
if (WIFEXITED(status) == 0 || retval != 0)
|
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)
|
memcmp(&oldst.st_mtime, &newst.st_mtime, sizeof(oldst.st_mtime)) == 0)
|
||||||
{
|
{
|
||||||
/* file has not changed */
|
/* file has not changed */
|
||||||
win_set_cursor(&win, CURSOR_ARROW);
|
goto end;
|
||||||
set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
restore_bar = false;
|
||||||
|
strncpy(win.bar.l, "Reloading image...", sizeof(win.bar.l));
|
||||||
|
win_update_bar(&win);
|
||||||
|
|
||||||
if (mode == MODE_IMAGE) {
|
if (mode == MODE_IMAGE) {
|
||||||
img_close(&img, true);
|
img_close(&img, true);
|
||||||
load_image(fileidx);
|
load_image(fileidx);
|
||||||
|
@ -520,6 +526,10 @@ void run_key_handler(const char *key, unsigned int mask)
|
||||||
if (tns.sel >= tns.cnt)
|
if (tns.sel >= tns.cnt)
|
||||||
tns.sel = tns.cnt - 1;
|
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();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
window.c
2
window.c
|
@ -481,6 +481,7 @@ void win_draw(win_t *win)
|
||||||
|
|
||||||
XCopyArea(win->env.dpy, win->pm, win->xwin, gc,
|
XCopyArea(win->env.dpy, win->pm, win->xwin, gc,
|
||||||
0, 0, win->w, win->h + win->bar.h, 0, 0);
|
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,
|
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);
|
win_draw_bar(win);
|
||||||
XCopyArea(win->env.dpy, win->pm, win->xwin, gc,
|
XCopyArea(win->env.dpy, win->pm, win->xwin, gc,
|
||||||
0, win->h, win->w, win->bar.h, 0, win->h);
|
0, win->h, win->w, win->bar.h, 0, win->h);
|
||||||
|
XFlush(win->env.dpy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue