fixed the scrolling bug and cleaned some stuff.
This commit is contained in:
		
							parent
							
								
									d5f4554431
								
							
						
					
					
						commit
						b8ffa1d7e9
					
				
							
								
								
									
										43
									
								
								st.c
								
								
								
								
							
							
						
						
									
										43
									
								
								st.c
								
								
								
								
							| 
						 | 
					@ -37,7 +37,7 @@
 | 
				
			||||||
enum { ATnone=0 , ATreverse=1 , ATunderline=2, ATbold=4 };
 | 
					enum { ATnone=0 , ATreverse=1 , ATunderline=2, ATbold=4 };
 | 
				
			||||||
enum { CSup, CSdown, CSright, CSleft, CShide, CSdraw, CSwrap, CSsave, CSload };
 | 
					enum { CSup, CSdown, CSright, CSleft, CShide, CSdraw, CSwrap, CSsave, CSload };
 | 
				
			||||||
enum { CRset=1, CRupdate=2 };
 | 
					enum { CRset=1, CRupdate=2 };
 | 
				
			||||||
enum { TMwrap=1, TMinsert=2, TMaltcharset };
 | 
					enum { TMwrap=1, TMinsert=2 };
 | 
				
			||||||
enum { SCupdate, SCredraw };
 | 
					enum { SCupdate, SCredraw };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef int Color;
 | 
					typedef int Color;
 | 
				
			||||||
| 
						 | 
					@ -154,6 +154,7 @@ void xdrawc(int, int, Glyph);
 | 
				
			||||||
void xinit(void);
 | 
					void xinit(void);
 | 
				
			||||||
