X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=0fc724b2dc43060fd842901e6c8f512626b8c684;hb=fbc589d50603e8b0de9239e4800e227ab5d0ea69;hp=28c083adf2b0cc22398b3ebac66c418172db93ac;hpb=369734c80c6e5049d704a00f436c59ecf4dafae8;p=st.git diff --git a/st.c b/st.c index 28c083a..0fc724b 100644 --- a/st.c +++ b/st.c @@ -150,10 +150,6 @@ enum selection_snap { SNAP_LINE = 2 }; -/* bit macro */ -#undef B0 -enum { B0=1, B1=2, B2=4, B3=8, B4=16, B5=32, B6=64, B7=128 }; - typedef unsigned char uchar; typedef unsigned int uint; typedef unsigned long ulong; @@ -527,17 +523,17 @@ utf8decode(char *s, long *u) { rtn = 1; c = *s; - if(~c & B7) { /* 0xxxxxxx */ + if(~c & 0x80) { /* 0xxxxxxx */ *u = c; return rtn; - } else if((c & (B7|B6|B5)) == (B7|B6)) { /* 110xxxxx */ - *u = c&(B4|B3|B2|B1|B0); + } else if((c & 0xE0) == 0xC0) { /* 110xxxxx */ + *u = c & 0x1F; n = 1; - } else if((c & (B7|B6|B5|B4)) == (B7|B6|B5)) { /* 1110xxxx */ - *u = c&(B3|B2|B1|B0); + } else if((c & 0xF0) == 0xE0) { /* 1110xxxx */ + *u = c & 0x0F; n = 2; - } else if((c & (B7|B6|B5|B4|B3)) == (B7|B6|B5|B4)) { /* 11110xxx */ - *u = c & (B2|B1|B0); + } else if((c & 0xF8) == 0xF0) { /* 11110xxx */ + *u = c & 0x07; n = 3; } else { goto invalid; @@ -545,10 +541,10 @@ utf8decode(char *s, long *u) { for(i = n, ++s; i > 0; --i, ++rtn, ++s) { c = *s; - if((c & (B7|B6)) != B7) /* 10xxxxxx */ + if((c & 0xC0) != 0x80) /* 10xxxxxx */ goto invalid; *u <<= 6; - *u |= c & (B5|B4|B3|B2|B1|B0); + *u |= c & 0x3F; } if((n == 1 && *u < 0x80) || @@ -577,20 +573,20 @@ utf8encode(long *u, char *s) { *sp = uc; /* 0xxxxxxx */ return 1; } else if(*u < 0x800) { - *sp = (uc >> 6) | (B7|B6); /* 110xxxxx */ + *sp = (uc >> 6) | 0xC0; /* 110xxxxx */ n = 1; } else if(uc < 0x10000) { - *sp = (uc >> 12) | (B7|B6|B5); /* 1110xxxx */ + *sp = (uc >> 12) | 0xE0; /* 1110xxxx */ n = 2; } else if(uc <= 0x10FFFF) { - *sp = (uc >> 18) | (B7|B6|B5|B4); /* 11110xxx */ + *sp = (uc >> 18) | 0xF0; /* 11110xxx */ n = 3; } else { goto invalid; } for(i=n,++sp; i>0; --i,++sp) - *sp = ((uc >> 6*(i-1)) & (B5|B4|B3|B2|B1|B0)) | B7; /* 10xxxxxx */ + *sp = ((uc >> 6*(i-1)) & 0x3F) | 0x80; /* 10xxxxxx */ return n+1; invalid: @@ -613,16 +609,16 @@ isfullutf8(char *s, int b) { c3 = (uchar *)++s; if(b < 1) { return 0; - } else if((*c1&(B7|B6|B5)) == (B7|B6) && b == 1) { + } else if((*c1 & 0xE0) == 0xC0 && b == 1) { return 0; - } else if((*c1&(B7|B6|B5|B4)) == (B7|B6|B5) && + } else if((*c1 & 0xF0) == 0xE0 && ((b == 1) || - ((b == 2) && (*c2&(B7|B6)) == B7))) { + ((b == 2) && (*c2 & 0xC0) == 0x80))) { return 0; - } else if((*c1&(B7|B6|B5|B4|B3)) == (B7|B6|B5|B4) && + } else if((*c1 & 0xF8) == 0xF0 && ((b == 1) || - ((b == 2) && (*c2&(B7|B6)) == B7) || - ((b == 3) && (*c2&(B7|B6)) == B7 && (*c3&(B7|B6)) == B7))) { + ((b == 2) && (*c2 & 0xC0) == 0x80) || + ((b == 3) && (*c2 & 0xC0) == 0x80 && (*c3 & 0xC0) == 0x80))) { return 0; } else { return 1; @@ -633,11 +629,11 @@ int utf8size(char *s) { uchar c = *s; - if(~c&B7) { + if(~c & 0x80) { return 1; - } else if((c&(B7|B6|B5)) == (B7|B6)) { + } else if((c & 0xE0) == 0xC0) { return 2; - } else if((c&(B7|B6|B5|B4)) == (B7|B6|B5)) { + } else if((c & 0xF0) == 0xE0) { return 3; } else { return 4; @@ -888,11 +884,7 @@ bpress(XEvent *e) { gettimeofday(&now, NULL); /* Clear previous selection, logically and visually. */ - if(sel.ob.x != -1) { - sel.ob.x = -1; - tsetdirt(sel.nb.y, sel.ne.y); - draw(); - } + selclear(NULL); sel.mode = 1; sel.type = SEL_REGULAR; sel.oe.x = sel.ob.x = x2col(e->xbutton.x); @@ -920,7 +912,6 @@ bpress(XEvent *e) { if(sel.snap != 0) { sel.mode++; tsetdirt(sel.nb.y, sel.ne.y); - draw(); } sel.tclick2 = sel.tclick1; sel.tclick1 = now; @@ -1108,7 +1099,7 @@ brelease(XEvent *e) { selpaste(NULL); } else if(e->xbutton.button == Button1) { if(sel.mode < 2) { - sel.ob.x = -1; + selclear(NULL); } else { getbuttoninfo(e); selcopy(); @@ -1441,7 +1432,7 @@ selscroll(int orig, int n) { if(BETWEEN(sel.ob.y, orig, term.bot) || BETWEEN(sel.oe.y, orig, term.bot)) { if((sel.ob.y += n) > term.bot || (sel.oe.y += n) < term.top) { - sel.ob.x = -1; + selclear(NULL); return; } if(sel.type == SEL_RECTANGULAR) { @@ -1951,7 +1942,7 @@ csihandle(void) { tputtab(1); break; case 'J': /* ED -- Clear screen */ - sel.ob.x = -1; + selclear(NULL); switch(csiescseq.arg[0]) { case 0: /* below */ tclearregion(term.c.x, term.c.y, term.col-1, term.c.y); @@ -2448,7 +2439,7 @@ tputc(char *c, int len) { if(control && !(term.c.attr.mode & ATTR_GFX)) return; if(sel.ob.x != -1 && BETWEEN(term.c.y, sel.ob.y, sel.oe.y)) - sel.ob.x = -1; + selclear(NULL); if(IS_SET(MODE_WRAP) && (term.c.state & CURSOR_WRAPNEXT)) { term.line[term.c.y][term.c.x].mode |= ATTR_WRAP; tnewline(1); @@ -3360,17 +3351,17 @@ focus(XEvent *ev) { } } -inline bool +static inline bool match(uint mask, uint state) { - state &= ~(ignoremod); + state &= ~ignoremod; if(mask == XK_NO_MOD && state) return false; if(mask != XK_ANY_MOD && mask != XK_NO_MOD && !state) return false; - if((state & mask) != state) - return false; - return true; + if(mask == XK_ANY_MOD) + return true; + return state == mask; } void @@ -3380,7 +3371,6 @@ numlock(const Arg *dummy) { char* kmap(KeySym k, uint state) { - uint mask; Key *kp; int i; @@ -3395,12 +3385,10 @@ kmap(KeySym k, uint state) { } for(kp = key; kp < key + LEN(key); kp++) { - mask = kp->mask; - if(kp->k != k) continue; - if(!match(mask, state)) + if(!match(kp->mask, state)) continue; if(kp->appkey > 0) { @@ -3464,7 +3452,7 @@ kpress(XEvent *ev) { if(len == 1 && e->state & Mod1Mask) { if(IS_SET(MODE_8BIT)) { if(*xstr < 0177) { - c = *xstr | B7; + c = *xstr | 0x80; ret = utf8encode(&c, cp); cp += ret; len = 0; @@ -3532,10 +3520,28 @@ resize(XEvent *e) { void run(void) { XEvent ev; + int w = xw.w, h = xw.h; fd_set rfd; int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0; struct timeval drawtimeout, *tv = NULL, now, last, lastblink; + /* Waiting for window mapping */ + while(1) { + XNextEvent(xw.dpy, &ev); + if(ev.type == ConfigureNotify) { + w = ev.xconfigure.width; + h = ev.xconfigure.height; + } else if(ev.type == MapNotify) { + break; + } + } + + if(!xw.isfixed) + cresize(w, h); + else + cresize(xw.fw, xw.fh); + ttynew(); + gettimeofday(&lastblink, NULL); gettimeofday(&last, NULL); @@ -3639,7 +3645,7 @@ main(int argc, char *argv[]) { /* eat all remaining arguments */ if(argc > 1) { opt_cmd = &argv[1]; - if(argv[1] != NULL) { + if(argv[1] != NULL && opt_title == NULL) { titles = strdup(argv[1]); opt_title = basename(titles); } @@ -3685,10 +3691,7 @@ run: XSetLocaleModifiers(""); tnew(80, 24); xinit(); - ttynew(); selinit(); - if(xw.isfixed) - cresize(xw.h, xw.w); run(); return 0;