Xinqi Bao's Git

use GLYPH_SET to test if a char is set; cleanup.
[st.git] / st.c
diff --git a/st.c b/st.c
index 0b21404..665dc1a 100644 (file)
--- a/st.c
+++ b/st.c
@@ -245,7 +245,7 @@ static char *getseltext() {
        ptr = str = malloc (sz);
        for(y = 0; y < term.row; y++) {
                for(x = 0; x < term.col; x++) {
-                       if(term.line[y][x].c && (ls=selected(x, y))) {
+                       if(term.line[y][x].state & GLYPH_SET && (ls=selected(x, y))) {
                                *ptr = term.line[y][x].c;
                                ptr++;
                        }
@@ -828,22 +828,17 @@ csihandle(void) {
                        case 25:
                                term.c.state |= CURSOR_HIDE;
                                break;
+                       case 1049: /* = 1047 and 1048 */
                        case 1047:
                                if(IS_SET(MODE_ALTSCREEN)) {
                                        tclearregion(0, 0, term.col-1, term.row-1);
                                        tswapscreen();
                                }
-                               break;
+                               if(escseq.arg[0] == 1047)
+                                       break;
                        case 1048:
                                tcursor(CURSOR_LOAD);
                                break;
-                       case 1049:
-                               tcursor(CURSOR_LOAD);
-                               if(IS_SET(MODE_ALTSCREEN)) {
-                                       tclearregion(0, 0, term.col-1, term.row-1);
-                                       tswapscreen();
-                               }
-                               break;
                        default:
                                goto unknown;
                        }
@@ -888,22 +883,17 @@ csihandle(void) {
                        case 25:
                                term.c.state &= ~CURSOR_HIDE;
                                break;
+                       case 1049: /* = 1047 and 1048 */
                        case 1047:
                                if(IS_SET(MODE_ALTSCREEN))
                                        tclearregion(0, 0, term.col-1, term.row-1);
                                else
                                        tswapscreen();
-                               break;                          
+                               if(escseq.arg[0] == 1047)
+                                       break;
                        case 1048:
                                tcursor(CURSOR_SAVE);
                                break;
-                       case 1049:
-                               tcursor(CURSOR_SAVE);
-                               if(IS_SET(MODE_ALTSCREEN))
-                                       tclearregion(0, 0, term.col-1, term.row-1);
-                               else
-                                       tswapscreen();
-                               break;
                        default: goto unknown;
                        }
                } else {
@@ -1222,6 +1212,7 @@ xinit(void) {
        xw.bufw = xw.w - 2*BORDER;
        xw.bufh = xw.h - 2*BORDER;
        xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
+       xw.hasfocus = 1;
        /* gc */
        dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL);
        XMapWindow(xw.dis, xw.win);
@@ -1322,7 +1313,7 @@ draw(int redraw_all) {
                for(x = 0; x < term.col; x++) {
                        new = term.line[y][x];
                        if(selbx!=-1 && new.c && selected(x, y))
-                               new.mode = ATTR_REVERSE;
+                               new.mode ^= ATTR_REVERSE;
                        if(i > 0 && (!(new.state & GLYPH_SET) || ATTRCMP(base, new) ||
                                        i >= DRAW_BUF_SIZ)) {
                                xdraws(buf, base, ox, y, i);
@@ -1430,6 +1421,8 @@ resize(XEvent *e) {
        row = xw.bufh / xw.ch;
        tresize(col, row);
        ttyresize(col, row);
+       xw.bufh = MAX(1, xw.bufh);
+       xw.bufw = MAX(1, xw.bufw);
        XFreePixmap(xw.dis, xw.buf);
        xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
        draw(SCREEN_REDRAW);
@@ -1440,12 +1433,14 @@ run(void) {
        XEvent ev;
        fd_set rfd;
        int xfd = XConnectionNumber(xw.dis);
-       long mask = ExposureMask | KeyPressMask | StructureNotifyMask | FocusChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
+       long mask = ExposureMask | KeyPressMask | StructureNotifyMask
+               | FocusChangeMask | PointerMotionMask | ButtonPressMask 
+               | ButtonReleaseMask;
 
        XSelectInput(xw.dis, xw.win, mask);
        XResizeWindow(xw.dis, xw.win, xw.w, xw.h); /* XXX: fix resize bug in wmii (?) */
 
-       while(1) {
+       for(;;) {
                FD_ZERO(&rfd);
                FD_SET(cmdfd, &rfd);
                FD_SET(xfd, &rfd);