aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien Aptel <aurelien.aptel@gmail.com>2010-06-02 16:01:30 +0200
committerAurélien Aptel <aurelien.aptel@gmail.com>2010-06-02 16:01:30 +0200
commit2f5ebe0a4d71aea0bb3aa0e500765a402e4a96f4 (patch)
tree8d325f8987072c900ef613ff14b93b29d939c75e
parent476f93794acc36ea69dfd33551e311863c8afc9a (diff)
downloadst-2f5ebe0a4d71aea0bb3aa0e500765a402e4a96f4.tar.gz
st-2f5ebe0a4d71aea0bb3aa0e500765a402e4a96f4.zip
rearranged code, resize fixed.
-rwxr-xr-xst.c106
1 files changed, 58 insertions, 48 deletions
diff --git a/st.c b/st.c
index ff43706..db5e04f 100755
--- a/st.c
+++ b/st.c
@@ -56,7 +56,7 @@ typedef struct {
56typedef Glyph* Line; 56typedef Glyph* Line;
57 57
58typedef struct { 58typedef struct {
59 Glyph attr; /* current char attributes */ 59 Glyph attr; /* current char attributes */
60 int x; 60 int x;
61 int y; 61 int y;
62} TCursor; 62} TCursor;
@@ -65,24 +65,24 @@ typedef struct {
65/* ESC '[' [[ [<priv>] <arg> [;]] <mode>] */ 65/* ESC '[' [[ [<priv>] <arg> [;]] <mode>] */
66typedef struct { 66typedef struct {
67 char buf[ESC_BUF_SIZ]; /* raw string */ 67 char buf[ESC_BUF_SIZ]; /* raw string */
68 int len; /* raw string length */ 68 int len; /* raw string length */
69 char priv; 69 char priv;
70 int arg[ESC_ARG_SIZ]; 70 int arg[ESC_ARG_SIZ];
71 int narg; /* nb of args */ 71 int narg; /* nb of args */
72 char mode; 72 char mode;
73} CSIEscape; 73} CSIEscape;
74 74
75/* Internal representation of the screen */ 75/* Internal representation of the screen */
76typedef struct { 76typedef struct {
77 int row; /* nb row */ 77 int row; /* nb row */
78 int col; /* nb col */ 78 int col; /* nb col */
79 Line* line; /* screen */ 79 Line* line; /* screen */
80 TCursor c; /* cursor */ 80 TCursor c; /* cursor */
81 char hidec; 81 char hidec;
82 int top; /* top scroll limit */ 82 int top; /* top scroll limit */
83 int bot; /* bottom scroll limit */ 83 int bot; /* bottom scroll limit */
84 int mode; /* terminal mode flags */ 84 int mode; /* terminal mode flags */
85 int esc; /* escape state flags */ 85 int esc; /* escape state flags */
86 char title[ESC_TITLE_SIZ]; 86 char title[ESC_TITLE_SIZ];
87 int titlelen; 87 int titlelen;
88} Term; 88} Term;
@@ -93,8 +93,10 @@ typedef struct {
93 Window win; 93 Window win;
94 Pixmap buf; 94 Pixmap buf;
95 int scr; 95 int scr;
96 int w; /* window width */ 96 int w; /* window width */
97 int h; /* window height */ 97 int h; /* window height */
98 int bufw; /* pixmap width */
99 int bufh; /* pixmap height */
98 int ch; /* char height */ 100 int ch; /* char height */
99 int cw; /* char width */ 101 int cw; /* char width */
100} XWindow; 102} XWindow;
@@ -216,7 +218,7 @@ execsh(void) {
216 218
217void 219void
218xbell(void) { /* visual bell */ 220xbell(void) { /* visual bell */
219 XRectangle r = { BORDER, BORDER, xw.w, xw.h }; 221 XRectangle r = { BORDER, BORDER, xw.bufw, xw.bufh };
220 XSetForeground(xw.dis, dc.gc, dc.col[BellCol]); 222 XSetForeground(xw.dis, dc.gc, dc.col[BellCol]);
221 XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1); 223 XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1);
222 /* usleep(30000); */ 224 /* usleep(30000); */
@@ -367,7 +369,7 @@ tscrolldown (int n) {
367 369
368 for(i = 0; i < n; i++) 370 for(i = 0; i < n; i++)
369 memset(term.line[term.bot-i], 0, term.col*sizeof(Glyph)); 371 memset(term.line[term.bot-i], 0, term.col*sizeof(Glyph));
370 372
371 for(i = term.bot; i >= term.top+n; i--) { 373 for(i = term.bot; i >= term.top+n; i--) {
372 temp = term.line[i]; 374 temp = term.line[i];
373 term.line[i] = term.line[i-n]; 375 term.line[i] = term.line[i-n];
@@ -582,7 +584,7 @@ tsetattr(int *attr, int l) {
582 term.c.attr.mode |= ATTR_REVERSE; 584 term.c.attr.mode |= ATTR_REVERSE;
583 break; 585 break;
584 case 22: 586 case 22:
585 term.c.attr.mode &= ~ATTR_BOLD; 587 term.c.attr.mode &= ~ATTR_BOLD;
586 break; 588 break;
587 case 24: 589 case 24:
588 term.c.attr.mode &= ~ATTR_UNDERLINE; 590 term.c.attr.mode &= ~ATTR_UNDERLINE;
@@ -665,7 +667,7 @@ csihandle(void) {
665 case 'G': /* CHA -- Move to <col> */ 667 case 'G': /* CHA -- Move to <col> */
666 case '`': /* XXX: HPA -- same? */ 668 case '`': /* XXX: HPA -- same? */
667 DEFAULT(escseq.arg[0], 1); 669 DEFAULT(escseq.arg[0], 1);
668 tmoveto(escseq.arg[0]-1, term.c.y); 670 tmoveto(escseq.arg[0]-1, term.c.y);
669 break; 671 break;
670 case 'H': /* CUP -- Move to <row> <col> */ 672 case 'H': /* CUP -- Move to <row> <col> */
671 case 'f': /* XXX: HVP -- same? */ 673 case 'f': /* XXX: HVP -- same? */
@@ -1027,11 +1029,22 @@ xclear(int x1, int y1, int x2, int y2) {
1027} 1029}
1028 1030
1029void 1031void
1032xhints(void)
1033{
1034 XClassHint chint = {TNAME, TNAME};
1035 XWMHints wmhint = {.flags = InputHint, .input = 1};
1036 XSizeHints shint = {
1037 .flags = PSize | PResizeInc,
1038 .height = xw.h, /* XXX: doesn't seem to work, see run() */
1039 .width = xw.w,
1040 .height_inc = xw.ch,
1041 .width_inc = xw.cw,
1042 };
1043 XSetWMProperties(xw.dis, xw.win, NULL, NULL, NULL, 0, &shint, &wmhint, &chint);
1044}
1045
1046void
1030xinit(void) { 1047xinit(void) {
1031 XClassHint chint;
1032 XWMHints wmhint;
1033 XSizeHints shint;
1034 char *args[] = {NULL};
1035 int i; 1048 int i;
1036 1049
1037 xw.dis = XOpenDisplay(NULL); 1050 xw.dis = XOpenDisplay(NULL);
@@ -1055,27 +1068,21 @@ xinit(void) {
1055 term.c.attr.bg = DefaultBG; 1068 term.c.attr.bg = DefaultBG;
1056 term.c.attr.mode = ATTR_NULL; 1069 term.c.attr.mode = ATTR_NULL;
1057 /* windows */ 1070 /* windows */
1058 xw.h = term.row * xw.ch; 1071 xw.h = term.row * xw.ch + 2*BORDER;
1059 xw.w = term.col * xw.cw; 1072 xw.w = term.col * xw.cw + 2*BORDER;
1060 xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0, 1073 xw.win = XCreateSimpleWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
1061 xw.w + 2*BORDER, xw.h + 2*BORDER, 0, 1074 xw.w, xw.h, 0,
1062 dc.col[DefaultBG], 1075 dc.col[DefaultBG],
1063 dc.col[DefaultBG]); 1076 dc.col[DefaultBG]);
1064 xw.buf = XCreatePixmap(xw.dis, xw.win, xw.w, xw.h, XDefaultDepth(xw.dis, xw.scr)); 1077 xw.bufw = xw.w - 2*BORDER;
1078 xw.bufh = xw.h - 2*BORDER;
1079 xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
1065 /* gc */ 1080 /* gc */
1066 dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL); 1081 dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL);
1067 XMapWindow(xw.dis, xw.win); 1082 XMapWindow(xw.dis, xw.win);
1068 /* wm stuff */ 1083 xhints();
1069 chint.res_name = TNAME, chint.res_class = TNAME;
1070 wmhint.input = 1, wmhint.flags = InputHint;
1071 shint.height_inc = xw.ch, shint.width_inc = xw.cw;
1072 shint.height = xw.h + 2*BORDER, shint.width = xw.w + 2*BORDER;
1073 shint.flags = PSize | PResizeInc;
1074 XSetWMProperties(xw.dis, xw.win, NULL, NULL, &args[0], 0, &shint, &wmhint, &chint);
1075 XStoreName(xw.dis, xw.win, TNAME); 1084 XStoreName(xw.dis, xw.win, TNAME);
1076 XFillRectangle(xw.dis, xw.buf, dc.gc, 0, 0, xw.w, xw.h);
1077 XSync(xw.dis, 0); 1085 XSync(xw.dis, 0);
1078
1079} 1086}
1080 1087
1081void 1088void
@@ -1152,7 +1159,7 @@ draw_(int dummy) {
1152 1159
1153 if(!term.hidec) 1160 if(!term.hidec)
1154 xcursor(CURSOR_DRAW); 1161 xcursor(CURSOR_DRAW);
1155 XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.w, xw.h, BORDER, BORDER); 1162 XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER);
1156 XFlush(xw.dis); 1163 XFlush(xw.dis);
1157} 1164}
1158#endif 1165#endif
@@ -1181,7 +1188,7 @@ draw(int redraw_all) {
1181 xdraws(buf, base, ox, y, i); 1188 xdraws(buf, base, ox, y, i);
1182 } 1189 }
1183 xcursor(term.hidec ? CURSOR_HIDE : CURSOR_DRAW); 1190 xcursor(term.hidec ? CURSOR_HIDE : CURSOR_DRAW);
1184 XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.w, xw.h, BORDER, BORDER); 1191 XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER);
1185 XFlush(xw.dis); 1192 XFlush(xw.dis);
1186} 1193}
1187 1194
@@ -1209,7 +1216,7 @@ kpress(XEvent *ev) {
1209 int meta; 1216 int meta;
1210 int shift; 1217 int shift;
1211 1218
1212 meta = e->state & Mod1Mask; 1219 meta = e->state & Mod1Mask;
1213 shift = e->state & ShiftMask; 1220 shift = e->state & ShiftMask;
1214 len = XLookupString(e, buf, sizeof(buf), &ksym, NULL); 1221 len = XLookupString(e, buf, sizeof(buf), &ksym, NULL);
1215 1222
@@ -1242,18 +1249,21 @@ kpress(XEvent *ev) {
1242void 1249void
1243resize(XEvent *e) { 1250resize(XEvent *e) {
1244 int col, row; 1251 int col, row;
1245 col = e->xconfigure.width / xw.cw;
1246 row = e->xconfigure.height / xw.ch;
1247 1252
1248 if(term.col != col || term.row != row) { 1253 if(e->xconfigure.width == xw.w && e->xconfigure.height == xw.h)
1249 tresize(col, row); 1254 return;
1250 ttyresize(col, row); 1255
1251 xw.w = e->xconfigure.width; 1256 xw.w = e->xconfigure.width;
1252 xw.h = e->xconfigure.height; 1257 xw.h = e->xconfigure.height;
1253 XFreePixmap(xw.dis, xw.buf); 1258 xw.bufw = xw.w - 2*BORDER;
1254 xw.buf = XCreatePixmap(xw.dis, xw.win, xw.w, xw.h, XDefaultDepth(xw.dis, xw.scr)); 1259 xw.bufh = xw.h - 2*BORDER;
1255 draw(SCREEN_REDRAW); 1260 col = xw.bufw / xw.cw;
1256 } 1261 row = xw.bufh / xw.ch;
1262 tresize(col, row);
1263 ttyresize(col, row);
1264 XFreePixmap(xw.dis, xw.buf);
1265 xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
1266 draw(SCREEN_REDRAW);
1257} 1267}
1258 1268
1259void 1269void
@@ -1264,7 +1274,7 @@ run(void) {
1264 1274
1265 running = 1; 1275 running = 1;
1266 XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask | StructureNotifyMask); 1276 XSelectInput(xw.dis, xw.win, ExposureMask | KeyPressMask | StructureNotifyMask);
1267 XResizeWindow(xw.dis, xw.win, xw.w+2*BORDER, xw.h+2*BORDER); /* fix resize bug in wmii (?) */ 1277 XResizeWindow(xw.dis, xw.win, xw.w, xw.h); /* XXX: fix resize bug in wmii (?) */
1268 1278
1269 while(running) { 1279 while(running) {
1270 FD_ZERO(&rfd); 1280 FD_ZERO(&rfd);