wmii

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

commit 543aaf3cd9a3030391e15cbeaafc74d3ae1324c7
parent 87588d1a5e09a3d44b930e8e8488deadbf135c6a
Author: garbeam <garbeam@localhost>
Date:   Wed, 11 Jan 2006 18:07:33 +0200

focus sanitizing/work in progress


Diffstat:
cmd/wm/client.c | 24+++++++++++++++++-------
cmd/wm/event.c | 48+++++-------------------------------------------
cmd/wm/frame.c | 53+++++------------------------------------------------
cmd/wm/layout_column.c | 8+++++---
cmd/wm/layout_float.c | 8+++++---
cmd/wm/mouse.c | 14--------------
cmd/wm/wm.h | 4+---
7 files changed, 38 insertions(+), 121 deletions(-)

diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -29,7 +29,18 @@ void focus_client(Client * c) { Frame *f = 0; + Client *old = sel_client(); + + if(old && (old != c)) { + fprintf(stderr, "%s", "grabbing everything for window\n"); + ungrab_client(old, AnyModifier, AnyButton); + grab_client(old, AnyModifier, AnyButton); + } + /* sel client */ + ungrab_client(c, AnyModifier, AnyButton); + grab_client(c, Mod1Mask, Button1); + grab_client(c, Mod1Mask, Button3); f = c->frame; f->sel = c; XRaiseWindow(dpy, c->win); @@ -54,8 +65,7 @@ show_client(Client * c) { XMapRaised(dpy, c->win); set_client_state(c, NormalState); - grab_client(c, Mod1Mask, Button1); - grab_client(c, Mod1Mask, Button3); + grab_client(c, AnyModifier, AnyButton); } void @@ -76,14 +86,14 @@ reparent_client(Client * c, Window w, int x, int y) void grab_client(Client * c, unsigned long mod, unsigned int button) { - XGrabButton(dpy, button, mod, c->win, False, - ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None); + XGrabButton(dpy, button, mod, c->win, True, + ButtonPressMask, GrabModeSync, GrabModeAsync, None, None); if((mod != AnyModifier) && num_lock_mask) { - XGrabButton(dpy, button, mod | num_lock_mask, c->win, False, - ButtonPressMask, GrabModeAsync, GrabModeAsync, None, + XGrabButton(dpy, button, mod | num_lock_mask, c->win, True, + ButtonPressMask, GrabModeSync, GrabModeAsync, None, None); XGrabButton(dpy, button, mod | num_lock_mask | LockMask, c->win, - False, ButtonPressMask, GrabModeAsync, GrabModeAsync, + True, ButtonPressMask, GrabModeSync, GrabModeAsync, None, None); } } diff --git a/cmd/wm/event.c b/cmd/wm/event.c @@ -19,12 +19,8 @@ static void handle_maprequest(XEvent * e); static void handle_motionnotify(XEvent * e); static void handle_propertynotify(XEvent * e); static void handle_unmapnotify(XEvent * e); -static void handle_enternotify(XEvent * e); -static void handle_ignore_enternotify_crap(XEvent * e); static void handle_clientmessage(XEvent * e); -static unsigned int ignore_enternotify_crap = 0; - void (*handler[LASTEvent]) (XEvent *); void @@ -37,16 +33,11 @@ init_event_hander() } handler[ButtonPress] = handle_buttonpress; handler[ConfigureRequest] = handle_configurerequest; - handler[ConfigureNotify] = handle_ignore_enternotify_crap; - handler[CirculateNotify] = handle_ignore_enternotify_crap; handler[DestroyNotify] = handle_destroynotify; - handler[EnterNotify] = handle_enternotify; handler[Expose] = handle_expose; - handler[GravityNotify] = handle_ignore_enternotify_crap; handler[MapRequest] = handle_maprequest; handler[MotionNotify] = handle_motionnotify; handler[PropertyNotify] = handle_propertynotify; - handler[MapNotify] = handle_ignore_enternotify_crap; handler[UnmapNotify] = handle_unmapnotify; handler[ClientMessage] = handle_clientmessage; } @@ -69,17 +60,13 @@ handle_buttonpress(XEvent * e) XButtonPressedEvent *ev = &e->xbutton; Frame *f = win_to_frame(ev->window); - if(f) { + if(f) handle_frame_buttonpress(ev, f); - return; - } - if(ev->window == root) { - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); - XSync(dpy, False); - return; - } - if((c = win_to_client(ev->window))) { + else if((c = win_to_client(ev->window))) { if(c->frame) { /* client is attached */ + focus_area(c->frame->area); + c->frame->area->layout->focus(c->frame, False); + focus_client(c); ev->state &= valid_mask; if(ev->state & Mod1Mask) { Align align; @@ -275,7 +262,6 @@ handle_unmapnotify(XEvent * e) { XUnmapEvent *ev = &e->xunmap; Client *c; - handle_ignore_enternotify_crap(e); if((c = win_to_client(ev->window))) { if(!c->ignore_unmap) detach_client(c, True); @@ -284,30 +270,6 @@ handle_unmapnotify(XEvent * e) } } -static void -handle_enternotify(XEvent * e) -{ - XCrossingEvent *ev = &e->xcrossing; - Client *c; - - if((ev->mode != NotifyNormal) || (ev->detail == NotifyInferior) - || (ev->serial == ignore_enternotify_crap)) - return; - - c = win_to_client(ev->window); - if(c && c->frame) { - focus_area(c->frame->area); - c->frame->area->layout->focus(c->frame, False); - } -} - -static void -handle_ignore_enternotify_crap(XEvent * e) -{ - ignore_enternotify_crap = e->xany.serial; - XSync(dpy, False); -} - static void handle_clientmessage(XEvent *e) { XClientMessageEvent *ev = &e->xclient; diff --git a/cmd/wm/frame.c b/cmd/wm/frame.c @@ -10,16 +10,9 @@ #include "wm.h" -static void select_client(void *obj, char *arg); static void handle_after_write_frame(IXPServer * s, File * file); static void handle_before_read_frame(IXPServer * s, File * file); -/* action table for /frame/?/ namespace */ -Action frame_acttbl[] = { - {"select", select_client}, - {0, 0} -}; - Frame * alloc_frame(XRectangle * r) { @@ -37,9 +30,6 @@ alloc_frame(XRectangle * r) snprintf(buf, MAX_BUF, "/detached/%d/name", id); f->file[F_NAME] = ixp_create(ixps, buf); f->file[F_NAME]->before_read = handle_before_read_frame; - snprintf(buf, MAX_BUF, "/detached/%d/ctl", id); - f->file[F_CTL] = ixp_create(ixps, buf); - f->file[F_CTL]->after_write = handle_after_write_frame; snprintf(buf, MAX_BUF, "/detached/%d/geometry", id); f->file[F_GEOMETRY] = ixp_create(ixps, buf); f->file[F_GEOMETRY]->before_read = handle_before_read_frame; @@ -269,17 +259,17 @@ handle_frame_buttonpress(XButtonEvent * e, Frame * f) { Align align; int bindex, cindex = e->x / (f->rect.width / f->nclients); - f->sel = clientat(f->clients, cindex); + Client *new = clientat(f->clients, cindex); + f->area->layout->focus(f, False); + sel_client(new); if(e->button == Button1) { align = cursor_to_align(f->cursor); if(align == CENTER) mouse_move(f); else mouse_resize(f, align); - f->area->layout->focus(f, False); return; } - f->area->layout->focus(f, False); bindex = WM_EVENT_B2PRESS - 2 + e->button; /* frame mouse handling */ if(def[bindex]->content) @@ -300,7 +290,6 @@ attach_client_to_frame(Frame * f, Client * client) c->next = client; } f->nclients++; - f->sel = client; client->frame = f; resize_frame(f, &f->rect, 0); reparent_client(client, f->win, client->rect.x, client->rect.y); @@ -311,15 +300,10 @@ void detach_client_from_frame(Client * c, Bool unmap) { Frame *f = c->frame; - Client *cl; c->frame = nil; - if(f->sel == c) { - if(c->prev) - f->sel = c->prev; - else - f->sel = nil; - } + if(f->sel == c) + f->sel = nil; if(f->clients == c) { if(c->next) @@ -332,8 +316,6 @@ detach_client_from_frame(Client * c, Bool unmap) } f->nclients--; - if(!f->sel) - f->sel = f->clients; if(!c->destroyed) { if(!unmap) { @@ -344,27 +326,6 @@ detach_client_from_frame(Client * c, Bool unmap) c->rect.y = f->rect.y; reparent_client(c, root, c->rect.x, c->rect.y); } - if((cl = sel_client())) { - sel_area()->layout->focus(sel_frame(), False); - focus_client(cl); - } -} - -static void -select_client(void *obj, char *arg) -{ - Client *c; - Frame *f = obj; - if(!f || !arg || !f->clients->next) - return; - if(!strncmp(arg, "prev", 5)) - c = f->sel->prev; - else if(!strncmp(arg, "next", 5)) - c = f->sel->next; - else - c = clientat(f->clients, blitz_strtonum(arg, 0, f->nclients - 1)); - focus_client(c); - f->area->layout->focus(f, False); } static Frame * @@ -415,10 +376,6 @@ handle_after_write_frames(IXPServer * s, File * file, Area * a) { Frame *f; for(f = a->layout->frames(a); f; f = f->next) { - if(file == f->file[F_CTL]) { - run_action(file, f, frame_acttbl); - return f; - } if(file == f->file[F_TAB] || file == f->file[F_BORDER] || file == f->file[F_HANDLE_INC]) { f->area->layout->arrange(f->area); diff --git a/cmd/wm/layout_column.c b/cmd/wm/layout_column.c @@ -431,13 +431,15 @@ focus_col(Frame * f, Bool raise) Acme *acme = a->aux; Frame *old = sel_col(a); Cell *cell = f->aux; + Client *c = f->sel ? f->sel : f->clients; acme->sel = cell->col; cell->col->sel = cell; a->file[A_SEL_FRAME]->content = f->file[F_PREFIX]->content; - if(raise) - center_pointer(f); - focus_client(f->sel); + if(raise && c) + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, + c->rect.width / 2, c->rect.height / 2); + focus_client(c); if(old && old != f) draw_frame(old); draw_frame(f); diff --git a/cmd/wm/layout_float.c b/cmd/wm/layout_float.c @@ -188,15 +188,17 @@ focus_float(Frame * f, Bool raise) Area *a = f->area; Float *fl = a->aux; Frame *old = fl->sel; + Client *c = f->sel ? f->sel : f->clients; - sel_client(f->sel); fl->sel = f; a->file[A_SEL_FRAME]->content = f->file[F_PREFIX]->content; if(raise) { XRaiseWindow(dpy, f->win); - center_pointer(f); + if(c) + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, + c->rect.width / 2, c->rect.height / 2); } - focus_client(f->sel); + focus_client(c); if(old && old != f) draw_frame(old); draw_frame(f); diff --git a/cmd/wm/mouse.c b/cmd/wm/mouse.c @@ -609,17 +609,3 @@ mouse_resize(Frame * f, Align align) } } } - -void -center_pointer(Frame * f) -{ - Window dummy; - int wex, wey, ex, ey, i; - unsigned int dmask; - if(!f) - return; - XQueryPointer(dpy, f->win, &dummy, &dummy, &i, &i, &wex, &wey, &dmask); - XTranslateCoordinates(dpy, f->win, root, wex, wey, &ex, &ey, &dummy); - /* suppress EnterNotify's while mouse warping */ - XWarpPointer(dpy, None, f->win, 0, 0, 0, 0, f->rect.width / 2, f->rect.height / 2); -} diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -32,7 +32,6 @@ enum { enum { F_PREFIX, F_NAME, - F_CTL, F_GEOMETRY, F_BORDER, F_TAB, @@ -86,7 +85,7 @@ enum { #define GAP 5 #define ROOT_MASK SubstructureRedirectMask -#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask) +#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | ButtonPressMask) typedef struct Page Page; typedef struct RunInPage RunInPage; @@ -266,7 +265,6 @@ Cursor cursor_for_motion(Frame * f, int x, int y); Align cursor_to_align(Cursor cursor); Align xy_to_align(XRectangle * rect, int x, int y); void drop_move(Frame * f, XRectangle * new, XPoint * pt); -void center_pointer(Frame * f); /* page.c */ Page *pageat(unsigned int idx);