| @@ -31,6 +31,8 @@ void on_keypress(XEvent*); |
| 31 | 31 | | void on_configurenotify(XEvent*); |
| 32 | 32 | | void on_expose(XEvent*); |
| 33 | 33 | | |
| 34 | + | void update_title(); |
| 35 | + | |
| 34 | 36 | | static void (*handler[LASTEvent])(XEvent*) = { |
| 35 | 37 | | [Expose] = on_expose, |
| 36 | 38 | | [ConfigureNotify] = on_configurenotify, |
| @@ -44,6 +46,9 @@ const char **filenames; |
| 44 | 46 | | unsigned int filecnt; |
| 45 | 47 | | unsigned int fileidx; |
| 46 | 48 | | |
| 49 | + | #define TITLE_LEN 256 |
| 50 | + | char win_title[TITLE_LEN]; |
| 51 | + | |
| 47 | 52 | | void run() { |
| 48 | 53 | | XEvent ev; |
| 49 | 54 | | |
| @@ -90,6 +95,7 @@ int main(int argc, char **argv) { |
| 90 | 95 | | |
| 91 | 96 | | img_load(&img, filenames[fileidx]); |
| 92 | 97 | | img_display(&img, &win); |
| 98 | + | update_title(); |
| 93 | 99 | | |
| 94 | 100 | | run(); |
| 95 | 101 | | |
| @@ -127,6 +133,7 @@ void on_keypress(XEvent *ev) { |
| 127 | 133 | | if (fileidx + 1 < filecnt) { |
| 128 | 134 | | img_load(&img, filenames[++fileidx]); |
| 129 | 135 | | img_display(&img, &win); |
| 136 | + | update_title(); |
| 130 | 137 | | } |
| 131 | 138 | | break; |
| 132 | 139 | | case XK_p: |
| @@ -134,6 +141,7 @@ void on_keypress(XEvent *ev) { |
| 134 | 141 | | if (fileidx > 0) { |
| 135 | 142 | | img_load(&img, filenames[--fileidx]); |
| 136 | 143 | | img_display(&img, &win); |
| 144 | + | update_title(); |
| 137 | 145 | | } |
| 138 | 146 | | break; |
| 139 | 147 | | } |
| @@ -153,3 +161,18 @@ void on_expose(XEvent *ev) { |
| 153 | 161 | | img_render(&img, &win, ev->xexpose.x, ev->xexpose.y, |
| 154 | 162 | | ev->xexpose.width, ev->xexpose.height); |
| 155 | 163 | | } |
| 164 | + | |
| 165 | + | void update_title() { |
| 166 | + | int n; |
| 167 | + | |
| 168 | + | n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] <%d%%> %s", fileidx + 1, |
| 169 | + | filecnt, (int) (img.zoom * 100.0), filenames[fileidx]); |
| 170 | + | |
| 171 | + | if (n >= TITLE_LEN) { |
| 172 | + | win_title[TITLE_LEN - 2] = '.'; |
| 173 | + | win_title[TITLE_LEN - 3] = '.'; |
| 174 | + | win_title[TITLE_LEN - 4] = '.'; |
| 175 | + | } |
| 176 | + | |
| 177 | + | win_set_title(&win, win_title); |
| 178 | + | } |