Eliminate some round trips. Some rather ugly cleanup.

This commit is contained in:
Kris Maglione 2008-05-24 20:32:01 -04:00
parent 962d2784f0
commit 918fa1cf9d
9 changed files with 73 additions and 88 deletions

View File

@ -132,6 +132,7 @@ client_create(XWindow w, XWindowAttributes *wa) {
fwa.colormap = XCreateColormap(display, scr.root.w, vis, AllocNone);
fwa.event_mask = SubstructureRedirectMask
| SubstructureNotifyMask
| StructureNotifyMask
| ExposureMask
| EnterWindowMask
| PointerMotionMask
@ -141,7 +142,7 @@ client_create(XWindow w, XWindowAttributes *wa) {
c->framewin = createwindow_visual(&scr.root, c->r,
depth, vis, InputOutput,
&fwa, CWBackPixmap
/* These next two matter for argb windows. Donno why. */
/* These next two matter for ARGB windows. Donno why. */
| CWBorderPixel
| CWColormap
| CWEventMask
@ -226,7 +227,7 @@ client_manage(Client *c) {
view_restack(c->sel->view);
}
flushenterevents();
ignoreenter = true;
}
static int /* Temporary Xlib error handler */
@ -284,7 +285,7 @@ client_destroy(Client *c) {
group_remove(c);
event("DestroyClient %C\n", c);
flushenterevents();
ignoreenter = true;
flushevents(FocusChangeMask, true);
free(c->w.hints);
free(c);
@ -533,9 +534,6 @@ client_resize(Client *c, Rectangle r) {
client_configure(c);
ewmh_framesize(c);
}
sync(); /* Not ideal. */
flushenterevents();
flushevents(FocusChangeMask|ExposureMask, true);
}
void
@ -834,8 +832,6 @@ configreq_event(Window *w, XConfigureRequestEvent *e) {
if(c->sel->area->floating) {
client_resize(c, r);
sync();
flushenterevents();
}else {
c->sel->floatr = r;
client_configure(c);
@ -855,7 +851,7 @@ enter_event(Window *w, XCrossingEvent *e) {
c = w->aux;
if(e->detail != NotifyInferior) {
if(screen->focus != c) {
if(!ignoreenter && screen->focus != c) {
Dprint(DFocus, "enter_notify([%C]%s)\n", c, c->name);
focus(c, false);
}

View File

@ -369,6 +369,7 @@ EXTERN XHandler handler[LASTEvent];
/* Misc */
EXTERN bool starting;
EXTERN bool ignoreenter;
EXTERN char* user;
EXTERN char* execstr;
EXTERN int debugflag;

View File

@ -137,6 +137,16 @@ configurerequest(XEvent *e) {
}
}
static void
configurenotify(XEvent *e) {
XConfigureEvent *ev;
Window *w;
ev = &e->xconfigure;
if((w = findwin(ev->window)))
handle(w, config, ev);
}
static void
clientmessage(XEvent *e) {
XClientMessageEvent *ev;
@ -323,6 +333,8 @@ motionnotify(XEvent *e) {
XMotionEvent *ev;
Window *w;
ignoreenter = false;
ev = &e->xmotion;
xtime = ev->time;
if((w = findwin(ev->window)))
@ -366,6 +378,7 @@ void (*handler[LASTEvent]) (XEvent *) = {
[ButtonPress] = buttonpress,
[ButtonRelease] = buttonrelease,
[ConfigureRequest] = configurerequest,
[ConfigureNotify] = configurenotify,
[ClientMessage] = clientmessage,
[DestroyNotify] = destroynotify,
[EnterNotify] = enternotify,

View File

@ -197,6 +197,13 @@ bdown_event(Window *w, XButtonEvent *e) {
}
}
static void
config_event(Window *w, XConfigureEvent *e) {
USED(w, e);
ignoreenter = true;
}
static void
enter_event(Window *w, XCrossingEvent *e) {
Client *c;
@ -206,7 +213,7 @@ enter_event(Window *w, XCrossingEvent *e) {
f = c->sel;
if(screen->focus != c || selclient() != c) {
Dprint(DFocus, "enter_notify(f) => %s\n", f->client->name);
if(f->area->floating || !f->collapsed)
if(!ignoreenter && (f->area->floating || !f->collapsed))
focus(f->client, false);
}
mouse_checkresize(f, Pt(e->x, e->y), false);
@ -237,6 +244,7 @@ motion_event(Window *w, XMotionEvent *e) {
Handlers framehandler = {
.bup = bup_event,
.bdown = bdown_event,
.config = config_event,
.enter = enter_event,
.expose = expose_event,
.motion = motion_event,
@ -341,7 +349,7 @@ frame_resize(Frame *f, Rectangle r) {
Rectangle fr, cr;
int collapsed, dx;
if(btassert("4 full", Dx(r) <= 0 || Dy(r) <= 0)) {
if(btassert("8 full", Dx(r) <= 0 || Dy(r) <= 0)) {
fprint(2, "Frame rect: %R\n", r);
r.max.x = min(r.min.x+1, r.max.x);
r.max.y = min(r.min.y+1, r.max.y);

View File

@ -507,27 +507,30 @@ lookup_file(FileId *parent, char *name)
uint id;
int i;
if(!(parent->tab.perm & DMDIR))
return nil;
dir = dirtab[parent->tab.type];
last = &ret;
ret = nil;
for(; dir->name; dir++) {
# define push_file(nam) \
file = get_file(); \
*last = file; \
last = &file->next; \
file->tab = *dir; \
file->tab.name = estrdup(nam)
/* Dynamic dirs */
if(dir->name[0] == '\0') {
switch(parent->tab.type) {
case FsDClients:
if(!name || !strcmp(name, "sel")) {
if((c = selclient())) {
file = get_file();
*last = file;
last = &file->next;
push_file("sel");
file->volatil = true;
file->p.client = c;
file->id = c->w.w;
file->index = c->w.w;
file->tab = *dir;
file->tab.name = estrdup("sel");
}if(name) goto LastItem;
}
SET(id);
@ -537,15 +540,11 @@ lookup_file(FileId *parent, char *name)
}
for(c=client; c; c=c->next) {
if(!name || c->w.w == id) {
file = get_file();
*last = file;
last = &file->next;
push_file(sxprint("%C", c));
file->volatil = true;
file->p.client = c;
file->id = c->w.w;
file->index = c->w.w;
file->tab = *dir;
file->tab.name = smprint("%C", c);
assert(file->tab.name);
if(name) goto LastItem;
}
@ -554,38 +553,26 @@ lookup_file(FileId *parent, char *name)
case FsDDebug:
for(i=0; i < nelem(pdebug); i++)
if(!name || !strcmp(name, debugtab[i])) {
file = get_file();
*last = file;
last = &file->next;
push_file(debugtab[i]);
file->id = i;
file->tab = *dir;
file->tab.name = estrdup(debugtab[i]);
if(name) goto LastItem;
}
break;
case FsDTags:
if(!name || !strcmp(name, "sel")) {
if(screen->sel) {
file = get_file();
*last = file;
last = &file->next;
push_file("sel");
file->volatil = true;
file->p.view = screen->sel;
file->id = screen->sel->id;
file->tab = *dir;
file->tab.name = estrdup("sel");
}if(name) goto LastItem;
}
for(v=view; v; v=v->next) {
if(!name || !strcmp(name, v->name)) {
file = get_file();
*last = file;
last = &file->next;
push_file(v->name);
file->volatil = true;
file->p.view = v;
file->id = v->id;
file->tab = *dir;
file->tab.name = estrdup(v->name);
if(name) goto LastItem;
}
}
@ -593,14 +580,10 @@ lookup_file(FileId *parent, char *name)
case FsDBars:
for(b=*parent->p.bar_p; b; b=b->next) {
if(!name || !strcmp(name, b->name)) {
file = get_file();
*last = file;
last = &file->next;
push_file(b->name);
file->volatil = true;
file->p.bar = b;
file->id = b->id;
file->tab = *dir;
file->tab.name = estrdup(b->name);
if(name) goto LastItem;
}
}
@ -608,14 +591,10 @@ lookup_file(FileId *parent, char *name)
}
}else /* Static dirs */
if(!name && !(dir->flags & FLHide) || name && !strcmp(name, dir->name)) {
file = get_file();
*last = file;
last = &file->next;
push_file(file->tab.name);
file->id = 0;
file->p.ref = parent->p.ref;
file->index = parent->index;
file->tab = *dir;
file->tab.name = estrdup(file->tab.name);
/* Special considerations: */
switch(file->tab.type) {
case FsDBars:
@ -635,6 +614,7 @@ lookup_file(FileId *parent, char *name)
}
NextItem:
continue;
# undef push_file
}
LastItem:
*last = nil;

View File

@ -15,7 +15,7 @@
#include "fns.h"
static const char
version[] = "wmii-"VERSION", ©2007 Kris Maglione\n";
version[] = "wmii-"VERSION", ©2008 Kris Maglione\n";
static int (*xlib_errorhandler) (Display*, XErrorEvent*);
static char* address;
@ -332,7 +332,8 @@ main(int argc, char *argv[]) {
check_other_wm = true;
selectinput(&scr.root, SubstructureRedirectMask
| EnterWindowMask);
| EnterWindowMask
| PointerMotionMask);
sync();
check_other_wm = false;

View File

@ -931,7 +931,6 @@ msg_sendclient(View *v, IxpMsg *m, bool swap) {
else
return Ebadvalue;
flushenterevents();
frame_focus(client_viewframe(c, v));
/* view_arrange(v); */
view_update_all();
@ -971,7 +970,6 @@ msg_sendframe(Frame *f, int sym, bool swap) {
/* view_arrange(f->view); */
flushenterevents();
frame_focus(client_viewframe(c, f->view));
view_update_all();
return nil;

View File

@ -97,46 +97,37 @@ rect_morph(Rectangle *r, Point d, Align *mask) {
}
}
/* Yes, yes, macros are evil. So are patterns. */
#define frob(xy, yx) \
Rectangle *rp; \
int i, txy; \
\
for(i=0; i < nrect; i++) { \
rp = &rects[i]; \
if((rp->min.yx <= r->max.yx) && (rp->max.yx >= r->min.yx)) { \
txy = rp->min.xy; \
if(abs(txy - xy) <= abs(dxy)) \
dxy = txy - xy; \
\
txy = rp->max.xy; \
if(abs(txy - xy) <= abs(dxy)) \
dxy = txy - xy; \
} \
} \
return dxy \
static int
snap_hline(Rectangle *rects, int nrect, int dy, Rectangle *r, int y) {
Rectangle *rp;
int i, ty;
for(i=0; i < nrect; i++) {
rp = &rects[i];
if((rp->min.x <= r->max.x) && (rp->max.x >= r->min.x)) {
ty = rp->min.y;
if(abs(ty - y) <= abs(dy))
dy = ty - y;
ty = rp->max.y;
if(abs(ty - y) <= abs(dy))
dy = ty - y;
}
}
return dy;
snap_hline(Rectangle *rects, int nrect, int dxy, Rectangle *r, int y) {
frob(y, x);
}
static int
snap_vline(Rectangle *rects, int nrect, int dx, Rectangle *r, int x) {
Rectangle *rp;
int i, tx;
for(i=0; i < nrect; i++) {
rp = &rects[i];
if((rp->min.y <= r->max.y) && (rp->max.y >= r->min.y)) {
tx = rp->min.x;
if(abs(tx - x) <= abs(dx))
dx = tx - x;
tx = rp->max.x;
if(abs(tx - x) <= abs(dx))
dx = tx - x;
}
}
return dx;
snap_vline(Rectangle *rects, int nrect, int dxy, Rectangle *r, int x) {
frob(x, y);
}
#undef frob
/* Returns a gravity for increment handling. It's normally the opposite of the mask
* (the directions that we're resizing in), unless a snap occurs, in which case, it's the
* direction of the snap.
@ -240,7 +231,7 @@ mouse_resizecolframe(Frame *f, Align align) {
/* At any rate, set the limits of where this box may be
* dragged.
*/
#define frob(pred, f, aprev, rmin, rmax, plus, minus, xy) BLOCK( \
#define frob(pred, f, aprev, rmin, rmax, plus, minus, xy) BLOCK( \
if(pred) { \
r.rmin.xy = f->aprev->r.rmin.xy plus min.xy; \
r.rmax.xy = f->r.rmax.xy minus min.xy; \

View File

@ -259,9 +259,6 @@ view_update(View *v) {
else
area_focus(v->sel);
frame_draw_all();
sync();
flushenterevents();
}
void