From 4f30f3b44464f9b89512224095474200390b03e9 Mon Sep 17 00:00:00 2001 From: rsc Date: Tue, 30 Mar 2004 05:03:29 +0000 Subject: grey out 9term when it loses focus. --- CHANGES | 8 +++++++ include/mouse.h | 3 +++ src/cmd/9term/9term.c | 24 ++++++++++++++++++-- src/cmd/9term/win.c | 2 +- src/libdraw/x11-init.c | 58 ++++++++++++++++++++++++++++------------------- src/libdraw/x11-memdraw.h | 3 +++ src/libdraw/x11-mouse.c | 40 ++++++++++++++++++++++++++++++++ 7 files changed, 112 insertions(+), 26 deletions(-) diff --git a/CHANGES b/CHANGES index fc81fa98..fd73bec4 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,11 @@ +March 29, 2004 + + Add window resizing by dragging borders to rio. + Code from Axel Belinfante. + + Added code to make 9term fade itself when it loses + focus running under rio. + March 26, 2004 Fix 9term chording paste bug reported by Sam. diff --git a/include/mouse.h b/include/mouse.h index 2c190b23..9b563faf 100644 --- a/include/mouse.h +++ b/include/mouse.h @@ -48,6 +48,9 @@ extern void drawgetrect(Rectangle, int); extern Rectangle getrect(int, Mousectl*); extern int menuhit(int, Mousectl*, Menu*, Screen*); +extern void bouncemouse(Mouse*); +extern int _windowhasfocus; /* XXX do better */ +extern int _wantfocuschanges; #if defined(__cplusplus) } diff --git a/src/cmd/9term/9term.c b/src/cmd/9term/9term.c index f8eaf432..2923deea 100644 --- a/src/cmd/9term/9term.c +++ b/src/cmd/9term/9term.c @@ -152,6 +152,9 @@ char *menu2str[] = { Image* cols[NCOL]; Image* hcols[NCOL]; +Image* palegrey; +Image* paleblue; +Image* blue; Image *plumbcolor; Image *execcolor; @@ -187,6 +190,7 @@ threadmain(int argc, char *argv[]) char *p; rfork(RFNOTEG); + _wantfocuschanges = 1; mainpid = getpid(); ARGBEGIN{ default: @@ -236,16 +240,22 @@ threadmain(int argc, char *argv[]) } cols[TEXT] = display->black; cols[HTEXT] = display->black; + palegrey = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x666666FF); hcols[BACK] = cols[BACK]; hcols[HIGH] = cols[HIGH]; - hcols[BORD] = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DMedblue); + blue = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DMedblue); + paleblue = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DGreyblue); + + hcols[BORD] = blue; hcols[TEXT] = hcols[BORD]; hcols[HTEXT] = hcols[TEXT]; plumbcolor = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x006600FF); execcolor = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xAA0000FF); + if(!blue || !palegrey || !paleblue || !plumbcolor || !execcolor) + sysfatal("alloc colors: %r"); draw(screen, screen->r, cols[BACK], nil, ZP); geom(); loop(); @@ -365,6 +375,16 @@ geom(void) Point p; Rectangle r; + if(!acmecolors){ + if(_windowhasfocus){ + cols[TEXT] = cols[HTEXT] = display->black; + hcols[TEXT] = hcols[HTEXT] = blue; + }else{ + cols[TEXT] = cols[HTEXT] = palegrey; + hcols[TEXT] = hcols[HTEXT] = paleblue; + } + } + r = screen->r; r.min.y++; r.max.y--; @@ -1535,7 +1555,7 @@ scrdraw(void) { Rectangle r, r1, r2; static Image *scrx; - + r = scrollr; r.min.x += 1; /* border between margin and bar */ r1 = r; diff --git a/src/cmd/9term/win.c b/src/cmd/9term/win.c index d1fc5e1c..d5dbef2c 100644 --- a/src/cmd/9term/win.c +++ b/src/cmd/9term/win.c @@ -572,7 +572,7 @@ sendtype(int fd0) while(ntypebreak){ for(i=0; i #include "x11-memdraw.h" +int _windowhasfocus = 1; +int _wantfocuschanges; + void moveto(Mousectl *m, Point pt) { @@ -48,6 +51,7 @@ void _ioproc(void *arg) { int fd, one; + Atom a; ulong mask; Mouse m; Mousectl *mc; @@ -99,6 +103,20 @@ _ioproc(void *arg) */ mc->m = m; break; + case ClientMessage: + if(xevent.xclient.message_type == _x.wmprotos){ + a = xevent.xclient.data.l[0]; + if(_wantfocuschanges && a == _x.takefocus){ + _windowhasfocus = 1; + _x.newscreenr = _x.screenr; + nbsend(mc->resizec, &one); + }else if(_wantfocuschanges && a == _x.losefocus){ + _windowhasfocus = 0; + _x.newscreenr = _x.screenr; + nbsend(mc->resizec, &one); + } + } + break; } } } @@ -124,3 +142,25 @@ setcursor(Mousectl *mc, Cursor *c) _xsetcursor(c); } +void +bouncemouse(Mouse *m) +{ + XButtonEvent e; + + e.type = ButtonPress; + e.window = DefaultRootWindow(_x.display); + e.state = 0; + e.button = 0; + if(m->buttons&1) + e.button = 1; + else if(m->buttons&2) + e.button = 2; + else if(m->buttons&4) + e.button = 3; + e.x = m->xy.x; + e.y = m->xy.y; +#undef time + e.time = CurrentTime; + XSendEvent(_x.display, e.window, True, ButtonPressMask, (XEvent*)&e); + XFlush(_x.display); +} -- cgit v1.2.3