rearranged code, resize fixed.

dev
Aurélien Aptel 2010-06-02 16:01:30 +02:00
parent 476f93794a
commit 2f5ebe0a4d
1 changed files with 58 additions and 48 deletions

66
st.c
View File

@ -95,6 +95,8 @@ typedef struct {
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); */
@ -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);
} }
@ -1242,19 +1249,22 @@ 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;
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); 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); draw(SCREEN_REDRAW);
} }
}
void void
run(void) { run(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);