mirror of
https://github.com/alrayyes/st.git
synced 2024-11-22 11:26:21 +00:00
rearranged code, resize fixed.
This commit is contained in:
parent
476f93794a
commit
2f5ebe0a4d
1 changed files with 58 additions and 48 deletions
66
st.c
66
st.c
|
@ -95,6 +95,8 @@ typedef struct {
|
|||
int scr;
|
||||
int w; /* window width */
|
||||
int h; /* window height */
|
||||
int bufw; /* pixmap width */
|
||||
int bufh; /* pixmap height */
|
||||
int ch; /* char height */
|
||||
int cw; /* char width */
|
||||
} XWindow;
|
||||
|
@ -216,7 +218,7 @@ execsh(void) {
|
|||
|
||||
void
|
||||
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]);
|
||||
XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1);
|
||||
/* usleep(30000); */
|
||||
|
@ -1026,12 +1028,23 @@ xclear(int x1, int y1, int x2, int y2) {
|
|||
(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
|
||||
xinit(void) {
|
||||
XClassHint chint;
|
||||
XWMHints wmhint;
|
||||
XSizeHints shint;
|
||||
char *args[] = {NULL};
|
||||
int i;
|
||||
|
||||
xw.dis = XOpenDisplay(NULL);
|
||||
|
@ -1055,27 +1068,21 @@ xinit(void) {
|
|||
term.c.attr.bg = DefaultBG;
|
||||
term.c.attr.mode = ATTR_NULL;
|
||||
/* windows */
|
||||
xw.h = term.row * xw.ch;
|
||||
xw.w = term.col * xw.cw;
|
||||
xw.h = term.row * xw.ch + 2*BORDER;
|
||||
xw.w = term.col * xw.cw + 2*BORDER;
|
||||
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]);
|
||||
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 */
|
||||
dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL);
|
||||
XMapWindow(xw.dis, xw.win);
|
||||
/* wm stuff */
|
||||
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);
|
||||
xhints();
|
||||
XStoreName(xw.dis, xw.win, TNAME);
|
||||
XFillRectangle(xw.dis, xw.buf, dc.gc, 0, 0, xw.w, xw.h);
|
||||
XSync(xw.dis, 0);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1152,7 +1159,7 @@ draw_(int dummy) {
|
|||
|
||||
if(!term.hidec)
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
@ -1181,7 +1188,7 @@ draw(int redraw_all) {
|
|||
xdraws(buf, base, ox, y, i);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1242,19 +1249,22 @@ kpress(XEvent *ev) {
|
|||
void
|
||||
resize(XEvent *e) {
|
||||
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);
|
||||
if(e->xconfigure.width == xw.w && e->xconfigure.height == xw.h)
|
||||
return;
|
||||
|
||||
xw.w = e->xconfigure.width;
|
||||
xw.h = e->xconfigure.height;
|
||||
xw.bufw = xw.w - 2*BORDER;
|
||||
xw.bufh = xw.h - 2*BORDER;
|
||||
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.w, xw.h, XDefaultDepth(xw.dis, xw.scr));
|
||||
xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
|
||||
draw(SCREEN_REDRAW);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run(void) {
|
||||
|
@ -1264,7 +1274,7 @@ run(void) {
|
|||
|
||||
running = 1;
|
||||
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) {
|
||||
FD_ZERO(&rfd);
|
||||
|
|
Loading…
Reference in a new issue