diff options
author | Bert <ber.t@gmx.com> | 2011-01-20 17:00:59 +0100 |
---|---|---|
committer | Bert <ber.t@gmx.com> | 2011-01-20 17:00:59 +0100 |
commit | 08018427c61435de9cd8dca1d1cc9bb69ca2fd74 (patch) | |
tree | 33b4144194d1e30c87331ae6613d151c1147c947 /main.c | |
parent | eeb58886a5b9d7460f81a1e3216692b5dc3a6341 (diff) |
Put some useful information in the window title
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -31,6 +31,8 @@ void on_keypress(XEvent*); void on_configurenotify(XEvent*); void on_expose(XEvent*); +void update_title(); + static void (*handler[LASTEvent])(XEvent*) = { [Expose] = on_expose, [ConfigureNotify] = on_configurenotify, @@ -44,6 +46,9 @@ const char **filenames; unsigned int filecnt; unsigned int fileidx; +#define TITLE_LEN 256 +char win_title[TITLE_LEN]; + void run() { XEvent ev; @@ -90,6 +95,7 @@ int main(int argc, char **argv) { img_load(&img, filenames[fileidx]); img_display(&img, &win); + update_title(); run(); @@ -127,6 +133,7 @@ void on_keypress(XEvent *ev) { if (fileidx + 1 < filecnt) { img_load(&img, filenames[++fileidx]); img_display(&img, &win); + update_title(); } break; case XK_p: @@ -134,6 +141,7 @@ void on_keypress(XEvent *ev) { if (fileidx > 0) { img_load(&img, filenames[--fileidx]); img_display(&img, &win); + update_title(); } break; } @@ -153,3 +161,18 @@ void on_expose(XEvent *ev) { img_render(&img, &win, ev->xexpose.x, ev->xexpose.y, ev->xexpose.width, ev->xexpose.height); } + +void update_title() { + int n; + + n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] <%d%%> %s", fileidx + 1, + filecnt, (int) (img.zoom * 100.0), filenames[fileidx]); + + if (n >= TITLE_LEN) { + win_title[TITLE_LEN - 2] = '.'; + win_title[TITLE_LEN - 3] = '.'; + win_title[TITLE_LEN - 4] = '.'; + } + + win_set_title(&win, win_title); +} |