From ca77b0cd999e906ec3cfdf943e51215c43af63c1 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Fri, 13 Apr 2007 19:23:24 -0400 Subject: [PATCH] Some preliminary changes to make managed mode more cohesive. --- cmd/wmii/client.c | 4 +-- cmd/wmii/event.c | 11 ++++-- cmd/wmii/fns.h | 5 +-- cmd/wmii/frame.c | 85 +++++++++++++++++++++++++++++++++++++++++------ cmd/wmii/fs.c | 2 -- cmd/wmii/main.c | 39 +++++++++++----------- util/compile | 10 +++--- 7 files changed, 112 insertions(+), 44 deletions(-) diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c index 7e8afae9..f21d23b7 100644 --- a/cmd/wmii/client.c +++ b/cmd/wmii/client.c @@ -513,7 +513,7 @@ apply_sizehints(Client *c, XRectangle *r, Bool floating, Bool frame, BlitzAlign s = &c->size; orig = *r; if(frame) - frame2client(r); + frame2client(c->sel, r); bw = 0; bh = 0; @@ -564,7 +564,7 @@ apply_sizehints(Client *c, XRectangle *r, Bool floating, Bool frame, BlitzAlign } if(frame) - client2frame(r); + client2frame(c->sel, r); if(!(s->flags & PMinSize) || !floating) { if(r->width > orig.width) diff --git a/cmd/wmii/event.c b/cmd/wmii/event.c index b2947ebf..dce2b678 100644 --- a/cmd/wmii/event.c +++ b/cmd/wmii/event.c @@ -80,10 +80,15 @@ buttonpress(XEvent *e) { if(frame_to_top(f)) restack_view(f->view); - if(ptinrect(ev->x, ev->y, &f->grabbox)) + if(ingrabbox(f, ev->x, ev->y)) + do_mouse_resize(f->client, False, + quadrant(&f->rect, ev->x_root, ev->y_root) & (EAST|WEST)); + else if(ptinrect(ev->x, ev->y, &f->grabbox)) do_mouse_resize(f->client, True, CENTER); - else if(!ev->subwindow && !ptinrect(ev->x, ev->y, &f->titlebar)) - do_mouse_resize(f->client, False, quadrant(&f->rect, ev->x_root, ev->y_root)); + else if(f->area->floating) + if(!ev->subwindow && !ptinrect(ev->x, ev->y, &f->titlebar)) + do_mouse_resize(f->client, False, + quadrant(&f->rect, ev->x_root, ev->y_root)); if(f->client != selclient()) focus(f->client, True); diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h index 1063883e..30d5614d 100644 --- a/cmd/wmii/fns.h +++ b/cmd/wmii/fns.h @@ -91,8 +91,9 @@ Bool frame_to_top(Frame *f); void set_frame_cursor(Frame *f, int x, int y); void swap_frames(Frame *fa, Frame *fb); int frame_delta_h(); -void frame2client(XRectangle *r); -void client2frame(XRectangle *r); +void frame2client(Frame *f, XRectangle *r); +void client2frame(Frame *f, XRectangle *r); +int ingrabbox(Frame *f, int x, int y); void draw_frame(Frame *f); void draw_frames(); void update_frame_widget_colors(Frame *f); diff --git a/cmd/wmii/frame.c b/cmd/wmii/frame.c index f6a98d35..eea1a223 100644 --- a/cmd/wmii/frame.c +++ b/cmd/wmii/frame.c @@ -1,6 +1,8 @@ /* Copyright ©2006-2007 Kris Maglione * See LICENSE file for license details. */ +#include +#include #include #include "dat.h" #include "fns.h" @@ -72,15 +74,25 @@ insert_frame(Frame *pos, Frame *f, Bool before) { } void -frame2client(XRectangle *r) { - r->width = max(r->width - def.border * 2, 1); - r->height = max(r->height - frame_delta_h(), 1); +frame2client(Frame *f, XRectangle *r) { + if(f->area->floating) { + r->width = max(r->width - def.border * 2, 1); + r->height = max(r->height - frame_delta_h(), 1); + }else { + r->width = max(r->width - 2, 1); + r->height = max(r->height - labelh(&def.font) - 1, 1); + } } void -client2frame(XRectangle *r) { - r->width += def.border * 2; - r->height += frame_delta_h(); +client2frame(Frame *f, XRectangle *r) { + if(f->area->floating) { + r->width += def.border * 2; + r->height += frame_delta_h(); + }else { + r->width += 2; + r->height +=labelh(&def.font) + 1; + } } void @@ -98,7 +110,7 @@ resize_frame(Frame *f, XRectangle *r) { if(f->area->floating) f->rect = f->crect; - frame2client(&f->crect); + frame2client(f, &f->crect); if(f->crect.height < labelh(&def.font)) f->collapsed = True; @@ -126,7 +138,7 @@ resize_frame(Frame *f, XRectangle *r) { f->rect = f->crect; f->rect.x = -def.border; f->rect.y = -labelh(&def.font); - client2frame(&f->rect); + client2frame(f, &f->rect); }else check_frame_constraints(&f->rect); } @@ -137,14 +149,16 @@ set_frame_cursor(Frame *f, int x, int y) { XRectangle r; Cursor cur; - if(!ptinrect(x, y, &f->titlebar) - &&!ptinrect(x, y, &f->crect)) { + if(f->area->floating + && !ptinrect(x, y, &f->titlebar) + && !ptinrect(x, y, &f->crect) + && !ingrabbox(f, x, y)) { r = f->rect; r.x = 0; r.y = 0; cur = cursor_of_quad(quadrant(&r, x, y)); set_cursor(f->client, cur); - }else + } else set_cursor(f->client, cursor[CurNormal]); } @@ -248,10 +262,35 @@ frame_delta_h() { return def.border + labelh(&def.font); } +int +ingrabbox(Frame *f, int x, int y) { + int dx, h; + + if(f->area->floating) + return 0; + + h = labelh(&def.font) / 3; + h = max(h, 4); + + if((f == f->area->frame) && f->area->next) + if(x >= f->rect.width - h) { + dx = x - (f->rect.width - h); + if(y <= dx) + return 1; + } + if((f == f->area->frame) && (f->area != f->view->area->next)) + if(x <= h && y <= h - x) + return 1; + + return 0; +} + void draw_frame(Frame *f) { BlitzBrush br = { 0 }; + XPoint pt[3]; Frame *tf; + int h; if(f->view != screen->sel) return; @@ -302,6 +341,30 @@ draw_frame(Frame *f) { f->grabbox = br.rect; draw_tile(&br); + if(!f->area->floating) { + XSetLineAttributes(blz.dpy, br.gc, 1, LineSolid, CapButt, JoinMiter); + h = labelh(&def.font) / 3; + h = max(h, 4); + if((f == f->area->frame) && f->area->next) { + pt[0] = (XPoint){ f->rect.width - h, 0 }; + pt[1] = (XPoint){ f->rect.width, h }; + pt[2] = (XPoint){ f->rect.width, 0 }; + XSetForeground(blz.dpy, br.gc, def.normcolor.bg); + XFillPolygon(blz.dpy, br.drawable, br.gc, pt, 3, Convex, CoordModeOrigin); + XSetForeground(blz.dpy, br.gc, br.color.border); + XDrawLines(blz.dpy, br.drawable, br.gc, pt, 2, CoordModeOrigin); + } + if((f == f->area->frame) && (f->area != f->view->area->next)) { + pt[0] = (XPoint){ h, 0 }; + pt[1] = (XPoint){ 0, h }; + pt[2] = (XPoint){ 0, 0 }; + XSetForeground(blz.dpy, br.gc, def.normcolor.bg); + XFillPolygon(blz.dpy, br.drawable, br.gc, pt, 3, Convex, CoordModeOrigin); + XSetForeground(blz.dpy, br.gc, br.color.border); + XDrawLines(blz.dpy, br.drawable, br.gc, pt, 2, CoordModeOrigin); + } + } + XCopyArea( /* display */ blz.dpy, /* src */ pmap, diff --git a/cmd/wmii/fs.c b/cmd/wmii/fs.c index 678e7121..2313a25c 100644 --- a/cmd/wmii/fs.c +++ b/cmd/wmii/fs.c @@ -13,7 +13,6 @@ /* Datatypes: */ -/**************/ typedef struct Dirtab Dirtab; struct Dirtab { char *name; @@ -48,7 +47,6 @@ struct FileId { }; /* Constants */ -/*************/ enum { /* Dirs */ FsRoot, FsDClient, FsDClients, FsDBars, FsDTag, FsDTags, diff --git a/cmd/wmii/main.c b/cmd/wmii/main.c index ebd0670d..c043098e 100644 --- a/cmd/wmii/main.c +++ b/cmd/wmii/main.c @@ -27,7 +27,7 @@ static char *address, *ns_path; static Bool check_other_wm; static struct sigaction sa; static struct passwd *passwd; -static int sleeperfd, sock; +static int sleeperfd, sock, exitsignal; static void usage() { @@ -54,8 +54,8 @@ scan_wins() { for(i = 0; i < num; i++) { if(!XGetWindowAttributes(blz.dpy, wins[i], &wa)) continue; - if(XGetTransientForHint(blz.dpy, wins[i], &d1) - && wa.map_state == IsViewable) + if((XGetTransientForHint(blz.dpy, wins[i], &d1)) + && (wa.map_state == IsViewable)) manage_client(create_client(wins[i], &wa)); } } @@ -167,11 +167,9 @@ init_ns() { if(stat(ns_path, &st)) fatal("Can't stat ns_path '%s':", ns_path); if(getuid() != st.st_uid) - fatal("ns_path '%s' exists but is not owned by you", - ns_path); + fatal("ns_path '%s' exists but is not owned by you", ns_path); if(st.st_mode & 077) - fatal("ns_path '%s' exists, but has group or world permissions", - ns_path); + fatal("ns_path '%s' exists, but has group or world permissions", ns_path); } static void @@ -295,7 +293,7 @@ wmii_error_handler(Display *dpy, XErrorEvent *error) { for(i = 0; i < nelem(itab); i++) if((itab[i].rcode == 0 || itab[i].rcode == error->request_code) - &&(itab[i].ecode == 0 || itab[i].ecode == error->error_code)) + && (itab[i].ecode == 0 || itab[i].ecode == error->error_code)) return 0; fprintf(stderr, "%s: fatal error: Xrequest code=%d, Xerror code=%d\n", @@ -317,14 +315,13 @@ cleanup_handler(int signal) { sa.sa_handler = SIG_DFL; sigaction(signal, &sa, nil); + srv.running = False; + switch(signal) { - case SIGINT: - srv.running = False; - break; default: - cleanup(); - XCloseDisplay(blz.dpy); - raise(signal); + exitsignal = signal; + break; + case SIGINT: break; } } @@ -429,11 +426,8 @@ main(int argc, char *argv[]) { XSetWindowAttributes wa; int i; - passwd = getpwuid(getuid()); - user = estrdup(passwd->pw_name); wmiirc = "wmiistartrc"; - /* command line args */ ARGBEGIN{ case 'v': printf("%s", version); @@ -452,6 +446,9 @@ main(int argc, char *argv[]) { break; }ARGEND; + if(argc) + usage(); + setlocale(LC_CTYPE, ""); starting = True; @@ -467,8 +464,10 @@ main(int argc, char *argv[]) { XSync(blz.dpy, False); check_other_wm = False; + passwd = getpwuid(getuid()); + user = estrdup(passwd->pw_name); + init_environment(); - init_traps(); errstr = nil; sock = ixp_announce(address); @@ -497,6 +496,7 @@ main(int argc, char *argv[]) { loadcolor(&blz, &def.focuscolor); loadcolor(&blz, &def.normcolor); + init_traps(); init_atoms(); init_cursors(); loadfont(&blz, &def.font); @@ -580,9 +580,10 @@ main(int argc, char *argv[]) { ixp_server_close(&srv); close(sleeperfd); + if(exitsignal) + raise(exitsignal); if(execstr) execl("/bin/sh", "sh", "-c", execstr, nil); - if(errstr) return 1; return 0; diff --git a/util/compile b/util/compile index 751494a2..a4f7159f 100755 --- a/util/compile +++ b/util/compile @@ -10,11 +10,11 @@ echo CC ${BASE}$outfile $CC -o $outfile $CFLAGS $@ 2>$xtmp status=$? -cat $xtmp \ -| egrep -v ': error: .Each undeclared identifier|: error: for each function it appears|is dangerous, better use|is almost always misused|: In function |: At top level:|support .long long.|use of C99 long long|ISO C forbids conversion' \ -| sed 's/ .first use in this function.$//; s/\"\([^\"][^\"]*\)\", line \([0-9][0-9]*\)/\1:\2/g' \ -| uniq 1>&2 +cat $xtmp | + egrep -v ': error: .Each undeclared identifier|: error: for each function it appears|is dangerous, better use|is almost always misused|: In function |: At top level:|support .long long.|use of C99 long long|ISO C forbids conversion' | + sed 's/ .first use in this function.$//; s/\"\([^\"][^\"]*\)\", line \([0-9][0-9]*\)/\1:\2/g' | + uniq 1>&2 -rm -f $xtmp $xtmp.status +rm -f $xtmp exit $status