X-Git-Url: https://git.xinqibao.xyz/st.git/blobdiff_plain/f693476365c9383ac83420319dd69372c55f9f50..6faedce53a8de8a81da1ba045ffbc2b7603128cd:/st.c?ds=inline diff --git a/st.c b/st.c index d2f8c2e..99ab085 100644 --- a/st.c +++ b/st.c @@ -114,7 +114,8 @@ typedef struct { int bufh; /* pixmap height */ int ch; /* char height */ int cw; /* char width */ - int hasfocus; + int focus; + int vis; /* is visible */ } XWindow; typedef struct { @@ -187,6 +188,8 @@ static void xloadcols(void); static void xseturgency(int); static void expose(XEvent *); +static void visibility(XEvent *); +static void unmap(XEvent *); static char* kmap(KeySym); static void kpress(XEvent *); static void resize(XEvent *); @@ -198,8 +201,10 @@ static void bmotion(XEvent *); static void (*handler[LASTEvent])(XEvent *) = { [KeyPress] = kpress, - [Expose] = expose, [ConfigureNotify] = resize, + [VisibilityNotify] = visibility, + [UnmapNotify] = unmap, + [Expose] = expose, [FocusIn] = focus, [FocusOut] = focus, [MotionNotify] = bmotion, @@ -1038,7 +1043,7 @@ tputc(char c) { tnewline(); break; case '\a': - if(!xw.hasfocus) + if(!xw.focus) xseturgency(1); break; case '\033': @@ -1211,9 +1216,9 @@ xinit(void) { attrs.background_pixel = dc.col[DefaultBG]; attrs.border_pixel = dc.col[DefaultBG]; attrs.bit_gravity = NorthWestGravity; - attrs.event_mask = ExposureMask | KeyPressMask - | StructureNotifyMask | FocusChangeMask | PointerMotionMask - | ButtonPressMask | ButtonReleaseMask; + attrs.event_mask = FocusChangeMask | KeyPressMask + | ExposureMask | VisibilityChangeMask | StructureNotifyMask + | PointerMotionMask | ButtonPressMask | ButtonReleaseMask; attrs.colormap = xw.cmap; xw.win = XCreateWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0, @@ -1281,7 +1286,7 @@ xdrawcursor(void) { xclear(oldx, oldy, oldx, oldy); /* draw the new one */ - if(!(term.c.state & CURSOR_HIDE) && xw.hasfocus) { + if(!(term.c.state & CURSOR_HIDE) && xw.focus) { xdraws(&g.c, g, term.c.x, term.c.y, 1); oldx = term.c.x, oldy = term.c.y; } @@ -1321,6 +1326,9 @@ draw(int redraw_all) { Glyph base, new; char buf[DRAW_BUF_SIZ]; + if(!xw.vis) + return; + xclear(0, 0, term.col-1, term.row-1); for(y = 0; y < term.row; y++) { base = term.line[y][0]; @@ -1357,6 +1365,19 @@ expose(XEvent *ev) { 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 xseturgency(int add) { XWMHints *h = XGetWMHints(xw.dis, xw.win); @@ -1367,7 +1388,7 @@ xseturgency(int add) { void focus(XEvent *ev) { - if((xw.hasfocus = ev->type == FocusIn)) + if((xw.focus = ev->type == FocusIn)) xseturgency(0); draw(SCREEN_UPDATE); }