[hackers] [wmii] Restrict the pointer to some Xinerama screen || Kris Maglione

From: <hg_AT_suckless.org>
Date: Fri, 17 Oct 2008 21:09:48 +0000 (UTC)

changeset: 2386:403e508074cc
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Fri Oct 17 17:09:46 2008 -0400
files: cmd/wmii/Makefile cmd/wmii/client.c cmd/wmii/event.c cmd/wmii/fns.h cmd/wmii/frame.c cmd/wmii/layout.c cmd/wmii/main.c cmd/wmii/mouse.c include/x11.h
description:
Restrict the pointer to some Xinerama screen

diff -r 7156dbf89315 -r 403e508074cc cmd/wmii/Makefile
--- a/cmd/wmii/Makefile Fri Oct 17 12:08:44 2008 -0400
+++ b/cmd/wmii/Makefile Fri Oct 17 17:09:46 2008 -0400
@@ -30,6 +30,7 @@
         map \
         message \
         mouse \
+ root \
         rule \
         printevent\
         screen \
diff -r 7156dbf89315 -r 403e508074cc cmd/wmii/client.c
--- a/cmd/wmii/client.c Fri Oct 17 12:08:44 2008 -0400
+++ b/cmd/wmii/client.c Fri Oct 17 17:09:46 2008 -0400
@@ -1013,6 +1013,7 @@
 client_extratags(Client *c) {
         Frame *f;
         char *toks[32];
+ char **tags;
         char *s, *s2;
         int i;
 
@@ -1022,10 +1023,12 @@
                 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 -r 7156dbf89315 -r 403e508074cc cmd/wmii/event.c
--- a/cmd/wmii/event.c Fri Oct 17 12:08:44 2008 -0400
+++ b/cmd/wmii/event.c Fri Oct 17 17:09:46 2008 -0400
@@ -173,20 +173,15 @@
 
         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 @@
         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 @@
 
 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 @@
 
 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 -r 7156dbf89315 -r 403e508074cc cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Fri Oct 17 12:08:44 2008 -0400
+++ b/cmd/wmii/fns.h Fri Oct 17 17:09:46 2008 -0400
@@ -156,7 +156,7 @@
 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 @@
 /* printevent.c */
 void printevent(XEvent*);
 
+/* root.c */
+void root_init(void);
+
 /* screen.c */
 int ownerscreen(Rectangle);
 
diff -r 7156dbf89315 -r 403e508074cc cmd/wmii/frame.c
--- a/cmd/wmii/frame.c Fri Oct 17 12:08:44 2008 -0400
+++ b/cmd/wmii/frame.c Fri Oct 17 17:09:46 2008 -0400
@@ -363,7 +363,7 @@
 
         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 @@
 }
 
 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 -r 7156dbf89315 -r 403e508074cc cmd/wmii/layout.c
--- a/cmd/wmii/layout.c Fri Oct 17 12:08:44 2008 -0400
+++ b/cmd/wmii/layout.c Fri Oct 17 17:09:46 2008 -0400
@@ -567,14 +567,14 @@
                 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 -r 7156dbf89315 -r 403e508074cc cmd/wmii/main.c
--- a/cmd/wmii/main.c Fri Oct 17 12:08:44 2008 -0400
+++ b/cmd/wmii/main.c Fri Oct 17 17:09:46 2008 -0400
@@ -204,7 +204,6 @@
                         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 @@
 main(int argc, char *argv[]) {
         char **oargv;
         char *wmiirc;
- WinAttr wa;
         int i;
 
         quotefmtinstall();
@@ -357,9 +355,8 @@
         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 @@
         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 -r 7156dbf89315 -r 403e508074cc cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Fri Oct 17 12:08:44 2008 -0400
+++ b/cmd/wmii/mouse.c Fri Oct 17 17:09:46 2008 -0400
@@ -431,13 +431,13 @@
                 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 -r 7156dbf89315 -r 403e508074cc include/x11.h
--- a/include/x11.h Fri Oct 17 12:08:44 2008 -0400
+++ b/include/x11.h Fri Oct 17 17:09:46 2008 -0400
@@ -99,6 +99,7 @@
         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*);
Received on Fri Oct 17 2008 - 21:09:48 UTC

This archive was generated by hypermail 2.2.0 : Fri Oct 17 2008 - 21:12:04 UTC