Skip to content

Commit

Permalink
merged xyb3rt#453
Browse files Browse the repository at this point in the history
  • Loading branch information
eylles committed Aug 15, 2021
1 parent afadb14 commit 2ea2631
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 7 deletions.
2 changes: 2 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions rxiv.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions rxiv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions thumbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down
58 changes: 51 additions & 7 deletions window.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <locale.h>
#include <unistd.h>
#include <X11/cursorfont.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2ea2631

Please sign in to comment.