aboutsummaryrefslogtreecommitdiffstats
path: root/window.c
diff options
context:
space:
mode:
authorqsmodo <75080827+qsmodo@users.noreply.github.com>2021-09-12 20:26:07 +0200
committerBerke Kocaoğlu <berke.kocaoglu@metu.edu.tr>2021-09-16 21:55:31 +0200
commit156a53780c7b27aeb7b4de7de56450f26c55a192 (patch)
tree6d8820c2b8d862e7b878cb9cf9bf31d32e26eb56 /window.c
parent91d9b3128eb5502306f688e68c42e83b3020cb56 (diff)
downloadnsxiv-156a53780c7b27aeb7b4de7de56450f26c55a192.tar.zst
set title based on prefix and suffix (#23)
Co-authored-by: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com> Co-authored-by: NRK <nrk@disroot.org> Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Diffstat (limited to 'window.c')
-rw-r--r--window.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/window.c b/window.c
index bd9b0c3..dd17134 100644
--- a/window.c
+++ b/window.c
@@ -276,7 +276,9 @@ void win_open(win_t *win)
}
free(icon_data);
- win_set_title(win, "sxiv");
+ /* These two atoms won't change and thus only need to be set once. */
+ XStoreName(win->env.dpy, win->xwin, "sxiv");
+ XSetIconName(win->env.dpy, win->xwin, "sxiv");
classhint.res_class = RES_CLASS;
classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv";
@@ -486,10 +488,20 @@ 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);
+ const unsigned int title_max = strlen(path) + strlen(options->title_prefix) + 1;
+ char title[title_max];
+ const char *basename = strrchr(path, '/') + 1;
+
+ /* Return if window is not ready yet */
+ if (win->xwin == None)
+ return;
+
+ snprintf(title, title_max, "%s%s", options->title_prefix,
+ (options->title_suffixmode == SUFFIX_BASENAME) ? basename : path);
+ if (options->title_suffixmode == SUFFIX_EMPTY)
+ *(title+strlen(options->title_prefix)) = '\0';
XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_NAME],
XInternAtom(win->env.dpy, "UTF8_STRING", False), 8,