From 700d9f46c7725159a56b87d0b391a5967cfb081a Mon Sep 17 00:00:00 2001 From: NRK Date: Mon, 28 Feb 2022 00:38:27 +0600 Subject: [PATCH] fix: window title not working on certain WMs not all WMs support `_NET_WM_NAME` and `_NET_WM_ICON_NAME` this patch sets `WM_NAME` and `WM_ICON_NAME` inside win_set_title() Closes: https://github.com/nsxiv/nsxiv/issues/233 --- nsxiv.h | 2 ++ window.c | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/nsxiv.h b/nsxiv.h index 8576d51..4350864 100644 --- a/nsxiv.h +++ b/nsxiv.h @@ -381,6 +381,8 @@ enum { ATOM__NET_WM_PID, ATOM__NET_WM_STATE_FULLSCREEN, ATOM_UTF8_STRING, + ATOM_WM_NAME, + ATOM_WM_ICON_NAME, ATOM_COUNT }; diff --git a/window.c b/window.c index fb9c776..df5a5a7 100644 --- a/window.c +++ b/window.c @@ -171,6 +171,8 @@ void win_init(win_t *win) INIT_ATOM_(_NET_WM_PID); INIT_ATOM_(_NET_WM_STATE_FULLSCREEN); INIT_ATOM_(UTF8_STRING); + INIT_ATOM_(WM_NAME); + INIT_ATOM_(WM_ICON_NAME); } void win_open(win_t *win) @@ -289,10 +291,7 @@ void win_open(win_t *win) } free(icon_data); - XStoreName(win->env.dpy, win->xwin, res_name); - XSetIconName(win->env.dpy, win->xwin, res_name); win_set_title(win, true); - classhint.res_class = res_class; classhint.res_name = options->res_name != NULL ? options->res_name : res_name; XSetClassHint(e->dpy, win->xwin, &classhint); @@ -505,16 +504,16 @@ void win_draw_rect(win_t *win, int x, int y, int w, int h, bool fill, int lw, void win_set_title(win_t *win, bool init) { + size_t len, i; unsigned char title[512]; - size_t len; + int targets[] = { ATOM_WM_NAME, ATOM_WM_ICON_NAME, ATOM__NET_WM_NAME, ATOM__NET_WM_ICON_NAME }; - if ((len = get_win_title(title, ARRLEN(title), init)) <= 0) - return; - - XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_NAME], - atoms[ATOM_UTF8_STRING], 8, PropModeReplace, title, len); - XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_ICON_NAME], - atoms[ATOM_UTF8_STRING], 8, PropModeReplace, title, len); + if ((len = get_win_title(title, ARRLEN(title), init)) > 0) { + for (i = 0; i < ARRLEN(targets); ++i) { + XChangeProperty(win->env.dpy, win->xwin, atoms[targets[i]], + atoms[ATOM_UTF8_STRING], 8, PropModeReplace, title, len); + } + } } void win_set_cursor(win_t *win, cursor_t cursor)