X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=7ddce0cb5104ba2bce3a7aa5d298273d542f995b;hb=7cb0d95509d1b2837e4fa7d131f497800b20d22c;hp=c6a840de4c05ed389f99c20a36a1e6dc343e8d4e;hpb=1b6c6535c10172facb350f4b8fef442f7f8ddc5a;p=st.git diff --git a/st.c b/st.c index c6a840d..7ddce0c 100644 --- a/st.c +++ b/st.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -267,9 +266,10 @@ typedef struct { } Shortcut; /* function definitions used in config.h */ -static void xzoom(const Arg *); -static void selpaste(const Arg *); +static void clippaste(const Arg *); static void numlock(const Arg *); +static void selpaste(const Arg *); +static void xzoom(const Arg *); /* Config.h for applying patches and the configuration. */ #include "config.h" @@ -351,6 +351,7 @@ static void xloadcols(void); static int xsetcolorname(int, const char *); static int xloadfont(Font *, FcPattern *); static void xloadfonts(char *, int); +static void xsettitle(char *); static void xresettitle(void); static void xseturgency(int); static void xsetsel(char*); @@ -423,8 +424,6 @@ static char *opt_embed = NULL; static char *opt_class = NULL; static char *opt_font = NULL; -bool usedbe = False; - static char *usedfont = NULL; static int usedfontsize = 0; @@ -832,7 +831,17 @@ selpaste(const Arg *dummy) { xw.win, CurrentTime); } -void selclear(XEvent *e) { +void +clippaste(const Arg *dummy) { + Atom clipboard; + + clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0); + XConvertSelection(xw.dpy, clipboard, sel.xtarget, XA_PRIMARY, + xw.win, CurrentTime); +} + +void +selclear(XEvent *e) { if(sel.bx == -1) return; sel.bx = -1; @@ -1287,17 +1296,24 @@ tnewline(int first_col) { void csiparse(void) { /* int noarg = 1; */ - char *p = csiescseq.buf; + char *p = csiescseq.buf, *np; + long int v; csiescseq.narg = 0; - if(*p == '?') - csiescseq.priv = 1, p++; + if(*p == '?') { + csiescseq.priv = 1; + p++; + } while(p < csiescseq.buf+csiescseq.len) { - while(isdigit(*p)) { - csiescseq.arg[csiescseq.narg] *= 10; - csiescseq.arg[csiescseq.narg] += *p++ - '0'/*, noarg = 0 */; - } + np = NULL; + v = strtol(p, &np, 10); + if(v == LONG_MAX || v == LONG_MIN) + v = -1; + csiescseq.arg[csiescseq.narg] = v; + if(np != NULL) + p = np; + if(*p == ';' && csiescseq.narg+1 < ESC_ARG_SIZ) { csiescseq.narg++, p++; } else { @@ -1861,12 +1877,8 @@ csireset(void) { void strhandle(void) { char *p = NULL; - int i, j; - int narg; + int i, j, narg; - /* - * TODO: make this being useful in case of color palette change. - */ strparse(); narg = strescseq.narg; @@ -1876,11 +1888,8 @@ strhandle(void) { case 0: case 1: case 2: - /* - * TODO: Handle special chars in string, like umlauts. - */ if(narg > 1) - XStoreName(xw.dpy, xw.win, strescseq.args[2]); + xsettitle(strescseq.args[1]); break; case 4: /* color set */ if(narg < 3) @@ -1892,7 +1901,11 @@ strhandle(void) { if (!xsetcolorname(j, p)) { fprintf(stderr, "erresc: invalid color %s\n", p); } else { - redraw(0); /* TODO if defaultbg color is changed, borders are dirty */ + /* + * TODO if defaultbg color is changed, borders + * are dirty + */ + redraw(0); } break; default: @@ -1902,7 +1915,7 @@ strhandle(void) { } break; case 'k': /* old title set compatibility */ - XStoreName(xw.dpy, xw.win, strescseq.buf); + xsettitle(strescseq.args[0]); break; case 'P': /* DSC -- Device Control String */ case '_': /* APC -- Application Program Command */ @@ -1917,23 +1930,17 @@ strhandle(void) { void strparse(void) { - /* - * TODO: Implement parsing like for CSI when required. - * Format: ESC type cmd ';' arg0 [';' argn] ESC \ - */ - 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; - } + char *p = strescseq.buf, *np, *sp; + + strescseq.narg = 0; + np = strtok_r(strescseq.buf, ";", &sp); + while(p < strescseq.buf+strescseq.len && np != NULL) { + strescseq.args[strescseq.narg++] = p; + + np = strtok_r(NULL, ";", &sp); + if(np != NULL) + p = np; } - strescseq.narg = narg + 1; } void @@ -2110,7 +2117,8 @@ tputc(char *c, int len) { if(BETWEEN(ascii, 0x40, 0x7E) || csiescseq.len >= ESC_BUF_SIZ) { term.esc = 0; - csiparse(), csihandle(); + csiparse(); + csihandle(); } } else if(term.esc & ESC_STR_END) { term.esc = 0; @@ -2337,13 +2345,11 @@ xresize(int col, int row) { xw.tw = MAX(1, col * xw.cw); xw.th = MAX(1, row * xw.ch); - if(!usedbe) { - XFreePixmap(xw.dpy, xw.buf); - xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h, - DefaultDepth(xw.dpy, xw.scr)); - XSetForeground(xw.dpy, dc.gc, dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg].pixel); - XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, xw.w, xw.h); - } + XFreePixmap(xw.dpy, xw.buf); + xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h, + DefaultDepth(xw.dpy, xw.scr)); + XSetForeground(xw.dpy, dc.gc, dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg].pixel); + XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, xw.w, xw.h); XftDrawChange(xw.draw, xw.buf); } @@ -2605,7 +2611,7 @@ xinit(void) { XGCValues gcvalues; Cursor cursor; Window parent; - int sw, sh, major, minor; + int sw, sh; if(!(xw.dpy = XOpenDisplay(NULL))) die("Can't open display\n"); @@ -2660,26 +2666,14 @@ xinit(void) { | CWColormap, &attrs); - /* double buffering */ - /* - if(XdbeQueryExtension(xw.dpy, &major, &minor)) { - xw.buf = XdbeAllocateBackBufferName(xw.dpy, xw.win, - XdbeBackground); - usedbe = True; - } else { - */ - memset(&gcvalues, 0, sizeof(gcvalues)); - gcvalues.graphics_exposures = False; - dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures, - &gcvalues); - xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h, - DefaultDepth(xw.dpy, xw.scr)); - XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel); - XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, xw.w, xw.h); - //xw.buf = xw.win; - /* - } - */ + memset(&gcvalues, 0, sizeof(gcvalues)); + gcvalues.graphics_exposures = False; + dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures, + &gcvalues); + xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h, + DefaultDepth(xw.dpy, xw.scr)); + XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel); + XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, xw.w, xw.h); /* Xft rendering context */ xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap); @@ -2970,9 +2964,19 @@ xdrawcursor(void) { } } + +void +xsettitle(char *p) { + XTextProperty prop; + + Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, + &prop); + XSetWMName(xw.dpy, xw.win, &prop); +} + void xresettitle(void) { - XStoreName(xw.dpy, xw.win, opt_title ? opt_title : "st"); + xsettitle(opt_title ? opt_title : "st"); } void @@ -2990,16 +2994,12 @@ redraw(int timeout) { void draw(void) { - XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}}; - drawregion(0, 0, term.col, term.row); - if(usedbe) { - XdbeSwapBuffers(xw.dpy, swpinfo, 1); - } else { - XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.w, - xw.h, 0, 0); - XSetForeground(xw.dpy, dc.gc, dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg].pixel); - } + XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.w, + xw.h, 0, 0); + XSetForeground(xw.dpy, dc.gc, + dc.col[IS_SET(MODE_REVERSE)? + defaultfg : defaultbg].pixel); } void