Remove x.c dependency on term

The xinit function only needs to the rows/cols, so pass those in rather
than accessing term directly.  With a bit of arithmetic, we are able to
avoid the need for term.row and term.col in x2col, y2row, and
xdrawglyphfontspecs as well, completing the removal.

Term is now fully internal to st.c.

Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
master
Devin J. Pohly 2018-02-24 15:32:48 -06:00
parent a5dc1b4697
commit a3beb626d2
3 changed files with 39 additions and 39 deletions

22
st.c
View File

@ -95,6 +95,26 @@ enum escape_state {
ESC_DCS =128, ESC_DCS =128,
}; };
/* Internal representation of the screen */
typedef struct {
int row; /* nb row */
int col; /* nb col */
Line *line; /* screen */
Line *alt; /* alternate screen */
int *dirty; /* dirtyness of lines */
TCursor c; /* cursor */
int ocx; /* old cursor col */
int ocy; /* old cursor row */
int top; /* top scroll limit */
int bot; /* bottom scroll limit */
int mode; /* terminal mode flags */
int esc; /* escape state flags */
char trantbl[4]; /* charset table translation */
int charset; /* current charset */
int icharset; /* selected charset for sequence */
int *tabs;
} Term;
/* CSI Escape sequence structs */ /* CSI Escape sequence structs */
/* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */ /* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */
typedef struct { typedef struct {
@ -181,11 +201,11 @@ static char *base64dec(const char *);
static ssize_t xwrite(int, const char *, size_t); static ssize_t xwrite(int, const char *, size_t);
/* Globals */ /* Globals */
Term term;
int cmdfd; int cmdfd;
pid_t pid; pid_t pid;
int oldbutton = 3; /* button event on startup: 3 = release */ int oldbutton = 3; /* button event on startup: 3 = release */
static Term term;
static Selection sel; static Selection sel;
static CSIEscape csiescseq; static CSIEscape csiescseq;
static STREscape strescseq; static STREscape strescseq;

21
st.h
View File

@ -76,26 +76,6 @@ typedef struct {
char state; char state;
} TCursor; } TCursor;
/* Internal representation of the screen */
typedef struct {
int row; /* nb row */
int col; /* nb col */
Line *line; /* screen */
Line *alt; /* alternate screen */
int *dirty; /* dirtyness of lines */
TCursor c; /* cursor */
int ocx; /* old cursor col */
int ocy; /* old cursor row */
int top; /* top scroll limit */
int bot; /* bottom scroll limit */
int mode; /* terminal mode flags */
int esc; /* escape state flags */
char trantbl[4]; /* charset table translation */
int charset; /* current charset */
int icharset; /* selected charset for sequence */
int *tabs;
} Term;
/* Purely graphic info */ /* Purely graphic info */
typedef struct { typedef struct {
int tw, th; /* tty width and height */ int tw, th; /* tty width and height */
@ -168,7 +148,6 @@ void *xrealloc(void *, size_t);
char *xstrdup(char *); char *xstrdup(char *);
/* Globals */ /* Globals */
extern Term term;
extern int cmdfd; extern int cmdfd;
extern pid_t pid; extern pid_t pid;
extern int oldbutton; extern int oldbutton;

35
x.c
View File

@ -130,7 +130,7 @@ static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
static void xdrawglyph(Glyph, int, int); static void xdrawglyph(Glyph, int, int);
static void xclear(int, int, int, int); static void xclear(int, int, int, int);
static int xgeommasktogravity(int); static int xgeommasktogravity(int);
static void xinit(void); static void xinit(int, int);
static void cresize(int, int); static void cresize(int, int);
static void xresize(int, int); static void xresize(int, int);
static int xloadfont(Font *, FcPattern *); static int xloadfont(Font *, FcPattern *);
@ -299,18 +299,16 @@ int
x2col(int x) x2col(int x)
{ {
x -= borderpx; x -= borderpx;
x /= win.cw; LIMIT(x, 0, win.tw - 1);
return x / win.cw;
return LIMIT(x, 0, term.col-1);
} }
int int
y2row(int y) y2row(int y)
{ {
y -= borderpx; y -= borderpx;
y /= win.ch; LIMIT(y, 0, win.th - 1);
return y / win.ch;
return LIMIT(y, 0, term.row-1);
} }
void void
@ -984,7 +982,7 @@ xunloadfonts(void)
} }
void void
xinit(void) xinit(int cols, int rows)
{ {
XGCValues gcvalues; XGCValues gcvalues;
Cursor cursor; Cursor cursor;
@ -1009,8 +1007,8 @@ xinit(void)
xloadcols(); xloadcols();
/* adjust fixed window geometry */ /* adjust fixed window geometry */
win.w = 2 * borderpx + term.col * win.cw; win.w = 2 * borderpx + cols * win.cw;
win.h = 2 * borderpx + term.row * win.ch; win.h = 2 * borderpx + rows * win.ch;
if (xw.gm & XNegative) if (xw.gm & XNegative)
xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2; xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2;
if (xw.gm & YNegative) if (xw.gm & YNegative)
@ -1042,7 +1040,7 @@ xinit(void)
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h); XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
/* font spec buffer */ /* font spec buffer */
xw.specbuf = xmalloc(term.col * sizeof(GlyphFontSpec)); xw.specbuf = xmalloc(cols * sizeof(GlyphFontSpec));
/* Xft rendering context */ /* Xft rendering context */
xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap); xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
@ -1337,15 +1335,16 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
/* Intelligent cleaning up of the borders. */ /* Intelligent cleaning up of the borders. */
if (x == 0) { if (x == 0) {
xclear(0, (y == 0)? 0 : winy, borderpx, xclear(0, (y == 0)? 0 : winy, borderpx,
winy + win.ch + ((y >= term.row-1)? win.h : 0)); winy + win.ch +
((winy + win.ch >= borderpx + win.th)? win.h : 0));
} }
if (x + charlen >= term.col) { if (winx + width >= borderpx + win.tw) {
xclear(winx + width, (y == 0)? 0 : winy, win.w, xclear(winx + width, (y == 0)? 0 : winy, win.w,
((y >= term.row-1)? win.h : (winy + win.ch))); ((winy + win.ch >= borderpx + win.th)? win.h : (winy + win.ch)));
} }
if (y == 0) if (y == 0)
xclear(winx, 0, winx + width, borderpx); xclear(winx, 0, winx + width, borderpx);
if (y == term.row-1) if (winy + win.ch >= borderpx + win.th)
xclear(winx, winy + win.ch, winx + width, win.h); xclear(winx, winy + win.ch, winx + width, win.h);
/* Clean up the region we want to draw to. */ /* Clean up the region we want to draw to. */
@ -1930,8 +1929,10 @@ run:
} }
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
XSetLocaleModifiers(""); XSetLocaleModifiers("");
tnew(MAX(cols, 1), MAX(rows, 1)); cols = MAX(cols, 1);
xinit(); rows = MAX(rows, 1);
tnew(cols, rows);
xinit(cols, rows);
xsetenv(); xsetenv();
selinit(); selinit();
run(); run();