diff --git a/main.c b/main.c index 85776825..1884a116 100644 --- a/main.c +++ b/main.c @@ -314,6 +314,7 @@ void load_image(int new) close_info(); open_info(); arl_setup(&arl, files[fileidx].path); + win_set_title(&win, files[fileidx].path); if (img.multi.cnt > 0 && img.multi.animate) set_timeout(animate, img.multi.frames[img.multi.sel].delay, true); @@ -937,6 +938,7 @@ int main(int argc, char **argv) load_image(fileidx); } win_open(&win); + win_set_title(&win, files[fileidx].path); win_set_cursor(&win, CURSOR_WATCH); atexit(cleanup); diff --git a/rxiv.1 b/rxiv.1 index eac97f92..f1a23c12 100644 --- a/rxiv.1 +++ b/rxiv.1 @@ -426,6 +426,21 @@ Color of the bar foreground, if not set defaults to window background .B font Name of Xft bar font .TP +.B titlePrefix +Any string literal to be used as the window title prefix. +.TP +.B titleSuffix +The format of the window title suffix. + +.EX + Value Format + 0 Basename of file + 1 Basename of directory + 2 Full path to file + 3 Full path to directory + 4 Empty string +.EE +.TP Please see xrdb(1) on how to change them. .SH STATUS BAR The information displayed on the left side of the status bar can be replaced diff --git a/rxiv.h b/rxiv.h index 69428975..67a4bfcf 100644 --- a/rxiv.h +++ b/rxiv.h @@ -116,6 +116,16 @@ typedef enum { FF_TN_INIT = 4 } fileflags_t; +typedef enum { + BASE_CFILE, + BASE_CDIR, + CFILE, + CDIR, + EMPTY, + + SUFFIXMODE_COUNT, +} suffixmode_t; + typedef struct { const char *name; /* as given by user */ const char *path; /* always absolute */ @@ -423,6 +433,10 @@ struct win { XftColor bbg; XftColor bfg; + suffixmode_t suffixmode; + const char *prefix; + const char *suffix; + int x; int y; unsigned int w; diff --git a/thumbs.c b/thumbs.c index f104e3eb..4e62db84 100644 --- a/thumbs.c +++ b/thumbs.c @@ -35,6 +35,7 @@ void exif_auto_orientate(const fileinfo_t*); Imlib_Image img_open(const fileinfo_t*); static char *cache_dir; +extern const int fileidx; char* tns_cache_filepath(const char *filepath) { @@ -541,6 +542,7 @@ bool tns_move_selection(tns_t *tns, direction_t dir, int cnt) if (!tns->dirty) tns_highlight(tns, *tns->sel, true); } + win_set_title(tns->win, tns->files[fileidx].path); return *tns->sel != old; } diff --git a/window.c b/window.c index 46cd1409..8390454a 100644 --- a/window.c +++ b/window.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -120,6 +121,10 @@ void win_init(win_t *win) f = win_res(db, RES_CLASS ".font", "monospace-8"); win_init_font(e, f); + win->prefix = win_res(db, RES_CLASS ".titlePrefix", "rxiv - "); + win->suffixmode = strtol(win_res(db, RES_CLASS ".titleSuffix", "0"), + NULL, 10) % SUFFIXMODE_COUNT; + bg = win_res(db, RES_CLASS ".background", "white"); fg = win_res(db, RES_CLASS ".foreground", "black"); bbg = win_res(db, RES_CLASS ".bar.background", fg); @@ -263,8 +268,6 @@ void win_open(win_t *win) } free(icon_data); - win_set_title(win, "rxiv"); - classhint.res_class = RES_CLASS; classhint.res_name = options->res_name != NULL ? options->res_name : "rxiv"; XSetClassHint(e->dpy, win->xwin, &classhint); @@ -473,17 +476,58 @@ void win_draw_rect(win_t *win, int x, int y, int w, int h, bool fill, int lw, XDrawRectangle(win->env.dpy, win->buf.pm, gc, x, y, w, h); } -void win_set_title(win_t *win, const char *title) +void win_set_title(win_t *win, const char *path) { - XStoreName(win->env.dpy, win->xwin, title); - XSetIconName(win->env.dpy, win->xwin, title); + char *title, *suffix=""; + static bool first_time = true; + + /* Return if window is not ready yet, otherwise we get an X fault. */ + if (win->xwin == None) + return; + + /* Get title suffix type from X-resources. Default: BASE_CDIR. */ + suffix = estrdup(path); + switch (win->suffixmode) { + case CFILE: + win->suffix = suffix; + break; + case BASE_CFILE: + win->suffix = basename(suffix); + break; + case CDIR: + win->suffix = dirname(suffix); + break; + case BASE_CDIR: + win->suffix = basename(dirname(suffix)); + break; + case SUFFIXMODE_COUNT: // Never happens + case EMPTY: + win->suffix = ""; + break; + } + + /* Some ancient WM's that don't comply to EMWH (e.g. mwm) only use WM_NAME for + * the window title, which is set by XStoreName below. */ + title = emalloc(strlen(win->prefix) + strlen(win->suffix) + 1); + (void)sprintf(title, "%s%s", win->prefix, win->suffix); XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_NAME], XInternAtom(win->env.dpy, "UTF8_STRING", False), 8, - PropModeReplace, (unsigned char *) title, strlen(title)); + /* PropModeReplace, (unsigned char *) title, strlen(title)); */ + PropModeReplace, (unsigned char *)title, strlen(title)); XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_ICON_NAME], XInternAtom(win->env.dpy, "UTF8_STRING", False), 8, - PropModeReplace, (unsigned char *) title, strlen(title)); + /* PropModeReplace, (unsigned char *) title, strlen(title)); */ + PropModeReplace, (unsigned char *)title, strlen(title)); + free(title); + free(suffix); + + /* These two atoms won't change and thus only need to be set once. */ + if (first_time) { + XStoreName(win->env.dpy, win->xwin, "rxiv"); + XSetIconName(win->env.dpy, win->xwin, "rxiv"); + first_time = false; + } } void win_set_cursor(win_t *win, cursor_t cursor)