wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit bec3694667fd2852d439983d7df71d93075a892b
parent bb15c97023c03be8d094f4703dc8fdefcd0ea63d
Author: Kris Maglione <jg@suckless.org>
Date:   Fri, 17 Oct 2008 17:09:46 -0400

Restrict the pointer to some Xinerama screen

Diffstat:
cmd/wmii/Makefile | 1+
cmd/wmii/client.c | 5++++-
cmd/wmii/event.c | 37++++++++++---------------------------
cmd/wmii/fns.h | 5++++-
cmd/wmii/frame.c | 64+++++++++++++++++++++++++++++++---------------------------------
cmd/wmii/layout.c | 4++--
cmd/wmii/main.c | 18+++---------------
cmd/wmii/mouse.c | 4++--
include/x11.h | 1+
9 files changed, 58 insertions(+), 81 deletions(-)

diff --git a/cmd/wmii/Makefile b/cmd/wmii/Makefile @@ -30,6 +30,7 @@ OBJ = area \ map \ message \ mouse \ + root \ rule \ printevent\ screen \ diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c @@ -1013,6 +1013,7 @@ char* client_extratags(Client *c) { Frame *f; char *toks[32]; + char **tags; char *s, *s2; int i; @@ -1022,10 +1023,12 @@ client_extratags(Client *c) { if(f != c->sel) toks[i++] = f->view->name; toks[i] = nil; + tags = comm(CLeft, toks, c->retags); s = nil; if(i > 1) - s = join(toks, "+"); + s = join(tags, "+"); + free(tags); if(!c->tagre.regex && !c->tagvre.regex) return s; diff --git a/cmd/wmii/event.c b/cmd/wmii/event.c @@ -173,20 +173,15 @@ enternotify(XCrossingEvent *ev) { if((w = findwin(ev->window))) handle(w, enter, ev); - else if(ev->window == scr.root.w) { - disp.sel = true; - frame_draw_all(); - } } static void leavenotify(XCrossingEvent *ev) { + Window *w; xtime = ev->time; - if((ev->window == scr.root.w) && !ev->same_screen) { - disp.sel = true; - frame_draw_all(); - } + if((w = findwin(ev->window))) + handle(w, leave, ev); } void @@ -225,10 +220,8 @@ focusin(XFocusChangeEvent *ev) { else if((w = findwin(ev->window))) handle(w, focusin, ev); else if(ev->mode == NotifyGrab) { - if(ev->window == scr.root.w) - disp.hasgrab = &c_root; /* Some unmanaged window has grabbed focus */ - else if((c = disp.focus)) { + if((c = disp.focus)) { print_focus("focusin", &c_magic, "<magic>"); disp.focus = &c_magic; if(c->sel) @@ -269,11 +262,11 @@ expose(XExposeEvent *ev) { static void keypress(XKeyEvent *ev) { + Window *w; xtime = ev->time; - ev->state &= valid_mask; - if(ev->window == scr.root.w) - kpress(scr.root.w, ev->state, (KeyCode)ev->keycode); + if((w = findwin(ev->window))) + handle(w, kdown, ev); } static void @@ -286,20 +279,10 @@ mappingnotify(XMappingEvent *ev) { static void maprequest(XMapRequestEvent *ev) { - XWindowAttributes wa; + Window *w; - if(!XGetWindowAttributes(display, ev->window, &wa)) - return; - if(wa.override_redirect) { - /* Do I really want these? */ - /* Probably not. - XSelectInput(display, ev->window, - PropertyChangeMask | StructureNotifyMask); - */ - return; - } - if(!win2client(ev->window)) - client_create(ev->window, &wa); + if((w = findwin(ev->parent))) + handle(w, mapreq, ev); } static void diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h @@ -156,7 +156,7 @@ bool frame_restack(Frame*, Frame*); void frame_swap(Frame*, Frame*); int ingrabbox_p(Frame*, int x, int y); void move_focus(Frame*, Frame*); -Rectangle constrain(Rectangle); +Rectangle constrain(Rectangle, int); Rectangle frame_client2rect(Client*, Rectangle, bool); WinHints frame_gethints(Frame*); Rectangle frame_hints(Frame*, Rectangle, Align); @@ -236,6 +236,9 @@ Align snap_rect(Rectangle *rects, int num, Rectangle *current, Align *mask, int /* printevent.c */ void printevent(XEvent*); +/* root.c */ +void root_init(void); + /* screen.c */ int ownerscreen(Rectangle); diff --git a/cmd/wmii/frame.c b/cmd/wmii/frame.c @@ -363,7 +363,7 @@ frame_resize(Frame *f, Rectangle r) { fr = frame_hints(f, r, get_sticky(f->r, r)); if(f->area->floating && !c->strut) - fr = constrain(fr); + fr = constrain(fr, -1); /* Collapse managed frames which are too small */ /* XXX. */ @@ -636,45 +636,43 @@ frame_delta_h(void) { } Rectangle -constrain(Rectangle r) { - WMScreen *s, *bestx, *besty; - Rectangle isect; +constrain(Rectangle r, int inset) { + WMScreen **sp; + WMScreen *s, *sbest; + Rectangle isect, rbest; Point p; - int i, nbestx, nbesty; + int best, n; - /* Find the screen that this intersects most with - * (or doesn't intersect least with), and then make - * sure that it overlaps that screen, in the opposite - * direction. + if(inset < 0) + inset = Dy(screen->brect); + /* + * FIXME: This will cause problems for windows with + * D(r) < 2 * isect */ - SET(nbestx); - SET(nbesty); - SET(s); - - bestx = nil; - besty = nil; - for(i=0; i < nscreens; i++) { - s = screens[i]; - if(!s->showing) - continue; - isect = rect_intersection(r, s->r); - if(!bestx || Dx(isect) > nbestx && Dy(isect) > 0) { - bestx = s; - nbestx = Dx(isect); - } - if(!besty || Dy(isect) > nbesty && Dy(isect) > 0) { - besty = s; - nbesty = Dy(isect); + + sbest = nil; + rbest = ZR; /* SET(rbest) */ + SET(best); + for(sp=screens; (s = *sp); sp++) { + isect = rect_intersection(r, insetrect(s->r, inset)); + if(Dx(isect) >= 0 && Dy(isect) >= 0) + return r; + if(Dx(isect) < 0 && Dy(isect) < 0) + n = max(Dx(isect), Dy(isect)); + else + n = min(Dx(isect), Dy(isect)); + if(!sbest || n > best) { + sbest = s; + best = n; } } p = ZP; - isect = insetrect(bestx->r, Dy(screen->brect)); - p.x -= min(r.max.x - isect.min.x, 0); - p.x -= max(r.min.x - isect.max.x, 0); - isect = insetrect(besty->r, Dy(screen->brect)); - p.y -= min(r.max.y - isect.min.y, 0); - p.y -= max(r.min.y - isect.max.y, 0); + rbest = insetrect(sbest->r, inset); + p.x -= min(r.max.x - rbest.min.x, 0); + p.x -= max(r.min.x - rbest.max.x, 0); + p.y -= min(r.max.y - rbest.min.y, 0); + p.y -= max(r.min.y - rbest.max.y, 0); return rectaddpt(r, p); } diff --git a/cmd/wmii/layout.c b/cmd/wmii/layout.c @@ -567,14 +567,14 @@ shut_up_ken: case MotionNotify: case_motion: origin = rectaddpt(origin, subpt(pt, pt1)); - origin = constrain(origin); + origin = constrain(origin, -1); frect = origin; align = Center; snap_rect(rects, nrect, &frect, &align, def.snap); frect = frame_hints(f, frect, Center); - frect = constrain(frect); + frect = constrain(frect, -1); client_resize(c, frect); continue; case ButtonRelease: diff --git a/cmd/wmii/main.c b/cmd/wmii/main.c @@ -204,7 +204,6 @@ init_screens(void) { screen->r = rects[i]; else screen->r = rectsetorigin(screen->r, scr.rect.max); - print("screens[%d]->r = %R\n", i, screens[i]->r); def.snap = Dy(screen->r) / 63; bar_init(screens[i]); } @@ -320,7 +319,6 @@ int main(int argc, char *argv[]) { char **oargv; char *wmiirc; - WinAttr wa; int i; quotefmtinstall(); @@ -357,9 +355,8 @@ extern int fmtevent(Fmt*); initdisplay(); traperrors(true); - selectinput(&scr.root, SubstructureRedirectMask - | EnterWindowMask); - sync(); + selectinput(&scr.root, EnterWindowMask + | SubstructureRedirectMask); if(traperrors(false)) fatal("another window manager is already running"); @@ -401,16 +398,7 @@ extern int fmtevent(Fmt*); disp.sel = pointerscreen(); init_screens(); - - wa.event_mask = SubstructureRedirectMask - | SubstructureNotifyMask - | EnterWindowMask - | LeaveWindowMask - | FocusChangeMask; - wa.cursor = cursor[CurNormal]; - setwinattr(&scr.root, &wa, - CWEventMask - | CWCursor); + root_init(); disp.focus = nil; setfocus(screen->barwin, RevertToParent); diff --git a/cmd/wmii/mouse.c b/cmd/wmii/mouse.c @@ -431,13 +431,13 @@ mouse_resize(Client *c, Align align, bool grabmod) { pt = addpt(pt, d); rect_morph(&origin, d, &align); - origin = constrain(origin); + origin = constrain(origin, -1); frect = origin; grav = snap_rect(rects, nrect, &frect, &align, def.snap); frect = frame_hints(f, frect, grav); - frect = constrain(frect); + frect = constrain(frect, -1); client_resize(c, frect); } diff --git a/include/x11.h b/include/x11.h @@ -99,6 +99,7 @@ struct Handlers { void (*kup)(Window*, XKeyEvent*); void (*leave)(Window*, XCrossingEvent*); void (*map)(Window*, XMapEvent*); + void (*mapreq)(Window*, XMapRequestEvent*); void (*motion)(Window*, XMotionEvent*); void (*property)(Window*, XPropertyEvent*); void (*unmap)(Window*, XUnmapEvent*);