Put some useful information in the window title

This commit is contained in:
Bert 2011-01-20 17:00:59 +01:00
parent eeb58886a5
commit 08018427c6
3 changed files with 37 additions and 2 deletions

23
main.c
View File

@ -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);
}

View File

@ -72,8 +72,7 @@ void win_open(win_t *win) {
XSelectInput(e->dpy, win->xwin,
StructureNotifyMask | ExposureMask | KeyPressMask);
XStoreName(e->dpy, win->xwin, "sxiv");
XSetIconName(e->dpy, win->xwin, "Sxiv");
win_set_title(win, "sxiv");
if ((classhint = XAllocClassHint())) {
classhint->res_name = "sxiv";
@ -94,6 +93,17 @@ void win_close(win_t *win) {
XCloseDisplay(win->env.dpy);
}
void win_set_title(win_t *win, const char *title) {
if (!win)
return;
if (!title)
title = "sxiv";
XStoreName(win->env.dpy, win->xwin, title);
XSetIconName(win->env.dpy, win->xwin, title);
}
int win_configure(win_t *win, XConfigureEvent *cev) {
int changed;

View File

@ -46,6 +46,8 @@ typedef struct win_s {
void win_open(win_t*);
void win_close(win_t*);
void win_set_title(win_t*, const char*);
int win_configure(win_t*, XConfigureEvent*);
void win_clear(win_t*);