aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c23
-rw-r--r--window.c14
-rw-r--r--window.h2
3 files changed, 37 insertions, 2 deletions
diff --git a/main.c b/main.c
index 08189c2..4b4eb63 100644
--- a/main.c
+++ b/main.c
@@ -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);
+}
diff --git a/window.c b/window.c
index 3bc35f9..846117c 100644
--- a/window.c
+++ b/window.c
@@ -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;
diff --git a/window.h b/window.h
index 3a1b230..f090d26 100644
--- a/window.h
+++ b/window.h
@@ -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*);