grey out 9term when it loses focus.

This commit is contained in:
rsc 2004-03-30 05:03:29 +00:00
parent c005568a7f
commit 4f30f3b444
7 changed files with 112 additions and 26 deletions

View file

@ -188,6 +188,7 @@ xattach(char *label)
XWindow xrootwin;
XWindowAttributes wattr;
XWMHints hint;
Atom atoms[2];
/*
if(XInitThreads() == 0){
@ -335,14 +336,6 @@ xattach(char *label)
&attr /* attributes (the above aren't?!) */
);
if(!XGetWindowAttributes(_x.display, _x.drawable, &wattr))
fprint(2, "XGetWindowAttributes failed\n");
else if(wattr.width && wattr.height){
r.max.x = wattr.width;
r.max.y = wattr.height;
if(0) fprint(2, "new rect %dx%d\n", r.max.x, r.max.y);
}
/*
* Label and other properties required by ICCCCM.
*/
@ -384,6 +377,40 @@ xattach(char *label)
);
XFlush(_x.display);
/*
* Look up clipboard atom.
*/
_x.clipboard = XInternAtom(_x.display, "CLIPBOARD", False);
_x.utf8string = XInternAtom(_x.display, "UTF8_STRING", False);
_x.targets = XInternAtom(_x.display, "TARGETS", False);
_x.text = XInternAtom(_x.display, "TEXT", False);
_x.compoundtext = XInternAtom(_x.display, "COMPOUND_TEXT", False);
_x.takefocus = XInternAtom(_x.display, "WM_TAKE_FOCUS", False);
_x.losefocus = XInternAtom(_x.display, "_9WM_LOSE_FOCUS", False);
_x.wmprotos = XInternAtom(_x.display, "WM_PROTOCOLS", False);
atoms[0] = _x.takefocus;
atoms[1] = _x.losefocus;
XChangeProperty(_x.display, _x.drawable, _x.wmprotos, XA_ATOM, 32,
PropModeReplace, (uchar*)atoms, 2);
/*
* Put the window on the screen, check to see what size we actually got.
*/
XMapWindow(_x.display, _x.drawable);
XSync(_x.display, False);
if(!XGetWindowAttributes(_x.display, _x.drawable, &wattr))
fprint(2, "XGetWindowAttributes failed\n");
else if(wattr.width && wattr.height){
if(wattr.width != Dx(r) || wattr.height != Dy(r)){
r.max.x = wattr.width;
r.max.y = wattr.height;
}
fprint(2, "new rect %dx%d\n", r.max.x, r.max.y);
}else
fprint(2, "bad attrs\n");
/*
* Allocate our local backing store.
*/
@ -409,21 +436,6 @@ xattach(char *label)
_x.gcreplsrc0 = xgc(pmid, FillTiled, -1);
XFreePixmap(_x.display, pmid);
/*
* Put the window on the screen.
*/
XMapWindow(_x.display, _x.drawable);
XFlush(_x.display);
/*
* Look up clipboard atom.
*/
_x.clipboard = XInternAtom(_x.display, "CLIPBOARD", False);
_x.utf8string = XInternAtom(_x.display, "UTF8_STRING", False);
_x.targets = XInternAtom(_x.display, "TARGETS", False);
_x.text = XInternAtom(_x.display, "TEXT", False);
_x.compoundtext = XInternAtom(_x.display, "COMPOUND_TEXT", False);
/*
* Lots of display connections for various procs.
*/

View file

@ -69,6 +69,9 @@ struct Xprivate {
Atom targets;
Atom text;
Atom compoundtext;
Atom takefocus;
Atom losefocus;
Atom wmprotos;
uint putsnarf;
uint assertsnarf;
int destroyed;

View file

@ -8,6 +8,9 @@
#include <memdraw.h>
#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);
}