rearranged code, resize fixed.
This commit is contained in:
parent
476f93794a
commit
2f5ebe0a4d
106
st.c
106
st.c
|
@ -56,7 +56,7 @@ typedef struct {
|
||||||
typedef Glyph* Line;
|
typedef Glyph* Line;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Glyph attr; /* current char attributes */
|
Glyph attr; /* current char attributes */
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
} TCursor;
|
} TCursor;
|
||||||
|
@ -65,24 +65,24 @@ typedef struct {
|
||||||
/* ESC '[' [[ [<priv>] <arg> [;]] <mode>] */
|
/* ESC '[' [[ [<priv>] <arg> [;]] <mode>] */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char buf[ESC_BUF_SIZ]; /* raw string */
|
char buf[ESC_BUF_SIZ]; /* raw string */
|
||||||
int len; /* raw string length */
|
int len; /* raw string length */
|
||||||
char priv;
|
char priv;
|
||||||
int arg[ESC_ARG_SIZ];
|
int arg[ESC_ARG_SIZ];
|
||||||
int narg; /* nb of args */
|
int narg; /* nb of args */
|
||||||
char mode;
|
char mode;
|
||||||
} CSIEscape;
|
} CSIEscape;
|
||||||
|
|
||||||
/* Internal representation of the screen */
|
/* Internal representation of the screen */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int row; /* nb row */
|
int row; /* nb row */
|
||||||
int col; /* nb col */
|
int col; /* nb col */
|
||||||
Line* line; /* screen */
|
Line* line; /* screen */
|
||||||
TCursor c; /* cursor */
|
TCursor c; /* cursor */
|
||||||
char hidec;
|
char hidec;
|
||||||
int top; /* top scroll limit */
|
int top; /* top scroll limit */
|
||||||
int bot; /* bottom scroll limit */
|
int bot; /* bottom scroll limit */
|
||||||
int mode; /* terminal mode flags */
|
int mode; /* terminal mode flags */
|
||||||
int esc; /* escape state flags */
|
int esc; /* escape state flags */
|
||||||
char title[ESC_TITLE_SIZ];
|
char title[ESC_TITLE_SIZ];
|
||||||
int titlelen;
|
int titlelen;
|
||||||
} Term;
|
} Term;
|
||||||
|
@ -93,8 +93,10 @@ typedef struct {
|
||||||
Window win;
|
Window win;
|
||||||
Pixmap buf;
|
Pixmap buf;
|
||||||
int scr;
|
int scr;
|
||||||
int w; /* window width */
|
int w; /* window width */
|
||||||
int h; /* window height */
|
int h; /* window height */
|
||||||
|
int bufw; /* pixmap width */
|
||||||
|
int bufh; /* pixmap height */
|
||||||
int ch; /* char height */
|
int ch; /* char height */
|
||||||
int cw; /* char width */
|
int cw; /* char width */
|
||||||
} XWindow;
|
} XWindow;
|
||||||
|
@ -216,7 +218,7 @@ execsh(void) {
|
||||||
|
|
||||||
void
|
void
|
||||||
xbell(void) { /* visual bell */
|
xbell(void) { /* visual bell */
|
||||||
XRectangle r = { BORDER, BORDER, xw.w, xw.h };
|
XRectangle r = { BORDER, BORDER, xw.bufw, xw.bufh };
|
||||||
XSetForeground(xw.dis, dc.gc, dc.col[BellCol]);
|
XSetForeground(xw.dis, dc.gc, dc.col[BellCol]);
|
||||||
XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1);
|
XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1);
|
||||||
/* usleep(30000); */
|
/* usleep(30000); */
|
||||||
|
@ -367,7 +369,7 @@ tscrolldown (int n) {
|
||||||
|
|
||||||
for(i = 0; i < n; i++)
|
for(i = 0; i < n; i++)
|
||||||
memset(term.line[term.bot-i], 0, term.col*sizeof(Glyph));
|
memset(term.line[term.bot-i], 0, term.col*sizeof(Glyph));
|
||||||
|
|
||||||
for(i = term.bot; i >= term.top+n; i--) {
|
for(i = term.bot; i >= term.top+n; i--) {
|
||||||
temp = term.line[i];
|
temp = term.line[i];
|
||||||
term.line[i] = term.line[i-n];
|
term.line[i] = term.line[i-n];
|
||||||
|
@ -582,7 +584,7 @@ tsetattr(int *attr, int l) {
|
||||||
term.c.attr.mode |= ATTR_REVERSE;
|
term.c.attr.mode |= ATTR_REVERSE;
|
||||||
break;
|
break;
|
||||||
case 22:
|
case 22:
|
||||||
term.c.attr.mode &= ~ATTR_BOLD;
|
term.c.attr.mode &= ~ATTR_BOLD;
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
term.c.attr.mode &= ~ATTR_UNDERLINE;
|
term.c.attr.mode &= ~ATTR_UNDERLINE;
|
||||||
|
@ -665,7 +667,7 @@ csihandle(void) {
|
||||||
case 'G': /* CHA -- Move to <col> */
|
case 'G': /* CHA -- Move to <col> */
|
||||||
case '`': /* XXX: HPA -- same? */
|
case '`': /* XXX: HPA -- same? */
|
||||||
DEFAULT(escseq.arg[0], 1);
|
DEFAULT(escseq.arg[0], 1);
|
||||||
tmoveto(escseq.arg[0]-1, term.c.y);
|
tmoveto(escseq.arg[0]-1, term.c.y);
|
||||||
break;
|
break;
|
||||||
case 'H': /* CUP -- Move to <row> <col> */
|
case 'H': /* CUP -- Move to <row> <col> */
|
||||||
case 'f': /* XXX: HVP -- same? */
|
case 'f': /* XXX: HVP -- same? */
|
||||||
|
@ -1026,12 +1028,23 @@ xclear(int x1, int y1, int x2, int y2) {
|
||||||
(x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch);
|
(x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xhints(void)
|
||||||
|
{
|
||||||
|
XClassHint chint = {TNAME, TNAME};
|
||||||
|
XWMHints wmhint = {.flags = InputHint, .input = 1};
|
||||||
|
XSizeHints shint = {
|
||||||
|
.flags = PSize | PResizeInc,
|
||||||
|
.height = xw.h, /* XXX: doesn't seem to work, see run() */
|
||||||
|
.width = xw.w,
|
||||||
|
.height_inc = xw.ch,
|
||||||
|
.width_inc = xw.cw,
|
||||||
|
};
|
||||||
|
XSetWMProperties(xw.dis, xw.win, NULL, NULL, NULL, 0, &shint, &wmhint, &chint);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xinit(void) {
|
xinit(void) {
|
||||||
XClassHint chint;
|
|
||||||
XWMHints wmhint;
|
|
||||||
XSizeHints shint;
|
|
||||||
char *args[] = {NULL};
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
xw.dis = XOpenDisplay(NULL);
|
xw.dis = XOpenDisplay(NULL);
|
||||||
|
@ -1055,27 +1068,21 @@ xinit(void) {
|
||||||
term.c.attr.bg = DefaultBG;
|
term.c.attr.bg = DefaultBG;
|
||||||
term.c.attr.mode = ATTR_NULL;
|
term.c.attr.mode = ATTR_NULL;
|
||||||
/* windows */
|
/* windows */
|
||||||
xw.h = term.row * xw.ch;
|
xw.h = term.row * xw.ch + 2*BORDER;
|
||||||
xw.w = term.col * xw.cw;
|
xw.w = term.col * xw.cw + 2*BORDER;
|
||||||
xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
|
xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
|
||||||
xw.w + 2*BORDER, xw.h + 2*BORDER, 0,
|
xw.w, xw.h, 0,
|
||||||
dc.col[DefaultBG],
|
dc.col[DefaultBG],
|
||||||
dc.col[DefaultBG]);
|
dc.col[DefaultBG]);
|
||||||
xw.buf = XCreatePixmap(xw.dis, xw.win, xw.w, xw.h, XDefaultDepth(xw.dis, xw.scr));
|
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));
|
||||||
/* gc */
|
/* gc */
|
||||||
dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL);
|
dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL);
|
||||||
XMapWindow(xw.dis, xw.win);
|
XMapWindow(xw.dis, xw.win);
|
||||||
/* wm stuff */
|
xhints();
|
||||||
chint.res_name = TNAME, chint.res_class = TNAME;
|
|
||||||
wmhint.input = 1, wmhint.flags = InputHint;
|
|
||||||
shint.height_inc = xw.ch, shint.width_inc = xw.cw;
|
|
||||||
shint.height = xw.h + 2*BORDER, shint.width = xw.w + 2*BORDER;
|
|
||||||
shint.flags = PSize | PResizeInc;
|
|
||||||
XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint);
|
|
||||||
XStoreName(xw.dis, xw.win, TNAME);
|
XStoreName(xw.dis, xw.win, TNAME);
|
||||||
XFillRectangle(xw.dis, xw.buf, dc.gc, 0, 0, xw.w, xw.h);
|
|
||||||
XSync(xw.dis, 0);
|
XSync(xw.dis, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1152,7 +1159,7 @@ draw_(int dummy) {
|
||||||
|
|
||||||
if(!term.hidec)
|
if(!term.hidec)
|
||||||
xcursor(CURSOR_DRAW);
|
xcursor(CURSOR_DRAW);
|
||||||
XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.w, xw.h, BORDER, BORDER);
|
XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER);
|
||||||
XFlush(xw.dis);
|
XFlush(xw.dis);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1181,7 +1188,7 @@ draw(int redraw_all) {
|
||||||
xdraws(buf, base, ox, y, i);
|
xdraws(buf, base, ox, y, i);
|
||||||
}
|
}
|
||||||
xcursor(term.hidec ? CURSOR_HIDE : CURSOR_DRAW);
|
xcursor(term.hidec ? CURSOR_HIDE : CURSOR_DRAW);
|
||||||
XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.w, xw.h, BORDER, BORDER);
|
XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER);
|
||||||
XFlush(xw.dis);
|
XFlush(xw.dis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1209,7 +1216,7 @@ kpress(XEvent *ev) {
|
||||||
int meta;
|
int meta;
|
||||||
int shift;
|
int shift;
|
||||||
|
|
||||||
meta = e->state & Mod1Mask;
|
meta = e->state & Mod1Mask;
|
||||||
shift = e->state & ShiftMask;
|
shift = e->state & ShiftMask;
|
||||||
len = XLookupString(e, buf, sizeof(buf), &ksym, NULL);
|
len = XLookupString(e, buf, sizeof(buf), &ksym, NULL);
|
||||||
|
|
||||||
|
@ -1242,18 +1249,21 @@ kpress(XEvent *ev) {
|
||||||
void
|
void
|
||||||
resize(XEvent *e) {
|
resize(XEvent *e) {
|
||||||
int col, row;
|
int col, row;
|
||||||
col = e->xconfigure.width / xw.cw;
|
|
||||||
row = e->xconfigure.height / xw.ch;
|
|
||||||
|
|
||||||
if(term.col != col || term.row != row) {
|
if(e->xconfigure.width == xw.w && e->xconfigure.height == xw.h)
|
||||||
tresize(col, row);
|
return;
|
||||||
ttyresize(col, row);
|
|
||||||
xw.w = e->xconfigure.width;
|
xw.w = e->xconfigure.width;
|
||||||
xw.h = e->xconfigure.height;
|
xw.h = e->xconfigure.height;
|
||||||
XFreePixmap(xw.dis, xw.buf);
|
xw.bufw = xw.w - 2*BORDER;
|
||||||
xw.buf = XCreatePixmap(xw.dis, xw.win, xw.w, xw.h, XDefaultDepth(xw.dis, xw.scr));
|
xw.bufh = xw.h - 2*BORDER;
|
||||||
draw(SCREEN_REDRAW);
|
col = xw.bufw / xw.cw;
|
||||||
}
|
row = xw.bufh / xw.ch;
|
||||||
|
tresize(col, row);
|
||||||
|
ttyresize(col, row);
|
||||||
|
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
|
void
|
||||||
|
@ -1264,7 +1274,7 @@ run(void) {
|
||||||
|
|
||||||
running = 1;
|
running = 1;
|
||||||
XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask | StructureNotifyMask);
|
XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask | StructureNotifyMask);
|
||||||
XResizeWindow(xw.dis, xw.win, xw.w+2*BORDER, xw.h+2*BORDER); /* fix resize bug in wmii (?) */
|
XResizeWindow(xw.dis, xw.win, xw.w, xw.h); /* XXX: fix resize bug in wmii (?) */
|
||||||
|
|
||||||
while(running) {
|
while(running) {
|
||||||
FD_ZERO(&rfd);
|
FD_ZERO(&rfd);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user