[hackers] [wmii] Some preliminary changes to make managed mode more cohesive.

From: Kris Maglione <jg_AT_suckless.org>
Date: Sat Apr 14 01:24:03 2007

changeset: 2066:29c1ffbc7d86
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Fri Apr 13 19:23:24 2007 -0400
summary: Some preliminary changes to make managed mode more cohesive.

diff -r ae9e0fb84fa5 -r 29c1ffbc7d86 cmd/wmii/client.c
--- a/cmd/wmii/client.c Tue Apr 10 05:04:19 2007 -0400
+++ b/cmd/wmii/client.c Fri Apr 13 19:23:24 2007 -0400
@@ -513,7 +513,7 @@ apply_sizehints(Client *c, XRectangle *r
         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
         }
 
         if(frame)
- client2frame(r);
+ client2frame(c->sel, r);
 
         if(!(s->flags & PMinSize) || !floating) {
                 if(r->width > orig.width)
diff -r ae9e0fb84fa5 -r 29c1ffbc7d86 cmd/wmii/event.c
--- a/cmd/wmii/event.c Tue Apr 10 05:04:19 2007 -0400
+++ b/cmd/wmii/event.c Fri Apr 13 19:23:24 2007 -0400
@@ -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 -r ae9e0fb84fa5 -r 29c1ffbc7d86 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Tue Apr 10 05:04:19 2007 -0400
+++ b/cmd/wmii/fns.h Fri Apr 13 19:23:24 2007 -0400
@@ -91,8 +91,9 @@ void set_frame_cursor(Frame *f, int x, i
 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 -r ae9e0fb84fa5 -r 29c1ffbc7d86 cmd/wmii/frame.c
--- a/cmd/wmii/frame.c Tue Apr 10 05:04:19 2007 -0400
+++ b/cmd/wmii/frame.c Fri Apr 13 19:23:24 2007 -0400
@@ -1,6 +1,8 @@
 /* Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
+#include <math.h>
+#include <stdio.h>
 #include <util.h>
 #include "dat.h"
 #include "fns.h"
@@ -72,15 +74,25 @@ insert_frame(Frame *pos, Frame *f, Bool
 }
 
 void
-frame2client(XRectangle *r) {
- r->width = max(r->width - def.border * 2, 1);
- r->height = max(r->height - frame_delta_h(), 1);
-}
-
-void
-client2frame(XRectangle *r) {
- r->width += def.border * 2;
- r->height += frame_delta_h();
+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(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 -r ae9e0fb84fa5 -r 29c1ffbc7d86 cmd/wmii/fs.c
--- a/cmd/wmii/fs.c Tue Apr 10 05:04:19 2007 -0400
+++ b/cmd/wmii/fs.c Fri Apr 13 19:23:24 2007 -0400
@@ -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 -r ae9e0fb84fa5 -r 29c1ffbc7d86 cmd/wmii/main.c
--- a/cmd/wmii/main.c Tue Apr 10 05:04:19 2007 -0400
+++ b/cmd/wmii/main.c Fri Apr 13 19:23:24 2007 -0400
@@ -27,7 +27,7 @@ static Bool check_other_wm;
 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, XErrorE
 
         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) {
+ default:
+ exitsignal = signal;
+ break;
         case SIGINT:
- srv.running = False;
- break;
- default:
- cleanup();
- XCloseDisplay(blz.dpy);
- raise(signal);
                 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 -r ae9e0fb84fa5 -r 29c1ffbc7d86 util/compile
--- a/util/compile Tue Apr 10 05:04:19 2007 -0400
+++ b/util/compile Fri Apr 13 19:23:24 2007 -0400
@@ -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
 
Received on Sat Apr 14 2007 - 01:24:03 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:37 UTC