Krolyxon
Commit 5d0679b

Branches

Refs →

nsxiv5d0679b

Show key handler status in bar while it is running

Author
Bert Münnich
Date
2014-06-15 14:15 +0200
Parent
5cfae63
Commit
5d0679b855bb42aaaf3435a3182ac5ddb4412e1f

+20 −8

3 files changed

  1. M Makefile +1 −1
  2. M main.c +17 −7
  3. M window.c +2 −0
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20140610
1+VERSION = git-20140615
22
33 PREFIX = /usr/local
44 MANPREFIX = $(PREFIX)/share/man
M main.c View
@@ -465,7 +465,8 @@ void run_key_handler(const char *key, unsigned int mask)
465465 {
466466 pid_t pid;
467467 int retval, status, n = mode == MODE_IMAGE ? fileidx : tns.sel;
468− char kstr[32];
468+ char kstr[32], oldbar[sizeof(win.bar.l)];
469+ bool restore_bar = mode == MODE_IMAGE && info.cmd != NULL;
469470 struct stat oldst, newst;
470471
471472 if (keyhandler.cmd == NULL) {
@@ -483,6 +484,11 @@ void run_key_handler(const char *key, unsigned int mask)
483484 mask & Mod1Mask ? "M-" : "",
484485 mask & ShiftMask ? "S-" : "", key);
485486
487+ if (restore_bar)
488+ memcpy(oldbar, win.bar.l, sizeof(win.bar.l));
489+ strncpy(win.bar.l, "Running key handler...", sizeof(win.bar.l));
490+ win_update_bar(&win);
491+ win_set_cursor(&win, CURSOR_WATCH);
486492 stat(files[n].path, &oldst);
487493
488494 if ((pid = fork()) == 0) {
@@ -491,10 +497,8 @@ void run_key_handler(const char *key, unsigned int mask)
491497 exit(EXIT_FAILURE);
492498 } else if (pid < 0) {
493499 warn("could not fork key handler");
494− return;
500+ goto end;
495501 }
496− win_set_cursor(&win, CURSOR_WATCH);
497−
498502 waitpid(pid, &status, 0);
499503 retval = WEXITSTATUS(status);
500504 if (WIFEXITED(status) == 0 || retval != 0)
@@ -504,10 +508,12 @@ void run_key_handler(const char *key, unsigned int mask)
504508 memcmp(&oldst.st_mtime, &newst.st_mtime, sizeof(oldst.st_mtime)) == 0)
505509 {
506510 /* file has not changed */
507− win_set_cursor(&win, CURSOR_ARROW);
508− set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
509− return;
511+ goto end;
510512 }
513+ restore_bar = false;
514+ strncpy(win.bar.l, "Reloading image...", sizeof(win.bar.l));
515+ win_update_bar(&win);
516+
511517 if (mode == MODE_IMAGE) {
512518 img_close(&img, true);
513519 load_image(fileidx);
@@ -520,6 +526,10 @@ void run_key_handler(const char *key, unsigned int mask)
520526 if (tns.sel >= tns.cnt)
521527 tns.sel = tns.cnt - 1;
522528 }
529+end:
530+ if (restore_bar)
531+ memcpy(win.bar.l, oldbar, sizeof(win.bar.l));
532+ set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
523533 redraw();
524534 }
525535
M window.c View
@@ -481,6 +481,7 @@ void win_draw(win_t *win)
481481
482482 XCopyArea(win->env.dpy, win->pm, win->xwin, gc,
483483 0, 0, win->w, win->h + win->bar.h, 0, 0);
484+ XFlush(win->env.dpy);
484485 }
485486
486487 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)
510511 win_draw_bar(win);
511512 XCopyArea(win->env.dpy, win->pm, win->xwin, gc,
512513 0, win->h, win->w, win->bar.h, 0, win->h);
514+ XFlush(win->env.dpy);
513515 }
514516 }
515517