From 7168b0fa01ec85e6667c96624590da9b2088a354 Mon Sep 17 00:00:00 2001 From: ketmar Date: Tue, 24 Apr 2012 18:56:07 +0300 Subject: [PATCH] using _NET_WM_NAME for setting window title (it works with utf-8 strings) --- src/sterm.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/sterm.c b/src/sterm.c index 2575a17..6d52761 100644 --- a/src/sterm.c +++ b/src/sterm.c @@ -463,6 +463,7 @@ static Atom XA_VT_SELECTION; static Atom XA_CLIPBOARD; static Atom XA_UTF8; static Atom XA_TARGETS; +static Atom XA_NETWM_NAME; //////////////////////////////////////////////////////////////////////////////// @@ -903,20 +904,25 @@ static __attribute__((noreturn)) __attribute__((format(printf,1,2))) void die (c //////////////////////////////////////////////////////////////////////////////// +static void fixWindowTitle (const Term *t) { + const char *title = (t != NULL) ? t->title : NULL; + // + if (title == NULL || !title[0]) { + title = opt_title; + if (title == NULL) title = ""; + } + XStoreName(xw.dpy, xw.win, title); + XChangeProperty(xw.dpy, xw.win, XA_NETWM_NAME, XA_UTF8, 8, PropModeReplace, (const unsigned char *)title, strlen(title)); +} + + static void switchToTerm (int idx, int redraw) { if (idx >= 0 && idx < term_count && term_array[idx] != NULL && term_array[idx] != term) { - const char *title; - // termidx = idx; term = term_array[termidx]; xseturgency(0); tfulldirt(); - // - title = term->title; - if (!title[0]) title = opt_title; - if (title == NULL) title = ""; - XStoreName(xw.dpy, xw.win, title); - // + fixWindowTitle(term); updateTabBar = 1; if (redraw) draw(1); xfixsel(); @@ -2780,7 +2786,7 @@ static void tputc (const char *c) { if (ascii == '\a' || term->titlelen+1 >= ESC_TITLE_SIZ) { term->esc = 0; term->title[term->titlelen] = '\0'; - XStoreName(xw.dpy, xw.win, term->title); + fixWindowTitle(term); updateTabBar = 1; } else { int len = utf8size(c); @@ -2963,7 +2969,6 @@ static int tresize (int col, int row) { term->dirty = realloc(term->dirty, row*sizeof(*term->dirty)); } // - //fprintf(stderr, "row=%d; lc=%d\n", row, term->linecount); /* resize each row to new width, zero-pad if needed */ for (int f = 0; f < term->linecount; ++f) { term->line[f] = realloc(term->line[f], col*sizeof(Glyph)); @@ -2983,7 +2988,6 @@ static int tresize (int col, int row) { /* reset scrolling region */ tsetscroll(0, row-1); tfulldirt(); - // return (slide > 0); } @@ -2992,6 +2996,7 @@ static void xresize (int col, int row) { Pixmap newbuf; int oldw, oldh; // + if (term == NULL) return; oldw = term->picbufw; oldh = term->picbufh; term->picbufw = MAX(1, col*xw.cw); @@ -3011,6 +3016,7 @@ static void xresize (int col, int row) { XClearArea(xw.dpy, xw.win, opt_border, opt_border+term->picbufh, xw.w-2*opt_border, xw.h-term->picbufh-opt_border-xw.tabheight, False); } term->picbuf = newbuf; + tfulldirt(); updateTabBar = 1; } @@ -3029,7 +3035,7 @@ static void xloadcols (void) { const char *cname = opt_colornames[f]!=NULL?opt_colornames[f]:defcolornames[f]; // if (!XAllocNamedColor(xw.dpy, xw.cmap, cname, &color, &color)) { - fprintf(stderr, "Could not allocate color #%d: '%s'\n", f, cname); + fprintf(stderr, "WARNING: could not allocate color #%d: '%s'\n", f, cname); } else { dc.col[f] = color.pixel; } @@ -3044,7 +3050,7 @@ static void xloadcols (void) { } if (cname == NULL) continue; if (!XAllocNamedColor(xw.dpy, xw.cmap, cname, &color, &color)) { - fprintf(stderr, "Could not allocate color #%d: '%s'\n", f, cname); + fprintf(stderr, "WARNING: could not allocate color #%d: '%s'\n", f, cname); } else { dc.col[f] = color.pixel; } @@ -3055,7 +3061,7 @@ static void xloadcols (void) { for (b = 0; b < 6; ++b) { if (opt_colornames[f] != NULL) { if (!XAllocNamedColor(xw.dpy, xw.cmap, opt_colornames[f], &color, &color)) { - fprintf(stderr, "Could not allocate color #%d: '%s'\n", f, opt_colornames[f]); + fprintf(stderr, "WARNING: could not allocate color #%d: '%s'\n", f, opt_colornames[f]); } else { dc.col[f] = color.pixel; } @@ -3064,7 +3070,7 @@ static void xloadcols (void) { color.green = g == 0 ? 0 : 0x3737+0x2828*g; color.blue = b == 0 ? 0 : 0x3737+0x2828*b; if (!XAllocColor(xw.dpy, xw.cmap, &color)) { - fprintf(stderr, "Could not allocate color #%d\n", f); + fprintf(stderr, "WARNING: could not allocate color #%d\n", f); } else { dc.col[f] = color.pixel; } @@ -3076,14 +3082,14 @@ static void xloadcols (void) { for (r = 0; r < 24; ++r, ++f) { if (opt_colornames[f] != NULL) { if (!XAllocNamedColor(xw.dpy, xw.cmap, opt_colornames[f], &color, &color)) { - fprintf(stderr, "Could not allocate color #%d: '%s'\n", f, opt_colornames[f]); + fprintf(stderr, "WARNING: could not allocate color #%d: '%s'\n", f, opt_colornames[f]); } else { dc.col[f] = color.pixel; } } else { color.red = color.green = color.blue = 0x0808+0x0a0a*r; if (!XAllocColor(xw.dpy, xw.cmap, &color)) { - fprintf(stderr, "Could not allocate color #%d\n", f); + fprintf(stderr, "WARNING: could not allocate color #%d\n", f); } else { dc.col[f] = color.pixel; } @@ -3170,6 +3176,7 @@ static void xinit (void) { XA_VT_SELECTION = XInternAtom(xw.dpy, "_STERM_SELECTION_", 0); XA_CLIPBOARD = XInternAtom(xw.dpy, "CLIPBOARD", 0); XA_UTF8 = XInternAtom(xw.dpy, "UTF8_STRING", 0); + XA_NETWM_NAME = XInternAtom(xw.dpy, "_NET_WM_NAME", 0); XA_TARGETS = XInternAtom(xw.dpy, "TARGETS", 0); // xw.scr = XDefaultScreen(xw.dpy); @@ -3222,7 +3229,8 @@ static void xinit (void) { &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff}, &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000}); xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False); - XStoreName(xw.dpy, xw.win, opt_title); + fixWindowTitle(term); + //XStoreName(xw.dpy, xw.win, opt_title); // XSetForeground(xw.dpy, dc.gc, 0); XFillRectangle(xw.dpy, term->picbuf, dc.gc, 0, 0, term->picbufw, term->picbufh); -- 2.11.4.GIT