don't draw if the window is not visible.

master
Aurélien Aptel 2010-09-11 16:05:57 +02:00
parent f693476365
commit ab7037cb33
1 changed files with 25 additions and 4 deletions

29
st.c
View File

@ -115,6 +115,7 @@ typedef struct {
int ch; /* char height */ int ch; /* char height */
int cw; /* char width */ int cw; /* char width */
int hasfocus; int hasfocus;
int vis; /* is visible */
} XWindow; } XWindow;
typedef struct { typedef struct {
@ -187,6 +188,8 @@ static void xloadcols(void);
static void xseturgency(int); static void xseturgency(int);
static void expose(XEvent *); static void expose(XEvent *);
static void visibility(XEvent *);
static void unmap(XEvent *);
static char* kmap(KeySym); static char* kmap(KeySym);
static void kpress(XEvent *); static void kpress(XEvent *);
static void resize(XEvent *); static void resize(XEvent *);
@ -198,8 +201,10 @@ static void bmotion(XEvent *);
static void (*handler[LASTEvent])(XEvent *) = { static void (*handler[LASTEvent])(XEvent *) = {
[KeyPress] = kpress, [KeyPress] = kpress,
[Expose] = expose,
[ConfigureNotify] = resize, [ConfigureNotify] = resize,
[VisibilityNotify] = visibility,
[UnmapNotify] = unmap,
[Expose] = expose,
[FocusIn] = focus, [FocusIn] = focus,
[FocusOut] = focus, [FocusOut] = focus,
[MotionNotify] = bmotion, [MotionNotify] = bmotion,
@ -1211,9 +1216,9 @@ xinit(void) {
attrs.background_pixel = dc.col[DefaultBG]; attrs.background_pixel = dc.col[DefaultBG];
attrs.border_pixel = dc.col[DefaultBG]; attrs.border_pixel = dc.col[DefaultBG];
attrs.bit_gravity = NorthWestGravity; attrs.bit_gravity = NorthWestGravity;
attrs.event_mask = ExposureMask | KeyPressMask attrs.event_mask = FocusChangeMask | KeyPressMask
| StructureNotifyMask | FocusChangeMask | PointerMotionMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask
| ButtonPressMask | ButtonReleaseMask; | PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
attrs.colormap = xw.cmap; attrs.colormap = xw.cmap;
xw.win = XCreateWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0, xw.win = XCreateWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
@ -1321,6 +1326,9 @@ draw(int redraw_all) {
Glyph base, new; Glyph base, new;
char buf[DRAW_BUF_SIZ]; char buf[DRAW_BUF_SIZ];
if(!xw.vis)
return;
xclear(0, 0, term.col-1, term.row-1); xclear(0, 0, term.col-1, term.row-1);
for(y = 0; y < term.row; y++) { for(y = 0; y < term.row; y++) {
base = term.line[y][0]; base = term.line[y][0];
@ -1357,6 +1365,19 @@ expose(XEvent *ev) {
draw(SCREEN_REDRAW); draw(SCREEN_REDRAW);
} }
void
visibility(XEvent *ev) {
XVisibilityEvent *e = &ev->xvisibility;
/* XXX if this goes from 0 to 1, need a full redraw for next Expose,
* not just a buf copy */
xw.vis = e->state != VisibilityFullyObscured;
}
void
unmap(XEvent *ev) {
xw.vis = 0;
}
void void
xseturgency(int add) { xseturgency(int add) {
XWMHints *h = XGetWMHints(xw.dis, xw.win); XWMHints *h = XGetWMHints(xw.dis, xw.win);