JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
use xclear() in draw().
[st.git] / st.c
diff --git a/st.c b/st.c
index ab43a43..d2f8c2e 100644 (file)
--- a/st.c
+++ b/st.c
@@ -104,6 +104,7 @@ typedef struct {
 /* Purely graphic info */
 typedef struct {
        Display* dis;
+       Colormap cmap;
        Window win;
        Pixmap buf;
        int scr;
@@ -796,6 +797,8 @@ csihandle(void) {
                        case 1:
                                term.mode &= ~MODE_APPKEYPAD;
                                break;
+                       case 5: /* TODO: DECSCNM -- Remove reverse video */
+                               break;
                        case 7:
                                term.mode &= ~MODE_WRAP;
                                break;
@@ -851,6 +854,9 @@ csihandle(void) {
                        case 1:
                                term.mode |= MODE_APPKEYPAD;
                                break;
+                       case 5: /* DECSCNM -- Reverve video */
+                               /* TODO: set REVERSE on the whole screen (f) */
+                               break;
                        case 7:
                                term.mode |= MODE_WRAP;
                                break;
@@ -1116,11 +1122,10 @@ void
 xloadcols(void) {
        int i, r, g, b;
        XColor color;
-       Colormap cmap = DefaultColormap(xw.dis, xw.scr);
        unsigned long white = WhitePixel(xw.dis, xw.scr);
 
        for(i = 0; i < 16; i++) {
-               if (!XAllocNamedColor(xw.dis, cmap, colorname[i], &color, &color)) {
+               if (!XAllocNamedColor(xw.dis, xw.cmap, colorname[i], &color, &color)) {
                        dc.col[i] = white;
                        fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]);
                } else
@@ -1134,7 +1139,7 @@ xloadcols(void) {
                                color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r;
                                color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g;
                                color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b;
-                               if (!XAllocColor(xw.dis, cmap, &color)) {
+                               if (!XAllocColor(xw.dis, xw.cmap, &color)) {
                                        dc.col[i] = white;
                                        fprintf(stderr, "Could not allocate color %d\n", i);
                                } else
@@ -1144,7 +1149,7 @@ xloadcols(void) {
 
        for(r = 0; r < 24; r++, i++) {
                color.red = color.green = color.blue = 0x0808 + 0x0a0a * r;
-               if (!XAllocColor(xw.dis, cmap, &color)) {
+               if (!XAllocColor(xw.dis, xw.cmap, &color)) {
                        dc.col[i] = white;
                        fprintf(stderr, "Could not allocate color %d\n", i);
                } else
@@ -1179,6 +1184,8 @@ xhints(void)
 
 void
 xinit(void) {
+       XSetWindowAttributes attrs;
+
        if(!(xw.dis = XOpenDisplay(NULL)))
                die("Can't open display\n");
        xw.scr = XDefaultScreen(xw.dis);
@@ -1192,25 +1199,32 @@ xinit(void) {
        xw.ch = dc.font->ascent + dc.font->descent;
 
        /* colors */
+       xw.cmap = XDefaultColormap(xw.dis, xw.scr);
        xloadcols();
 
-       /* windows */
-       xw.bufh = term.row * xw.ch;
-       xw.bufw = term.col * xw.cw;
+       /* window - default size */
+       xw.bufh = 24 * xw.ch;
+       xw.bufw = 80 * xw.cw;
        xw.h = xw.bufh + 2*BORDER;
        xw.w = xw.bufw + 2*BORDER;
-       xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
-                       xw.w, xw.h, 0,
-                       dc.col[DefaultBG],
-                       dc.col[DefaultBG]);
+
+       attrs.background_pixel = dc.col[DefaultBG];
+       attrs.border_pixel = dc.col[DefaultBG];
+       attrs.bit_gravity = NorthWestGravity;
+       attrs.event_mask = ExposureMask | KeyPressMask
+               | StructureNotifyMask | FocusChangeMask | PointerMotionMask
+               | ButtonPressMask | ButtonReleaseMask;
+       attrs.colormap = xw.cmap;
+
+       xw.win = XCreateWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
+                       xw.w, xw.h, 0, XDefaultDepth(xw.dis, xw.scr), InputOutput,
+                       XDefaultVisual(xw.dis, xw.scr),
+                       CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask
+                       | CWColormap,
+                       &attrs);
        xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
        /* gc */
        dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL);
-
-       /* event mask */
-       XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask
-               | StructureNotifyMask | FocusChangeMask | PointerMotionMask
-               | ButtonPressMask | ButtonReleaseMask);
        
        XMapWindow(xw.dis, xw.win);
        xhints();
@@ -1307,8 +1321,7 @@ draw(int redraw_all) {
        Glyph base, new;
        char buf[DRAW_BUF_SIZ];
 
-       XSetForeground(xw.dis, dc.gc, dc.col[DefaultBG]);
-       XFillRectangle(xw.dis, xw.buf, dc.gc, 0, 0, xw.bufw, xw.bufh);
+       xclear(0, 0, term.col-1, term.row-1);
        for(y = 0; y < term.row; y++) {
                base = term.line[y][0];
                i = ox = 0;
@@ -1427,7 +1440,6 @@ resize(XEvent *e) {
        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);
 }
 
 void