X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=6117c929df5a053b5114f913574a7f9000f02379;hb=efaf1c2a94ed9193c04c3a67f374d31f988b0e9a;hp=300e5ec571b19ce24e5f3af43a3a11b4486e908f;hpb=3865e9eaaf4e1c7820b1f41ce9d0b1d7b109fb26;p=st.git diff --git a/st.c b/st.c index 300e5ec..6117c92 100644 --- a/st.c +++ b/st.c @@ -348,6 +348,7 @@ static void xclear(int, int, int, int); static void xdrawcursor(void); static void xinit(void); static void xloadcols(void); +static int xsetcolorname(int, const char *); static int xloadfont(Font *, FcPattern *); static void xloadfonts(char *, int); static void xresettitle(void); @@ -939,7 +940,7 @@ brelease(XEvent *e) { void bmotion(XEvent *e) { - int oldey, oldex; + int oldey, oldex, oldsby, oldsey; if(IS_SET(MODE_MOUSE)) { mousereport(e); @@ -951,10 +952,12 @@ bmotion(XEvent *e) { oldey = sel.ey; oldex = sel.ex; + oldsby = sel.b.y; + oldsey = sel.e.y; getbuttoninfo(e); if(oldey != sel.ey || oldex != sel.ex) { - tsetdirt(sel.b.y, sel.e.y); + tsetdirt(MIN(sel.b.y, oldsby), MAX(sel.e.y, oldsey)); } } @@ -1857,32 +1860,38 @@ csireset(void) { void strhandle(void) { - char *p; + char *p = NULL; + int i, j, narg; + XTextProperty prop; - /* - * TODO: make this being useful in case of color palette change. - */ strparse(); - - p = strescseq.buf; + narg = strescseq.narg; switch(strescseq.type) { case ']': /* OSC -- Operating System Command */ - switch(p[0]) { - case '0': - case '1': - case '2': - /* - * TODO: Handle special chars in string, like umlauts. - */ - if(p[1] == ';') { - XStoreName(xw.dpy, xw.win, strescseq.buf+2); + switch(i = atoi(strescseq.args[0])) { + case 0: + case 1: + case 2: + if(narg > 1) { + p += 2; + Xutf8TextListToTextProperty(xw.dpy, &p, 1, + XUTF8StringStyle, &prop); + XSetWMName(xw.dpy, xw.win, &prop); } break; - case ';': - XStoreName(xw.dpy, xw.win, strescseq.buf+1); - break; - case '4': /* TODO: Set color (arg0) to "rgb:%hexr/$hexg/$hexb" (arg1) */ + case 4: /* color set */ + if(narg < 3) + break; + p = strescseq.args[2]; + /* fall through */ + case 104: /* color reset, here p = NULL */ + j = (narg > 1) ? atoi(strescseq.args[1]) : -1; + if (!xsetcolorname(j, p)) { + fprintf(stderr, "erresc: invalid color %s\n", p); + } else { + redraw(0); /* TODO if defaultbg color is changed, borders are dirty */ + } break; default: fprintf(stderr, "erresc: unknown str "); @@ -1891,7 +1900,10 @@ strhandle(void) { } break; case 'k': /* old title set compatibility */ - XStoreName(xw.dpy, xw.win, strescseq.buf); + p += 1; + Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, + &prop); + XSetWMName(xw.dpy, xw.win, &prop); break; case 'P': /* DSC -- Device Control String */ case '_': /* APC -- Application Program Command */ @@ -1910,7 +1922,19 @@ strparse(void) { * TODO: Implement parsing like for CSI when required. * Format: ESC type cmd ';' arg0 [';' argn] ESC \ */ - return; + int narg = 0; + char *start = strescseq.buf, *end = start + strescseq.len; + strescseq.args[0] = start; + while(start < end && narg < LEN(strescseq.args)) { + start = memchr(start, ';', end - start); + if(!start) + break; + *start++ = '\0'; + if(start < end) { + strescseq.args[++narg] = start; + } + } + strescseq.narg = narg + 1; } void @@ -2325,6 +2349,11 @@ xresize(int col, int row) { XftDrawChange(xw.draw, xw.buf); } +static inline ushort +sixd_to_16bit(int x) { + return x == 0 ? 0 : 0x3737 + 0x2828 * x; +} + void xloadcols(void) { int i, r, g, b; @@ -2343,9 +2372,9 @@ xloadcols(void) { for(i = 16, r = 0; r < 6; r++) { for(g = 0; g < 6; g++) { for(b = 0; b < 6; b++) { - color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r; - color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g; - color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b; + color.red = sixd_to_16bit(r); + color.green = sixd_to_16bit(g); + color.blue = sixd_to_16bit(b); if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &dc.col[i])) { die("Could not allocate color %d\n", i); } @@ -2363,6 +2392,38 @@ xloadcols(void) { } } +int +xsetcolorname(int x, const char *name) { + XRenderColor color = { .alpha = 0xffff }; + Colour colour; + if (x < 0 || x > LEN(colorname)) + return -1; + if(!name) { + if(16 <= x && x < 16 + 216) { + int r = (x - 16) / 36, g = ((x - 16) % 36) / 6, b = (x - 16) % 6; + color.red = sixd_to_16bit(r); + color.green = sixd_to_16bit(g); + color.blue = sixd_to_16bit(b); + if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &colour)) + return 0; /* something went wrong */ + dc.col[x] = colour; + return 1; + } else if (16 + 216 <= x && x < 256) { + color.red = color.green = color.blue = 0x0808 + 0x0a0a * (x - (16 + 216)); + if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, &colour)) + return 0; /* something went wrong */ + dc.col[x] = colour; + return 1; + } else { + name = colorname[x]; + } + } + if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, &colour)) + return 0; + dc.col[x] = colour; + return 1; +} + void xtermclear(int col1, int row1, int col2, int row2) { XftDrawRect(xw.draw,