-/* See LICENSE for licence details. */
+/* See LICENSE for licence details. */
#include "st.h"
/* Globals */
}
void
-xbell(void) { /* visual bell */
+xbell(void) { /* visual bell */
XRectangle r = { 0, 0, xw.w, xw.h };
XSetForeground(xw.dis, dc.gc, dc.col[BellCol]);
XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1);
- XFlush(xw.dis);
usleep(30000);
draw(SCredraw);
}
}
else if(BETWEEN(c, 0x40, 0x7E))
return 1;
- return 0;
+ return 0;
}
void
term.line[i] = term.line[i+1];
memset(temp, 0, sizeof(Glyph) * term.col);
term.line[term.bot] = temp;
- xscroll();
+ xscroll();
}
void
term.c.attr.bg = DefaultBG;
break;
case 1:
- term.c.attr.mode |= ATbold;
+ term.c.attr.mode |= ATbold;
break;
case 4:
term.c.attr.mode |= ATunderline;
break;
case 7:
- term.c.attr.mode |= ATreverse;
+ term.c.attr.mode |= ATreverse;
break;
case 8:
term.c.hidden = CShide;
term.c.attr.mode &= ~ATunderline;
break;
case 27:
- term.c.attr.mode &= ~ATreverse;
+ term.c.attr.mode &= ~ATreverse;
break;
case 39:
term.c.attr.fg = DefaultFG;
b = temp;
}
term.top = t;
- term.bot = b;
+ term.bot = b;
}
break;
case 2: /* all */
tclearregion(0, 0, term.col-1, term.row-1);
- break;
+ break;
}
break;
case 'K': /* Clear line */
DEFAULT(escseq.arg[0], 1);
tinsertblankline(escseq.arg[0]);
break;
+ case 'l':
+ if(escseq.priv && escseq.arg[0] == 25)
+ term.c.hidden = 1;
+ break;
case 'M': /* Delete <n> lines */
DEFAULT(escseq.arg[0], 1);
tdeleteline(escseq.arg[0]);
tmoveto(term.c.x, escseq.arg[0]-1);
break;
case 'h': /* Set terminal mode */
+ if(escseq.priv && escseq.arg[0] == 25)
+ term.c.hidden = 0;
break;
case 'm': /* Terminal attribute (color) */
tsetattr(escseq.arg, escseq.narg);
escdump(void) {
int i;
puts("------");
- printf("rawbuf : %s\n", escseq.buf);
+ printf("rawbuf : %s\n", escseq.buf);
printf("prechar : %c\n", escseq.pre);
printf("private : %c\n", escseq.priv ? '?' : ' ');
- printf("narg : %d\n", escseq.narg);
+ printf("narg : %d\n", escseq.narg);
if(escseq.narg) {
for(i = 0; i < escseq.narg; i++)
printf("\targ %d = %d\n", i, escseq.arg[i]);
}
- printf("mode : %c\n", escseq.mode);
+ printf("mode : %c\n", escseq.mode);
}
void
void
tputtab(void) {
- int space = TAB - term.c.x % TAB;
-
- if(term.c.x + space >= term.col)
- space--;
-
- for(; space > 0; space--)
- tcursor(CSright);
+ int space = TAB - term.c.x % TAB;
+
+ if(term.c.x + space >= term.col)
+ space--;
+
+ for(; space > 0; space--)
+ tcursor(CSright);
}
void
tputc(char c) {
static int inesc = 0;
-
- //dump(c);
+#if 0
+ dump(c);
+#endif
/* start of escseq */
if(c == '\033')
escreset(), inesc = 1;
tsetchar(c);
tcursor(CSright);
break;
- case '\t':
- tputtab();
- break;
+ case '\t':
+ tputtab();
+ break;
case '\b':
tcursor(CSleft);
break;
if(col < 1 || row < 1)
return;
- /* alloc */
+ /* alloc */
line = calloc(row, sizeof(Line));
for(i = 0 ; i < row; i++)
line[i] = calloc(col, sizeof(Glyph));
- /* copy */
- for(i = 0 ; i < minrow; i++)
- memcpy(line[i], term.line[i], mincol * sizeof(Glyph));
- /* free */
- for(i = 0; i < term.row; i++)
- free(term.line[i]);
+ /* copy */
+ for(i = 0 ; i < minrow; i++)
+ memcpy(line[i], term.line[i], mincol * sizeof(Glyph));
+ /* free */
+ for(i = 0; i < term.row; i++)
+ free(term.line[i]);
free(term.line);
-
+
LIMIT(term.c.x, 0, col-1);
LIMIT(term.c.y, 0, row-1);
LIMIT(term.top, 0, row-1);
LIMIT(term.bot, 0, row-1);
-
- term.bot = row-1;
+
+ term.bot = row-1;
term.line = line;
term.col = col, term.row = row;
}
xw.dis = XOpenDisplay(NULL);
xw.scr = XDefaultScreen(xw.dis);
- if(!xw.dis)
- die("can not open display");
-
+ if(!xw.dis)
+ die("can not open display");
+
/* font */
if(!(dc.font = XLoadQueryFont(xw.dis, FONT)))
- die("can not find font " FONT);
+ die("can not find font " FONT);
xw.cw = dc.font->max_bounds.rbearing - dc.font->min_bounds.lbearing;
xw.ch = dc.font->ascent + dc.font->descent + LINESPACE;
term.c.attr.bg = DefaultBG;
term.c.attr.mode = ATnone;
/* windows */
- xw.h = term.row * xw.ch;
+ xw.h = term.row * xw.ch;
xw.w = term.col * xw.cw;
/* XXX: this BORDER is useless after the first resize, handle it in xdraws() */
xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint);
XStoreName(xw.dis, xw.win, TNAME);
XSync(xw.dis, 0);
-
}
void
/* string */
XSetForeground(xw.dis, dc.gc, xfg);
XDrawString(xw.dis, xw.win, dc.gc, r.x, r.y+dc.font->ascent, &(g.c), 1);
- if(g.mode & ATbold) /* XXX: bold hack (draw again at x+1) */
+ if(g.mode & ATbold) /* XXX: bold hack (draw again at x+1) */
XDrawString(xw.dis, xw.win, dc.gc, r.x+1, r.y+dc.font->ascent, &(g.c), 1);
/* underline */
if(g.mode & ATunderline) {
static int oldx = 0;
static int oldy = 0;
Glyph g = {' ', ATnone, DefaultBG, DefaultCS, 0};
-
- LIMIT(oldx, 0, term.col-1);
+
+ LIMIT(oldx, 0, term.col-1);
LIMIT(oldy, 0, term.row-1);
-
+
if(term.line[term.c.y][term.c.x].state & CRset)
g.c = term.line[term.c.y][term.c.x].c;
/* remove the old cursor */
int meta;
int shift;
- meta = e->state & Mod4Mask;
+ meta = e->state & Mod1Mask;
shift = e->state & ShiftMask;
len = XLookupString(e, buf, sizeof(buf), &ksym, NULL);
if(len > 0) {
return;
}
switch(ksym) {
-#ifdef DEBUG1
default:
- printf("errkey: %d\n", (int)ksym);
+ fprintf(stderr, "errkey: %d\n", (int)ksym);
break;
-#endif
case XK_Up:
case XK_Down:
case XK_Left:
ttywrite(buf, 3);
break;
case XK_Delete: ttywrite(KEYDELETE, sizeof(KEYDELETE)-1); break;
- case XK_Home: ttywrite( KEYHOME, sizeof( KEYHOME)-1); break;
- case XK_End: ttywrite( KEYEND, sizeof( KEYEND)-1); break;
- case XK_Prior: ttywrite( KEYPREV, sizeof( KEYPREV)-1); break;
- case XK_Next: ttywrite( KEYNEXT, sizeof( KEYNEXT)-1); break;
+ case XK_Home: ttywrite(KEYHOME, sizeof(KEYHOME)-1); break;
+ case XK_End: ttywrite(KEYEND, sizeof(KEYEND) -1); break;
+ case XK_Prior: ttywrite(KEYPREV, sizeof(KEYPREV)-1); break;
+ case XK_Next: ttywrite(KEYNEXT, sizeof(KEYNEXT)-1); break;
case XK_Insert:
/* XXX: paste X clipboard */
- if(shift);
+ if(shift)
+ ;
break;
}
}
int col, row;
col = e->xconfigure.width / xw.cw;
row = e->xconfigure.height / xw.ch;
-
+
if(term.col != col || term.row != row) {
tresize(col, row);
ttyresize(col, row);
int ret;
XEvent ev;
fd_set rfd;
- struct timeval tv = {0, 10000};
+ int xfd = XConnectionNumber(xw.dis);
running = 1;
XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask | StructureNotifyMask);
XResizeWindow(xw.dis, xw.win, xw.w , xw.h); /* seems to fix the resize bug in wmii */
+
while(running) {
- while(XPending(xw.dis)) {
- XNextEvent(xw.dis, &ev);
- switch (ev.type) {
- default:
- break;
- case KeyPress:
- kpress(&ev.xkey);
- break;
- case Expose:
- draw(SCredraw);
- break;
- case ConfigureNotify:
- resize(&ev);
- break;
- }
- }
FD_ZERO(&rfd);
FD_SET(cmdfd, &rfd);
- ret = select(cmdfd+1, &rfd, NULL, NULL, &tv);
+ FD_SET(xfd, &rfd);
+ XFlush(xw.dis);
+ ret = select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, NULL);
+
if(ret < 0) {
fprintf(stderr, "select: %m\n");
running = 0;
}
- if(!ret)
- continue;
+
+ if(FD_ISSET(xfd, &rfd)) {
+ while(XPending(xw.dis)) {
+ XNextEvent(xw.dis, &ev);
+ switch (ev.type) {
+ default:
+ break;
+ case KeyPress:
+ kpress(&ev.xkey);
+ break;
+ case Expose:
+ draw(SCredraw);
+ break;
+ case ConfigureNotify:
+ resize(&ev);
+ break;
+ }
+ }
+ }
if(FD_ISSET(cmdfd, &rfd)) {
ttyread();
draw(SCupdate);
else if(argc != 1)
die("usage: st [-v]\n");
setlocale(LC_CTYPE, "");
- tnew(80, 24);
- ttynew();
- xinit();
- run();
+ tnew(80, 24);
+ ttynew();
+ xinit();
+ run();
return 0;
}