void xscroll(void);
 | 
					void xscroll(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void cursor(int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Globals */
 | 
					/* Globals */
 | 
				
			||||||
DC dc;
 | 
					DC dc;
 | 
				
			||||||
| 
						 | 
					@ -201,7 +202,6 @@ sigchld(int a) {
 | 
				
			||||||
		exit(EXIT_FAILURE);
 | 
							exit(EXIT_FAILURE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
ttynew(void) {
 | 
					ttynew(void) {
 | 
				
			||||||
	int m, s;
 | 
						int m, s;
 | 
				
			||||||
| 
						 | 
					@ -328,21 +328,19 @@ void
 | 
				
			||||||
tscroll(void) {
 | 
					tscroll(void) {
 | 
				
			||||||
	Line temp = term.line[term.top];
 | 
						Line temp = term.line[term.top];
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
 | 
						/* X stuff _before_ the line swapping (results in wrong line index) */
 | 
				
			||||||
 | 
						xscroll();
 | 
				
			||||||
	for(i = term.top; i < term.bot; i++)
 | 
						for(i = term.top; i < term.bot; i++)
 | 
				
			||||||
		term.line[i] = term.line[i+1];
 | 
							term.line[i] = term.line[i+1];
 | 
				
			||||||
	memset(temp, 0, sizeof(Glyph) * term.col);
 | 
						memset(temp, 0, sizeof(Glyph) * term.col);
 | 
				
			||||||
	term.line[term.bot] = temp;
 | 
						term.line[term.bot] = temp;
 | 
				
			||||||
	xscroll();	  
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
tnewline(void) {
 | 
					tnewline(void) {
 | 
				
			||||||
	int y = term.c.y + 1;
 | 
						int y = term.c.y + 1;
 | 
				
			||||||
 | 
						if(y > term.bot)
 | 
				
			||||||
	if(y > term.bot) {
 | 
					 | 
				
			||||||
		tscroll(), y = term.bot;
 | 
							tscroll(), y = term.bot;
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	tmoveto(0, y);
 | 
						tmoveto(0, y);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -476,6 +474,13 @@ tinsertblank(int n) {
 | 
				
			||||||
	tclearregion(src, term.c.y, dst, term.c.y);
 | 
						tclearregion(src, term.c.y, dst, term.c.y);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					tsetlinestate(int n, int state) {
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
						for(i = 0; i < term.col; i++)
 | 
				
			||||||
 | 
							term.line[n][i].state |= state;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
tinsertblankline (int n) {
 | 
					tinsertblankline (int n) {
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
| 
						 | 
					@ -497,10 +502,11 @@ tinsertblankline (int n) {
 | 
				
			||||||
		term.line[i-n] = blank;
 | 
							term.line[i-n] = blank;
 | 
				
			||||||
		/* blank it */
 | 
							/* blank it */
 | 
				
			||||||
		memset(blank, 0, term.col * sizeof(Glyph));
 | 
							memset(blank, 0, term.col * sizeof(Glyph));
 | 
				
			||||||
 | 
							tsetlinestate(i, CRupdate);
 | 
				
			||||||
 | 
							tsetlinestate(i-n, CRupdate);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
tdeleteline(int n) {
 | 
					tdeleteline(int n) {
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
| 
						 | 
					@ -522,6 +528,8 @@ tdeleteline(int n) {
 | 
				
			||||||
		term.line[i+n] = blank;
 | 
							term.line[i+n] = blank;
 | 
				
			||||||
		/* blank it */
 | 
							/* blank it */
 | 
				
			||||||
		memset(blank, 0, term.col * sizeof(Glyph));
 | 
							memset(blank, 0, term.col * sizeof(Glyph));
 | 
				
			||||||
 | 
							tsetlinestate(i, CRupdate);
 | 
				
			||||||
 | 
							tsetlinestate(i-n, CRupdate);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -588,7 +596,6 @@ tsetscroll(int t, int b) {
 | 
				
			||||||
	term.bot = b;	 
 | 
						term.bot = b;	 
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
eschandle(void) {
 | 
					eschandle(void) {
 | 
				
			||||||
	switch(escseq.pre) {
 | 
						switch(escseq.pre) {
 | 
				
			||||||
| 
						 | 
					@ -846,7 +853,6 @@ xgetcol(const char *s) {
 | 
				
			||||||
	return color.pixel;
 | 
						return color.pixel;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
xclear(int x1, int y1, int x2, int y2) {
 | 
					xclear(int x1, int y1, int x2, int y2) {
 | 
				
			||||||
	XClearArea(xw.dis, xw.win, 
 | 
						XClearArea(xw.dis, xw.win, 
 | 
				
			||||||
| 
						 | 
					@ -855,7 +861,6 @@ xclear(int x1, int y1, int x2, int y2) {
 | 
				
			||||||
			False);
 | 
								False);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
xscroll(void) {
 | 
					xscroll(void) {
 | 
				
			||||||
	int srcy = (term.top+1) * xw.ch;
 | 
						int srcy = (term.top+1) * xw.ch;
 | 
				
			||||||
| 
						 | 
					@ -867,9 +872,6 @@ xscroll(void) {
 | 
				
			||||||
	xclear(0, term.bot, term.col-1, term.bot);
 | 
						xclear(0, term.bot, term.col-1, term.bot);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
xinit(void) {
 | 
					xinit(void) {
 | 
				
			||||||
	XGCValues values;
 | 
						XGCValues values;
 | 
				
			||||||
| 
						 | 
					@ -963,14 +965,15 @@ xcursor(int mode) {
 | 
				
			||||||
	/* remove the old cursor */
 | 
						/* remove the old cursor */
 | 
				
			||||||
	if(term.line[oldy][oldx].state & CRset)
 | 
						if(term.line[oldy][oldx].state & CRset)
 | 
				
			||||||
		xdrawc(oldx, oldy, term.line[oldy][oldx]);
 | 
							xdrawc(oldx, oldy, term.line[oldy][oldx]);
 | 
				
			||||||
	else xclear(oldx, oldy, oldx, oldy); /* XXX: maybe a bug */
 | 
						else 
 | 
				
			||||||
	if(mode == CSdraw && !term.c.hidden) {
 | 
							xclear(oldx, oldy, oldx, oldy);
 | 
				
			||||||
 | 
						/* draw the new one */
 | 
				
			||||||
 | 
						if(mode == CSdraw) {
 | 
				
			||||||
		xdrawc(term.c.x, term.c.y, g);
 | 
							xdrawc(term.c.x, term.c.y, g);
 | 
				
			||||||
		oldx = term.c.x, oldy = term.c.y;
 | 
							oldx = term.c.x, oldy = term.c.y;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
draw(int redraw_all) {
 | 
					draw(int redraw_all) {
 | 
				
			||||||
	int x, y;
 | 
						int x, y;
 | 
				
			||||||
| 
						 | 
					@ -978,14 +981,18 @@ draw(int redraw_all) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(redraw_all)
 | 
						if(redraw_all)
 | 
				
			||||||
		XClearWindow(xw.dis, xw.win);
 | 
							XClearWindow(xw.dis, xw.win);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* XXX: drawing could be optimised */
 | 
						/* XXX: drawing could be optimised */
 | 
				
			||||||
	for(y = 0; y < term.row; y++) {
 | 
						for(y = 0; y < term.row; y++) {
 | 
				
			||||||
		for(x = 0; x < term.col; x++) {
 | 
							for(x = 0; x < term.col; x++) {
 | 
				
			||||||
			changed = term.line[y][x].state & CRupdate;
 | 
								changed = term.line[y][x].state & CRupdate;
 | 
				
			||||||
			set = term.line[y][x].state & CRset;
 | 
								set = term.line[y][x].state & CRset;
 | 
				
			||||||
			if((changed && set) || (redraw_all && set)) {
 | 
								if(redraw_all || changed) {
 | 
				
			||||||
				term.line[y][x].state &= ~CRupdate;
 | 
									term.line[y][x].state &= ~CRupdate;
 | 
				
			||||||
 | 
									if(set)
 | 
				
			||||||
					xdrawc(x, y, term.line[y][x]);
 | 
										xdrawc(x, y, term.line[y][x]);
 | 
				
			||||||
 | 
									else
 | 
				
			||||||
 | 
										xclear(x, y, x, y);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue