Krolyxon
Commit 30802ce

Branches

Refs →

nsxiv30802ce

Spawn info script & update bar contents only when needed

Author
Bert Münnich
Date
2013-02-12 17:55 +0100
Committer
Bert Münnich · 2013-03-19 21:14 +0100
Parent
f329840
Commit
30802cec0f233aa9977256684cb749df6c7e28c0

+26 −11

3 files changed

  1. M commands.c +6 −2
  2. M main.c +17 −7
  3. M window.c +3 −2
M commands.c View
@@ -33,6 +33,7 @@
3333 void cleanup(void);
3434 void remove_file(int, bool);
3535 void load_image(int);
36+void open_info(void);
3637 void redraw(void);
3738 void reset_cursor(void);
3839 void animate(void);
@@ -92,10 +93,13 @@ bool it_toggle_fullscreen(arg_t a)
9293 bool it_toggle_bar(arg_t a)
9394 {
9495 win_toggle_bar(&win);
95− if (mode == MODE_IMAGE)
96+ if (mode == MODE_IMAGE) {
9697 img.checkpan = img.dirty = true;
97− else
98+ if (win.bar.h > 0)
99+ open_info();
100+ } else {
98101 tns.dirty = true;
102+ }
99103 return true;
100104 }
101105
M main.c View
@@ -76,6 +76,7 @@ struct {
7676 char *script;
7777 int fd;
7878 unsigned int i, lastsep;
79+ bool open;
7980 } info;
8081
8182 timeout_t timeouts[] = {
@@ -218,23 +219,25 @@ void open_info(void)
218219 static pid_t pid;
219220 int pfd[2];
220221
221− win.bar.l[0] = '\0';
222−
222+ if (info.script == NULL || info.open || win.bar.h == 0)
223+ return;
223224 if (info.fd != -1) {
224225 close(info.fd);
225226 kill(pid, SIGTERM);
226227 while (waitpid(-1, NULL, WNOHANG) > 0);
227228 info.fd = -1;
228229 }
229− if (info.script == NULL || pipe(pfd) < 0)
230− return;
230+ win.bar.l[0] = '\0';
231231
232+ if (pipe(pfd) < 0)
233+ return;
232234 pid = fork();
233235 if (pid > 0) {
234236 close(pfd[1]);
235237 fcntl(pfd[0], F_SETFL, O_NONBLOCK);
236238 info.fd = pfd[0];
237239 info.i = info.lastsep = 0;
240+ info.open = true;
238241 } else if (pid == 0) {
239242 close(pfd[0]);
240243 dup2(pfd[1], 1);
@@ -293,6 +296,7 @@ void load_image(int new)
293296 alternate = fileidx;
294297 fileidx = new;
295298
299+ info.open = false;
296300 open_info();
297301
298302 if (img.multi.cnt > 0 && img.multi.animate)
@@ -312,9 +316,18 @@ void update_info(void)
312316 for (fw = 0, i = filecnt; i > 0; fw++, i /= 10);
313317 sel = mode == MODE_IMAGE ? fileidx : tns.sel;
314318
319+ /* update window title */
315320 if (mode == MODE_THUMB) {
316321 win_set_title(&win, "sxiv");
322+ } else {
323+ snprintf(title, sizeof(title), "sxiv - %s", files[sel].name);
324+ win_set_title(&win, title);
325+ }
317326
327+ /* update bar contents */
328+ if (win.bar.h == 0)
329+ return;
330+ if (mode == MODE_THUMB) {
318331 if (tns.cnt == filecnt) {
319332 n = snprintf(rt, rlen, "%0*d/%d", fw, sel + 1, filecnt);
320333 ow_info = true;
@@ -324,9 +337,6 @@ void update_info(void)
324337 ow_info = false;
325338 }
326339 } else {
327− snprintf(title, sizeof(title), "sxiv - %s", files[sel].name);
328− win_set_title(&win, title);
329−
330340 n = snprintf(rt, rlen, "%3d%% ", (int) (img.zoom * 100.0));
331341 if (img.multi.cnt > 0) {
332342 for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10);
M window.c View
@@ -119,12 +119,15 @@ void win_init(win_t *win)
119119 e->cmap = DefaultColormap(e->dpy, e->scr);
120120 e->depth = DefaultDepth(e->dpy, e->scr);
121121
122+ win_init_font(e->dpy, BAR_FONT);
123+
122124 win->white = WhitePixel(e->dpy, e->scr);
123125 win->bgcol = win_alloc_color(win, WIN_BG_COLOR);
124126 win->fscol = win_alloc_color(win, WIN_FS_COLOR);
125127 win->selcol = win_alloc_color(win, SEL_COLOR);
126128 win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR);
127129 win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR);
130+ win->bar.h = options->hide_bar ? 0 : barheight;
128131
129132 win->sizehints.flags = PWinGravity;
130133 win->sizehints.win_gravity = NorthWestGravity;
@@ -135,8 +138,6 @@ void win_init(win_t *win)
135138 if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0)
136139 warn("no locale support");
137140
138− win_init_font(e->dpy, BAR_FONT);
139−
140141 wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False);
141142 }
142143