X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=st.c;h=bb8c365207451ffbaea4d803bb9d8d159abf6d72;hb=56abffb4b67f235d20de30f29ba027ab34c171e3;hp=79bf1c8cb3ae1afd3c929bf4f984e551031171ac;hpb=39ae1a4de5c471c8626c80ef1e961f0c83f5199d;p=st.git diff --git a/st.c b/st.c index 79bf1c8..bb8c365 100644 --- a/st.c +++ b/st.c @@ -1,4 +1,4 @@ -/* See LICENSE for licence details. */ +/* See LICENSE for license details. */ #include #include #include @@ -423,7 +423,7 @@ static void xsettitle(char *); static void xresettitle(void); static void xsetpointermotion(int); static void xseturgency(int); -static void xsetsel(char *); +static void xsetsel(char *, Time); static void xtermclear(int, int, int, int); static void xunloadfont(Font *); static void xunloadfonts(void); @@ -449,7 +449,7 @@ static void selinit(void); static void selnormalize(void); static inline bool selected(int, int); static char *getsel(void); -static void selcopy(void); +static void selcopy(Time); static void selscroll(int, int); static void selsnap(int, int *, int *, int); static int x2col(int); @@ -984,8 +984,8 @@ getsel(void) { } void -selcopy(void) { - xsetsel(getsel()); +selcopy(Time t) { + xsetsel(getsel(), t); } void @@ -997,7 +997,7 @@ selnotify(XEvent *e) { XSelectionEvent *xsev; ofs = 0; - xsev = (XSelectionEvent *)e; + xsev = &e->xselection; if (xsev->property == None) return; do { @@ -1083,6 +1083,9 @@ selrequest(XEvent *e) { xev.selection = xsre->selection; xev.target = xsre->target; xev.time = xsre->time; + if (xsre->property == None) + xsre->property = xsre->target; + /* reject */ xev.property = None; @@ -1125,11 +1128,13 @@ selrequest(XEvent *e) { } void -xsetsel(char *str) { +xsetsel(char *str, Time t) { free(sel.primary); sel.primary = str; - XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, CurrentTime); + XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, t); + if (XGetSelectionOwner(xw.dpy, XA_PRIMARY) != xw.win) + selclear(0); } void @@ -1146,7 +1151,7 @@ brelease(XEvent *e) { selclear(NULL); } else { getbuttoninfo(e); - selcopy(); + selcopy(e->xbutton.time); } sel.mode = 0; tsetdirt(sel.nb.y, sel.ne.y); @@ -1571,11 +1576,9 @@ tmoveto(int x, int y) { miny = 0; maxy = term.row - 1; } - LIMIT(x, 0, term.col-1); - LIMIT(y, miny, maxy); term.c.state &= ~CURSOR_WRAPNEXT; - term.c.x = x; - term.c.y = y; + term.c.x = LIMIT(x, 0, term.col-1); + term.c.y = LIMIT(y, miny, maxy); } void @@ -2392,7 +2395,7 @@ tputtab(int n) { for(--x; x > 0 && !term.tabs[x]; --x) /* nothing */ ; } - tmoveto(x, term.c.y); + term.c.x = LIMIT(x, 0, term.col-1); } void @@ -2446,21 +2449,19 @@ tdectest(char c) { void tstrsequence(uchar c) { - if (c & 0x80) { - switch (c) { - case 0x90: /* DCS -- Device Control String */ - c = 'P'; - break; - case 0x9f: /* APC -- Application Program Command */ - c = '_'; - break; - case 0x9e: /* PM -- Privacy Message */ - c = '^'; - break; - case 0x9d: /* OSC -- Operating System Command */ - c = ']'; - break; - } + switch (c) { + case 0x90: /* DCS -- Device Control String */ + c = 'P'; + break; + case 0x9f: /* APC -- Application Program Command */ + c = '_'; + break; + case 0x9e: /* PM -- Privacy Message */ + c = '^'; + break; + case 0x9d: /* OSC -- Operating System Command */ + c = ']'; + break; } strreset(); strescseq.type = c; @@ -2769,7 +2770,6 @@ tresize(int col, int row) { int i; int minrow = MIN(row, term.row); int mincol = MIN(col, term.col); - int slide = term.c.y - row + 1; bool *bp; TCursor c; @@ -2784,13 +2784,14 @@ tresize(int col, int row) { * tscrollup would work here, but we can optimize to * memmove because we're freeing the earlier lines */ - for(i = 0; i < slide; i++) { + for(i = 0; i <= term.c.y - row; i++) { free(term.line[i]); free(term.alt[i]); } - if(slide > 0) { - memmove(term.line, term.line + slide, row * sizeof(Line)); - memmove(term.alt, term.alt + slide, row * sizeof(Line)); + /* ensure that both src and dst are not NULL */ + if (i > 0) { + memmove(term.line, term.line + i, row * sizeof(Line)); + memmove(term.alt, term.alt + i, row * sizeof(Line)); } for(i += row; i < term.row; i++) { free(term.line[i]); @@ -4010,12 +4011,12 @@ void usage(void) { die("%s " VERSION " (c) 2010-2015 st engineers\n" \ "usage: st [-a] [-v] [-c class] [-f font] [-g geometry] [-o file]\n" - " [-i] [-t title] [-w windowid] [-e command ...]\n", argv0); + " [-i] [-t title] [-w windowid] [-e command ...] [command ...]\n", + argv0); } int main(int argc, char *argv[]) { - char *titles; uint cols = 80, rows = 24; xw.l = xw.t = 0; @@ -4030,14 +4031,8 @@ main(int argc, char *argv[]) { opt_class = EARGF(usage()); break; case 'e': - /* eat all remaining arguments */ - if(argc > 1) { - opt_cmd = &argv[1]; - if(argv[1] != NULL && opt_title == NULL) { - titles = xstrdup(argv[1]); - opt_title = basename(titles); - } - } + if(argc > 1) + --argc, ++argv; goto run; case 'f': opt_font = EARGF(usage()); @@ -4064,6 +4059,12 @@ main(int argc, char *argv[]) { } ARGEND; run: + if(argc > 0) { + /* eat all remaining arguments */ + opt_cmd = argv; + if(!opt_title) + opt_title = basename(xstrdup(argv[0])); + } setlocale(LC_CTYPE, ""); XSetLocaleModifiers(""); tnew(MAX(cols, 1), MAX(rows, 1));