[hackers] [wmii] Pre-merge mess.

From: Kris Maglione <jg_AT_suckless.org>
Date: Mon Jan 21 00:31:15 2008

changeset: 2239:3a29c2ddccbb
parent: 2230:dd1ce947a303
user: Kris Maglione <jg_AT_suckless.org>
date: Fri Jan 18 15:05:45 2008 -0500
summary: Pre-merge mess.

diff -r 3c06b49f84d1 -r 3a29c2ddccbb .hgtags
--- a/.hgtags Sat Jan 19 22:21:47 2008 -0500
+++ b/.hgtags Fri Jan 18 15:05:45 2008 -0500
@@ -17,3 +17,4 @@ 3a6f482d7c506d20f94fdf732ad1150e202a441e
 3a6f482d7c506d20f94fdf732ad1150e202a441e snap20070218
 e9e7dddcacffa58d34820579fc6456403a793d54 snap
 e9e7dddcacffa58d34820579fc6456403a793d54 snap20070303
+6071068bd217023a855e3460217b29beb19f5a61 3.6
diff -r 3c06b49f84d1 -r 3a29c2ddccbb DISTRIBUTORS
--- a/DISTRIBUTORS Sat Jan 19 22:21:47 2008 -0500
+++ b/DISTRIBUTORS Fri Jan 18 15:05:45 2008 -0500
@@ -5,7 +5,7 @@ When in doubt about any of these conditi
 When in doubt about any of these conditions or other matters
 of packaging or distrobution, , please contact the wmii
 mailing lists <wmii-hackers_AT_suckless.org> or
-<wmii_AT_suckless.org>, or Kris Maglione <fbsdaemon_AT_gmail.com>.
+<wmii_AT_suckless.org>.
 
 Any binary distribution of wmii MUST have a properly set
 version string. This string may normally be set in
diff -r 3c06b49f84d1 -r 3a29c2ddccbb Makefile
--- a/Makefile Sat Jan 19 22:21:47 2008 -0500
+++ b/Makefile Fri Jan 18 15:05:45 2008 -0500
@@ -2,16 +2,15 @@ include ${ROOT}/mk/hdr.mk
 include ${ROOT}/mk/hdr.mk
 
 PDIRS = \
- cmd \
- libwmii_hack \
- rc \
+ cmd \
+ rc \
         man
 
 DIRS = \
- libbio \
- libfmt \
- libregexp \
- libutf \
+ libutf \
+ libfmt \
+ libbio \
+ libregexp\
         ${PDIRS}
 
 config:
@@ -24,5 +23,6 @@ deb:
         dpkg-buildpackage -rfakeroot
 
 include ${ROOT}/mk/dir.mk
+include ${ROOT}/mk/common.mk
 INSTDIRS = ${PDIRS}
 
diff -r 3c06b49f84d1 -r 3a29c2ddccbb NOTES
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/NOTES Fri Jan 18 15:05:45 2008 -0500
@@ -0,0 +1,3 @@
+3.6 Release Notes
+
+wmiirc users: the semantics of WMII_MENU, WMII_9MENU and WMII_TERM have changed. If you're using them in custom scripts you'll need to change them to "eval $WMII_MENU" instead of just "$WMII_MENU".
diff -r 3c06b49f84d1 -r 3a29c2ddccbb README
--- a/README Sat Jan 19 22:21:47 2008 -0500
+++ b/README Fri Jan 18 15:05:45 2008 -0500
@@ -2,7 +2,7 @@ Abstract
 --------
 window manager improved-improved is a dynamic window manager for X11.
 It supports classic and tiled window management with extended
-keyboard, mouse, and 9P-based [2] remote control.
+keyboard, mouse, and 9P-based [1] remote control.
 It consists of the wmiiwm(1) window manager and the wmiir(1)
 the remote access utility.
 
@@ -11,7 +11,7 @@ Requirements
 ------------
 In order to build wmii you need the Xlib header files and libixp. xmessage
 and dmenu are used by the default scripts. libixp and dmenu can be obtained
-from http://suckless.org/. Either plan9port or 9base is recommended.
+from http://suckless.org/. Either plan9port[2] or 9base is recommended.
 
 
 Installation
@@ -59,7 +59,7 @@ The following people have contributed es
 - Christoph Wegscheider <christoph dot wegscheider at wegi dot net>
 - Georg Neis <gn at suckless dot org>
 - Uwe Zeisberger <zeisberg at informatik dot uni-freiburg dot de>
-- Uriel <uriel at suckless dot org>
+- Uriel <uriel99 at gmail dot com>
 - Scot Doyle <scot at scotdoyle dot com>
 - Sebastian Hartmann <seb dot wmi at gmx dot de>
 - Bernhard Leiner <bleiner at gmail dot com>
@@ -85,5 +85,5 @@ The following people have contributed es
 
 References
 ----------
-[1] http://www.suckless.org/
-[2] http://www.cs.bell-labs.com/sys/man/5/INDEX.html
+[1] http://9p.cat-v.org
+[2] http://plan9.us
diff -r 3c06b49f84d1 -r 3a29c2ddccbb TODO
--- a/TODO Sat Jan 19 22:21:47 2008 -0500
+++ b/TODO Fri Jan 18 15:05:45 2008 -0500
@@ -1,12 +1,29 @@ 3.6
+BUGS
+* 'Fullscreen' menu option broken for menus in non-focused titlebars (stackmode).
+* collapsed clients outside stacked mode don't always uncollapse when they receive focus
+* resizing within a column affects clients it shouldn't (seems to average client size?)
+* geometry goes wacky with lots of clients in one column
+* floating clients have a tendency to move after being retagged
+* creating new columns via mouse drag doesn't work anymore
+*
+* various qiv brokenness
+* firefox full screen only works sometimes (and coming back from fs is broken)
+* dosbox won't grab the mouse
+
 3.6
+[bugfix only]
+
+4.0
 * Working grab boxes
 * Grow(and shrink?) ctl commands
 * Switch to mk for building
+* Use libbio, libfmt, libregex9
+* New dmenu(with real cursor and using Bio)? (use 9menu instead?)
+* Depend on p9p and replace script mess with a single set using p9p commands
 
-4.0
-* Get rid of colmodes
+4.1
+* Resizable managed area
+* bring back col creation with the mouse
 * (Multi line) Tag bars
-* Resizable managed area
 * Regex-based tag strings
-* New dmenu(with real cursor and using Bio)
-* Use libbio, libfmt, libregex9
+* Get rid of colmodes? (they suck, but sort of work and we need max mode anyway)
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/Makefile
--- a/cmd/Makefile Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/Makefile Fri Jan 18 15:05:45 2008 -0500
@@ -1,39 +1,31 @@ ROOT=..
 ROOT=..
-include $(ROOT)/mk/hdr.mk
-include $(ROOT)/mk/wmii.mk
+include ${ROOT}/mk/hdr.mk
+include ${ROOT}/mk/wmii.mk
 
-wmiir.c: $(ROOT)/mk/wmii.mk
+wmiir.c: ${ROOT}/mk/wmii.mk
 
 DIRS = wmii
-TARG = wihack \
- wmii.rc \
- wmii9menu \
+TARG = wmii9menu \
         wmii9rc \
         wmiiloop \
         wmiir \
         wmiistartrc
 
 OFILES = util.o
-FILTER = sed "s|CONFPREFIX|$(ETC)|g; \
- s|CONFVERSION|$(CONFVERSION)|g; \
- s|P9PATHS|$(P9PATHS)|g; \
- s|LIBDIR|$(LIBDIR)|g; \
- s|AWKPATH|$(AWKPATH)|g"
+FILTER = sed "s|CONFPREFIX|${ETC}|g; \
+ s|CONFVERSION|${CONFVERSION}|g; \
+ s|P9PATHS|${P9PATHS}|g; \
+ s|AWKPATH|${AWKPATH}|g"
 
 LDFLAGS += -lfmt -lutf
-CFLAGS += $(INCX11) -DVERSION=\"$(VERSION)\"
+CFLAGS += ${INCX11} -DVERSION=\"${VERSION}\"
 
-include $(ROOT)/mk/many.mk
-include $(ROOT)/mk/dir.mk
+include ${ROOT}/mk/many.mk
+include ${ROOT}/mk/dir.mk
 
-OWMIIR=wmiir.o $(OFILES) $(LIBIXP)
-wmiir.O: $(OWMIIR)
- $(LINK) $@ $(STATIC) $(OWMIIR)
+OWMIIR=wmiir.o ${OFILES} ${LIBIXP}
+wmiir.O: ${OWMIIR}
+ ${LINK} $@ ${STATIC} ${OWMIIR}
 
-OMENU=menu.o wmii/x11.o $(OFILES) $(LIBIXP)
-menu.O: $(OMENU) dall
- $(LINK) $@ $(OMENU)
-
-wmii9menu.O: wmii9menu.o $(OFILES)
- $(LINK) $@ $*.o $(OFILES) $(LIBX11)
-
+wmii9menu.O: wmii9menu.o ${OFILES}
+ ${LINK} $@ $*.o ${OFILES} ${LIBX11}
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/util.c
--- a/cmd/util.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/util.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,8 +1,6 @@
 /* Written by Kris Maglione <fbsdaemon at gmail dot com> */
 /* Public domain */
 #include <errno.h>
-#include <sys/types.h>
-#include <signal.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -44,43 +42,6 @@ fatal(const char *fmt, ...) {
         va_end(fp.args);
 
         exit(1);
-}
-
-char*
-vsxprint(const char *fmt, va_list ap) {
- static char* bufs[16];
- static long nbuf;
- int id;
-
- id = nbuf++ % nelem(bufs);
- if(bufs[id])
- free(bufs[id]);
- bufs[id] = vsmprint(fmt, ap);
- return bufs[id];
-}
-
-char*
-sxprint(const char *fmt, ...) {
- va_list ap;
- char *ret;
-
- va_start(ap, fmt);
- ret = vsxprint(fmt, ap);
- va_end(ap);
- return ret;
-}
-
-void
-_die(char *file, int line, char *msg) {
- fprint(2, "%s: dieing at %s:%d: %s\n",
- file, line, msg);
- kill(getpid(), SIGABRT);
- abort(); /* Adds too many frames:
- * _die()
- * abort()
- * raise(SIGABRT)
- * kill(getpid(), SIGABRT)
- */
 }
 
 /* Can't malloc */
@@ -174,6 +135,13 @@ min(int a, int b) {
         return b;
 }
 
+char *
+str_nil(char *s) {
+ if(s)
+ return s;
+ return "<nil>";
+}
+
 int
 utflcpy(char *to, const char *from, int l) {
         char *p;
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wihack.sh
--- a/cmd/wihack.sh Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-#!/bin/sh -f
-
-usage() {
- echo 1>&2 Usage: \
- "$0 [-transient <window>] [-type <window_type>[,...]] [-tags <tags>] <command> [<arg> ...]"
- exit 1
-}
-
-checkarg='[ ${#@} -gt 0 ] || usage'
-export WMII_HACK_TIME=$(date +%s)
-
-while [ ${#@} -gt 0 ]
-do
- case $1 in
- -transient)
- shift; eval $checkarg
- export WMII_HACK_TRANSIENT=$1
- shift;;
- -type)
- shift; eval $checkarg
- export WMII_HACK_TYPE=$1
- shift;;
- -tags)
- shift; eval $checkarg
- export WMII_HACK_TAGS=$1
- shift;;
- -*)
- usage;;
- *)
- break;;
- esac
-done
-
-eval $checkarg
-
-if [ ! -u "`which $1`" -a ! -g "`which $1`" ]
-then
- export LD_PRELOAD=libwmii_hack.so
- export LD_LIBRARY_PATH="LIBDIR${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
-else
- unset WMII_HACK_TRANSIENT WMII_HACK_TYPE WMII_HACK_TAGS
-fi
-exec "$@"
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii.rc.rc
--- a/cmd/wmii.rc.rc Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,127 +0,0 @@
-
-wmiiscript=$1
-wmiikeys=()
-
-echo Start $wmiiscript | wmiir write /event >[2]/dev/null \
- || exit write
-
-if(~ $scriptname '')
- scriptname=$wmiiscript
-
-# Blech.
-if(! test -x $PLAN9/bin/read)
- fn read { sh -c 'read -r x || exit 1; echo $x' }
-
-fn wi_atexit {}
-fn sigexit {
- wi_atexit
-}
-
-fn Event-Start {
- if(~ $1 $wmiiscript)
- exit
-}
-
-fn Event-Key { Key-$1 $1 }
-
-fn wi_fatal {
- echo $scriptname: Fatal: $*
- exit fatal
-}
-
-fn wi_notice {
- xmessage $scriptname: Notice: $*
-}
-
-fn wi_readctl { wmiir read /ctl | sed -n 's/^'$1' (.*)/\1/p' }
-
-wmiifont=`{wi_readctl font}
-wmiinormcol=`{wi_readctl normcolors}
-wmiifocuscol=`{wi_readctl focuscolors}
-
-fn wi_menu {
- dmenu -b -fn $wmiifont \
- -nf $wmiinormcol(1) -nb $wmiinormcol(2) \
- -sf $wmiifocuscol(1) -sb $wmiifocuscol(2)
-}
-
-fn wi_9menu {
- wmii9menu -font `{echo $wmiifont | sed 's/,.*//'} \
- -^(nf nb br)^$wmiinormcol \
- -^(sf sb br)^$wmiifocuscol $*
-}
-
-fn wi_proglist {
- /bin/ls -lL `{echo $* | sed 'y/:/ /'} >[2]/dev/null \
- | awk '$1 ~ /^[^d].*x/ { print $NF }' \
- | sort | uniq
-}
-
-fn wi_actions {
- { wi_proglist $WMII_CONFPATH
- wi_getfuns Action
- } | sort | uniq
-}
-
-fn wi_script {
- prog = `{@{path=$confpath whatis $1} |
- grep -v '^fn|= ' || echo /dev/null}
- shift; echo $prog $*
-}
-
-
-fn wi_initkeys {
- ifs=() {
- wmiikeys = `{wmiir read /keys} {
- mykeys = `{comm -23 \
- <{wi_getfuns Key | sort | uniq} \
- <{echo $wmiikeys | sort | uniq}}
- {echo $wmiikeys; wi_getfuns Key} \
- | sort | uniq \
- | wmiir write /keys
- }
- }
- fn wi_atexit {
- wi_cleankeys
- }
-}
-
-fn wi_cleankeys {
- ifs=() {
- wmiikeys = `{wmiir read /keys} {
- comm -23 <{echo $wmiikeys | sort | uniq} \
- <{echo $mykeys} \
- | wmiir write /keys
- }
- }
-}
-
-fn wi_runcmd { @{
- rfork ns
- path=$oldpath
- if(~ $1 -t) {
- shift
- * = (wihack -tags `{wmiir read /tag/sel/ctl | sed 1q} $*)
- }
- eval exec $* &
- }
-}
-
-fn wi_getfuns {
- env | sed -n 's/^fn#'^$1^'-([^=]+).*/\1/p'
-}
-
-fn wi_tags {
- wmiir ls /tag | sed 's,/,,; /^sel$/d'
-}
-
-fn wi_eventloop {
- wi_initkeys
-
- wmiir read /event |
- while(*=`{read}) {
- event = $1; shift
- Event-$event $*
- } >[2]/dev/null </dev/null
-}
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/Makefile
--- a/cmd/wmii/Makefile Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/Makefile Fri Jan 18 15:05:45 2008 -0500
@@ -5,34 +5,29 @@ main.c: ${ROOT}/mk/wmii.mk
 main.c: ${ROOT}/mk/wmii.mk
 
 TARG = wmii
-HFILES= dat.h fns.h
+HFILES= dat.h fns.h x11.h
 
 LIB = ${LIBIXP}
-LDFLAGS += -lm ${LIBX11} -lXext -lXrandr ${LIBICONV} -lregexp9 -lbio -lfmt -lutf
-CFLAGS += ${INCX11} ${INCICONV} -DVERSION=\"${VERSION}\" \
- -DIXP_NEEDAPI=86
+LDFLAGS += -lm ${LIBX11} -lXext ${LIBICONV} -lregexp9 -lbio -lfmt -lutf
+CFLAGS += ${INCX11} ${INCICONV} -DVERSION=\"${VERSION}\"
 OBJ = area \
         bar \
         client \
         column \
- div \
         event \
- ewmh \
- float \
         frame \
- fs \
+ fs \
         geom \
- key \
- main \
- map \
+ key \
+ main \
+ map \
         message \
         mouse \
- rule \
+ rule \
         printevent\
- utf \
- view \
- x11 \
- xext \
+ utf \
+ view \
+ x11 \
         ../util
 
 include ${ROOT}/mk/one.mk
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/area.c
--- a/cmd/wmii/area.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/area.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,13 +1,17 @@
-/* Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+/* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
+ * Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #include "dat.h"
 #include <assert.h>
 #include <math.h>
-#include <sys/limits.h>
+#include <stdlib.h>
+#include <string.h>
 #include "fns.h"
 
-Client*
+static void place_frame(Frame *f);
+
+Client *
 area_selclient(Area *a) {
         if(a && a->sel)
                 return a->sel->client;
@@ -28,49 +32,49 @@ area_idx(Area *a) {
 
 char*
 area_name(Area *a) {
-
- if(a == nil)
- return "<nil>";
+ static char buf[16];
+
         if(a->floating)
                 return "~";
- return sxprint("%d", area_idx(a));
-}
-
-Area*
-area_create(View *v, Area *pos, uint w) {
+ snprint(buf, sizeof(buf), "%d", area_idx(a));
+ return buf;
+}
+
+Area *
+create_area(View *v, Area *pos, uint w) {
         static ushort id = 1;
         uint areanum, i;
         uint minwidth;
         int colnum;
         Area *a;
 
- minwidth = Dx(v->r)/NCOL;
+ minwidth = Dx(screen->r)/NCOL;
 
         i = 0;
- if(pos)
- i = area_idx(pos);
+ for(a = v->area; a != pos; a = a->next)
+ i++;
         areanum = 0;
- for(a=v->area; a; a=a->next)
+ for(a = v->area; a; a = a->next)
                 areanum++;
 
         colnum = areanum - 1;
         if(w == 0) {
                 if(colnum >= 0) {
- w = view_newcolw(v, i);
+ w = newcolw(v, i);
                         if (w == 0)
- w = Dx(v->r) / (colnum + 1);
- }
- else
- w = Dx(v->r);
+ w = Dx(screen->r) / (colnum + 1);
+ }
+ else
+ w = Dx(screen->r);
         }
 
         if(w < minwidth)
                 w = minwidth;
- if(colnum && (colnum * minwidth + w) > Dx(v->r))
+ if(colnum && (colnum * minwidth + w) > Dx(screen->r))
                 return nil;
 
         if(pos)
- view_scale(v, Dx(v->r) - w);
+ scale_view(v, Dx(screen->r) - w);
 
         a = emallocz(sizeof *a);
         a->view = v;
@@ -79,9 +83,10 @@ area_create(View *v, Area *pos, uint w)
         a->frame = nil;
         a->sel = nil;
 
- a->r = v->r;
+ a->r = screen->r;
         a->r.min.x = 0;
         a->r.max.x = w;
+ a->r.max.y = screen->brect.min.y;
 
         if(pos) {
                 a->next = pos->next;
@@ -99,56 +104,59 @@ area_create(View *v, Area *pos, uint w)
                 a->floating = True;
 
         if(v->sel == nil)
- area_focus(a);
+ focus_area(a);
 
         if(!a->floating)
- event("CreateColumn %ud\n", i);
+ write_event("CreateColumn %ud\n", i);
         return a;
 }
 
 void
-area_destroy(Area *a) {
+destroy_area(Area *a) {
+ Client *c;
         Area *ta;
         View *v;
- int idx;
+ uint i;
 
         v = a->view;
 
         if(a->frame)
- die("destroying non-empty area");
+ fatal("destroying non-empty area");
 
         if(v->revert == a)
                 v->revert = nil;
 
- idx = area_idx(a);
-
- if(a->prev && !a->prev->floating)
+ for(c=client; c; c=c->next)
+ if(c->revert == a)
+ c->revert = nil;
+
+ i = 0;
+ for(ta=v->area; ta != a; ta=ta->next)
+ i++;
+
+ if(a->prev)
                 ta = a->prev;
         else
                 ta = a->next;
 
- /* Can only destroy the floating area when destroying a
- * view---after destroying all columns.
- */
         assert(a->prev || a->next == nil);
         if(a->prev)
                 a->prev->next = a->next;
         if(a->next)
                 a->next->prev = a->prev;
 
- if(ta && v->sel == a)
- area_focus(ta);
- view_arrange(v);
- event("DestroyArea %d\n", idx);
- /* Deprecated */
- event("DestroyColumn %d\n", idx);
+ if(ta && v->sel == a) {
+ if(ta->floating && ta->next)
+ ta = ta->next;
+ focus_area(ta);
+ }
+ write_event("DestroyColumn %ud\n", i);
 
         free(a);
 }
 
 void
-area_moveto(Area *to, Frame *f) {
- Rectangle tr;
+send_to_area(Area *to, Frame *f) {
         Area *from;
 
         assert(to->view == f->view);
@@ -156,74 +164,257 @@ area_moveto(Area *to, Frame *f) {
         from = f->area;
 
         if(to->floating != from->floating) {
- /* XXX: This must be changed. */
- tr = f->revert;
+ Rectangle temp = f->revert;
                 f->revert = f->r;
- f->r = tr;
- }
-
- area_detach(f);
- area_attach(to, f);
-
- /* Temporary kludge. */
- if(!to->floating && to->floating != from->floating)
- column_resizeframe(f, &tr);
-}
-
-void
-area_setsel(Area *a, Frame *f) {
- View *v;
-
- v = a->view;
- if(a == v->sel && f)
- frame_focus(f);
- else
- a->sel = f;
-}
-
-void
-area_attach(Area *a, Frame *f) {
+ f->r = temp;
+ }
+ f->client->revert = from;
+
+ detach_from_area(f);
+ attach_to_area(to, f);
+}
+
+void
+attach_to_area(Area *a, Frame *f) {
+ uint n_frame;
+ Frame *ft;
+ Client *c;
+
+ c = f->client;
 
         f->area = a;
- if(a->floating)
- float_attach(a, f);
- else
- column_attach(a, f);
-
- view_restack(a->view);
+
+ n_frame = 0;
+ for(ft=a->frame; ft; ft=ft->anext)
+ n_frame++;
+ n_frame = max(n_frame, 1);
+
+ c->floating = a->floating;
+ if(!a->floating) {
+ f->r = a->r;
+ f->r.max.y = Dy(a->r) / n_frame;
+ }
+
+ insert_frame(a->sel, f);
+
+ if(a->floating) {
+ place_frame(f);
+ resize_frame(f, f->r);
+ }
+
+ focus_frame(f, False);
+ restack_view(a->view);
+
+ if(!a->floating)
+ arrange_column(a, False);
 
         if(a->frame)
                 assert(a->sel);
 }
 
 void
-area_detach(Frame *f) {
+detach_from_area(Frame *f) {
+ Frame *pr;
+ Client *c, *cp;
         Area *a;
+ View *v;
 
         a = f->area;
-
- if(a->floating)
- float_detach(f);
+ v = a->view;
+ c = f->client;
+
+ pr = f->aprev;
+ remove_frame(f);
+
+ if(a->sel == f) {
+ if(!pr)
+ pr = a->frame;
+ if(pr && (v->sel == a))
+ focus_frame(pr, False);
+ else
+ a->sel = pr;
+ }
+
+ if(!a->floating) {
+ if(a->frame)
+ arrange_column(a, False);
+ else {
+ if(v->area->next->next)
+ destroy_area(a);
+ else if((a->frame == nil) && (v->area->frame))
+ focus_area(v->area);
+
+ arrange_view(v);
+ }
+ }else if(!a->frame) {
+ if(c->trans) {
+ cp = win2client(c->trans);
+ if(cp && cp->frame) {
+ a = cp->sel->area;
+ if(a->view == v) {
+ focus_area(a);
+ return;
+ }
+ }
+ }
+ if(v->area->next->frame)
+ focus_area(v->area->next);
+ }else
+ assert(a->sel);
+}
+
+static void
+bit_set(uint *field, uint width, uint x, uint y, int set) {
+ enum { divisor = sizeof(uint) * 8 };
+ uint bx, mask;
+ div_t d;
+
+ d = div(x, divisor);
+ bx = d.quot;
+ mask = 1 << d.rem;
+ if(set)
+ field[y*width + bx] |= mask;
         else
- column_detach(f);
-}
-
-void
-area_focus(Area *a) {
+ field[y*width + bx] &= ~mask;
+}
+
+static Bool
+bit_get(uint *field, uint width, uint x, uint y) {
+ enum { divisor = sizeof(uint) * 8 };
+ uint bx, mask;
+ div_t d;
+
+ d = div(x, divisor);
+ bx = d.quot;
+ mask = 1 << d.rem;
+
+ return (field[y*width + bx] & mask) != 0;
+}
+
+static void
+place_frame(Frame *f) {
+ enum { divisor = sizeof(uint) * 8 };
+ enum { dx = 8, dy = 8 };
+
+ static uint mwidth, mx, my;
+ static uint *field = nil;
+ Align align;
+ Point p1 = ZP;
+ Point p2 = ZP;
+ Rectangle *rects;
+ Frame *fr;
+ Client *c;
+ Area *a;
+ Bool fit;
+ uint i, j, x, y, cx, cy, maxx, maxy, diff, num;
+ int snap;
+
+ snap = Dy(screen->r) / 66;
+ num = 0;
+ fit = False;
+ align = CENTER;
+
+ a = f->area;
+ c = f->client;
+
+ if(c->trans)
+ return;
+ if(c->fullscreen || c->w.hints->position || starting) {
+ f->r = gravclient(c, c->r);
+ return;
+ }
+ if(!field) {
+ mx = Dx(screen->r) / dx;
+ my = Dy(screen->r) / dy;
+ mwidth = ceil((float)mx / divisor);
+ field = emallocz(sizeof(uint) * mwidth * my);
+ }
+
+ SET(cx);
+ SET(cy);
+ memset(field, ~0, (sizeof(uint) * mwidth * my));
+ for(fr=a->frame; fr; fr=fr->anext) {
+ if(fr == f) {
+ cx = Dx(f->r) / dx;
+ cy = Dx(f->r) / dy;
+ continue;
+ }
+
+ if(fr->r.min.x < 0)
+ x = 0;
+ else
+ x = fr->r.min.x / dx;
+
+ if(fr->r.min.y < 0)
+ y = 0;
+ else
+ y = fr->r.min.y / dy;
+
+ maxx = fr->r.max.x / dx;
+ maxy = fr->r.max.y / dy;
+ for(j = y; j < my && j < maxy; j++)
+ for(i = x; i < mx && i < maxx; i++)
+ bit_set(field, mwidth, i, j, False);
+ }
+
+ for(y = 0; y < my; y++)
+ for(x = 0; x < mx; x++) {
+ if(bit_get(field, mwidth, x, y)) {
+ for(i = x; i < mx; i++)
+ if(bit_get(field, mwidth, i, y) == 0)
+ break;
+ for(j = y; j < my; j++)
+ if(bit_get(field, mwidth, x, j) == 0)
+ break;
+
+ if(((i - x) * (j - y) > (p2.x - p1.x) * (p2.y - p1.y))
+ && (i - x > cx) && (j - y > cy))
+ {
+ fit = True;
+ p1.x = x;
+ p1.y = y;
+ p2.x = i;
+ p2.y = j;
+ }
+ }
+ }
+
+ if(fit) {
+ p1.x *= dx;
+ p1.y *= dy;
+ }
+
+ if(!fit || (p1.x + Dx(f->r) > a->r.max.x)) {
+ diff = Dx(a->r) - Dx(f->r);
+ p1.x = a->r.min.x + (random() % max(diff, 1));
+ }
+
+ if(!fit && (p1.y + Dy(f->r) > a->r.max.y)) {
+ diff = Dy(a->r) - Dy(f->r);
+ p1.y = a->r.min.y + (random() % max(diff, 1));
+ }
+
+ p1 = subpt(p1, f->r.min);
+ f->r = rectaddpt(f->r, p1);
+
+ rects = rects_of_view(a->view, &num, nil);
+ snap_rect(rects, num, &f->r, &align, snap);
+ if(rects)
+ free(rects);
+}
+
+void
+focus_area(Area *a) {
         Frame *f;
         View *v;
         Area *old_a;
+ int i;
 
         v = a->view;
         f = a->sel;
         old_a = v->sel;
 
- if(view_fullscreen_p(v) && !a->floating)
- return;
-
         v->sel = a;
- if(!a->floating)
- v->selcol = area_idx(a);
 
         if((old_a) && (a->floating != old_a->floating))
                 v->revert = old_a;
@@ -231,20 +422,18 @@ area_focus(Area *a) {
         if(v != screen->sel)
                 return;
 
- move_focus(old_a->sel, f);
-
         if(f)
- client_focus(f->client);
+ focus_client(f->client);
         else
- client_focus(nil);
+ focus_client(nil);
 
         if(a != old_a) {
- event("AreaFocus %s\n", area_name(a));
- /* Deprecated */
+ i = 0;
+ for(a = v->area; a != v->sel; a = a->next)
+ i++;
                 if(a->floating)
- event("FocusFloating\n");
- else
- event("ColumnFocus %d\n", area_idx(a));
- }
-}
-
+ write_event("FocusFloating\n");
+ else
+ write_event("ColumnFocus %d\n", i);
+ }
+}
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/bar.c
--- a/cmd/wmii/bar.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/bar.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,15 +1,16 @@
 /* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
- * Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+ * Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #include "dat.h"
+#include <string.h>
 #include "fns.h"
 
 static Handlers handlers;
 static Bar *free_bars;
 
 void
-bar_init(WMScreen *s) {
+initbar(WMScreen *s) {
         WinAttr wa;
 
         s->brect = s->r;
@@ -33,12 +34,12 @@ bar_init(WMScreen *s) {
         mapwin(s->barwin);
 }
 
-Bar*
-bar_create(Bar **bp, const char *name) {
+Bar *
+create_bar(Bar **bp, char *name) {
         static uint id = 1;
         Bar *b;
 
- b = bar_find(*bp, name);;
+ b = bar_of_name(*bp, name);;
         if(b)
                 return b;
 
@@ -64,7 +65,7 @@ bar_create(Bar **bp, const char *name) {
 }
 
 void
-bar_destroy(Bar **bp, Bar *b) {
+destroy_bar(Bar **bp, Bar *b) {
         Bar **p;
 
         for(p = bp; *p; p = &p[0]->next)
@@ -76,7 +77,7 @@ bar_destroy(Bar **bp, Bar *b) {
 }
 
 void
-bar_resize(WMScreen *s) {
+resize_bar(WMScreen *s) {
         View *v;
 
         s->brect = s->r;
@@ -84,14 +85,14 @@ bar_resize(WMScreen *s) {
 
         reshapewin(s->barwin, s->brect);
 
- sync();
- bar_draw(s);
+ XSync(display, False);
+ draw_bar(s);
         for(v = view; v; v = v->next)
- view_arrange(v);
-}
-
-void
-bar_draw(WMScreen *s) {
+ arrange_view(v);
+}
+
+void
+draw_bar(WMScreen *s) {
         Bar *b, *tb, *largest, **pb;
         Rectangle r;
         Align align;
@@ -149,19 +150,19 @@ bar_draw(WMScreen *s) {
         fill(screen->ibuf, r, def.normcolor.bg);
         for(nb = 0; nb < nelem(s->bar); nb++)
                 for(b = s->bar[nb]; b; b=b->next) {
- align = Center;
+ align = CENTER;
                         if(b == s->bar[BarRight])
- align = East;
+ align = EAST;
                         fill(screen->ibuf, b->r, b->col.bg);
                         drawstring(screen->ibuf, def.font, b->r, align, b->text, b->col.fg);
                         border(screen->ibuf, b->r, 1, b->col.border);
                 }
         copyimage(s->barwin, r, screen->ibuf, ZP);
- sync();
+ XSync(display, False);
 }
 
 Bar*
-bar_find(Bar *bp, const char *name) {
+bar_of_name(Bar *bp, const char *name) {
         Bar *b;
 
         for(b = bp; b; b = b->next)
@@ -178,16 +179,16 @@ bdown_event(Window *w, XButtonPressedEve
 
         /* Ungrab so a menu can receive events before the button is released */
         XUngrabPointer(display, e->time);
- sync();
+ XSync(display, False);
 
         for(b=screen->bar[BarLeft]; b; b=b->next)
- if(rect_haspoint_p(Pt(e->x, e->y), b->r)) {
- event("LeftBarMouseDown %d %s\n", e->button, b->name);
+ if(ptinrect(Pt(e->x, e->y), b->r)) {
+ write_event("LeftBarMouseDown %d %s\n", e->button, b->name);
                         return;
                 }
         for(b=screen->bar[BarRight]; b; b=b->next)
- if(rect_haspoint_p(Pt(e->x, e->y), b->r)) {
- event("RightBarMouseDown %d %s\n", e->button, b->name);
+ if(ptinrect(Pt(e->x, e->y), b->r)) {
+ write_event("RightBarMouseDown %d %s\n", e->button, b->name);
                         return;
                 }
 }
@@ -199,13 +200,13 @@ bup_event(Window *w, XButtonPressedEvent
         USED(w, e);
 
         for(b=screen->bar[BarLeft]; b; b=b->next)
- if(rect_haspoint_p(Pt(e->x, e->y), b->r)) {
- event("LeftBarClick %d %s\n", e->button, b->name);
+ if(ptinrect(Pt(e->x, e->y), b->r)) {
+ write_event("LeftBarClick %d %s\n", e->button, b->name);
                         return;
                 }
         for(b=screen->bar[BarRight]; b; b=b->next)
- if(rect_haspoint_p(Pt(e->x, e->y), b->r)) {
- event("RightBarClick %d %s\n", e->button, b->name);
+ if(ptinrect(Pt(e->x, e->y), b->r)) {
+ write_event("RightBarClick %d %s\n", e->button, b->name);
                         return;
                 }
 }
@@ -213,7 +214,7 @@ static void
 static void
 expose_event(Window *w, XExposeEvent *e) {
         USED(w, e);
- bar_draw(screen);
+ draw_bar(screen);
 }
 
 static Handlers handlers = {
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/client.c
--- a/cmd/wmii/client.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/client.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,10 +1,11 @@
 /* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
- * Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+ * Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #include "dat.h"
-#include <assert.h>
 #include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
 #include <X11/Xatom.h>
 #include "fns.h"
 
@@ -23,78 +24,10 @@ enum {
                 | ButtonReleaseMask
 };
 
-static Group* group;
-
-static void
-group_init(Client *c) {
- Group *g;
- long *ret;
- XWindow w;
- long n;
-
- w = c->w.hints->group;
- if(w == 0) {
- /* Not quite ICCCM compliant, but it seems to work. */
- n = getprop_long(&c->w, "WM_CLIENT_LEADER", "WINDOW", 0L, &ret, 1L);
- if(n == 0)
- return;
- w = *ret;
- }
-
- for(g=group; g; g=g->next)
- if(g->leader == w)
- break;
- if(g == nil) {
- g = emallocz(sizeof *g);
- g->leader = w;
- g->next = group;
- group = g;
- }
- c->group = g;
- g->ref++;
-}
-
-static void
-group_remove(Client *c) {
- Group **gp;
- Group *g;
-
- g = c->group;
- if(g == nil)
- return;
- if(g->client == c)
- g->client = nil;
- g->ref--;
- if(g->ref == 0) {
- for(gp=&group; *gp; gp=&gp[0]->next)
- if(*gp == g)
- break;
- assert(*gp == g);
- gp[0] = gp[0]->next;
- }
-}
-
-static Client*
-group_leader(Group *g) {
- Client *c;
-
- c = win2client(g->leader);
- if(c)
- return c;
- if(g->client)
- return g->client;
- /* Could do better. */
- for(c=client; c; c=c->next)
- if(c->frame && c->group == g)
- break;
- return c;
-}
-
-Client*
-client_create(XWindow w, XWindowAttributes *wa) {
+Client *
+create_client(XWindow w, XWindowAttributes *wa) {
         Client **t, *c;
         WinAttr fwa;
- Point p;
 
         c = emallocz(sizeof(Client));
         c->border = wa->border_width;
@@ -105,14 +38,17 @@ client_create(XWindow w, XWindowAttribut
         c->w.type = WWindow;
         c->w.w = w;
         c->w.r = c->r;
-
- client_prop(c, xatom("WM_PROTOCOLS"));
- client_prop(c, xatom("WM_TRANSIENT_FOR"));
- client_prop(c, xatom("WM_NORMAL_HINTS"));
- client_prop(c, xatom("WM_HINTS"));
- client_prop(c, xatom("WM_CLASS"));
- client_prop(c, xatom("WM_NAME"));
- client_prop(c, xatom("_MOTIF_WM_HINTS"));
+
+ if((Dx(c->r) == Dx(screen->r)) && (Dy(c->r) == Dy(screen->r)))
+ fullscreen(c, True);
+
+ prop_client(c, xatom("WM_PROTOCOLS"));
+ prop_client(c, xatom("WM_TRANSIENT_FOR"));
+ prop_client(c, xatom("WM_NORMAL_HINTS"));
+ prop_client(c, xatom("WM_HINTS"));
+ prop_client(c, xatom("WM_CLASS"));
+ prop_client(c, xatom("WM_NAME"));
+ prop_client(c, xatom("_MOTIF_WM_HINTS"));
 
         XSetWindowBorderWidth(display, w, 0);
         XAddToSaveSet(display, w);
@@ -137,13 +73,6 @@ client_create(XWindow w, XWindowAttribut
         sethandler(c->framewin, &framehandler);
         sethandler(&c->w, &handlers);
 
- p.x = def.border;
- p.y = labelh(def.font);
- reparentwindow(&c->w, c->framewin, p);
-
- ewmh_initclient(c);
- group_init(c);
-
         grab_button(c->framewin->w, AnyButton, AnyModifier);
 
         for(t=&client ;; t=&t[0]->next)
@@ -153,59 +82,44 @@ client_create(XWindow w, XWindowAttribut
                         break;
                 }
 
- event("CreateClient %C\n", c);
- client_manage(c);
+ write_event("CreateClient %C\n", c);
+ manage_client(c);
         return c;
 }
 
 void
-client_manage(Client *c) {
+manage_client(Client *c) {
+ Point p;
         Client *trans;
- Frame *f;
         char *tags;
 
- if(Dx(c->r) == Dx(screen->r))
- if(Dy(c->r) == Dy(screen->r))
- fullscreen(c, true);
-
- tags = getprop_string(&c->w, "_WMII_TAGS");
-
- trans = win2client(c->trans);
- if(trans == nil && c->group)
- trans = group_leader(c->group);
-
- if(tags)
- utflcpy(c->tags, tags, sizeof c->tags);
- else if(trans)
- utflcpy(c->tags, trans->tags, sizeof c->tags);
+ tags = gettextproperty(&c->w, "_WMII_TAGS");
+ if(tags == nil)
+ tags = gettextproperty(&c->w, "_WIN_TAGS");
+
+ if((trans = win2client(c->trans)))
+ utflcpy(c->tags, trans->tags, sizeof(c->tags));
+ else if(tags)
+ utflcpy(c->tags, tags, sizeof(c->tags));
+
         free(tags);
 
- /* Maybe not the best idea... */
- if(!trans || !c->tags[0])
+ p.x = def.border;
+ p.y = labelh(def.font);
+
+ reparentwindow(&c->w, c->framewin, p);
+
+ if(c->tags[0])
+ apply_tags(c, c->tags);
+ else
                 apply_rules(c);
- apply_tags(c, c->tags);
 
         if(!starting)
- view_update_all();
-
- bool newgroup = !c->group
- || c->group->ref == 1
- || selclient() && (selclient()->group == c->group);
-
- f = c->sel;
- if(f->view == screen->sel)
- if(!(c->w.ewmh.type & TypeSplash))
- if(newgroup) {
- if(f->area != f->view->sel)
- f->view->oldsel = f->view->sel;
- focus(c, false);
- }
- else {
- frame_restack(c->sel, c->sel->area->sel);
- view_restack(c->sel->view);
- }
-
- flushenterevents();
+ update_views();
+
+ if(c->sel->view == screen->sel)
+ focus(c, True);
+ flushevents(EnterWindowMask, False);
 }
 
 static int /* Temporary Xlib error handler */
@@ -215,12 +129,14 @@ ignoreerrors(Display *d, XErrorEvent *e)
 }
 
 void
-client_destroy(Client *c) {
+destroy_client(Client *c) {
         int (*handler)(Display*, XErrorEvent*);
         Rectangle r;
- char *none;
+ char *dummy;
         Client **tc;
- bool hide;
+ Bool hide;
+
+ Dprint("client.c:destroy_client(%p) %s\n", c, c->name);
 
         unmapwin(c->framewin);
 
@@ -230,7 +146,7 @@ client_destroy(Client *c) {
                         break;
                 }
 
- r = client_grav(c, ZR);
+ r = gravclient(c, ZR);
 
         hide = False;
         if(!c->sel || c->sel->view != screen->sel)
@@ -241,8 +157,9 @@ client_destroy(Client *c) {
         /* In case the client is already unmapped */
         handler = XSetErrorHandler(ignoreerrors);
 
- none = nil;
- client_setviews(c, &none);
+ dummy = nil;
+ update_client_views(c, &dummy);
+ unmap_client(c, IconicState);
         sethandler(&c->w, nil);
 
         if(hide)
@@ -251,38 +168,26 @@ client_destroy(Client *c) {
                 reparentwindow(&c->w, &scr.root, r.min);
         destroywindow(c->framewin);
 
- sync();
+ XSync(display, False);
         XSetErrorHandler(handler);
         XUngrabServer(display);
 
- ewmh_destroyclient(c);
- group_remove(c);
- event("DestroyClient %C\n", c);
-
- flushenterevents();
+ write_event("DestroyClient %C\n", c);
+
+ flushevents(EnterWindowMask, False);
         free(c->w.hints);
         free(c);
 }
 
 /* Convenience functions */
-Frame*
-client_viewframe(Client *c, View *v) {
- Frame *f;
-
- for(f=c->frame; f; f=f->cnext)
- if(f->area->view == v)
- break;
- return f;
-}
-
-Client*
+Client *
 selclient(void) {
         if(screen->sel->sel->sel)
                 return screen->sel->sel->sel->client;
         return nil;
 }
 
-Client*
+Client *
 win2client(XWindow w) {
         Client *c;
         for(c=client; c; c=c->next)
@@ -300,7 +205,7 @@ Cfmt(Fmt *f) {
         return fmtprint(f, "<nil>");
 }
 
-char*
+char *
 clientname(Client *c) {
         if(c)
                 return c->name;
@@ -308,7 +213,7 @@ clientname(Client *c) {
 }
 
 Rectangle
-client_grav(Client *c, Rectangle rd) {
+gravclient(Client *c, Rectangle rd) {
         Rectangle r;
         Point sp;
         WinHints *h;
@@ -323,36 +228,18 @@ client_grav(Client *c, Rectangle rd) {
                         else
                                 r = c->sel->revert;
                 }else
- r = frame_client2rect(nil, c->r);
+ r = client2frame(nil, c->r);
                 r = gravitate(r, c->r, h->grav);
                 if(h->gravstatic)
                         r = rectaddpt(r, sp);
- return frame_rect2client(nil, r);
+ return frame2client(nil, r);
         }else {
- r = frame_client2rect(nil, rd);
+ r = client2frame(nil, rd);
                 r = gravitate(rd, r, h->grav);
                 if(h->gravstatic)
                         r = rectsubpt(r, sp);
- return frame_client2rect(nil, r);
- }
-}
-
-bool
-client_floats_p(Client *c) {
- return c->trans
- || c->floating
- || c->fixedsize
- || c->titleless
- || c->borderless
- || c->fullscreen
- || (c->w.ewmh.type & (TypeDialog|TypeSplash|TypeDock));
-}
-
-Frame*
-client_groupframe(Client *c, View *v) {
- if(c->group && c->group->client)
- return client_viewframe(c->group->client, v);
- return nil;
+ return client2frame(nil, r);
+ }
 }
 
 Rectangle
@@ -366,9 +253,9 @@ frame_hints(Frame *f, Rectangle r, Align
                 return r;
 
         or = r;
- r = frame_rect2client(f, r);
+ r = frame2client(f, r);
         r = sizehint(c->w.hints, r);
- r = frame_client2rect(f, r);
+ r = client2frame(f, r);
 
         if(!f->area->floating) {
                 /* Not allowed to grow */
@@ -379,34 +266,34 @@ frame_hints(Frame *f, Rectangle r, Align
         }
 
         p = ZP;
- if((sticky&(East|West)) == East)
+ if((sticky&(EAST|WEST)) == EAST)
                 p.x = Dx(or) - Dx(r);
- if((sticky&(North|South)) == South)
+ if((sticky&(NORTH|SOUTH)) == SOUTH)
                 p.y = Dy(or) - Dy(r);
 
         return rectaddpt(r, p);
 }
 
 static void
-client_setstate(Client * c, int state) {
+set_client_state(Client * c, int state) {
         long data[] = { state, None };
 
         changeprop_long(&c->w, "WM_STATE", "WM_STATE", data, nelem(data));
 }
 
 void
-client_map(Client *c) {
+map_client(Client *c) {
         if(!c->w.mapped) {
                 mapwin(&c->w);
- client_setstate(c, NormalState);
- }
-}
-
-void
-client_unmap(Client *c, int state) {
+ set_client_state(c, NormalState);
+ }
+}
+
+void
+unmap_client(Client *c, int state) {
         if(c->w.mapped) {
                 unmapwin(&c->w);
- client_setstate(c, state);
+ set_client_state(c, state);
         }
 }
 
@@ -421,59 +308,50 @@ unmap_frame(Client *c) {
 }
 
 void
-focus(Client *c, bool user) {
+focus(Client *c, Bool restack) {
         View *v;
         Frame *f;
 
         f = c->sel;
         if(!f)
                 return;
- /*
- if(!user && c->noinput)
- return;
- */
-
- v = f->view;
+
+ v = f->area->view;
         if(v != screen->sel)
- view_focus(screen, v);
- frame_focus(c->sel);
-}
-
-void
-client_focus(Client *c) {
+ focus_view(screen, v);
+ focus_frame(c->sel, restack);
+}
+
+void
+focus_client(Client *c) {
         flushevents(FocusChangeMask, True);
 
- Dprint(DFocus, "client_focus(%p[%C]) => %s\n", c, c, clientname(c));
-
- if(c) {
- if(c->noinput)
- return;
- if(c->group)
- c->group->client = c;
- }
-
- if(screen->focus != c) {
- Dprint(DFocus, "\t%s => %s\n", clientname(screen->focus), clientname(c));
+ Dprint("focus_client(%p[%C]) => %s\n", c, c, clientname(c));
+
+ if((c == nil || !c->noinput) && screen->focus != c) {
+ Dprint("\t%s => %s\n", clientname(screen->focus), clientname(c));
+
                 if(c)
                         setfocus(&c->w, RevertToParent);
                 else
                         setfocus(screen->barwin, RevertToParent);
- event("ClientFocus %C\n", c);
-
- sync();
+
+ write_event("ClientFocus %C\n", c);
+
+ XSync(display, False);
                 flushevents(FocusChangeMask, True);
         }
 }
 
 void
-client_resize(Client *c, Rectangle r) {
+resize_client(Client *c, Rectangle r) {
         Frame *f;
 
         f = c->sel;
- frame_resize(f, r);
+ resize_frame(f, r);
 
         if(f->area->view != screen->sel) {
- client_unmap(c, IconicState);
+ unmap_client(c, IconicState);
                 unmap_frame(c);
                 return;
         }
@@ -482,25 +360,24 @@ client_resize(Client *c, Rectangle r) {
 
         if((f->area->mode == Colmax) && (f->area->sel != f)) {
                 unmap_frame(c);
- client_unmap(c, IconicState);
+ unmap_client(c, IconicState);
         }else if(f->collapsed) {
                 reshapewin(c->framewin, f->r);
                 map_frame(c);
- client_unmap(c, IconicState);
+ unmap_client(c, IconicState);
         }else {
- client_map(c);
+ map_client(c);
                 reshapewin(c->framewin, f->r);
                 reshapewin(&c->w, f->crect);
                 map_frame(c);
- client_configure(c);
- ewmh_framesize(c);
+ configure_client(c);
         }
 
         flushevents(FocusChangeMask|ExposureMask, True);
 }
 
 void
-client_setcursor(Client *c, Cursor cur) {
+set_cursor(Client *c, Cursor cur) {
         WinAttr wa;
 
         if(c->cursor != cur) {
@@ -511,7 +388,7 @@ client_setcursor(Client *c, Cursor cur)
 }
 
 void
-client_configure(Client *c) {
+configure_client(Client *c) {
         XConfigureEvent e;
         Rectangle r;
 
@@ -529,15 +406,30 @@ client_configure(Client *c) {
         e.height = Dy(r);
         e.border_width = c->border;
 
- sendevent(&c->w, false, StructureNotifyMask, (XEvent*)&e);
-}
-
-void
-client_kill(Client *c, bool nice) {
- if(nice && (c->proto & ProtoDelete)) {
- sendmessage(&c->w, "WM_PROTOCOLS", "WM_DELETE_WINDOW", 0, 0, 0);
- ewmh_pingclient(c);
- }
+ XSendEvent(display, c->w.w,
+ /*propegate*/ False,
+ StructureNotifyMask,
+ (XEvent*)&e);
+}
+
+static void
+send_client_message(Client *c, char *name, char *value) {
+ XEvent e;
+
+ e.type = ClientMessage;
+ e.xclient.window = c->w.w;
+ e.xclient.message_type = xatom(name);
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = xatom(value);
+ e.xclient.data.l[1] = CurrentTime;
+ XSendEvent(display, c->w.w, False, NoEventMask, &e);
+ XSync(display, False);
+}
+
+void
+kill_client(Client * c) {
+ if(c->proto & WM_PROTOCOL_DELWIN)
+ send_client_message(c, "WM_PROTOCOLS", "WM_DELETE_WINDOW");
         else
                 XKillClient(display, c->w.w);
 }
@@ -545,58 +437,50 @@ void
 void
 fullscreen(Client *c, int fullscreen) {
         Frame *f;
- bool wassel;
         
         if(fullscreen == Toggle)
                 fullscreen = c->fullscreen ^ On;
         if(fullscreen == c->fullscreen)
                 return;
 
- event("Fullscreen %C %s\n", c, (fullscreen ? "on" : "off"));
+ write_event("Fullscreen %C %s\n", c, (fullscreen ? "on" : "off"));
         c->fullscreen = fullscreen;
- ewmh_updatestate(c);
-
- if(!fullscreen)
- for(f=c->frame; f; f=f->cnext) {
- if(f->oldarea == 0)
- frame_resize(f, f->oldr); /* XXX: oldr Replace with floatr */
- else if(f->oldarea > 0) {
- wassel = (f == f->area->sel);
- area_moveto(view_findarea(f->view, f->oldarea, true), f);
- f->revert = f->oldr; /* XXX: oldr */
- if(wassel)
- frame_focus(f);
+
+ if((f = c->sel)) {
+ if(fullscreen) {
+ if(f->area->floating)
+ f->revert = f->r;
+ else {
+ f->r = f->revert;
+ send_to_area(f->view->area, f);
                         }
- }
- else {
- for(f=c->frame; f; f=f->cnext)
- f->oldarea = -1;
- if((f = c->sel))
- if(f->view == screen->sel)
- view_focus(screen, f->view);
- }
-}
-
-void
-client_seturgent(Client *c, bool urgent, int from) {
+ focus_client(c);
+ }else
+ resize_frame(f, f->revert);
+ if(f->view == screen->sel)
+ focus_view(screen, f->view);
+ }
+}
+
+void
+set_urgent(Client *c, int urgent, Bool write) {
         XWMHints *wmh;
- char *cfrom, *cnot;
+ char *cwrite, *cnot;
         Frame *f, *ff;
         Area *a;
 
         if(urgent == Toggle)
                 urgent = c->urgent ^ On;
 
- cfrom = (from == UrgManager ? "Manager" : "Client");
+ cwrite = (write ? "Manager" : "Client");
         cnot = (urgent ? "" : "Not");
 
         if(urgent != c->urgent) {
- event("%sUrgent %C %s\n", cnot, c, cfrom);
+ write_event("%sUrgent %C %s\n", cnot, c, cwrite);
                 c->urgent = urgent;
- ewmh_updatestate(c);
                 if(c->sel) {
                         if(c->sel->view == screen->sel)
- frame_draw(c->sel);
+ draw_frame(c->sel);
                         for(f=c->frame; f; f=f->cnext) {
                                 SET(ff);
                                 if(!urgent)
@@ -604,12 +488,12 @@ client_seturgent(Client *c, bool urgent,
                                                 for(ff=a->frame; ff; ff=ff->anext)
                                                         if(ff->client->urgent) break;
                                 if(urgent || ff == nil)
- event("%sUrgentTag %s %s\n", cnot, cfrom, f->view->name);
+ write_event("%sUrgentTag %s %s\n", cnot, cwrite, f->view->name);
                         }
                 }
         }
 
- if(from == UrgManager) {
+ if(write) {
                 wmh = XGetWMHints(display, c->w.w);
                 if(wmh == nil)
                         wmh = emallocz(sizeof *wmh);
@@ -638,21 +522,21 @@ update_class(Client *c) {
 }
 
 static void
-client_updatename(Client *c) {
+update_client_name(Client *c) {
         char *str;
 
         c->name[0] = '\0';
 
- str = getprop_string(&c->w, "_NET_WM_NAME");
+ str = gettextproperty(&c->w, "_NET_WM_NAME");
         if(str == nil)
- str = getprop_string(&c->w, "WM_NAME");
+ str = gettextproperty(&c->w, "WM_NAME");
         if(str)
                 utflcpy(c->name, str, sizeof(c->name));
         free(str);
 
         update_class(c);
         if(c->sel)
- frame_draw(c->sel);
+ draw_frame(c->sel);
 }
 
 static void
@@ -660,57 +544,56 @@ updatemwm(Client *c) {
         enum {
                 All = 0x1,
                 Border = 0x2,
- Title = 0x8,
- FlagDecor = 0x2,
- Flags = 0,
- Decor = 2,
+ Title = 0x8,
+ FlagDecor = 0x2,
+ Flags = 0,
+ Decor = 2,
         };
         Rectangle r;
         ulong *ret;
+ Atom real;
         int n;
 
- n = getprop_long(&c->w, "_MOTIF_WM_HINTS", "_MOTIF_WM_HINTS",
- 0L, (long**)&ret, 3L);
+ n = getproperty(&c->w, "_MOTIF_WM_HINTS", "_MOTIF_WM_HINTS", &real,
+ 0L, (void*)&ret, 3L);
 
         if(c->sel)
- r = frame_rect2client(c->sel, c->sel->r);
-
- c->borderless = 0;
- c->titleless = 0;
+ r = frame2client(c->sel, c->sel->r);
+
         if(n >= 3 && (ret[Flags]&FlagDecor)) {
                 if(ret[Decor]&All)
                         ret[Decor] ^= ~0;
- c->borderless = !(ret[Decor]&Border);
- c->titleless = !(ret[Decor]&Title);
+ c->borderless = ((ret[Decor]&Border)==0);
+ c->titleless = ((ret[Decor]&Title)==0);
+ }else {
+ c->borderless = 0;
+ c->titleless = 0;
         }
         free(ret);
 
         if(c->sel) {
- r = frame_client2rect(c->sel, r);
- client_resize(c, r);
- frame_draw(c->sel);
- }
-}
-
-void
-client_prop(Client *c, Atom a) {
+ r = client2frame(c->sel, r);
+ resize_client(c, r);
+ draw_frame(c->sel);
+ }
+}
+
+void
+prop_client(Client *c, Atom a) {
         XWMHints *wmh;
         char **class;
         int n;
 
- if(a == xatom("WM_PROTOCOLS"))
+ if(a == xatom("WM_PROTOCOLS")) {
                 c->proto = winprotocols(&c->w);
- else
- if(a == xatom("_NET_WM_NAME"))
+ }
+ else if(a == xatom("_NET_WM_NAME")) {
                 goto wmname;
- else
- if(a == xatom("_MOTIF_WM_HINTS"))
+ }
+ else if(a == xatom("_MOTIF_WM_HINTS")) {
                 updatemwm(c);
- else
- switch (a) {
- default:
- ewmh_prop(c, a);
- break;
+ }
+ else switch (a) {
         case XA_WM_TRANSIENT_FOR:
                 XGetTransientForHint(display, c->w.w, &c->trans);
                 break;
@@ -723,12 +606,12 @@ client_prop(Client *c, Atom a) {
                 wmh = XGetWMHints(display, c->w.w);
                 if(wmh) {
                         c->noinput = !((wmh->flags&InputFocus) && wmh->input);
- client_seturgent(c, (wmh->flags & XUrgencyHint) != 0, UrgClient);
+ set_urgent(c, (wmh->flags & XUrgencyHint) != 0, False);
                         XFree(wmh);
                 }
                 break;
         case XA_WM_CLASS:
- n = getprop_textlist(&c->w, "WM_CLASS", &class);
+ n = gettextlistproperty(&c->w, "WM_CLASS", &class);
                 snprint(c->props, sizeof(c->props), "%s:%s:",
                                 (n > 0 ? class[0] : "<nil>"),
                                 (n > 1 ? class[1] : "<nil>"));
@@ -737,7 +620,7 @@ client_prop(Client *c, Atom a) {
                 break;
         case XA_WM_NAME:
 wmname:
- client_updatename(c);
+ update_client_name(c);
                 break;
         }
 }
@@ -750,33 +633,33 @@ configreq_event(Window *w, XConfigureReq
 
         c = w->aux;
 
- r = client_grav(c, ZR);
+ r = gravclient(c, ZR);
         r.max = subpt(r.max, r.min);
 
- if(e->value_mask & CWX)
+ if(e->value_mask&CWX)
                 r.min.x = e->x;
- if(e->value_mask & CWY)
+ if(e->value_mask&CWY)
                 r.min.y = e->y;
- if(e->value_mask & CWWidth)
+ if(e->value_mask&CWWidth)
                 r.max.x = e->width;
- if(e->value_mask & CWHeight)
+ if(e->value_mask&CWHeight)
                 r.max.y = e->height;
 
- if(e->value_mask & CWBorderWidth)
+ if(e->value_mask&CWBorderWidth)
                 c->border = e->border_width;
 
         r.max = addpt(r.min, r.max);
         cr = r;
- r = client_grav(c, r);
-
- if(c->sel->area->floating) {
- client_resize(c, r);
- sync();
- flushenterevents();
- }
+ r = gravclient(c, r);
+
+ if((Dx(cr) == Dx(screen->r)) && (Dy(cr) == Dy(screen->r)))
+ fullscreen(c, True);
+
+ if(c->sel->area->floating)
+ resize_client(c, r);
         else {
                 c->sel->revert = r;
- client_configure(c);
+ configure_client(c);
         }
 }
 
@@ -784,7 +667,8 @@ destroy_event(Window *w, XDestroyWindowE
 destroy_event(Window *w, XDestroyWindowEvent *e) {
         USED(w, e);
 
- client_destroy(w->aux);
+ Dprint("client.c:destroy_event(%W)\n", w);
+ destroy_client(w->aux);
 }
 
 static void
@@ -794,12 +678,11 @@ enter_event(Window *w, XCrossingEvent *e
         c = w->aux;
         if(e->detail != NotifyInferior) {
                 if(screen->focus != c) {
- Dprint(DGeneric, "enter_notify(c) => %s\n", c->name);
- focus(c, false);
- }
- client_setcursor(c, cursor[CurNormal]);
- }else
- Dprint(DGeneric, "enter_notify(c[NotifyInferior]) => %s\n", c->name);
+ Dprint("enter_notify(c) => %s\n", c->name);
+ focus(c, False);
+ }
+ set_cursor(c, cursor[CurNormal]);
+ }else Dprint("enter_notify(c[NotifyInferior]) => %s\n", c->name);
 }
 
 static void
@@ -817,7 +700,7 @@ focusin_event(Window *w, XFocusChangeEve
         screen->focus = c;
         if(c != old) {
                 if(c->sel)
- frame_draw(c->sel);
+ draw_frame(c->sel);
         }
 }
 
@@ -833,7 +716,7 @@ focusout_event(Window *w, XFocusChangeEv
                 print_focus(&c_magic, "<magic>");
                 screen->focus = &c_magic;
                 if(c->sel)
- frame_draw(c->sel);
+ draw_frame(c->sel);
         }
 }
 
@@ -844,7 +727,7 @@ unmap_event(Window *w, XUnmapEvent *e) {
         c = w->aux;
         if(!e->send_event)
                 c->unmapped--;
- client_destroy(c);
+ destroy_client(c);
 }
 
 static void
@@ -855,7 +738,7 @@ map_event(Window *w, XMapEvent *e) {
         
         c = w->aux;
         if(c == selclient())
- client_focus(c);
+ focus_client(c);
 }
 
 static void
@@ -866,7 +749,7 @@ property_event(Window *w, XPropertyEvent
                 return;
 
         c = w->aux;
- client_prop(c, e->atom);
+ prop_client(c, e->atom);
 }
 
 static Handlers handlers = {
@@ -881,8 +764,40 @@ static Handlers handlers = {
 };
 
 /* Other */
-void
-client_setviews(Client *c, char **tags) {
+#if 0 /* Not used at the moment */
+void
+newcol_client(Client *c, char *arg) {
+ Frame *f;
+ Area *to, *a;
+ View *v;
+
+ f = c->sel;
+ a = f->area;
+ v = f->view;
+
+ if(a->floating)
+ return;
+ if((f->anext == nil) && (f->aprev == nil))
+ return;
+
+ if(!strncmp(arg, "prev", 5)) {
+ for(to=v->area; to; to=to->next)
+ if(to->next == a) break;
+ to = new_column(v, to, 0);
+ send_to_area(to, f);
+ }
+ else if(!strncmp(arg, "next", 5)) {
+ to = new_column(v, a, 0);
+ send_to_area(to, f);
+ }
+ else
+ return;
+ flushevents(EnterWindowMask, False);
+}
+#endif
+
+void
+update_client_views(Client *c, char **tags) {
         Frame **fp, *f;
         int cmp;
 
@@ -897,7 +812,7 @@ client_setviews(Client *c, char **tags)
                         }
 
                         f = *fp;
- area_detach(f);
+ detach_from_area(f);
                         *fp = f->cnext;
                         if(c->sel == f)
                                 c->sel = *fp;
@@ -905,10 +820,10 @@ client_setviews(Client *c, char **tags)
                 }
                 if(*tags) {
                         if(!*fp || cmp > 0) {
- f = frame_create(c, view_create(*tags));
+ f = create_frame(c, get_view(*tags));
                                 if(f->view == screen->sel || !c->sel)
                                         c->sel = f;
- view_attach(f->view, f);
+ attach_to_view(f->view, f);
                                 f->cnext = *fp;
                                 *fp = f;
                         }
@@ -916,7 +831,7 @@ client_setviews(Client *c, char **tags)
                         tags++;
                 }
         }
- view_update_all();
+ update_views();
 }
 
 static int
@@ -928,7 +843,7 @@ strpcmp(const void *ap, const void *bp)
 strpcmp(const void *ap, const void *bp) {
         char **a, **b;
         
- a = (char**)ap;
+ a = (char**)ap; /* gcc wants this case. *sigh* */
         b = (char**)bp;
         return strcmp(*a, *b);
 }
@@ -942,7 +857,7 @@ void
 void
 apply_tags(Client *c, const char *tags) {
         uint i, j, k, n;
- bool add;
+ Bool add;
         char buf[512], last;
         char *toks[32], *cur;
 
@@ -970,9 +885,7 @@ apply_tags(Client *c, const char *tags)
         j = 0;
         while(buf[n] && n < sizeof(buf) && j < 32) {
                 for(i = n; i < sizeof(buf) - 1; i++)
- if(buf[i] == '+'
- || buf[i] == '-'
- || buf[i] == '\0')
+ if(buf[i] == '+' || buf[i] == '-' || buf[i] == '\0')
                                 break;
                 last = buf[i];
                 buf[i] = '\0';
@@ -980,11 +893,9 @@ apply_tags(Client *c, const char *tags)
                 cur = nil;
                 if(!strcmp(buf+n, "~"))
                         c->floating = add;
- else
- if(!strcmp(buf+n, "!") || !strcmp(buf+n, "sel"))
+ else if(!strcmp(buf+n, "!") || !strcmp(buf+n, "sel"))
                         cur = screen->sel->name;
- else
- if(!Mbsearch(buf+n, badtags, bsstrcmp))
+ else if(!Mbsearch(buf+n, badtags, bsstrcmp))
                         cur = buf+n;
 
                 n = i + 1;
@@ -999,45 +910,54 @@ apply_tags(Client *c, const char *tags)
                         }
                 }
 
- if(last == '+')
+ switch(last) {
+ case '+':
                         add = True;
- if(last == '-')
+ break;
+ case '-':
                         add = False;
- if(last == '\0')
+ break;
+ case '\0':
                         buf[n] = '\0';
+ break;
+ }
         }
 
         if(!j)
                 return;
 
- qsort(toks, j, sizeof *toks, strpcmp);
+ qsort(toks, j, sizeof(char *), strpcmp);
 
         c->tags[0] = '\0';
         for(i=0, n=0; i < j; i++)
                 if(n == 0 || strcmp(toks[i], toks[n-1])) {
                         if(i > 0)
- strlcat(c->tags, "+", sizeof c->tags);
- strlcat(c->tags, toks[i], sizeof c->tags);
+ strlcat(c->tags, "+", sizeof(c->tags));
+ strlcat(c->tags, toks[i], sizeof(c->tags));
                         toks[n++] = toks[i];
                 }
         toks[n] = nil;
 
- client_setviews(c, toks);
-
- changeprop_string(&c->w, "_WMII_TAGS", c->tags);
+ update_client_views(c, toks);
+
+ changeprop_char(&c->w, "_WMII_TAGS", "UTF8_STRING", c->tags, strlen(c->tags));
 }
 
 void
 apply_rules(Client *c) {
         Rule *r;
+
+ if(strlen(c->tags))
+ return;
 
         if(def.tagrules.string)
                 for(r=def.tagrules.rule; r; r=r->next)
                         if(regexec(r->regex, c->props, nil, 0)) {
                                 apply_tags(c, r->value);
- break;
+ if(c->tags[0] && strcmp(c->tags, "nil"))
+ break;
                         }
         if(c->tags[0] == '\0')
- apply_tags(c, "sel");
-}
-
+ apply_tags(c, "nil");
+}
+
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/column.c
--- a/cmd/wmii/column.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/column.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,12 +1,17 @@
 /* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
- * Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+ * Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #include "dat.h"
 #include <assert.h>
 #include <math.h>
+#include <string.h>
 #include <strings.h>
 #include "fns.h"
+
+static Image *divimg, *divmask;
+static CTuple divc;
+static Handlers divhandler;
 
 char *modes[] = {
         [Coldefault] = "default",
@@ -25,97 +30,181 @@ str2colmode(const char *str) {
 }
 
 char*
-colmode2str(uint i) {
+colmode2str(int i) {
         if(i < nelem(modes))
                 return modes[i];
         return nil;
 }
 
-Area*
-column_new(View *v, Area *pos, uint w) {
+static Divide*
+getdiv(Divide **dp) {
+ WinAttr wa;
+ Divide *d;
+
+ if(*dp)
+ return *dp;
+
+ d = emallocz(sizeof *d);
+
+ wa.override_redirect = True;
+ wa.cursor = cursor[CurDHArrow];
+ wa.event_mask =
+ ExposureMask
+ | EnterWindowMask
+ | ButtonPressMask
+ | ButtonReleaseMask;
+ d->w = createwindow(&scr.root, Rect(0, 0, 1, 1), scr.depth, InputOutput, &wa,
+ CWOverrideRedirect
+ | CWEventMask
+ | CWCursor);
+ d->w->aux = d;
+ sethandler(d->w, &divhandler);
+
+ *dp = d;
+ return d;
+}
+
+static void
+mapdiv(Divide *d) {
+ mapwin(d->w);
+}
+
+static void
+unmapdiv(Divide *d) {
+ unmapwin(d->w);
+}
+
+void
+setdiv(Divide *d, int x) {
+ Rectangle r;
+
+ d->x = x;
+ r = rectaddpt(divimg->r, Pt(x - Dx(divimg->r)/2, 0));
+ r.max.y = screen->brect.min.y;
+
+ reshapewin(d->w, r);
+ mapdiv(d);
+}
+
+static void
+drawimg(Image *img, ulong cbg, ulong cborder) {
+ Point pt[6];
+
+ pt[0] = Pt(0, 0);
+ pt[1] = Pt(Dx(img->r)/2 - 1, Dx(img->r)/2 - 1);
+
+ pt[2] = Pt(pt[1].x, Dy(img->r));
+ pt[3] = Pt(Dx(img->r)/2, pt[2].y);
+
+ pt[4] = Pt(pt[3].x, Dx(img->r)/2 - 1);
+ pt[5] = Pt(Dx(img->r) - 1, 0);
+
+ fillpoly(img, pt, nelem(pt), cbg);
+ drawpoly(img, pt, nelem(pt), CapNotLast, 1, cborder);
+}
+
+static void
+drawdiv(Divide *d) {
+ copyimage(d->w, divimg->r, divimg, ZP);
+ setshapemask(d->w, divmask, ZP);
+}
+
+static void
+update_imgs(void) {
+ Divide *d;
+ int w, h;
+
+ w = 2 * (labelh(def.font) / 3);
+ w = max(w, 10);
+ h = Dy(screen->r);
+
+ if(divimg) {
+ if(w == Dx(divimg->r) && h == Dy(divimg->r)
+ && !memcmp(&divc, &def.normcolor, sizeof(divc)))
+ return;
+ freeimage(divimg);
+ freeimage(divmask);
+ }
+
+ divimg = allocimage(w, h, scr.depth);
+ divmask = allocimage(w, h, 1);
+ divc = def.normcolor;
+
+ fill(divmask, divmask->r, 0);
+ drawimg(divmask, 1, 1);
+ drawimg(divimg, divc.bg, divc.border);
+
+ for(d = divs; d && d->w->mapped; d = d->next)
+ drawdiv(d);
+}
+
+void
+update_divs(void) {
+ Divide **dp, *d;
         Area *a;
-
- a = area_create(v, pos, w);
+ View *v;
+
+ update_imgs();
+
+ v = screen->sel;
+ dp = &divs;
+ for(a = v->area->next; a; a = a->next) {
+ d = getdiv(dp);
+ dp = &d->next;
+ setdiv(d, a->r.min.x);
+
+ if(!a->next) {
+ d = getdiv(dp);
+ dp = &d->next;
+ setdiv(d, a->r.max.x);
+ }
+ }
+ for(d = *dp; d; d = d->next)
+ unmapdiv(d);
+}
+
+/* Div Handlers */
+static void
+bdown_event(Window *w, XButtonEvent *e) {
+ Divide *d;
+
+ USED(e);
+
+ d = w->aux;
+ mouse_resizecol(d);
+}
+
+static void
+expose_event(Window *w, XExposeEvent *e) {
+ Divide *d;
+
+ USED(e);
+
+ d = w->aux;
+ drawdiv(d);
+}
+
+static Handlers divhandler = {
+ .bdown = bdown_event,
+ .expose = expose_event,
+};
+
+Area *
+new_column(View *v, Area *pos, uint w) {
+ Area *a;
+
+ a = create_area(v, pos, w);
         if(!a)
                 return nil;
 
- view_arrange(v);
+ arrange_view(v);
         if(v == screen->sel)
- view_focus(screen, v);
+ focus_view(screen, v);
         return a;
 }
 
-void
-column_insert(Area *a, Frame *f, Frame *pos) {
-
- f->area = a;
- f->client->floating = false;
- f->column = area_idx(a);
- frame_insert(f, pos);
-}
-
-void
-column_attach(Area *a, Frame *f) {
- uint nframe;
- Frame *ft;
-
- nframe = 0;
- for(ft=a->frame; ft; ft=ft->anext)
- nframe++;
- nframe = max(nframe, 1);
-
- f->r = a->r;
- f->r.max.y = Dy(a->r) / nframe;
-
- column_insert(a, f, a->sel);
- if(a->sel == nil)
- area_setsel(a, f);
- column_arrange(a, false);
-}
-
-void
-column_remove(Frame *f, bool arrange) {
- Client *c;
- Frame *pr;
- Area *a;
- View *v;
-
- a = f->area;
- v = a->view;
- c = f->client;
-
- pr = f->aprev;
-
- frame_remove(f);
-
- f->area = nil;
- if(a->sel == f) {
- if(!pr)
- pr = a->frame;
- a->sel = nil;
- area_setsel(a, pr);
- }
-
- if(a->frame) {
- if(arrange)
- column_arrange(a, False);
- }
- else {
- if(v->area->next->next)
- area_destroy(a);
- else if(v->area->frame)
- area_focus(v->area);
- }
-}
-
-void
-column_detach(Frame *f) {
-
- column_remove(f, true);
-}
-
-static void
-column_scale(Area *a) {
+static void
+scale_column(Area *a) {
         Frame *f, **fp;
         uint minh, yoff, dy;
         uint ncol, nuncol;
@@ -133,7 +222,7 @@ column_scale(Area *a) {
         nuncol = 0;
         dy = 0;
         for(f=a->frame; f; f=f->anext) {
- frame_resize(f, f->r);
+ resize_frame(f, f->r);
                 if(f->collapsed)
                         ncol++;
                 else
@@ -170,7 +259,7 @@ column_scale(Area *a) {
                 if(f->collapsed) {
                         if(i < 0 && (f != a->sel)) {
                                 f->collapsed = False;
- area_moveto(f->view->area, f);
+ send_to_area(f->view->area, f);
                                 continue;
                         }
                         i--;
@@ -180,7 +269,7 @@ column_scale(Area *a) {
                         j--;
                 }
                 /* Doesn't change if we 'continue' */
- fp = &f->anext;
+ fp=&f->anext;
         }
 
         surplus = 0;
@@ -208,7 +297,7 @@ column_scale(Area *a) {
                 for(f=a->frame; f; f=f->anext) {
                         if(!f->collapsed)
                                 f->r.max.y += f->ratio * surplus;
- frame_resize(f, f->r);
+ resize_frame(f, f->r);
                         dy += Dy(f->r);
                 }
                 surplus = Dy(a->r) - dy;
@@ -217,7 +306,7 @@ column_scale(Area *a) {
                 if(!f->collapsed) {
                         dy = Dy(f->r);
                         f->r.max.y += surplus;
- frame_resize(f, f->r);
+ resize_frame(f, f->r);
                         f->r.max.y = Dy(f->crect) + labelh(def.font) + 1;
                         surplus -= Dy(f->r) - dy;
                 }
@@ -239,7 +328,7 @@ column_scale(Area *a) {
 }
 
 void
-column_arrange(Area *a, bool dirty) {
+arrange_column(Area *a, Bool dirty) {
         Frame *f;
 
         if(a->floating || !a->frame)
@@ -262,26 +351,26 @@ column_arrange(Area *a, bool dirty) {
                 }
                 goto resize;
         default:
- die("can't get here");
+ assert(!"Can't happen");
                 break;
         }
- column_scale(a);
+ scale_column(a);
 resize:
         if(a->view == screen->sel) {
- view_restack(a->view);
- client_resize(a->sel->client, a->sel->r);
+ restack_view(a->view);
+ resize_client(a->sel->client, a->sel->r);
 
                 for(f=a->frame; f; f=f->anext)
                         if(!f->collapsed && f != a->sel)
- client_resize(f->client, f->r);
+ resize_client(f->client, f->r);
                 for(f=a->frame; f; f=f->anext)
                         if(f->collapsed && f != a->sel)
- client_resize(f->client, f->r);
- }
-}
-
-void
-column_resize(Area *a, int w) {
+ resize_client(f->client, f->r);
+ }
+}
+
+void
+resize_column(Area *a, int w) {
         Area *an;
         int dw;
 
@@ -292,12 +381,12 @@ column_resize(Area *a, int w) {
         a->r.max.x += dw;
         an->r.min.x += dw;
 
- view_arrange(a->view);
- view_focus(screen, a->view);
-}
-
-static void
-column_resizeframe_h(Frame *f, Rectangle *r) {
+ arrange_view(a->view);
+ focus_view(screen, a->view);
+}
+
+static void
+resize_colframeh(Frame *f, Rectangle *r) {
         Area *a;
         Frame *fn, *fp;
         uint minh;
@@ -320,18 +409,18 @@ column_resizeframe_h(Frame *f, Rectangle
 
         if(fp) {
                 fp->r.max.y = r->min.y;
- frame_resize(fp, fp->r);
+ resize_frame(fp, fp->r);
         }
         if(fn) {
                 fn->r.min.y = r->max.y;
- frame_resize(fn, fn->r);
- }
-
- frame_resize(f, *r);
-}
-
-void
-column_resizeframe(Frame *f, Rectangle *r) {
+ resize_frame(fn, fn->r);
+ }
+
+ resize_frame(f, *r);
+}
+
+void
+resize_colframe(Frame *f, Rectangle *r) {
         Area *a, *al, *ar;
         View *v;
         uint minw;
@@ -341,7 +430,7 @@ column_resizeframe(Frame *f, Rectangle *
         v = a->view;
         maxx = r->max.x;
 
- minw = Dx(v->r) / NCOL;
+ minw = Dx(screen->r) / NCOL;
 
         al = a->prev;
         ar = a->next;
@@ -351,26 +440,29 @@ column_resizeframe(Frame *f, Rectangle *
         else
                 r->min.x = max(r->min.x, 0);
 
- if(ar)
- maxx = min(maxx, a->r.max.x - minw);
+ if(ar) {
+ if(maxx >= ar->r.max.x - minw)
+ maxx = ar->r.max.x - minw;
+ }
         else
- maxx = min(maxx, v->r.max.x);
+ if(maxx > screen->r.max.x)
+ maxx = screen->r.max.x;
 
         dx = a->r.min.x - r->min.x;
         dw = maxx - a->r.max.x;
         if(al) {
                 al->r.max.x -= dx;
- column_arrange(al, False);
+ arrange_column(al, False);
         }
         if(ar) {
                 ar->r.max.x -= dw;
- column_arrange(ar, False);
- }
-
- column_resizeframe_h(f, r);
+ arrange_column(ar, False);
+ }
+
+ resize_colframeh(f, r);
 
         a->r.max.x = maxx;
- view_arrange(a->view);
-
- view_focus(screen, v);
-}
+ arrange_view(a->view);
+
+ focus_view(screen, v);
+}
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/dat.h
--- a/cmd/wmii/dat.h Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/dat.h Fri Jan 18 15:05:45 2008 -0500
@@ -1,4 +1,4 @@
-/* Copyright ©2007-2008 Kris Maglione <jg_AT_suckless.org>
+/* © 2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
  * See LICENSE file for license details.
  */
 
@@ -6,49 +6,43 @@
 #define IXP_P9_STRUCTS
 #define IXP_NO_P9_
 #include <regexp9.h>
-#include <stdbool.h>
 #include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
 #include <ixp.h>
 #include <util.h>
 #include <utf.h>
 #include <fmt.h>
-#include <x11.h>
+#include "x11.h"
 
 #define FONT "-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*"
 #define FOCUSCOLORS "#ffffff #335577 #447799"
 #define NORMCOLORS "#222222 #eeeeee #666666"
 
-enum {
- PingTime = 10000,
-};
-
-enum {
- UrgManager,
- UrgClient,
-};
-
-enum EWMHType {
- TypeDesktop = 1<<0,
- TypeDock = 1<<1,
- TypeToolbar = 1<<2,
- TypeMenu = 1<<3,
- TypeUtility = 1<<4,
- TypeSplash = 1<<5,
- TypeDialog = 1<<6,
- TypeNormal = 1<<7,
+enum Align {
+ NORTH = 0x01,
+ EAST = 0x02,
+ SOUTH = 0x04,
+ WEST = 0x08,
+ NEAST = NORTH | EAST,
+ NWEST = NORTH | WEST,
+ SEAST = SOUTH | EAST,
+ SWEST = SOUTH | WEST,
+ CENTER = NEAST | SWEST,
+};
+
+typedef struct CTuple CTuple;
+typedef enum Align Align;
+
+struct CTuple {
+ ulong bg;
+ ulong fg;
+ ulong border;
+ char colstr[24]; /* #RRGGBB #RRGGBB #RRGGBB */
 };
 
 enum {
         Coldefault, Colstack, Colmax,
 };
 
-#define TOGGLE(x) \
- (x == On ? "On" : \
- x == Off ? "Off" : \
- x == Toggle ? "Toggle" : \
- "<toggle>")
 enum {
         Off,
         On,
@@ -65,191 +59,137 @@ enum {
 
 enum {
         NCOL = 16,
-};
-
-enum Protocols {
- ProtoDelete = 1<<0,
- ProtoTakeFocus = 1<<1,
- ProtoPing = 1<<2,
-};
-
-enum DebugOpt {
- DEvent = 1<<0,
- DEwmh = 1<<1,
- DFocus = 1<<2,
- DGeneric= 1<<3,
+ WM_PROTOCOL_DELWIN = 1,
 };
 
 /* Data Structures */
+typedef struct View View;
 typedef struct Area Area;
-typedef struct Bar Bar;
+typedef struct Frame Frame;
 typedef struct Client Client;
 typedef struct Divide Divide;
-typedef struct Frame Frame;
-typedef struct Group Group;
 typedef struct Key Key;
+typedef struct Bar Bar;
+typedef struct Rule Rule;
+typedef struct Ruleset Ruleset;
+typedef struct WMScreen WMScreen;
 typedef struct Map Map;
 typedef struct MapEnt MapEnt;
-typedef struct Rule Rule;
-typedef struct Ruleset Ruleset;
-typedef struct Strut Strut;
-typedef struct View View;
-typedef struct WMScreen WMScreen;
+
+struct Map {
+ MapEnt **bucket;
+ uint nhash;
+};
+
+struct MapEnt {
+ ulong hash;
+ char *key;
+ void *val;
+ MapEnt *next;
+};
+
+struct View {
+ View *next;
+ char name[256];
+ ushort id;
+ Area *area;
+ Area *sel;
+ Area *revert;
+};
 
 struct Area {
- Area* next;
- Area* prev;
- Frame* frame;
- Frame* stack;
- Frame* sel;
- View* view;
- bool floating;
- ushort id;
- int mode;
- Rectangle r;
+ Area *next, *prev;
+ Frame *frame;
+ Frame *stack;
+ Frame *sel;
+ View *view;
+ Bool floating;
+ ushort id;
+ int mode;
+ Rectangle r;
+};
+
+struct Frame {
+ Frame *cnext;
+ Frame *anext, *aprev;
+ Frame *snext, *sprev;
+ View *view;
+ Area *area;
+ ushort id;
+ Rectangle r;
+ Rectangle crect;
+ Rectangle revert;
+ Client *client;
+ Bool collapsed;
+ Rectangle grabbox;
+ Rectangle titlebar;
+ float ratio;
+};
+
+struct Client {
+ Client *next;
+ Area *revert;
+ Frame *frame;
+ Frame *sel;
+ Window w;
+ Window *framewin;
+ XWindow trans;
+ Cursor cursor;
+ Rectangle r;
+ char name[256];
+ char tags[256];
+ char props[512];
+ uint border;
+ int proto;
+ char floating;
+ char fixedsize;
+ char fullscreen;
+ char urgent;
+ char borderless;
+ char titleless;
+ char noinput;
+ int unmapped;
+};
+
+struct Divide {
+ Divide *next;
+ Window *w;
+ Bool mapped;
+ int x;
+};
+
+struct Key {
+ Key *next;
+ Key *lnext;
+ Key *tnext;
+ ushort id;
+ char name[128];
+ ulong mod;
+ KeyCode key;
 };
 
 struct Bar {
- Bar* next;
- Bar* smaller;
- char buf[280];
- char text[256];
- char name[256];
- ushort id;
- Rectangle r;
- CTuple col;
-};
-
-struct Client {
- Client* next;
- Frame* frame;
- Frame* sel;
- Window w;
- Window* framewin;
- XWindow trans;
- Group* group;
- Strut* strut;
- Cursor cursor;
- Rectangle r;
- char name[256];
- char tags[256];
- char props[512];
- uint border;
- long proto;
- char floating;
- char fixedsize;
- char fullscreen;
- char urgent;
- char borderless;
- char titleless;
- char noinput;
- int unmapped;
-};
-
-struct Divide {
- Divide* next;
- Window* w;
- bool mapped;
- int x;
-};
-
-struct Frame {
- Frame* cnext;
- Frame* anext;
- Frame* aprev;
- Frame* snext;
- Frame* sprev;
- Client* client;
- View* view;
- Area* area;
- int oldarea;
- int column;
- ushort id;
- bool collapsed;
- float ratio;
- Rectangle r;
- Rectangle oldr;
- Rectangle crect;
- Rectangle revert;
- Rectangle grabbox;
- Rectangle titlebar;
-};
-
-struct Group {
- Group* next;
- XWindow leader;
- Client *client;
- int ref;
-};
-
-struct Key {
- Key* next;
- Key* lnext;
- Key* tnext;
- ushort id;
- char name[128];
- ulong mod;
- KeyCode key;
-};
-
-struct Map {
- MapEnt**bucket;
- uint nhash;
-};
-
-struct MapEnt {
- ulong hash;
- const char* key;
- void* val;
- MapEnt* next;
+ Bar *next;
+ Bar *smaller;
+ char buf[280];
+ char text[256];
+ char name[256];
+ ushort id;
+ Rectangle r;
+ CTuple col;
 };
 
 struct Rule {
- Rule* next;
- Reprog* regex;
- char value[256];
+ Rule *next;
+ Reprog *regex;
+ char value[256];
 };
 
 struct Ruleset {
- Rule* rule;
- char* string;
- uint size;
-};
-
-struct Strut {
- Rectangle left;
- Rectangle right;
- Rectangle top;
- Rectangle bottom;
-};
-
-struct View {
- View* next;
- char name[256];
- ushort id;
- Area* area;
- Area* sel;
- Area* oldsel;
- Area* revert;
- int selcol;
- Rectangle r;
-};
-
-/* Yuck. */
-#define VECTOR(type, nam, c) \
-typedef struct Vector_##nam Vector_##nam; \
-struct Vector_##nam { \
- type* ary; \
- long n; \
- long size; \
-}; \
-void vector_##c##free(Vector_##nam*); \
-void vector_##c##init(Vector_##nam*); \
-void vector_##c##push(Vector_##nam*, type); \
-
-VECTOR(long, long, l)
-VECTOR(Rectangle, rect, r)
-#undef VECTOR
+ Rule *rule;
+ char *string;
+ uint size;
+};
 
 #ifndef EXTERN
 # define EXTERN extern
@@ -257,33 +197,31 @@ VECTOR(Rectangle, rect, r)
 
 /* global variables */
 EXTERN struct {
- CTuple focuscolor;
- CTuple normcolor;
- Font* font;
- char* keys;
- uint keyssz;
+ CTuple focuscolor;
+ CTuple normcolor;
+ Font *font;
+ char *keys;
         Ruleset tagrules;
         Ruleset colrules;
- char grabmod[5];
- ulong mod;
- uint border;
- uint snap;
- int colmode;
+ char grabmod[5];
+ ulong mod;
+ uint border;
+ uint snap;
+ uint keyssz;
+ int colmode;
 } def;
 
 enum {
         BarLeft, BarRight
 };
 
-#define BLOCK(x) do { x; }while(0)
-
 EXTERN struct WMScreen {
- Bar* bar[2];
- View* sel;
- Client* focus;
- Client* hasgrab;
- Window* barwin;
- Image* ibuf;
+ Bar *bar[2];
+ View *sel;
+ Client *focus;
+ Client *hasgrab;
+ Window *barwin;
+ Image *ibuf;
 
         Rectangle r;
         Rectangle brect;
@@ -299,13 +237,6 @@ EXTERN Handlers framehandler;
 EXTERN Handlers framehandler;
 
 EXTERN char buffer[8092];
-EXTERN char* _buffer;
-static char* const _buf_end = buffer + sizeof buffer;
-
-#define bufclear() \
- BLOCK( _buffer = buffer; _buffer[0] = '\0' )
-#define bufprint(...) \
- _buffer = seprint(_buffer, _buf_end, __VA_ARGS__)
 
 /* IXP */
 EXTERN IxpServer srv;
@@ -314,8 +245,8 @@ EXTERN Ixp9Srv p9srv;
 /* X11 */
 EXTERN uint num_screens;
 EXTERN uint valid_mask;
-EXTERN uint numlock_mask;
-EXTERN bool sel_screen;
+EXTERN uint num_lock_mask;
+EXTERN Bool sel_screen;
 
 EXTERN Cursor cursor[CurLast];
 
@@ -323,12 +254,14 @@ EXTERN XHandler handler[LASTEvent];
 EXTERN XHandler handler[LASTEvent];
 
 /* Misc */
-EXTERN bool starting;
+EXTERN Image* broken;
+EXTERN Bool starting;
+EXTERN Bool verbose;
 EXTERN char* user;
 EXTERN char* execstr;
-EXTERN int debug;
-EXTERN long xtime;
-
-#define Debug(x) if(debug&(x))
-#define Dprint(x, ...) BLOCK( Debug(x) fprint(2, __VA_ARGS__) )
-
+
+#define BLOCK(x) do { x; }while(0)
+
+#define Debug if(verbose)
+#define Dprint(...) BLOCK( Debug fprint(2, __VA_ARGS__) )
+
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/div.c
--- a/cmd/wmii/div.c Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,163 +0,0 @@
-/* Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
- * See LICENSE file for license details.
- */
-#include "dat.h"
-#include "fns.h"
-
-static Image *divimg, *divmask;
-static CTuple divc;
-static Handlers handlers;
-
-static Divide*
-getdiv(Divide **dp) {
- WinAttr wa;
- Divide *d;
-
- if(*dp)
- return *dp;
-
- d = emallocz(sizeof *d);
-
- wa.override_redirect = True;
- wa.cursor = cursor[CurDHArrow];
- wa.event_mask =
- ExposureMask
- | EnterWindowMask
- | ButtonPressMask
- | ButtonReleaseMask;
- d->w = createwindow(&scr.root, Rect(0, 0, 1, 1), scr.depth, InputOutput, &wa,
- CWOverrideRedirect
- | CWEventMask
- | CWCursor);
- d->w->aux = d;
- sethandler(d->w, &handlers);
-
- *dp = d;
- return d;
-}
-
-static void
-mapdiv(Divide *d) {
- mapwin(d->w);
-}
-
-static void
-unmapdiv(Divide *d) {
- unmapwin(d->w);
-}
-
-void
-div_set(Divide *d, int x) {
- Rectangle r;
-
- d->x = x;
- r = rectaddpt(divimg->r, Pt(x - Dx(divimg->r)/2, 0));
- r.max.y = screen->brect.min.y;
-
- reshapewin(d->w, r);
- mapdiv(d);
-}
-
-static void
-drawimg(Image *img, ulong cbg, ulong cborder) {
- Point pt[6];
-
- pt[0] = Pt(0, 0);
- pt[1] = Pt(Dx(img->r)/2 - 1, Dx(img->r)/2 - 1);
-
- pt[2] = Pt(pt[1].x, Dy(img->r));
- pt[3] = Pt(Dx(img->r)/2, pt[2].y);
-
- pt[4] = Pt(pt[3].x, Dx(img->r)/2 - 1);
- pt[5] = Pt(Dx(img->r) - 1, 0);
-
- fillpoly(img, pt, nelem(pt), cbg);
- drawpoly(img, pt, nelem(pt), CapNotLast, 1, cborder);
-}
-
-static void
-drawdiv(Divide *d) {
- copyimage(d->w, divimg->r, divimg, ZP);
- setshapemask(d->w, divmask, ZP);
-}
-
-static void
-update_imgs(void) {
- Divide *d;
- int w, h;
-
- w = 2 * (labelh(def.font) / 3);
- w = max(w, 10);
- h = Dy(screen->sel->r);
-
- if(divimg) {
- if(w == Dx(divimg->r) && h == Dy(divimg->r)
- && !memcmp(&divc, &def.normcolor, sizeof(divc)))
- return;
- freeimage(divimg);
- freeimage(divmask);
- }
-
- divimg = allocimage(w, h, scr.depth);
- divmask = allocimage(w, h, 1);
- divc = def.normcolor;
-
- fill(divmask, divmask->r, 0);
- drawimg(divmask, 1, 1);
- drawimg(divimg, divc.bg, divc.border);
-
- for(d = divs; d && d->w->mapped; d = d->next)
- drawdiv(d);
-}
-
-void
-div_update_all(void) {
- Divide **dp, *d;
- Area *a;
- View *v;
-
- update_imgs();
-
- v = screen->sel;
- dp = &divs;
- for(a = v->area->next; a; a = a->next) {
- d = getdiv(dp);
- dp = &d->next;
- div_set(d, a->r.min.x);
-
- if(!a->next) {
- d = getdiv(dp);
- dp = &d->next;
- div_set(d, a->r.max.x);
- }
- }
- for(d = *dp; d; d = d->next)
- unmapdiv(d);
-}
-
-/* Div Handlers */
-static void
-bdown_event(Window *w, XButtonEvent *e) {
- Divide *d;
-
- USED(e);
-
- d = w->aux;
- mouse_resizecol(d);
-}
-
-static void
-expose_event(Window *w, XExposeEvent *e) {
- Divide *d;
-
- USED(e);
-
- d = w->aux;
- drawdiv(d);
-}
-
-static Handlers handlers = {
- .bdown = bdown_event,
- .expose = expose_event,
-};
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/event.c
--- a/cmd/wmii/event.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/event.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,4 +1,4 @@
-/* Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+/* Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #include "dat.h"
@@ -8,19 +8,15 @@
 
 void
 dispatch_event(XEvent *e) {
- Debug(DEvent)
- printevent(e);
- if(e->type < nelem(handler) && handler[e->type])
+ Debug printevent(e);
+ if(handler[e->type])
                 handler[e->type](e);
- else
- xext_event(e);
-}
-
-#define handle(w, fn, ev) \
- BLOCK(if((w)->handler->fn) (w)->handler->fn((w), ev))
+}
+
+#define handle(w, fn, ev) if(!(w)->handler->fn) {}else (w)->handler->fn((w), ev)
 
 uint
-flushevents(long event_mask, bool dispatch) {
+flushevents(long event_mask, Bool dispatch) {
         XEvent ev;
         uint n = 0;
 
@@ -29,37 +25,6 @@ flushevents(long event_mask, bool dispat
                         dispatch_event(&ev);
                 n++;
         }
- return n;
-}
-
-static Bool
-findenter(Display *d, XEvent *e, XPointer v) {
- long *l;
-
- l = (long*)v;
- if(*l)
- return False;
- if(e->type == EnterNotify)
- return True;
- if(e->type == MotionNotify)
- (*l)++;
- return False;
-}
-
-/* This isn't perfect. If there were motion events in the queue
- * before this was called, then it flushes nothing. If we don't
- * check for them, we might lose a legitamate enter event.
- */
-uint
-flushenterevents(void) {
- XEvent e;
- long l;
- int n;
-
- l = 0;
- n = 0;
- while(XCheckIfEvent(display, &e, findenter, (void*)&l))
- n++;
         return n;
 }
 
@@ -107,14 +72,6 @@ configurerequest(XEvent *e) {
 }
 
 static void
-clientmessage(XEvent *e) {
- XClientMessageEvent *ev;
-
- ev = &e->xclient;
- ewmh_clientmessage(ev);
-}
-
-static void
 destroynotify(XEvent *e) {
         XDestroyWindowEvent *ev;
         Window *w;
@@ -124,7 +81,7 @@ destroynotify(XEvent *e) {
         if((w = findwin(ev->window)))
                 handle(w, destroy, ev);
         else {
- Dprint(DGeneric, "DestroyWindow(%ux) (no handler)\n", (uint)ev->window);
+ Dprint("DestroyWindow(%ux) (no handler)\n", (uint)ev->window);
                 if((c = win2client(ev->window)))
                         fprint(2, "Badness: Unhandled DestroyNotify: "
                                 "Client: %p, Window: %W, Name: %s\n", c, &c->w, c->name);
@@ -137,7 +94,6 @@ enternotify(XEvent *e) {
         Window *w;
 
         ev = &e->xcrossing;
- xtime = ev->time;
         if(ev->mode != NotifyNormal)
                 return;
 
@@ -145,7 +101,7 @@ enternotify(XEvent *e) {
                 handle(w, enter, ev);
         else if(ev->window == scr.root.w) {
                 sel_screen = True;
- frame_draw_all();
+ draw_frames();
         }
 }
 
@@ -154,18 +110,17 @@ leavenotify(XEvent *e) {
         XCrossingEvent *ev;
 
         ev = &e->xcrossing;
- xtime = ev->time;
         if((ev->window == scr.root.w) && !ev->same_screen) {
                 sel_screen = True;
- frame_draw_all();
+ draw_frames();
         }
 }
 
 void
-print_focus(Client *c, const char *to) {
- Dprint(DFocus, "screen->focus: %p[%C] => %p[%C]\n",
+print_focus(Client *c, char *to) {
+ Dprint("screen->focus: %p[%C] => %p[%C]\n",
                         screen->focus, screen->focus, c, c);
- Dprint(DFocus, "\t%s => %s\n", clientname(screen->focus), to);
+ Dprint("\t%s => %s\n", clientname(screen->focus), to);
 }
 
 static void
@@ -206,7 +161,7 @@ focusin(XEvent *e) {
                         print_focus(&c_magic, "<magic>");
                         screen->focus = &c_magic;
                         if(c->sel)
- frame_draw(c->sel);
+ draw_frame(c->sel);
                 }
         }
 }
@@ -251,7 +206,6 @@ keypress(XEvent *e) {
         XKeyEvent *ev;
 
         ev = &e->xkey;
- xtime = ev->time;
         ev->state &= valid_mask;
         if(ev->window == scr.root.w)
                 kpress(scr.root.w, ev->state, (KeyCode) ev->keycode);
@@ -273,16 +227,17 @@ maprequest(XEvent *e) {
         XWindowAttributes wa;
 
         ev = &e->xmaprequest;
+
         if(!XGetWindowAttributes(display, ev->window, &wa))
                 return;
+
         if(wa.override_redirect) {
- /* Do I really want these? */
                 XSelectInput(display, ev->window,
- (StructureNotifyMask | PropertyChangeMask));
+ (StructureNotifyMask | PropertyChangeMask));
                 return;
         }
         if(!win2client(ev->window))
- client_create(ev->window, &wa);
+ create_client(ev->window, &wa);
 }
 
 static void
@@ -291,7 +246,6 @@ motionnotify(XEvent *e) {
         Window *w;
 
         ev = &e->xmotion;
- xtime = ev->time;
         if((w = findwin(ev->window)))
                 handle(w, motion, ev);
 }
@@ -302,7 +256,6 @@ propertynotify(XEvent *e) {
         Window *w;
 
         ev = &e->xproperty;
- xtime = ev->time;
         if((w = findwin(ev->window)))
                 handle(w, property, ev);
 }
@@ -333,7 +286,6 @@ void (*handler[LASTEvent]) (XEvent *) =
         [ButtonPress] = buttonpress,
         [ButtonRelease] = buttonrelease,
         [ConfigureRequest] = configurerequest,
- [ClientMessage] = clientmessage,
         [DestroyNotify] = destroynotify,
         [EnterNotify] = enternotify,
         [Expose] = expose,
@@ -358,5 +310,7 @@ check_x_event(IxpConn *c) {
         while(XPending(display)) {
                 XNextEvent(display, &ev);
                 dispatch_event(&ev);
- }
-}
+ /* Hack to alleviate an apparant Xlib bug */
+ XPending(display);
+ }
+}
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/ewmh.c
--- a/cmd/wmii/ewmh.c Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,488 +0,0 @@
-/* Copyright ©2007-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
- * See LICENSE file for license details.
- */
-#include "dat.h"
-#include <assert.h>
-#include <sys/limits.h>
-#include "fns.h"
-
-Window *ewmhwin;
-
-#define Net(x) ("_NET_" x)
-#define Action(x) ("_NET_WM_ACTION_" x)
-#define State(x) ("_NET_WM_STATE_" x)
-#define Type(x) ("_NET_WM_WINDOW_TYPE_" x)
-#define NET(x) xatom(Net(x))
-#define ACTION(x) xatom(Action(x))
-#define STATE(x) xatom(State(x))
-#define TYPE(x) xatom(Type(x))
-
-void
-ewmh_init(void) {
- WinAttr wa;
- char myname[] = "wmii";
- long win[1];
-
- ewmhwin = createwindow(&scr.root,
- Rect(0, 0, 1, 1), 0 /*depth*/,
- InputOnly, &wa, 0);
-
- win[0] = ewmhwin->w;
- changeprop_long(&scr.root, Net("SUPPORTING_WM_CHECK"), "WINDOW", win, 1);
- changeprop_long(ewmhwin, Net("SUPPORTING_WM_CHECK"), "WINDOW", win, 1);
- changeprop_string(ewmhwin, Net("WM_NAME"), myname);
- changeprop_long(&scr.root, Net("DESKTOP_VIEWPORT"), "CARDINAL",
- (long[]){0, 0}, 2);
-
- long supported[] = {
- /* Misc */
- NET("SUPPORTED"),
- /* Root Properties */
- NET("ACTIVE_WINDOW"),
- NET("CURRENT_DESKTOP"),
- /* Client Properties */
- NET("WM_NAME"),
- NET("WM_STRUT_PARTIAL"),
- NET("WM_DESKTOP"),
- NET("FRAME_EXTENTS"),
- /* States */
- NET("WM_STATE"),
- STATE("DEMANDS_ATTENTION"),
- STATE("FULLSCREEN"),
- STATE("SHADED"),
- /* Window Types */
- NET("WM_WINDOW_TYPE"),
- TYPE("DIALOG"),
- TYPE("DOCK"),
- TYPE("NORMAL"),
- TYPE("SPLASH"),
- /* Actions */
- NET("WM_ALLOWED_ACTIONS"),
- ACTION("FULLSCREEN"),
- /* Desktops */
- NET("DESKTOP_NAMES"),
- NET("NUMBER_OF_DESKTOPS"),
- /* Client List */
- NET("CLIENT_LIST"),
- NET("CLIENT_LIST_STACKING"),
- };
- changeprop_long(&scr.root, Net("SUPPORTED"), "ATOM", supported, nelem(supported));
-}
-
-void
-ewmh_updateclientlist(void) {
- Client *c;
- long *list;
- int i;
-
- i = 0;
- for(c=client; c; c=c->next)
- i++;
- list = emalloc(i * sizeof *list);
- for(c=client, i=0; c; c=c->next)
- list[i++] = c->w.w;
- changeprop_long(&scr.root, Net("CLIENT_LIST"), "WINDOW", list, i);
-}
-
-void
-ewmh_updatestacking(void) {
- Vector_long vec;
- Frame *f;
- Area *a;
- View *v;
-
- vector_linit(&vec);
-
- for(v=view; v; v=v->next)
- for(f=v->area->stack; f; f=f->snext)
- if(f->client->sel == f)
- vector_lpush(&vec, f->client->w.w);
- for(v=view; v; v=v->next)
- for(a=v->area->next; a; a=a->next)
- for(f=a->frame; f; f=f->anext)
- if(f->client->sel == f)
- vector_lpush(&vec, f->client->w.w);
-
- changeprop_long(&scr.root, Net("CLIENT_LIST_STACKING"), "WINDOW", vec.ary, vec.n);
- vector_lfree(&vec);
-}
-
-void
-ewmh_initclient(Client *c) {
- long allowed[] = {
- ACTION("FULLSCREEN"),
- };
-
- changeprop_long(&c->w, Net("WM_ALLOWED_ACTIONS"), "ATOM",
- allowed, nelem(allowed));
- ewmh_getwintype(c);
- ewmh_updateclientlist();
-}
-
-void
-ewmh_destroyclient(Client *c) {
- Ewmh *e;
-
- ewmh_updateclientlist();
-
- e = &c->w.ewmh;
- if(e->timer)
- if(!ixp_unsettimer(&srv, e->timer))
- fprint(2, "Badness: %C: Can't unset timer\n", c);
-}
-
-static void
-pingtimeout(long id, void *v) {
- Client *c;
-
- c = v;
- event("Unresponsive %C\n", c);
- c->w.ewmh.ping = 0;
- c->w.ewmh.timer = 0;
-}
-
-void
-ewmh_pingclient(Client *c) {
- Ewmh *e;
-
- if(!(c->proto & ProtoPing))
- return;
-
- e = &c->w.ewmh;
- if(e->ping)
- return;
-
- sendmessage(&c->w, "WM_PROTOCOLS", Net("WM_PING"), c->w.w, 0, 0);
- e->ping = xtime++;
- e->timer = ixp_settimer(&srv, PingTime, pingtimeout, c);
-}
-
-int
-ewmh_prop(Client *c, Atom a) {
- if(a == NET("WM_WINDOW_TYPE"))
- ewmh_getwintype(c);
- else
- if(a == NET("WM_STRUT_PARTIAL"))
- ewmh_getstrut(c);
- else
- return 0;
- return 1;
-}
-
-typedef struct Prop Prop;
-struct Prop {
- char* name;
- long mask;
- Atom atom;
-};
-
-static long
-getmask(Prop *props, long *vals, int n) {
- Prop *p;
- long ret;
-
- if(props[0].atom == 0)
- for(p=props; p->name; p++)
- p->atom = xatom(p->name);
-
- ret = 0;
- while(n--) {
- Dprint(DEwmh, "\tvals[%d] = \"%A\"\n", n, vals[n]);
- for(p=props; p->name; p++)
- if(p->atom == vals[n]) {
- ret |= p->mask;
- break;
- }
- }
- return ret;
-}
-
-void
-ewmh_getwintype(Client *c) {
- static Prop props[] = {
- {Type("DESKTOP"), TypeDesktop},
- {Type("DOCK"), TypeDock},
- {Type("TOOLBAR"), TypeToolbar},
- {Type("MENU"), TypeMenu},
- {Type("UTILITY"), TypeUtility},
- {Type("SPLASH"), TypeSplash},
- {Type("DIALOG"), TypeDialog},
- {Type("NORMAL"), TypeNormal},
- {0, }
- };
- long *types;
- long n, mask;
-
- n = getprop_long(&c->w, Net("WM_WINDOW_TYPE"), "ATOM",
- 0L, &types, 16);
- Dprint(DEwmh, "ewmh_getwintype(%C) n = %ld\n", c, n);
- mask = getmask(props, types, n);
- free(types);
-
- c->w.ewmh.type = mask;
- if(mask & TypeDock) {
- c->borderless = 1;
- c->titleless = 1;
- }
-}
-
-long
-ewmh_protocols(Window *w) {
- static Prop props[] = {
- {"WM_DELETE_WINDOW", ProtoDelete},
- {"WM_TAKE_FOCUS", ProtoTakeFocus},
- {Net("WM_PING"), ProtoPing},
- {0, }
- };
- long *protos;
- long n, mask;
-
- n = getprop_long(w, "WM_PROTOCOLS", "ATOM",
- 0L, &protos, 16);
- Dprint(DEwmh, "ewmh_protocols(%W) n = %ld\n", w, n);
- mask = getmask(props, protos, n);
- free(protos);
- return mask;
-}
-
-void
-ewmh_getstrut(Client *c) {
- enum {
- Left, Right, Top, Bottom,
- LeftMin, LeftMax,
- RightMin, RightMax,
- TopMin, TopMax,
- BottomMin, BottomMax,
- Last = BottomMax
- };
- long *strut;
- ulong n;
-
- if(c->strut)
- free(c->strut);
- c->strut = nil;
-
- n = getprop_long(&c->w, Net("WM_STRUT_PARTIAL"), "CARDINAL",
- 0L, &strut, Last);
- if(n != nelem(strut)) {
- free(strut);
- n = getprop_long(&c->w, Net("WM_STRUT"), "CARDINAL",
- 0L, &strut, 4L);
- if(n != 4) {
- free(strut);
- return;
- }
- strut = erealloc(strut, Last * sizeof *strut);
- strut[LeftMin] = strut[RightMin] = 0;
- strut[LeftMax] = strut[RightMax] = INT_MAX;
- strut[TopMin] = strut[BottomMin] = 0;
- strut[TopMax] = strut[BottomMax] = INT_MAX;
- }
- c->strut = emalloc(sizeof *c->strut);
- c->strut->left = Rect(0, strut[LeftMin], strut[Left], strut[LeftMax]);
- c->strut->right = Rect(-strut[Right], strut[RightMin], 0, strut[RightMax]);
- c->strut->top = Rect(strut[TopMin], 0, strut[TopMax], strut[Top]);
- c->strut->bottom = Rect(strut[BottomMin], -strut[Bottom], strut[BottomMax], 0);
- free(strut);
-}
-
-int
-ewmh_clientmessage(XClientMessageEvent *e) {
- Client *c;
- View *v;
- long *l;
- int msg, action, i;
-
- l = e->data.l;
- msg = e->message_type;
- Dprint(DEwmh, "ClientMessage: %A\n", msg);
-
- if(msg == NET("WM_STATE")) {
- enum {
- StateUnset,
- StateSet,
- StateToggle,
- };
- if(e->format != 32)
- return -1;
- c = win2client(e->window);
- if(c == nil)
- return 0;
- switch(l[0]) {
- case StateUnset: action = Off; break;
- case StateSet: action = On; break;
- case StateToggle: action = Toggle; break;
- default:
- return -1;
- }
- Dprint(DEwmh, "\tAction: %s\n", TOGGLE(action));
- for(i = 1; i <= 2; i++) {
- if(l[i] == 0)
- break;
- Dprint(DEwmh, "\tl[%d] = %A\n", i, l[i]);
- if(l[i] == STATE("FULLSCREEN"))
- fullscreen(c, action);
- else
- if(l[i] == STATE("DEMANDS_ATTENTION"))
- client_seturgent(c, action, UrgClient);
- }
- return 1;
- }else
- if(msg == NET("ACTIVE_WINDOW")) {
- if(e->format != 32)
- return -1;
- Dprint(DEwmh, "\tsource: %ld\n", l[0]);
- Dprint(DEwmh, "\twindow: 0x%lx\n", e->window);
- c = win2client(e->window);
- if(c == nil)
- return 1;
- Dprint(DEwmh, "\tclient: %s\n", clientname(c));
- if(l[0] != 2)
- return 1;
- focus(c, true);
- return 1;
- }else
- if(msg == NET("CURRENT_DESKTOP")) {
- if(e->format != 32)
- return -1;
- for(v=view, i=l[0]; v; v=v->next, i--)
- if(i == 0)
- break;
- Dprint(DEwmh, "\t%s\n", v->name);
- if(i == 0)
- view_select(v->name);
- return 1;
- }else
- if(msg == xatom("WM_PROTOCOLS")) {
- Dprint(DEwmh, "\t%A\n", l[0]);
- if(l[0] == NET("WM_PING")) {
- if(e->format != 32)
- return -1;
- if(e->window != scr.root.w)
- return -1;
- c = win2client(l[2]);
- if(c == nil)
- return 1;
- Dprint(DEwmh, "\tclient = [%C]\"%s\"\n", c, clientname(c));
- Dprint(DEwmh, "\ttimer = %ld, ping = %ld\n",
- c->w.ewmh.timer, c->w.ewmh.ping);
- if(c->w.ewmh.timer)
- ixp_unsettimer(&srv, c->w.ewmh.timer);
- c->w.ewmh.timer = 0;
- c->w.ewmh.ping = 0;
- return 1;
- }
- }
-
- return 0;
-}
-
-void
-ewmh_framesize(Client *c) {
- Rectangle r;
- Frame *f;
-
- f = c->sel;
- r.min.x = f->crect.min.x;
- r.min.y = f->crect.min.y;
- r.max.x = f->r.max.x - f->crect.max.x;
- r.max.y = f->r.max.y - f->crect.max.y;
-
- long extents[] = {
- r.min.x, r.max.x,
- r.min.y, r.max.y,
- };
- changeprop_long(&c->w, Net("FRAME_EXTENTS"), "CARDINAL",
- extents, nelem(extents));
-}
-
-void
-ewmh_updatestate(Client *c) {
- long state[16];
- Frame *f;
- int i;
-
- f = c->sel;
- if(f == nil || f->view != screen->sel)
- return;
-
- i = 0;
- if(f->collapsed)
- state[i++] = STATE("SHADED");
- if(c->fullscreen)
- state[i++] = STATE("FULLSCREEN");
- if(c->urgent)
- state[i++] = STATE("DEMANDS_ATTENTION");
-
- if(i > 0)
- changeprop_long(&c->w, Net("WM_STATE"), "ATOM", state, i);
- else
- delproperty(&c->w, Net("WM_STATE"));
-}
-
-/* Views */
-void
-ewmh_updateviews(void) {
- View *v;
- char **tags;
- long i;
-
- if(starting)
- return;
-
- for(v=view, i=0; v; v=v->next)
- i++;
- tags = emalloc((i + 1) * sizeof *tags);
- for(v=view, i=0; v; v=v->next)
- tags[i++] = v->name;
- tags[i] = nil;
- changeprop_textlist(&scr.root, Net("DESKTOP_NAMES"), "UTF8_STRING", tags);
- changeprop_long(&scr.root, Net("NUMBER_OF_DESKTOPS"), "CARDINAL", &i, 1);
- ewmh_updateview();
- ewmh_updateclients();
-}
-
-static int
-viewidx(View *v) {
- View *vp;
- int i;
-
- for(vp=view, i=0; vp; vp=vp->next, i++)
- if(vp == v)
- break;
- assert(vp);
- return i;
-}
-
-void
-ewmh_updateview(void) {
- long i;
-
- if(starting)
- return;
-
- i = viewidx(screen->sel);
- changeprop_long(&scr.root, Net("CURRENT_DESKTOP"), "CARDINAL", &i, 1);
-}
-
-void
-ewmh_updateclient(Client *c) {
- long i;
-
- i = -1;
- if(c->sel)
- i = viewidx(c->sel->view);
- changeprop_long(&c->w, Net("WM_DESKTOP"), "CARDINAL", &i, 1);
-}
-
-void
-ewmh_updateclients(void) {
- Client *c;
-
- if(starting)
- return;
-
- for(c=client; c; c=c->next)
- ewmh_updateclient(c);
-}
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/float.c
--- a/cmd/wmii/float.c Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,144 +0,0 @@
-/* Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
- * See LICENSE file for license details.
- */
-#include "dat.h"
-#include <sys/limits.h>
-#include "fns.h"
-
-static void float_placeframe(Frame*);
-
-void
-float_attach(Area *a, Frame *f) {
-
- f->client->floating = true;
-
- float_placeframe(f);
- frame_insert(f, a->sel);
-
- if(a->sel == nil)
- area_setsel(a, f);
-}
-
-void
-float_detach(Frame *f) {
- Frame *pr;
- Area *a, *sel;
- View *v;
-
- v = f->view;
- a = f->area;
- sel = view_findarea(v, v->selcol, false);
- pr = f->aprev;
-
- frame_remove(f);
-
- f->area = nil;
- if(a->sel == f) {
- if(!pr)
- pr = a->frame;
- a->sel = nil;
- area_setsel(a, pr);
- }
-
- if(v->oldsel)
- area_focus(v->oldsel);
- else if(!a->frame)
- if(sel->frame)
- area_focus(sel);
-}
-
-static void
-rect_push(Vector_rect *vec, Rectangle r) {
- Rectangle *rp;
- int i;
-
- for(i=0; i < vec->n; i++) {
- rp = &vec->ary[i];
- if(rect_contains_p(*rp, r))
- return;
- if(rect_contains_p(r, *rp)) {
- *rp = r;
- return;
- }
- }
- vector_rpush(vec, r);
-}
-
-static void
-float_placeframe(Frame *f) {
- static Vector_rect rvec, rvec2;
- Vector_rect *vp, *vp2, *vptemp;
- Rectangle *rp;
- Rectangle r, fr;
- Point dim, p;
- Client *c;
- Frame *ff;
- Area *a;
- long area, l;
- int i;
-
- a = f->area;
- c = f->client;
-
- if(c->trans)
- return;
- if(c->fullscreen || c->w.hints->position || starting) {
- f->r = client_grav(c, c->r);
- return;
- }
-
- dim.x = Dx(f->r);
- dim.y = Dy(f->r);
-
- rvec.n = 0;
- rvec2.n = 0;
- vp = &rvec;
- vp2 = &rvec2;
-
- /* Find all rectangles on the floating layer into which
- * the new frame would fit. (Please ignore the man behind
- * the curtain).
- */
- vector_rpush(vp, a->r);
- for(ff=a->frame; ff; ff=ff->anext) {
- fr = ff->r;
- vp2->n = 0;
- for(i=0; i < vp->n; i++) {
- r = vp->ary[i];
- if(!rect_intersect_p(fr, r)) {
- rect_push(vp2, r);
- continue;
- }
- if(r.min.x < fr.min.x && fr.min.x - r.min.x >= dim.x)
- rect_push(vp2, Rect(r.min.x, r.min.y, fr.min.x, r.max.y));
- if(r.max.x > fr.max.x && r.max.x - fr.max.x >= dim.x)
- rect_push(vp2, Rect(fr.max.x, r.min.y, r.max.x, r.max.y));
- if(r.min.y < fr.min.y && fr.min.y - r.min.y >= dim.y)
- rect_push(vp2, Rect(r.min.x, r.min.y, r.max.x, fr.min.y));
- if(r.max.y > fr.max.y && r.max.y - fr.max.y >= dim.y)
- rect_push(vp2, Rect(r.min.x, fr.max.y, r.max.x, r.max.y));
- }
- vptemp = vp;
- vp = vp2;
- vp2 = vptemp;
- }
-
- if(vp->n == 0) {
- p.x = random() % max(0, Dx(a->r) - dim.x);
- p.y = random() % max(0, Dy(a->r) - dim.y);
- }else {
- area = LONG_MAX;
- for(i=0; i < vp->n; i++) {
- rp = &vp->ary[i];
- l = Dx(*rp) * Dy(*rp);
- if(l < area) {
- area = l;
- p = rp->min;
- }
- }
- }
-
- fr = rectsubpt(f->r, f->r.min);
- f->r = rectaddpt(fr, p);
-}
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/fns.h Fri Jan 18 15:05:45 2008 -0500
@@ -1,128 +1,101 @@
-/* Copyright ©2007-2008 Kris Maglione <jg_AT_suckless.org>
+/* © 2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
  * See LICENSE file for license details.
  */
 
 #ifdef VARARGCK
-# pragma varargck argpos event 1
+# pragma varargck argpos write_event 1
 #
 # pragma varargck type "C" Client*
+# pragma varargck type "W" Window*
+# pragma varargck type "P" Point
+# pragma varargck type "R" Rectangle
 # pragma varargck type "r" void
 #endif
 
 /* area.c */
-void area_attach(Area*, Frame*);
-Area* area_create(View*, Area *pos, uint w);
-void area_destroy(Area*);
-void area_detach(Frame*);
-void area_focus(Area*);
 uint area_idx(Area*);
-void area_moveto(Area*, Frame*);
 char* area_name(Area*);
 Client* area_selclient(Area*);
-void area_setsel(Area*, Frame*);
+void attach_to_area(Area*, Frame*);
+Area* create_area(View*, Area *pos, uint w);
+void destroy_area(Area*);
+void detach_from_area(Frame*);
+void focus_area(Area*);
+void send_to_area(Area*, Frame*);
 
 /* bar.c */
-Bar* bar_create(Bar**, const char*);
-void bar_destroy(Bar**, Bar*);
-void bar_draw(WMScreen*);
-Bar* bar_find(Bar*, const char*);
-void bar_init(WMScreen*);
-void bar_resize(WMScreen*);
+Bar* bar_of_name(Bar*, const char*);
+Bar* create_bar(Bar**, char*);
+void destroy_bar(Bar**, Bar*);
+void draw_bar(WMScreen*);
+void initbar(WMScreen*);
+void resize_bar(WMScreen*);
 
 /* client.c */
 int Cfmt(Fmt *f);
 void apply_rules(Client*);
 void apply_tags(Client*, const char*);
-void client_configure(Client*);
-Client* client_create(XWindow, XWindowAttributes*);
-void client_destroy(Client*);
-bool client_floats_p(Client*);
-void client_focus(Client*);
-Frame* client_groupframe(Client*, View*);
-void client_kill(Client*, bool);
-void client_manage(Client*);
-void client_map(Client*);
-void client_prop(Client*, Atom);
-void client_reparent(Client*, Window*, Point);
-void client_resize(Client*, Rectangle);
-void client_setcursor(Client*, Cursor);
-void client_seturgent(Client*, bool, int);
-void client_unmap(Client*, int state);
-Frame* client_viewframe(Client *c, View *v);
 char* clientname(Client*);
-void focus(Client*, bool restack);
-void fullscreen(Client*, int);
+void configure_client(Client*);
+Client* create_client(XWindow, XWindowAttributes*);
+void destroy_client(Client*);
+void focus(Client*, Bool restack);
+void focus_client(Client*);
+void focus_frame(Frame*, Bool restack);
+void fullscreen(Client*, Bool);
+void kill_client(Client*);
+void manage_client(Client*);
+void map_client(Client*);
 int map_frame(Client*);
+void move_client(Client*, char*);
+void prop_client(Client*, Atom);
+void reparent_client(Client*, Window*, Point);
+void resize_client(Client*, Rectangle);
 Client* selclient(void);
+void set_cursor(Client*, Cursor);
+void set_urgent(Client *, Bool urgent, Bool write);
+void size_client(Client*, char*);
+void unmap_client(Client*, int state);
 int unmap_frame(Client*);
 void update_class(Client*);
 Client* win2client(XWindow);
-Rectangle client_grav(Client*, Rectangle);
+Rectangle gravclient(Client*, Rectangle);
 
 /* column.c */
-char* colmode2str(uint);
-void column_arrange(Area*, bool dirty);
-void column_attach(Area*, Frame*);
-void column_detach(Frame*);
-void column_insert(Area*, Frame*, Frame*);
-Area* column_new(View*, Area *, uint);
-void column_remove(Frame*, bool);
-void column_resize(Area*, int);
-void column_resizeframe(Frame*, Rectangle*);
-void div_draw(Divide*);
-void div_set(Divide*, int x);
-void div_update_all(void);
+void arrange_column(Area*, Bool dirty);
+char* colmode2str(int);
+void draw_div(Divide*);
+Area* new_column(View*, Area *, uint);
+void resize_colframe(Frame*, Rectangle*);
+void resize_column(Area*, int);
+void setdiv(Divide*, int x);
 int str2colmode(const char*);
+void update_divs(void);
 
 /* event.c */
 void check_x_event(IxpConn*);
 void dispatch_event(XEvent*);
-uint flushenterevents(void);
-uint flushevents(long, bool dispatch);
-void print_focus(Client*, const char*);
-
-/* ewmh.c */
-int ewmh_clientmessage(XClientMessageEvent*);
-void ewmh_destroyclient(Client*);
-void ewmh_framesize(Client*);
-void ewmh_getstrut(Client*);
-void ewmh_getwintype(Client*);
-void ewmh_init(void);
-void ewmh_initclient(Client*);
-void ewmh_pingclient(Client*);
-int ewmh_prop(Client*, Atom);
-long ewmh_protocols(Window*);
-void ewmh_updateclient(Client*);
-void ewmh_updateclientlist(void);
-void ewmh_updateclients(void);
-void ewmh_updatestacking(void);
-void ewmh_updatestate(Client*);
-void ewmh_updateview(void);
-void ewmh_updateviews(void);
-
-/* float.c */
-void float_attach(Area*, Frame*);
-void float_detach(Frame*);
+uint flushevents(long, Bool dispatch);
+void print_focus(Client*, char*);
 
 /* frame.c */
-Frame* frame_create(Client*, View*);
+Frame* create_frame(Client*, View*);
+void draw_frame(Frame*);
+void draw_frames(void);
 int frame_delta_h(void);
-void frame_draw(Frame*);
-void frame_draw_all(void);
-void frame_focus(Frame*);
 uint frame_idx(Frame*);
-void frame_insert(Frame*, Frame *pos);
-void frame_remove(Frame*);
-void frame_resize(Frame*, Rectangle);
-bool frame_restack(Frame*, Frame*);
-void frame_setcursor(Frame*, Point);
-void frame_swap(Frame*, Frame*);
-int ingrabbox_p(Frame*, int x, int y);
-void move_focus(Frame*, Frame*);
+Bool frame_to_top(Frame*);
+int ingrabbox(Frame*, int x, int y);
+void insert_frame(Frame *pos, Frame*);
+void remove_frame(Frame*);
+void resize_frame(Frame*, Rectangle);
+void set_frame_cursor(Frame*, Point);
+void swap_frames(Frame*, Frame*);
+void update_frame_widget_colors(Frame*);
 Rectangle constrain(Rectangle);
-Rectangle frame_client2rect(Frame*, Rectangle);
+Rectangle client2frame(Frame*, Rectangle);
+Rectangle frame2client(Frame*, Rectangle);
 Rectangle frame_hints(Frame*, Rectangle, Align);
-Rectangle frame_rect2client(Frame*, Rectangle);
 
 /* fs.c */
 void fs_attach(Ixp9Req*);
@@ -136,78 +109,136 @@ void fs_stat(Ixp9Req*);
 void fs_stat(Ixp9Req*);
 void fs_walk(Ixp9Req*);
 void fs_write(Ixp9Req*);
-void event(const char*, ...);
+void write_event(char*, ...);
 
 /* geom.c */
+Cursor cursor_of_quad(Align);
 Align get_sticky(Rectangle src, Rectangle dst);
-Cursor quad_cursor(Align);
+Bool ptinrect(Point, Rectangle);
 Align quadrant(Rectangle, Point);
-bool rect_contains_p(Rectangle, Rectangle);
-bool rect_haspoint_p(Point, Rectangle);
-bool rect_intersect_p(Rectangle, Rectangle);
-Rectangle rect_intersection(Rectangle, Rectangle);
 
 /* key.c */
 void init_lock_keys(void);
 void kpress(XWindow, ulong mod, KeyCode);
-ulong str2modmask(const char*);
+ulong str2modmask(char*);
 void update_keys(void);
 
 /* map.c */
-MapEnt* hash_get(Map*, const char*, int create);
-void* hash_rm(Map*, const char*);
-MapEnt* map_get(Map*, ulong, int create);
-void* map_rm(Map*, ulong);
+MapEnt* hashget(Map*, char*, int create);
+void* hashrm(Map*, char*);
+MapEnt* mapget(Map*, ulong, int create);
+void* maprm(Map*, ulong);
 
 /* message.c */
-int getlong(const char*, long*);
-int getulong(const char*, ulong*);
+int getlong(char*, long*);
+int getulong(char*, ulong*);
+char* getword(IxpMsg*);
 char* message_client(Client*, IxpMsg*);
 char* message_root(void*, IxpMsg*);
 char* message_view(View*, IxpMsg*);
-char* msg_getword(IxpMsg*);
-char* msg_parsecolors(IxpMsg*, CTuple*);
-char* msg_selectarea(Area*, IxpMsg*);
-char* msg_sendclient(View*, IxpMsg*, bool swap);
-char* readctl_root(void);
-char* readctl_view(View*);
-Area* strarea(View*, const char*);
+char* parse_colors(IxpMsg*, CTuple*);
+char* read_root_ctl(void);
+char* select_area(Area*, IxpMsg*);
+char* send_client(View*, IxpMsg*, Bool swap);
+Area* strarea(View*, char*);
 
 /* mouse.c */
-void mouse_resize(Client*, bool opaque, Align);
+void do_mouse_resize(Client*, Bool opaque, Align);
+void grab_button(XWindow, uint button, ulong mod);
+void grab_mouse(XWindow, ulong mod, ulong button);
 void mouse_resizecol(Divide*);
-void grab_button(XWindow, uint button, ulong mod);
 Align snap_rect(Rectangle *rects, int num, Rectangle *current, Align *mask, int snapw);
+void ungrab_mouse(XWindow, ulong mod, uint button);
 
 /* rule.c */
 void trim(char *str, const char *chars);
 void update_rules(Rule**, const char*);
 
 /* view.c */
-void view_arrange(View*);
-void view_attach(View*, Frame*);
-View* view_create(const char*);
-void view_destroy(View*);
-Area* view_findarea(View*, int, bool);
-void view_focus(WMScreen*, View*);
-bool view_fullscreen_p(View*);
-char* view_index(View*);
-uint view_newcolw(View*, int i);
-void view_restack(View*);
-void view_scale(View*, int w);
+View *get_view(const char*);
+void arrange_view(View*);
+void attach_to_view(View*, Frame*);
+View* create_view(const char*);
+void destroy_view(View*);
+void focus_view(WMScreen*, View*);
+char* message_view(View *v, IxpMsg *m);
+uint newcolw(View*, int i);
+void restack_view(View*);
+void scale_view(View*, int w);
+void select_view(const char*);
+void update_client_views(Client*, char**);
+void update_views(void);
+Frame* view_clientframe(View *v, Client *c);
+uchar* view_ctl(View *v);
+uchar* view_index(View*);
+View* view_of_id(ushort);
 Client* view_selclient(View*);
-void view_select(const char*);
-void client_setviews(Client*, char**);
-void view_update_all(void);
-Rectangle* view_rects(View*, uint *num, Frame *ignore);
+Rectangle* rects_of_view(View*, uint *num, Frame *ignore);
+
+/* wm.c */
+int win_proto(Window);
+
+/* x11.c */
+Window *createwindow(Window *parent, Rectangle, int depth, uint class, WinAttr*, int valuemask);
+char *gettextproperty(Window*, char*);
+Point addpt(Point, Point);
+Image* allocimage(int w, int h, int depth);
+void border(Image *dst, Rectangle, int w, ulong col);
+void changeprop_char(Window *w, char *prop, char *type, char data[], int len);
+void changeprop_long(Window *w, char *prop, char *type, long data[], int len);
+void changeprop_short(Window *w, char *prop, char *type, short data[], int len);
+void changeproperty(Window*, char *prop, char *type, int width, uchar *data, int n);
+void copyimage(Image *dst, Rectangle, Image *src, Point p);
+void destroywindow(Window*);
+Point divpt(Point, Point);
+void drawline(Image *dst, Point p1, Point p2, int cap, int w, ulong col);
+void drawpoly(Image *dst, Point *pt, int np, int cap, int w, ulong col);
+void drawstring(Image *dst, Font *font, Rectangle, Align align, char *text, ulong col);
+int eqpt(Point, Point);
+int eqrect(Rectangle, Rectangle);
+void fill(Image *dst, Rectangle, ulong col);
+void fillpoly(Image *dst, Point *pt, int np, ulong col);
+Window* findwin(XWindow);
+void freefont(Font*);
+void freeimage(Image *);
+void freestringlist(char**);
+ulong getproperty(Window *w, char *prop, char *type, Atom *actual, ulong offset, uchar **ret, ulong length);
+int gettextlistproperty(Window *w, char *name, char **ret[]);
+int grabpointer(Window*, Window *confine, Cursor, int mask);
+void initdisplay(void);
+uint labelh(Font*);
+Bool loadcolor(CTuple*, char*);
+Font* loadfont(char*);
+void lowerwin(Window*);
+int mapwin(Window*);
+void movewin(Window*, Point);
+Point mulpt(Point p, Point q);
+Bool namedcolor(char *name, ulong*);
+Point querypointer(Window*);
+void raisewin(Window*);
+void reparentwindow(Window*, Window*, Point);
+void reshapewin(Window*, Rectangle);
+void setfocus(Window*, int mode);
+void sethints(Window*);
+void setshapemask(Window *dst, Image *src, Point);
+void setwinattr(Window*, WinAttr*, int valmask);
+Point subpt(Point, Point);
+uint textwidth(Font*, char*);
+uint textwidth_l(Font*, char*, uint len);
+Point translate(Window*, Window*, Point);
+void ungrabpointer(void);
+int unmapwin(Window*);
+void warppointer(Point);
+uint winprotocols(Window*);
+Atom xatom(char*);
+Handlers* sethandler(Window*, Handlers*);
+XRectangle XRect(Rectangle);
+Rectangle gravitate(Rectangle dst, Rectangle src, Point grav);
+Rectangle insetrect(Rectangle, int);
+Rectangle rectaddpt(Rectangle, Point);
+Rectangle rectsubpt(Rectangle, Point);
+Rectangle sizehint(WinHints*, Rectangle);
 
 /* utf.c */
-char* toutf8(const char*);
-char* toutf8n(const char*, size_t);
-
-/* xext.c */
-void randr_event(XEvent*);
-void randr_init(void);
-void xext_event(XEvent*);
-void xext_init(void);
-
+char* toutf8(char*);
+char* toutf8n(char*, size_t);
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/frame.c
--- a/cmd/wmii/frame.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/frame.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,4 +1,4 @@
-/* Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+/* Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #include "dat.h"
@@ -16,8 +16,8 @@ frame_idx(Frame *f) {
         return i;
 }
 
-Frame*
-frame_create(Client *c, View *v) {
+Frame *
+create_frame(Client *c, View *v) {
         static ushort id = 1;
         Frame *f;
 
@@ -31,18 +31,17 @@ frame_create(Client *c, View *v) {
                 f->r = c->sel->r;
         }
         else{
- f->r = frame_client2rect(f, client_grav(c, ZR));
+ f->r = client2frame(f, gravclient(c, ZR));
                 f->revert = f->r;
                 c->sel = f;
         }
- f->collapsed = false;
- f->oldarea = -1;
+ f->collapsed = False;
 
         return f;
 }
 
 void
-frame_remove(Frame *f) {
+remove_frame(Frame *f) {
         Area *a;
 
         a = f->area;
@@ -65,7 +64,7 @@ frame_remove(Frame *f) {
 }
 
 void
-frame_insert(Frame *f, Frame *pos) {
+insert_frame(Frame *pos, Frame *f) {
         Area *a;
 
         a = f->area;
@@ -90,42 +89,32 @@ frame_insert(Frame *f, Frame *pos) {
         }
 }
 
-bool
-frame_restack(Frame *f, Frame *above) {
+Bool
+frame_to_top(Frame *f) {
         Area *a;
 
         a = f->area;
- if(!a->floating)
- return false;
- if(above && above->area != a)
- return false;
+ if(!a->floating || f == a->stack)
+ return False;
 
         if(f->sprev)
                 f->sprev->snext = f->snext;
- else
- a->stack = f->snext;
         if(f->snext)
                 f->snext->sprev = f->sprev;
 
- f->sprev = above;
- if(above == nil) {
- f->snext = a->stack;
- a->stack = f;
- }
- else {
- f->snext = above->snext;
- above->snext = f;
- }
+ f->snext = a->stack;
+ a->stack = f;
+ f->sprev = nil;
         if(f->snext)
                 f->snext->sprev = f;
 
- return true;
+ return True;
 }
 
 /* Handlers */
 static void
 bup_event(Window *w, XButtonEvent *e) {
- event("ClientClick %C %d\n", w->aux, e->button);
+ write_event("ClientClick %C %d\n", w->aux, e->button);
 }
 
 static void
@@ -139,15 +128,15 @@ bdown_event(Window *w, XButtonEvent *e)
         if((e->state & def.mod) == def.mod) {
                 switch(e->button) {
                 case Button1:
- mouse_resize(c, false, Center);
- focus(c, false);
- frame_restack(f, nil);
- focus(c, false); /* Blech */
+ do_mouse_resize(c, False, CENTER);
+ focus(c, True);
+ frame_to_top(f);
+ focus(c, True);
                         break;
                 case Button3:
- mouse_resize(c, false, quadrant(f->r, Pt(e->x_root, e->y_root)));
- frame_restack(f, nil);
- focus(c, false);
+ do_mouse_resize(c, False, quadrant(f->r, Pt(e->x_root, e->y_root)));
+ frame_to_top(f);
+ focus(c, True);
                         break;
                 default:
                         XAllowEvents(display, ReplayPointer, e->time);
@@ -157,25 +146,25 @@ bdown_event(Window *w, XButtonEvent *e)
                         XUngrabPointer(display, e->time);
         }else{
                 if(e->button == Button1) {
- if(frame_restack(f, nil))
- view_restack(f->view);
- else if(rect_haspoint_p(Pt(e->x, e->y), f->grabbox))
- mouse_resize(c, true, Center);
+ if(frame_to_top(f))
+ restack_view(f->view);
+ else if(ptinrect(Pt(e->x, e->y), f->grabbox))
+ do_mouse_resize(c, True, CENTER);
                         else if(f->area->floating)
- if(!e->subwindow && !rect_haspoint_p(Pt(e->x, e->y), f->titlebar))
- mouse_resize(c, false, quadrant(f->r, Pt(e->x_root, e->y_root)));
+ if(!e->subwindow && !ptinrect(Pt(e->x, e->y), f->titlebar))
+ do_mouse_resize(c, False, quadrant(f->r, Pt(e->x_root, e->y_root)));
 
                         if(f->client != selclient())
- focus(c, false);
+ focus(c, True);
                 }
                 if(e->subwindow)
                         XAllowEvents(display, ReplayPointer, e->time);
                 else {
                         /* Ungrab so a menu can receive events before the button is released */
                         XUngrabPointer(display, e->time);
- sync();
-
- event("ClientMouseDown %C %d\n", f->client, e->button);
+ XSync(display, False);
+
+ write_event("ClientMouseDown %C %d\n", f->client, e->button);
                 }
         }
 }
@@ -187,12 +176,12 @@ enter_event(Window *w, XCrossingEvent *e
 
         c = w->aux;
         f = c->sel;
- if(screen->focus != c || selclient() != c) {
- Dprint(DGeneric, "enter_notify(f) => %s\n", f->client->name);
+ if(screen->focus != c) {
+ Dprint("enter_notify(f) => %s\n", f->client->name);
                 if(f->area->floating || !f->collapsed)
- focus(f->client, false);
- }
- frame_setcursor(f, Pt(e->x, e->y));
+ focus(f->client, False);
+ }
+ set_frame_cursor(f, Pt(e->x, e->y));
 }
 
 static void
@@ -203,7 +192,7 @@ expose_event(Window *w, XExposeEvent *e)
 
         c = w->aux;
         if(c->sel)
- frame_draw(c->sel);
+ draw_frame(c->sel);
         else
                 fprint(2, "Badness: Expose event on a client frame which shouldn't be visible: %C\n",
                         c);
@@ -214,7 +203,7 @@ motion_event(Window *w, XMotionEvent *e)
         Client *c;
         
         c = w->aux;
- frame_setcursor(c->sel, Pt(e->x, e->y));
+ set_frame_cursor(c->sel, Pt(e->x, e->y));
 }
 
 Handlers framehandler = {
@@ -226,7 +215,7 @@ Handlers framehandler = {
 };
 
 Rectangle
-frame_rect2client(Frame *f, Rectangle r) {
+frame2client(Frame *f, Rectangle r) {
         if(f == nil || f->area == nil || f->area->floating) {
                 r.max.x -= def.border * 2;
                 r.max.y -= frame_delta_h();
@@ -248,7 +237,7 @@ frame_rect2client(Frame *f, Rectangle r)
 }
 
 Rectangle
-frame_client2rect(Frame *f, Rectangle r) {
+client2frame(Frame *f, Rectangle r) {
         if(f == nil || f->area == nil || f->area->floating) {
                 r.max.x += def.border * 2;
                 r.max.y += frame_delta_h();
@@ -268,11 +257,10 @@ frame_client2rect(Frame *f, Rectangle r)
 }
 
 void
-frame_resize(Frame *f, Rectangle r) {
+resize_frame(Frame *f, Rectangle r) {
         Align stickycorner;
         Point pt;
         Client *c;
- int collapsed;
 
         c = f->client;
         stickycorner = get_sticky(f->r, r);
@@ -287,10 +275,8 @@ frame_resize(Frame *f, Rectangle r) {
         else
                 f->r = r;
 
- f->crect = frame_rect2client(f, f->crect);
+ f->crect = frame2client(f, f->crect);
         f->crect = rectsubpt(f->crect, f->crect.min);
-
- collapsed = f->collapsed;
 
         if(!f->area->floating && f->area->mode == Coldefault) {
                 if(Dy(f->r) < 2 * labelh(def.font))
@@ -309,9 +295,6 @@ frame_resize(Frame *f, Rectangle r) {
                 f->crect = f->r;
         }
 
- if(collapsed != f->collapsed)
- ewmh_updatestate(c);
-
         pt = ZP;
         if(!f->client->borderless || !f->area->floating)
                 pt.y += 1;
@@ -321,7 +304,7 @@ frame_resize(Frame *f, Rectangle r) {
         if(f->area->floating) {
                 if(c->fullscreen) {
                         f->crect = screen->r;
- f->r = frame_client2rect(f, f->crect);
+ f->r = client2frame(f, f->crect);
                         pt.x = (Dx(f->r) - Dx(f->crect)) / 2;
                         f->r = rectsubpt(f->r, pt);
                 }else
@@ -332,22 +315,22 @@ frame_resize(Frame *f, Rectangle r) {
 }
 
 void
-frame_setcursor(Frame *f, Point pt) {
+set_frame_cursor(Frame *f, Point pt) {
         Rectangle r;
         Cursor cur;
 
         if(f->area->floating
- && !rect_haspoint_p(pt, f->titlebar)
- && !rect_haspoint_p(pt, f->crect)) {
+ && !ptinrect(pt, f->titlebar)
+ && !ptinrect(pt, f->crect)) {
                  r = rectsubpt(f->r, f->r.min);
- cur = quad_cursor(quadrant(r, pt));
- client_setcursor(f->client, cur);
+ cur = cursor_of_quad(quadrant(r, pt));
+ set_cursor(f->client, cur);
         } else
- client_setcursor(f->client, cursor[CurNormal]);
-}
-
-void
-frame_swap(Frame *fa, Frame *fb) {
+ set_cursor(f->client, cursor[CurNormal]);
+}
+
+void
+swap_frames(Frame *fa, Frame *fb) {
         Frame **fp;
         Client *c;
 
@@ -372,52 +355,33 @@ frame_swap(Frame *fa, Frame *fb) {
         c->frame = fa;
 
         if(c->sel && c->sel->view == screen->sel)
- view_focus(screen, c->sel->view);
-}
-
-void
-move_focus(Frame *old_f, Frame *f) {
- int noinput;
-
- noinput = (old_f && old_f->client->noinput) ||
- (f && f->client->noinput) ||
- screen->hasgrab != &c_root;
- if(noinput) {
- if(old_f)
- frame_draw(old_f);
- if(f)
- frame_draw(f);
- }
-}
-
-void
-frame_focus(Frame *f) {
- Client *c;
- Frame *old_f;
+ focus_view(screen, c->sel->view);
+}
+
+void
+focus_frame(Frame *f, Bool restack) {
         View *v;
         Area *a, *old_a;
 
- c = f->client;
+ a = f->area;
         v = f->view;
- a = f->area;
         old_a = v->sel;
 
- old_f = old_a->sel;
         a->sel = f;
 
         if(a != old_a)
- area_focus(f->area);
- if(old_a != v->oldsel && f != old_f)
- v->oldsel = nil;
-
- if(v != screen->sel || a != v->sel)
+ focus_area(f->area);
+
+ if(v != screen->sel)
                 return;
 
- move_focus(old_f, f);
- client_focus(f->client);
+ focus_client(f->client);
 
         if(!a->floating && ((a->mode == Colstack) || (a->mode == Colmax)))
- column_arrange(a, False);
+ arrange_column(a, False);
+
+ if(restack)
+ restack_view(v);
 }
 
 int
@@ -426,19 +390,15 @@ frame_delta_h(void) {
 }
 
 void
-frame_draw(Frame *f) {
+draw_frame(Frame *f) {
         Rectangle r, fr;
         CTuple *col;
         Frame *tf;
- uint w;
 
         if(f->view != screen->sel)
                 return;
- if(f->area == nil) /* Blech. */
- return;
-
- if(f->client == screen->focus
- || f->client == selclient())
+
+ if(f->client == screen->focus)
                 col = &def.focuscolor;
         else
                 col = &def.normcolor;
@@ -462,11 +422,6 @@ frame_draw(Frame *f) {
         f->titlebar = insetrect(r, 3);
         f->titlebar.max.y += 3;
 
- /* Odd state of focus. */
- if(f->client != selclient() && col == &def.focuscolor)
- border(screen->ibuf, insetrect(r, 1),
- 1, def.normcolor.bg);
-
         /* grabbox */
         r.min = Pt(2, 2);
         r.max.x = r.min.x + def.font->height - 3;
@@ -477,55 +432,25 @@ frame_draw(Frame *f) {
                 fill(screen->ibuf, r, col->fg);
         border(screen->ibuf, r, 1, col->border);
 
- /* Odd state of focus. */
- if(f->client != screen->focus && col == &def.focuscolor)
- border(screen->ibuf, insetrect(r, -1),
- 1, def.normcolor.bg);
-
- /* Label */
         r.min.x = r.max.x;
         r.max.x = fr.max.x;
         r.min.y = 0;
         r.max.y = labelh(def.font);
- if(f->client->floating)
- r.max.x -= Dx(f->grabbox);
- w = drawstring(screen->ibuf, def.font, r, West,
+ drawstring(screen->ibuf, def.font, r, WEST,
                         f->client->name, col->fg);
 
- if(f->area->floating) {
- r.min.x = r.min.x + w + 10;
- r.max.x = f->titlebar.max.x + 1;
- r.min.y = f->grabbox.min.y;
- r.max.y = f->grabbox.max.y;
- border(screen->ibuf, r, 1, col->border);
- }
-
- /* Border increment gaps... */
- r.min.y = f->crect.min.y;
- r.min.x = max(1, f->crect.min.x - 1);
- r.max.x = min(fr.max.x - 1, f->crect.max.x + 1);
- r.max.y = min(fr.max.y - 1, f->crect.max.y + 1);
- border(screen->ibuf, r, 1, col->border);
-
- /* Why? Because some non-ICCCM-compliant apps feel the need to
- * change the background properties of all of their ancestor windows
- * in order to implement pseudo-transparency.
- * What's more, the designers of X11 felt that it would be unfair to
- * implementers to make it possible to detect, or forbid, such changes.
- */
         XSetWindowBackgroundPixmap(display, f->client->framewin->w, None);
-
         copyimage(f->client->framewin, fr, screen->ibuf, ZP);
- sync();
-}
-
-void
-frame_draw_all(void) {
+ XSync(display, False);
+}
+
+void
+draw_frames(void) {
         Client *c;
 
         for(c=client; c; c=c->next)
                 if(c->sel && c->sel->view == screen->sel)
- frame_draw(c->sel);
+ draw_frame(c->sel);
 }
 
 Rectangle
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/fs.c
--- a/cmd/wmii/fs.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/fs.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,10 +1,12 @@
-/* Copyright ©2006-2008 Kris Maglione <fbsdaemon at gmail dot com>
+/* Copyright ©2006 Kris Maglione <fbsdaemon at gmail dot com>
  * See LICENSE file for license details.
  */
 #include "dat.h"
 #include <assert.h>
 #include <ctype.h>
 #include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include "fns.h"
 
@@ -107,7 +109,7 @@ dirtab_clients[]={{".", QTDIR, FsDClie
                   {nil}},
 dirtab_client[]= {{".", QTDIR, FsDClient, 0500|DMDIR },
                   {"ctl", QTAPPEND, FsFCctl, 0600|DMAPPEND },
- {"label", QTFILE, FsFClabel, 0600 },
+ {"label", QTFILE, FsFClabel, 0600 },
                   {"tags", QTFILE, FsFCtags, 0600 },
                   {"props", QTFILE, FsFprops, 0400 },
                   {nil}},
@@ -225,7 +227,7 @@ data_to_cstring(Ixp9Req *r) {
 
 typedef char* (*MsgFunc)(void*, IxpMsg*);
 
-static char*
+static char *
 message(Ixp9Req *r, MsgFunc fn) {
         char *err, *s, *p, c;
         FileId *f;
@@ -247,7 +249,7 @@ message(Ixp9Req *r, MsgFunc fn) {
                 c = *p;
                 *p = '\0';
 
- m = ixp_message(s, p-s, 0);
+ m = ixp_message((uchar*)s, p-s, 0);
                 s = fn(f->p.ref, &m);
                 if(s)
                         err = s;
@@ -271,7 +273,7 @@ respond_event(Ixp9Req *r) {
 }
 
 void
-event(const char *format, ...) {
+write_event(char *format, ...) {
         uint len, slen;
         va_list ap;
         FidLink *f;
@@ -455,7 +457,7 @@ LastItem:
         return ret;
 }
 
-static bool
+static Bool
 verify_file(FileId *f) {
         FileId *nf;
         int ret;
@@ -563,7 +565,7 @@ fs_stat(Ixp9Req *r) {
         IxpMsg m;
         Stat s;
         int size;
- char *buf;
+ uchar *buf;
         FileId *f;
         
         f = r->fid->aux;
@@ -589,7 +591,7 @@ fs_read(Ixp9Req *r) {
         char *buf;
         FileId *f, *tf;
         int n, offset;
- ulong size;
+ int size;
 
         f = r->fid->aux;
 
@@ -604,10 +606,8 @@ fs_read(Ixp9Req *r) {
 
                 offset = 0;
                 size = r->ifcall.count;
- if(size > IXP_MAX_MSG)
- size = r->fid->iounit;
                 buf = emallocz(size);
- m = ixp_message(buf, size, MsgPack);
+ m = ixp_message((uchar*)buf, size, MsgPack);
 
                 tf = f = lookup_file(f, nil);
                 /* Note: f->tab.name == "." so we skip it */
@@ -659,7 +659,7 @@ fs_read(Ixp9Req *r) {
                         respond(r, nil);
                         return;
                 case FsFRctl:
- buf = readctl_root();
+ buf = read_root_ctl();
                         write_buf(r, buf, strlen(buf));
                         respond(r, nil);
                         return;
@@ -673,13 +673,13 @@ fs_read(Ixp9Req *r) {
                         respond(r, nil);
                         return;
                 case FsFTindex:
- buf = view_index(f->p.view);
+ buf = (char*)view_index(f->p.view);
                         n = strlen(buf);
                         write_buf(r, buf, n);
                         respond(r, nil);
                         return;
                 case FsFTctl:
- buf = readctl_view(f->p.view);
+ buf = (char*)view_ctl(f->p.view);
                         n = strlen(buf);
                         write_buf(r, buf, n);
                         respond(r, nil);
@@ -693,7 +693,7 @@ fs_read(Ixp9Req *r) {
          * This is an assert because this should this should not be called if
          * the file is not open for reading.
          */
- die("Read called on an unreadable file");
+ assert(!"Read called on an unreadable file");
 }
 
 void
@@ -727,7 +727,7 @@ fs_write(Ixp9Req *r) {
         case FsFClabel:
                 data_to_cstring(r);
                 utfecpy(f->p.client->name, f->p.client->name+sizeof(client->name), r->ifcall.data);
- frame_draw(f->p.client->sel);
+ draw_frame(f->p.client->sel);
                 update_class(f->p.client);
                 r->ofcall.count = r->ifcall.count;
                 respond(r, nil);
@@ -763,9 +763,9 @@ fs_write(Ixp9Req *r) {
                 return;
         case FsFEvent:
                 if(r->ifcall.data[r->ifcall.count-1] == '\n')
- event("%.*s", (int)r->ifcall.count, r->ifcall.data);
+ write_event("%.*s", (int)r->ifcall.count, r->ifcall.data);
                 else
- event("%.*s\n", (int)r->ifcall.count, r->ifcall.data);
+ write_event("%.*s\n", (int)r->ifcall.count, r->ifcall.data);
                 r->ofcall.count = r->ifcall.count;
                 respond(r, nil);
                 return;
@@ -774,7 +774,7 @@ fs_write(Ixp9Req *r) {
          * This is an assert because this function should not be called if
          * the file is not open for writing.
          */
- die("Write called on an unwritable file");
+ assert(!"Write called on an unwritable file");
 }
 
 void
@@ -827,7 +827,7 @@ fs_create(Ixp9Req *r) {
                         respond(r, Ebadvalue);
                         return;
                 }
- bar_create(f->p.bar_p, r->ifcall.name);
+ create_bar(f->p.bar_p, r->ifcall.name);
                 f = lookup_file(f, r->ifcall.name);
                 if(!f) {
                         respond(r, Enofile);
@@ -857,8 +857,8 @@ fs_remove(Ixp9Req *r) {
                 respond(r, Enoperm);
                 return;
         case FsFBar:
- bar_destroy(f->next->p.bar_p, f->p.bar);
- bar_draw(screen);
+ destroy_bar(f->next->p.bar_p, f->p.bar);
+ draw_bar(screen);
                 respond(r, nil);
                 break;
         }
@@ -886,7 +886,7 @@ fs_clunk(Ixp9Req *r) {
                 update_rules(&f->p.rule->rule, f->p.rule->string);
                 for(c=client; c; c=c->next)
                         apply_rules(c);
- view_update_all();
+ update_views();
                 break;
         case FsFKeys:
                 update_keys();
@@ -894,8 +894,8 @@ fs_clunk(Ixp9Req *r) {
         case FsFBar:
                 p = toutf8(f->p.bar->buf);
                 
- m = ixp_message(p, strlen(p), 0);
- msg_parsecolors(&m, &f->p.bar->col);
+ m = ixp_message((uchar*)p, strlen(p), 0);
+ parse_colors(&m, &f->p.bar->col);
 
                 q = (char*)m.end-1;
                 while(q >= (char*)m.pos && *q == '\n')
@@ -906,7 +906,7 @@ fs_clunk(Ixp9Req *r) {
 
                 free(p);
 
- bar_draw(screen);
+ draw_bar(screen);
                 break;
         case FsFEvent:
                 for(fl=&peventfid; *fl; fl=&fl[0]->next)
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/geom.c
--- a/cmd/wmii/geom.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/geom.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,41 +1,13 @@
-/* Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+/* Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #include "dat.h"
 #include "fns.h"
 
-bool
-rect_haspoint_p(Point pt, Rectangle r) {
+Bool
+ptinrect(Point pt, Rectangle r) {
         return (pt.x >= r.min.x) && (pt.x < r.max.x)
                 && (pt.y >= r.min.y) && (pt.y < r.max.y);
-}
-
-bool
-rect_intersect_p(Rectangle r, Rectangle r2) {
- return r.min.x <= r2.max.x
- && r.max.x >= r2.min.x
- && r.min.y <= r2.max.y
- && r.max.y >= r2.min.y;
-}
-
-Rectangle
-rect_intersection(Rectangle r, Rectangle r2) {
- Rectangle ret;
-
- /* canonrect(ret) != ret if not intersection */
- ret.min.x = max(r.min.x, r2.min.x);
- ret.max.x = min(r.max.x, r2.max.x);
- ret.min.y = max(r.min.y, r2.min.y);
- ret.max.y = min(r.max.y, r2.max.y);
- return ret;
-}
-
-bool
-rect_contains_p(Rectangle r, Rectangle r2) {
- return r2.min.x >= r.min.x
- && r2.max.x <= r.max.x
- && r2.min.y >= r.min.y
- && r2.max.y <= r.max.y;
 }
 
 Align
@@ -46,27 +18,27 @@ quadrant(Rectangle r, Point pt) {
         ret = 0;
 
         if(pt.x >= Dx(r) * .5)
- ret |= East;
+ ret |= EAST;
         if(pt.x <= Dx(r) * .5)
- ret |= West;
+ ret |= WEST;
         if(pt.y <= Dy(r) * .5)
- ret |= North;
+ ret |= NORTH;
         if(pt.y >= Dy(r) * .5)
- ret |= South;
+ ret |= SOUTH;
 
         return ret;
 }
 
 Cursor
-quad_cursor(Align align) {
+cursor_of_quad(Align align) {
         switch(align) {
- case NEast:
+ case NEAST:
                 return cursor[CurNECorner];
- case NWest:
+ case NWEST:
                 return cursor[CurNWCorner];
- case SEast:
+ case SEAST:
                 return cursor[CurSECorner];
- case SWest:
+ case SWEST:
                 return cursor[CurSWCorner];
         default:
                 return cursor[CurMove];
@@ -78,42 +50,13 @@ get_sticky(Rectangle src, Rectangle dst)
         Align stickycorner = 0;
 
         if(src.min.x != dst.min.x && src.max.x == dst.max.x)
- stickycorner |= East;
+ stickycorner |= EAST;
         else
- stickycorner |= West;
+ stickycorner |= WEST;
         if(src.min.y != dst.min.y && src.max.y == dst.max.y)
- stickycorner |= South;
+ stickycorner |= SOUTH;
         else
- stickycorner |= North;
+ stickycorner |= NORTH;
 
         return stickycorner;
 }
-
-/* XXX: These don't belong here. */
-/* Blech. */
-#define VECTOR(type, nam, c) \
-void \
-vector_##c##init(Vector_##nam *v) { \
- memset(v, 0, sizeof *v); \
-} \
- \
-void \
-vector_##c##free(Vector_##nam *v) { \
- free(v->ary); \
- memset(v, 0, sizeof *v); \
-} \
- \
-void \
-vector_##c##push(Vector_##nam *v, type val) { \
- if(v->n == v->size) { \
- if(v->size == 0) \
- v->size = 2; \
- v->size <<= 2; \
- v->ary = erealloc(v->ary, v->size * sizeof *v->ary); \
- } \
- v->ary[v->n++] = val; \
-} \
-
-VECTOR(long, long, l)
-VECTOR(Rectangle, rect, r)
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/key.c
--- a/cmd/wmii/key.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/key.c Fri Jan 18 15:05:45 2008 -0500
@@ -2,38 +2,36 @@
  * See LICENSE file for license details.
  */
 #include "dat.h"
+#include <string.h>
+#include <stdlib.h>
 #include <X11/keysym.h>
 #include "fns.h"
 
 void
 init_lock_keys(void) {
         XModifierKeymap *modmap;
- KeyCode numlock;
+ KeyCode num_lock;
         static int masks[] = {
- ShiftMask, LockMask, ControlMask,
- Mod1Mask, Mod2Mask, Mod3Mask,
- Mod4Mask, Mod5Mask
+ ShiftMask, LockMask, ControlMask, Mod1Mask,
+ Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
         };
         int i;
 
- numlock_mask = 0;
+ num_lock_mask = 0;
         modmap = XGetModifierMapping(display);
- numlock = keycode("Num_Lock");
- if(numlock)
+ num_lock = XKeysymToKeycode(display, XStringToKeysym("Num_Lock"));
         if(modmap && modmap->max_keypermod > 0) {
- int max;
-
- max = nelem(masks) * modmap->max_keypermod;
+ int max = (sizeof(masks) / sizeof(int)) * modmap->max_keypermod;
                 for(i = 0; i < max; i++)
- if(modmap->modifiermap[i] == numlock)
- numlock_mask = masks[i / modmap->max_keypermod];
+ if(num_lock && (modmap->modifiermap[i] == num_lock))
+ num_lock_mask = masks[i / modmap->max_keypermod];
         }
         XFreeModifiermap(modmap);
- valid_mask = 255 & ~(numlock_mask | LockMask);
+ valid_mask = 255 & ~(num_lock_mask | LockMask);
 }
 
 ulong
-str2modmask(const char *val) {
+str2modmask(char *val) {
         ulong mod = 0;
 
         if (strstr(val, "Shift"))
@@ -54,40 +52,38 @@ str2modmask(const char *val) {
 }
 
 static void
-grabkey(Key *k) {
+grab_key(Key *k) {
         XGrabKey(display, k->key, k->mod, scr.root.w,
                         True, GrabModeAsync, GrabModeAsync);
- if(numlock_mask) {
- XGrabKey(display, k->key, k->mod | numlock_mask, scr.root.w,
+ if(num_lock_mask) {
+ XGrabKey(display, k->key, k->mod | num_lock_mask, scr.root.w,
                                 True, GrabModeAsync, GrabModeAsync);
- XGrabKey(display, k->key, k->mod | numlock_mask | LockMask, scr.root.w,
+ XGrabKey(display, k->key, k->mod | num_lock_mask | LockMask, scr.root.w,
                                 True, GrabModeAsync, GrabModeAsync);
         }
- sync();
-}
-
-static void
-ungrabkey(Key *k) {
+ XSync(display, False);
+}
+
+static void
+ungrab_key(Key *k) {
         XUngrabKey(display, k->key, k->mod, scr.root.w);
- if(numlock_mask) {
- XUngrabKey(display, k->key, k->mod | numlock_mask, scr.root.w);
- XUngrabKey(display, k->key, k->mod | numlock_mask | LockMask, scr.root.w);
- }
- sync();
+ if(num_lock_mask) {
+ XUngrabKey(display, k->key, k->mod | num_lock_mask, scr.root.w);
+ XUngrabKey(display, k->key, k->mod | num_lock_mask | LockMask, scr.root.w);
+ }
+ XSync(display, False);
 }
 
 static Key *
 name2key(const char *name) {
         Key *k;
-
         for(k=key; k; k=k->lnext)
- if(!strncmp(k->name, name, sizeof(k->name)))
- return k;
- return nil;
-}
-
-static Key *
-getkey(const char *name) {
+ if(!strncmp(k->name, name, sizeof(k->name))) break;
+ return k;
+}
+
+static Key *
+get_key(const char *name) {
         char buf[128];
         char *seq[8];
         char *kstr;
@@ -98,7 +94,7 @@ getkey(const char *name) {
         r = nil;
 
         if((k = name2key(name))) {
- ungrabkey(k);
+ ungrab_key(k);
                 return k;
         }
         utflcpy(buf, name, sizeof(buf));
@@ -143,30 +139,26 @@ next_keystroke(ulong *mod, KeyCode *code
 }
 
 static void
-fake_keypress(ulong mod, KeyCode key) {
- XKeyEvent e;
- Client *c;
-
- c = screen->focus;
- if(c == nil || c->w.w == 0)
- return;
-
- e.time = CurrentTime;
- e.window = c->w.w;
- e.display = display;
- e.state = mod;
- e.keycode = key;
-
- e.type = KeyPress;
- sendevent(&c->w, true, KeyPressMask, (XEvent*)&e);
- e.type = KeyRelease;
- sendevent(&c->w, true, KeyReleaseMask, (XEvent*)&e);
-
- sync();
-}
-
-static Key *
-match_keys(Key *k, ulong mod, KeyCode keycode, bool seq) {
+emulate_key_press(ulong mod, KeyCode key) {
+ XEvent e;
+ XWindow client_win;
+ int revert;
+
+ XGetInputFocus(display, &client_win, &revert);
+ e.xkey.type = KeyPress;
+ e.xkey.time = CurrentTime;
+ e.xkey.window = client_win;
+ e.xkey.display = display;
+ e.xkey.state = mod;
+ e.xkey.keycode = key;
+ XSendEvent(display, client_win, True, KeyPressMask, &e);
+ e.xkey.type = KeyRelease;
+ XSendEvent(display, client_win, True, KeyReleaseMask, &e);
+ XSync(display, False);
+}
+
+static Key *
+match_keys(Key *k, ulong mod, KeyCode keycode, Bool seq) {
         Key *ret = nil, *next;
 
         for(next = k->tnext; k; (k=next) && (next=k->tnext)) {
@@ -189,12 +181,12 @@ kpress_seq(XWindow w, Key *done) {
         next_keystroke(&mod, &key);
         found = match_keys(done, mod, key, True);
         if((done->mod == mod) && (done->key == key))
- fake_keypress(mod, key); /* double key */
+ emulate_key_press(mod, key); /* double key */
         else {
                 if(!found)
                         XBell(display, 0);
                 else if(!found->tnext && !found->next)
- event("Key %s\n", found->name);
+ write_event("Key %s\n", found->name);
                 else
                         kpress_seq(w, found);
         }
@@ -210,13 +202,13 @@ kpress(XWindow w, ulong mod, KeyCode key
         if(!found) /* grabbed but not found */
                 XBell(display, 0);
         else if(!found->tnext && !found->next)
- event("Key %s\n", found->name);
+ write_event("Key %s\n", found->name);
         else {
                 XGrabKeyboard(display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime);
                 flushevents(FocusChangeMask, True);
                 kpress_seq(w, found);
                 XUngrabKeyboard(display, CurrentTime);
- sync();
+ XSync(display, False);
         }
 }
 
@@ -228,7 +220,7 @@ update_keys(void) {
         init_lock_keys();
         while((k = key)) {
                 key = key->lnext;
- ungrabkey(k);
+ ungrab_key(k);
                 while((n = k)) {
                         k = k->next;
                         free(n);
@@ -237,8 +229,8 @@ update_keys(void) {
         for(l = p = def.keys; p && *p;) {
                 if(*p == '\n') {
                         *p = 0;
- if((k = getkey(l)))
- grabkey(k);
+ if((k = get_key(l)))
+ grab_key(k);
                         *p = '\n';
                         l = ++p;
                 }
@@ -246,8 +238,8 @@ update_keys(void) {
                         p++;
         }
         if(l < p && strlen(l)) {
- if((k = getkey(l)))
- grabkey(k);
- }
- sync();
-}
+ if((k = get_key(l)))
+ grab_key(k);
+ }
+ XSync(display, False);
+}
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/main.c
--- a/cmd/wmii/main.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/main.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,5 +1,5 @@
 /* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
- * Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+ * Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #define EXTERN
@@ -11,10 +11,14 @@
 #include <locale.h>
 #include <pwd.h>
 #include <signal.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <unistd.h>
 #include "fns.h"
+
+enum { false, true };
 
 static const char
         version[] = "wmii-"VERSION", ©2007 Kris Maglione\n";
@@ -48,19 +52,17 @@ scan_wins(void) {
                 for(i = 0; i < num; i++) {
                         if(!XGetWindowAttributes(display, wins[i], &wa))
                                 continue;
- /* Skip transients. */
                         if(wa.override_redirect || XGetTransientForHint(display, wins[i], &d1))
                                 continue;
                         if(wa.map_state == IsViewable)
- client_create(wins[i], &wa);
+ create_client(wins[i], &wa);
                 }
- /* Manage transients. */
                 for(i = 0; i < num; i++) {
                         if(!XGetWindowAttributes(display, wins[i], &wa))
                                 continue;
                         if((XGetTransientForHint(display, wins[i], &d1))
                         && (wa.map_state == IsViewable))
- client_create(wins[i], &wa);
+ create_client(wins[i], &wa);
                 }
         }
         if(wins)
@@ -133,8 +135,7 @@ init_ns(void) {
         if(getuid() != st.st_uid)
                 fatal("ns_path '%s' exists but is not owned by you", ns_path);
         if(st.st_mode & 077)
- if(chmod(ns_path, 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
@@ -146,6 +147,13 @@ init_environment(void) {
 
         setenv("WMII_NS_DIR", ns_path, True);
         setenv("WMII_ADDRESS", address, True);
+}
+
+static void
+init_atoms(void) {
+ Atom net[] = { xatom("_NET_SUPPORTED"), xatom("_NET_WM_NAME") };
+
+ changeprop_long(&scr.root, "_NET_SUPPORTED", "ATOM", (long*)net, nelem(net));
 }
 
 static void
@@ -186,17 +194,23 @@ init_cursors(void) {
 
 static void
 init_screen(WMScreen *screen) {
+ XWindow w;
+ int ret;
+ unsigned mask;
 
         screen->r = scr.rect;
         def.snap = Dy(scr.rect) / 63;
 
- sel_screen = pointerscreen();
+ sel_screen = XQueryPointer(display, scr.root.w,
+ &w, &w,
+ &ret, &ret, &ret, &ret,
+ &mask);
 }
 
 static void
 cleanup(void) {
         while(client)
- client_destroy(client);
+ destroy_client(client);
         ixp_server_close(&srv);
         close(sleeperfd);
 }
@@ -211,7 +225,6 @@ struct {
         { X_PolySegment, BadDrawable },
         { X_ConfigureWindow, BadMatch },
         { X_GrabKey, BadAccess },
- { X_GetAtomName, BadAtom },
 };
 
 /*
@@ -309,7 +322,7 @@ init_traps(void) {
                 /* Wait for parent to exit */
                 read(fd[0], buf, 1);
 
- setfocus(pointerwin, RevertToPointerRoot);
+ XSetInputFocus(display, PointerRoot, RevertToPointerRoot, CurrentTime);
                 XCloseDisplay(display);
                 exit(0);
         }
@@ -375,18 +388,18 @@ main(int argc, char *argv[]) {
         wmiirc = "wmiistartrc";
 
         ARGBEGIN{
- case 'a':
- address = EARGF(usage());
- break;
- case 'G':
- debug |= DGeneric;
- break;
- case 'r':
- wmiirc = EARGF(usage());
- break;
         case 'v':
                 print("%s", version);
                 exit(0);
+ case 'V':
+ verbose = true;
+ break;
+ case 'a':
+ address = EARGF(usage());
+ break;
+ case 'r':
+ wmiirc = EARGF(usage());
+ break;
         default:
                 usage();
                 break;
@@ -407,7 +420,7 @@ main(int argc, char *argv[]) {
         XSelectInput(display, scr.root.w,
                           SubstructureRedirectMask
                         | EnterWindowMask);
- sync();
+ XSync(display, False);
 
         check_other_wm = false;
 
@@ -425,10 +438,9 @@ main(int argc, char *argv[]) {
                 spawn_command(wmiirc);
 
         init_traps();
+ init_atoms();
         init_cursors();
         init_lock_keys();
- ewmh_init();
- xext_init();
 
         srv.preselect = check_preselect;
         ixp_listen(&srv, sock, &p9srv, serve_9pcon, nil);
@@ -463,20 +475,18 @@ main(int argc, char *argv[]) {
                 setwinattr(&scr.root, &wa,
                                   CWEventMask
                                 | CWCursor);
- bar_init(s);
+ initbar(s);
         }
 
         screen->focus = nil;
         setfocus(screen->barwin, RevertToParent);
- view_select("1");
 
         scan_wins();
         starting = false;
 
- view_update_all();
- ewmh_updateviews();
-
- event("FocusTag %s\n", screen->sel->name);
+ select_view("nil");
+ update_views();
+ write_event("FocusTag %s\n", screen->sel->name);
 
         i = ixp_serverloop(&srv);
         if(i)
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/map.c
--- a/cmd/wmii/map.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/map.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,6 +1,8 @@
 /* Written by Kris Maglione */
 /* Public domain */
 #include "dat.h"
+#include <stdlib.h>
+#include <string.h>
 #include "fns.h"
 
 /* Edit s/^([a-zA-Z].*)\n([a-z].*) {/\1 \2;/g x/^([^a-zA-Z]|static|$)/-+d s/ (\*map|val|*str)//g */
@@ -21,7 +23,7 @@ hash(const char *str) {
 }
 
 static void
-insert(MapEnt **e, ulong val, const char *key) {
+insert(MapEnt **e, ulong val, char *key) {
         MapEnt *te;
         
         te = emallocz(sizeof *te);
@@ -32,7 +34,7 @@ insert(MapEnt **e, ulong val, const char
 }
 
 static MapEnt**
-map_getp(Map *map, ulong val, int create) {
+mapgetp(Map *map, ulong val, int create) {
         MapEnt **e;
 
         e = &map->bucket[val%map->nhash];
@@ -48,13 +50,13 @@ map_getp(Map *map, ulong val, int create
 }
 
 static MapEnt**
-hash_getp(Map *map, const char *str, int create) {
+hashgetp(Map *map, char *str, int create) {
         MapEnt **e;
         ulong h;
         int cmp;
         
         h = hash(str);
- e = map_getp(map, h, create);
+ e = mapgetp(map, h, create);
         if(*e && (*e)->key == nil)
                 (*e)->key = str;
         else {
@@ -70,28 +72,28 @@ hash_getp(Map *map, const char *str, int
 }
 
 MapEnt*
-map_get(Map *map, ulong val, int create) {
+mapget(Map *map, ulong val, int create) {
         MapEnt **e;
         
- e = map_getp(map, val, create);
+ e = mapgetp(map, val, create);
         return *e;
 }
 
 MapEnt*
-hash_get(Map *map, const char *str, int create) {
+hashget(Map *map, char *str, int create) {
         MapEnt **e;
         
- e = hash_getp(map, str, create);
+ e = hashgetp(map, str, create);
         return *e;
 }
 
 void*
-map_rm(Map *map, ulong val) {
+maprm(Map *map, ulong val) {
         MapEnt **e, *te;
         void *ret;
         
         ret = nil;
- e = map_getp(map, val, 0);
+ e = mapgetp(map, val, 0);
         if(*e) {
                 te = *e;
                 ret = te->val;
@@ -102,12 +104,12 @@ map_rm(Map *map, ulong val) {
 }
 
 void*
-hash_rm(Map *map, const char *str) {
+hashrm(Map *map, char *str) {
         MapEnt **e, *te;
         void *ret;
         
         ret = nil;
- e = hash_getp(map, str, 0);
+ e = hashgetp(map, str, 0);
         if(*e) {
                 te = *e;
                 ret = te->val;
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/message.c
--- a/cmd/wmii/message.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/message.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,14 +1,12 @@
-/* Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+/* Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #include "dat.h"
 #include <assert.h>
 #include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
 #include "fns.h"
-
-static char* msg_debug(IxpMsg*);
-static char* msg_selectframe(Frame*, IxpMsg*, int);
-static char* msg_sendframe(Frame*, int, bool);
 
 static char
         Ebadcmd[] = "bad command",
@@ -22,7 +20,6 @@ enum {
         LBORDER,
         LCLIENT,
         LCOLMODE,
- LDEBUG,
         LDOWN,
         LEXEC,
         LFOCUSCOLORS,
@@ -38,7 +35,6 @@ enum {
         LSELCOLORS,
         LSELECT,
         LSEND,
- LSLAY,
         LSWAP,
         LTOGGLE,
         LUP,
@@ -51,7 +47,6 @@ char *symtab[] = {
         "border",
         "client",
         "colmode",
- "debug",
         "down",
         "exec",
         "focuscolors",
@@ -67,7 +62,6 @@ char *symtab[] = {
         "selcolors",
         "select",
         "send",
- "slay",
         "swap",
         "toggle",
         "up",
@@ -75,30 +69,23 @@ char *symtab[] = {
         "~",
 };
 
-char *debugtab[] = {
- "event",
- "ewmh",
- "focus",
- "generic",
-};
-
 /* Edit ,y/^[a-zA-Z].*\n.* {\n/d
  * Edit s/^([a-zA-Z].*)\n(.*) {\n/\1 \2;\n/
  * Edit ,x/^static.*\n/d
  */
 
 static int
-_bsearch(char *s, char **tab, int ntab) {
+getsym(char *s) {
         int i, n, m, cmp;
 
         if(s == nil)
                 return -1;
 
- n = ntab;
+ n = nelem(symtab);
         i = 0;
         while(n) {
                 m = n/2;
- cmp = strcmp(s, tab[i+m]);
+ cmp = strcmp(s, symtab[i+m]);
                 if(cmp == 0)
                         return i+m;
                 if(cmp < 0 || m == 0)
@@ -112,18 +99,8 @@ _bsearch(char *s, char **tab, int ntab)
 }
 
 static int
-getsym(char *s) {
- return _bsearch(s, symtab, nelem(symtab));
-}
-
-static int
-getdebug(char *s) {
- return _bsearch(s, debugtab, nelem(debugtab));
-}
-
-static int
 gettoggle(IxpMsg *m) {
- switch(getsym(msg_getword(m))) {
+ switch(getsym(getword(m))) {
         case LON:
                 return On;
         case LOFF:
@@ -150,19 +127,19 @@ eatrunes(IxpMsg *m, int (*p)(Rune), int
                 m->pos = m->end;
 }
 
-char*
-msg_getword(IxpMsg *m) {
+char *
+getword(IxpMsg *m) {
         char *ret;
         Rune r;
         int n;
 
- eatrunes(m, isspacerune, true);
+ eatrunes(m, isspacerune, 1);
         ret = m->pos;
- eatrunes(m, isspacerune, false);
+ eatrunes(m, isspacerune, 0);
         n = chartorune(&r, m->pos);
         *m->pos = '\0';
         m->pos += n;
- eatrunes(m, isspacerune, true);
+ eatrunes(m, isspacerune, 1);
 
         if(ret == m->end)
                 return nil;
@@ -171,23 +148,21 @@ msg_getword(IxpMsg *m) {
 
 #define strbcmp(str, const) (strncmp((str), (const), sizeof(const)-1))
 static int
-getbase(const char **s) {
- const char *p;
+getbase(char **s) {
+ char *p;
 
         p = *s;
         if(!strbcmp(p, "0x")) {
                 *s += 2;
                 return 16;
         }
- if(isdigit(p[0])) {
- if(p[1] == 'r') {
- *s += 2;
- return p[0] - '0';
- }
- if(isdigit(p[1]) && p[2] == 'r') {
- *s += 3;
- return 10*(p[0]-'0') + (p[1]-'0');
- }
+ if(isdigit(p[0]) && p[1] == 'r') {
+ *s += 2;
+ return p[0] - '0';
+ }
+ if(isdigit(p[0]) && isdigit(p[1]) && p[2] == 'r') {
+ *s += 3;
+ return 10*(p[0]-'0') + (p[1]-'0');
         }
         if(p[0] == '0') {
                 *s += 1;
@@ -197,9 +172,8 @@ getbase(const char **s) {
 }
 
 int
-getlong(const char *s, long *ret) {
- const char *end;
- char *rend;
+getlong(char *s, long *ret) {
+ char *end, *rend;
         int base;
 
         end = s+strlen(s);
@@ -210,9 +184,8 @@ getlong(const char *s, long *ret) {
 }
 
 int
-getulong(const char *s, ulong *ret) {
- const char *end;
- char *rend;
+getulong(char *s, ulong *ret) {
+ char *end, *rend;
         int base;
 
         end = s+strlen(s);
@@ -222,7 +195,7 @@ getulong(const char *s, ulong *ret) {
         return (end == rend);
 }
 
-static Client*
+static Client *
 strclient(View *v, char *s) {
         ulong id;
 
@@ -234,8 +207,8 @@ strclient(View *v, char *s) {
         return nil;
 }
 
-Area*
-strarea(View *v, const char *s) {
+Area *
+strarea(View *v, char *s) {
         Area *a;
         long i;
 
@@ -261,185 +234,48 @@ strarea(View *v, const char *s) {
         return a;
 }
 
-char*
-message_client(Client *c, IxpMsg *m) {
- char *s;
- int i;
-
- s = msg_getword(m);
-
- switch(getsym(s)) {
- case LFULLSCREEN:
- i = gettoggle(m);
- if(i == -1)
- return Ebadusage;
- fullscreen(c, i);
- break;
- case LKILL:
- client_kill(c, true);
- break;
- case LSLAY:
- client_kill(c, false);
- break;
- case LURGENT:
- i = gettoggle(m);
- if(i == -1)
- return Ebadusage;
- client_seturgent(c, i, UrgManager);
- break;
- default:
- return Ebadcmd;
- }
- return nil;
-}
-
-char*
-message_root(void *p, IxpMsg *m) {
- Font *fn;
- char *s, *ret;
- ulong n;
-
- USED(p);
- ret = nil;
- s = msg_getword(m);
-
- switch(getsym(s)) {
- case LBORDER:
- if(!getulong(msg_getword(m), &n))
- return Ebadvalue;
- def.border = n;
- view_focus(screen, screen->sel);
- break;
- case LDEBUG:
- ret = msg_debug(m);
- break;
- case LEXEC:
- execstr = smprint("exec %s", m->pos);
- srv.running = 0;
- break;
- case LFOCUSCOLORS:
- ret = msg_parsecolors(m, &def.focuscolor);
- view_focus(screen, screen->sel);
- break;
- case LFONT:
- fn = loadfont(m->pos);
- if(fn) {
- freefont(def.font);
- def.font = fn;
- bar_resize(screen);
- }else
- ret = "can't load font";
- view_focus(screen, screen->sel);
- break;
- case LGRABMOD:
- s = msg_getword(m);
- n = str2modmask(s);
-
- if((n & (Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) == 0)
- return Ebadvalue;
-
- utflcpy(def.grabmod, s, sizeof(def.grabmod));
- def.mod = n;
- break;
- case LNORMCOLORS:
- ret = msg_parsecolors(m, &def.normcolor);
- view_focus(screen, screen->sel);
- break;
- case LSELCOLORS:
- fprint(2, "%s: warning: selcolors have been removed\n", argv0);
- return Ebadcmd;
- case LVIEW:
- view_select(m->pos);
- break;
- case LQUIT:
- srv.running = 0;
- break;
- default:
- return Ebadcmd;
- }
- return ret;
-}
-
-char*
+char *
 message_view(View *v, IxpMsg *m) {
         Area *a;
         char *s;
         int i;
 
- s = msg_getword(m);
+ s = getword(m);
 
         switch(getsym(s)) {
+ case LSEND:
+ return send_client(v, m, 0);
+ case LSWAP:
+ return send_client(v, m, 1);
+ case LSELECT:
+ return select_area(v->sel, m);
         case LCOLMODE:
- s = msg_getword(m);
+ s = getword(m);
                 a = strarea(v, s);
                 if(a == nil || a->floating)
                         return Ebadvalue;
 
- s = msg_getword(m);
+ s = getword(m);
                 i = str2colmode(s);
                 if(i == -1)
                         return Ebadvalue;
 
                 a->mode = i;
- column_arrange(a, True);
- view_restack(v);
+ arrange_column(a, True);
+ restack_view(v);
 
                 if(v == screen->sel)
- view_focus(screen, v);
- frame_draw_all();
+ focus_view(screen, v);
+ draw_frames();
                 return nil;
- case LSELECT:
- return msg_selectarea(v->sel, m);
- case LSEND:
- return msg_sendclient(v, m, false);
- case LSWAP:
- return msg_sendclient(v, m, true);
         default:
                 return Ebadcmd;
         }
         /* not reached */
 }
 
-static void
-printdebug(void) {
- int i, j;
-
- for(i=0, j=0; i < nelem(debugtab); i++)
- Debug(1<<i) {
- if(j++ > 0)
- bufprint(" ");
- bufprint("%s", debugtab[i]);
- }
-}
-
-static char*
-msg_debug(IxpMsg *m) {
- char *opt;
- int d;
- char add;
-
- bufclear();
- while((opt = msg_getword(m))) {
- add = '+';
- if(opt[0] == '+' || opt[0] == '-')
- add = *opt++;
- d = getdebug(opt);
- if(d == -1) {
- bufprint(", %s", opt);
- continue;
- }
- if(add == '+')
- debug |= 1<<d;
- else
- debug &= ~(1<<d);
- }
- if(buffer[0] != '\0')
- return sxprint("Bad debug options: %s", buffer+2);
- return nil;
-}
-
-char*
-msg_parsecolors(IxpMsg *m, CTuple *col) {
+char *
+parse_colors(IxpMsg *m, CTuple *col) {
         static char Ebad[] = "bad color string";
         Rune r;
         char c, *p;
@@ -469,12 +305,285 @@ msg_parsecolors(IxpMsg *m, CTuple *col)
         *p = c;
 
         m->pos = p;
- eatrunes(m, isspacerune, true);
+ eatrunes(m, isspacerune, 1);
+ return nil;
+}
+
+char *
+message_root(void *p, IxpMsg *m) {
+ Font *fn;
+ char *s, *ret;
+ ulong n;
+
+ USED(p);
+ ret = nil;
+ s = getword(m);
+
+ switch(getsym(s)) {
+ case LQUIT:
+ srv.running = 0;
+ break;
+ case LEXEC:
+ execstr = smprint("exec %s", m->pos);
+ srv.running = 0;
+ break;
+ case LVIEW:
+ select_view(m->pos);
+ break;
+ case LSELCOLORS:
+ fprint(2, "%s: warning: selcolors have been removed\n", argv0);
+ return Ebadcmd;
+ case LFOCUSCOLORS:
+ ret = parse_colors(m, &def.focuscolor);
+ focus_view(screen, screen->sel);
+ break;
+ case LNORMCOLORS:
+ ret = parse_colors(m, &def.normcolor);
+ focus_view(screen, screen->sel);
+ break;
+ case LFONT:
+ fn = loadfont(m->pos);
+ if(fn) {
+ freefont(def.font);
+ def.font = fn;
+ resize_bar(screen);
+ }else
+ ret = "can't load font";
+ focus_view(screen, screen->sel);
+ break;
+ case LBORDER:
+ if(!getulong(getword(m), &n))
+ return Ebadvalue;
+ def.border = n;
+ focus_view(screen, screen->sel);
+ break;
+ case LGRABMOD:
+ s = getword(m);
+ n = str2modmask(s);
+
+ if((n & (Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) == 0)
+ return Ebadvalue;
+
+ utflcpy(def.grabmod, s, sizeof(def.grabmod));
+ def.mod = n;
+ break;
+ default:
+ return Ebadcmd;
+ }
+ return ret;
+}
+
+char *
+read_root_ctl(void) {
+ char *b, *e;
+
+ b = buffer;
+ e = b + sizeof(buffer) - 1;
+ b = seprint(b, e, "view %s\n", screen->sel->name);
+ b = seprint(b, e, "focuscolors %s\n", def.focuscolor.colstr);
+ b = seprint(b, e, "normcolors %s\n", def.normcolor.colstr);
+ b = seprint(b, e, "font %s\n", def.font->name);
+ b = seprint(b, e, "grabmod %s\n", def.grabmod);
+ b = seprint(b, e, "border %d\n", def.border);
+ USED(b);
+ return buffer;
+}
+
+char *
+message_client(Client *c, IxpMsg *m) {
+ char *s;
+ int i;
+
+ s = getword(m);
+
+ switch(getsym(s)) {
+ case LKILL:
+ kill_client(c);
+ break;
+ case LURGENT:
+ i = gettoggle(m);
+ if(i == -1)
+ return Ebadusage;
+ set_urgent(c, i, True);
+ break;
+ case LFULLSCREEN:
+ i = gettoggle(m);
+ if(i == -1)
+ return Ebadusage;
+ fullscreen(c, i);
+ break;
+ default:
+ return Ebadcmd;
+ }
+ return nil;
+}
+
+static char*
+send_frame(Frame *f, int sym, Bool swap) {
+ Frame *fp;
+
+ SET(fp);
+ switch(sym) {
+ case LUP:
+ fp = f->aprev;
+ if(!fp)
+ return Ebadvalue;
+ fp = fp->aprev;
+ break;
+ case LDOWN:
+ fp = f->anext;
+ if(!fp)
+ return Ebadvalue;
+ break;
+ default:
+ assert(!"can't get here");
+ }
+
+ if(swap) {
+ if(!fp)
+ return Ebadvalue;
+ swap_frames(f, fp);
+ }else {
+ remove_frame(f);
+ insert_frame(fp, f);
+ }
+
+ arrange_view(f->view);
+
+ flushevents(EnterWindowMask, False);
+ focus_frame(f, True);
+ update_views();
+ return nil;
+}
+
+char *
+send_client(View *v, IxpMsg *m, Bool swap) {
+ Area *to, *a;
+ Frame *f;
+ Client *c;
+ char *s;
+ ulong i;
+ int sym;
+
+ s = getword(m);
+
+ c = strclient(v, s);
+ if(c == nil)
+ return Ebadvalue;
+
+ f = view_clientframe(v, c);
+ if(f == nil)
+ return Ebadvalue;
+
+ a = f->area;
+ to = nil;
+
+ s = getword(m);
+ sym = getsym(s);
+
+ switch(sym) {
+ case LUP:
+ case LDOWN:
+ return send_frame(f, sym, swap);
+ case LLEFT:
+ if(a->floating)
+ return Ebadvalue;
+
+ if(a->prev != v->area)
+ to = a->prev;
+ a = v->area;
+ break;
+ case LRIGHT:
+ if(a->floating)
+ return Ebadvalue;
+
+ to = a->next;
+ break;
+ case LTOGGLE:
+ if(!a->floating)
+ to = v->area;
+ else if(c->revert && !c->revert->floating)
+ to = c->revert;
+ else
+ to = v->area->next;
+ break;
+ default:
+ if(!getulong(s, &i) || i == 0)
+ return Ebadvalue;
+
+ for(to=v->area; to; to=to->next)
+ if(!i--) break;
+ break;
+ }
+
+ if(!to && !swap && (f->anext || f != f->area->frame))
+ to = new_column(v, a, 0);
+
+ if(!to)
+ return Ebadvalue;
+
+ if(!swap)
+ send_to_area(to, f);
+ else if(to->sel)
+ swap_frames(f, to->sel);
+ else
+ return Ebadvalue;
+
+ flushevents(EnterWindowMask, False);
+ focus_frame(f, True);
+ arrange_view(v);
+ update_views();
+ return nil;
+}
+
+static char*
+select_frame(Frame *f, IxpMsg *m, int sym) {
+ Frame *fp;
+ Client *c;
+ Area *a;
+ char *s;
+ ulong i;
+
+ if(!f)
+ return Ebadvalue;
+ a = f->area;
+
+ SET(fp);
+ switch(sym) {
+ case LUP:
+ for(fp = a->frame; fp->anext; fp = fp->anext)
+ if(fp->anext == f) break;
+ break;
+ case LDOWN:
+ fp = f->anext;
+ if(fp == nil)
+ fp = a->frame;
+ break;
+ case LCLIENT:
+ s = getword(m);
+ if(s == nil || !getulong(s, &i))
+ return "usage: select client <client>";
+ c = win2client(i);
+ if(c == nil)
+ return "unknown client";
+ fp = view_clientframe(f->view, c);
+ break;
+ default:
+ assert(!"can't get here");
+ }
+
+ if(fp == nil)
+ return "invalid selection";
+
+ focus_frame(fp, False);
+ frame_to_top(fp);
+ if(f->view == screen->sel)
+ restack_view(f->view);
         return nil;
 }
 
 char*
-msg_selectarea(Area *a, IxpMsg *m) {
+select_area(Area *a, IxpMsg *m) {
         Frame *f;
         Area *ap;
         View *v;
@@ -483,9 +592,9 @@ msg_selectarea(Area *a, IxpMsg *m) {
         int sym;
 
         v = a->view;
- s = msg_getword(m);
+ s = getword(m);
         sym = getsym(s);
-
+
         switch(sym) {
         case LTOGGLE:
                 if(!a->floating)
@@ -498,7 +607,7 @@ msg_selectarea(Area *a, IxpMsg *m) {
         case LUP:
         case LDOWN:
         case LCLIENT:
- return msg_selectframe(a->sel, m, sym);
+ return select_frame(a->sel, m, sym);
         case LLEFT:
                 if(a->floating)
                         return Ebadvalue;
@@ -526,223 +635,18 @@ msg_selectarea(Area *a, IxpMsg *m) {
                         if(i != 0)
                                 return Ebadvalue;
                 }
- if((s = msg_getword(m))) {
+ if((s = getword(m))) {
                         if(!getulong(s, &i))
                                 return Ebadvalue;
                         for(f = ap->frame; f; f = f->anext)
                                 if(--i == 0) break;
                         if(i != 0)
                                 return Ebadvalue;
- frame_focus(f);
+ focus_frame(f, True);
                         return nil;
                 }
         }
 
- area_focus(ap);
- return nil;
-}
-
-static char*
-msg_selectframe(Frame *f, IxpMsg *m, int sym) {
- Frame *fp;
- Client *c;
- Area *a;
- char *s;
- ulong i;
-
- if(!f)
- return Ebadvalue;
- a = f->area;
-
- SET(fp);
- switch(sym) {
- case LUP:
- for(fp=a->frame; fp->anext; fp=fp->anext)
- if(fp->anext == f) break;
- break;
- case LDOWN:
- fp = f->anext;
- if(fp == nil)
- fp = a->frame;
- break;
- case LCLIENT:
- s = msg_getword(m);
- if(s == nil || !getulong(s, &i))
- return "usage: select client <client>";
- c = win2client(i);
- if(c == nil)
- return "unknown client";
- fp = client_viewframe(c, f->view);
- break;
- default:
- die("can't get here");
- }
-
- if(fp == nil)
- return "invalid selection";
-
- frame_focus(fp);
- frame_restack(fp, nil);
- if(f->view == screen->sel)
- view_restack(f->view);
- return nil;
-}
-
-char*
-msg_sendclient(View *v, IxpMsg *m, bool swap) {
- Area *to, *a;
- Frame *f;
- Client *c;
- char *s;
- ulong i;
- int sym;
-
- s = msg_getword(m);
-
- c = strclient(v, s);
- if(c == nil)
- return Ebadvalue;
-
- f = client_viewframe(c, v);
- if(f == nil)
- return Ebadvalue;
-
- a = f->area;
- to = nil;
-
- s = msg_getword(m);
- sym = getsym(s);
-
- switch(sym) {
- case LUP:
- case LDOWN:
- return msg_sendframe(f, sym, swap);
- case LLEFT:
- if(a->floating)
- return Ebadvalue;
-
- if(a->prev != v->area)
- to = a->prev;
- a = v->area;
- break;
- case LRIGHT:
- if(a->floating)
- return Ebadvalue;
-
- to = a->next;
- break;
- case LTOGGLE:
- if(!a->floating)
- to = v->area;
- else if(f->column)
- to = view_findarea(v, f->column, true);
- else
- to = view_findarea(v, v->selcol, true);
- break;
- default:
- if(!getulong(s, &i) || i == 0)
- return Ebadvalue;
-
- for(to=v->area; to; to=to->next)
- if(!i--) break;
- break;
- }
-
- if(!to && !swap && (f->anext || f != f->area->frame))
- to = column_new(v, a, 0);
-
- if(!to)
- return Ebadvalue;
-
- if(!swap)
- area_moveto(to, f);
- else if(to->sel)
- frame_swap(f, to->sel);
- else
- return Ebadvalue;
-
- flushenterevents();
- frame_focus(f);
- view_arrange(v);
- view_update_all();
- return nil;
-}
-
-static char*
-msg_sendframe(Frame *f, int sym, bool swap) {
- Frame *fp;
-
- SET(fp);
- switch(sym) {
- case LUP:
- fp = f->aprev;
- if(!fp)
- return Ebadvalue;
- fp = fp->aprev;
- break;
- case LDOWN:
- fp = f->anext;
- if(!fp)
- return Ebadvalue;
- break;
- default:
- die("can't get here");
- }
-
- if(swap) {
- if(!fp)
- return Ebadvalue;
- frame_swap(f, fp);
- }else {
- frame_remove(f);
- frame_insert(f, fp);
- }
-
- view_arrange(f->view);
-
- flushenterevents();
- frame_focus(f);
- view_update_all();
- return nil;
-}
-
-char*
-readctl_root(void) {
- bufclear();
- bufprint("view %s\n", screen->sel->name);
- bufprint("focuscolors %s\n", def.focuscolor.colstr);
- bufprint("normcolors %s\n", def.normcolor.colstr);
- bufprint("font %s\n", def.font->name);
- bufprint("grabmod %s\n", def.grabmod);
- bufprint("border %d\n", def.border);
- if(debug) {
- bufprint("debug ");
- printdebug();
- bufprint("\n");
- }
- return buffer;
-}
-
-char*
-readctl_view(View *v) {
- Area *a;
- uint i;
-
- bufclear();
- bufprint("%s\n", v->name);
-
- /* select <area>[ <frame>] */
- bufprint("select %s", area_name(v->sel));
- if(v->sel->sel)
- bufprint(" %d", frame_idx(v->sel->sel));
- bufprint("\n");
-
- /* select client <client> */
- if(v->sel->sel)
- bufprint("select client %C\n", v->sel->sel->client);
-
- for(a = v->area->next, i = 1; a; a = a->next, i++)
- bufprint("colmode %d %s\n", i, colmode2str(a->mode));
- return buffer;
-}
-
+ focus_area(ap);
+ return nil;
+}
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/mouse.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,11 +1,11 @@
-/* Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+/* Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #include "dat.h"
 #include <assert.h>
+#include <stdlib.h>
+#include <string.h>
 #include "fns.h"
-
-/* Here be dragons. */
 
 enum {
         ButtonMask =
@@ -19,16 +19,15 @@ enum { OHoriz, OVert };
 enum { OHoriz, OVert };
 typedef struct Framewin Framewin;
 struct Framewin {
- /* Todo... give these better names. */
- Window* w;
- Rectangle grabbox;
- Rectangle fprev_r;
- Frame* fprev;
- Frame* f;
- Area* ra;
- Point pt;
- int orientation;
- int xy;
+ Window *w;
+ Frame *f;
+ Frame *fp;
+ Rectangle fr;
+ Area *ra;
+ Rectangle gb;
+ Point pt;
+ int or;
+ int n;
 };
 
 static Rectangle
@@ -37,34 +36,34 @@ framerect(Framewin *f) {
         Point p;
 
         r.min = ZP;
- if(f->orientation == OHoriz) {
- r.max.x = f->xy;
- r.max.y = f->grabbox.max.y + f->grabbox.min.y;
+ if(f->or == OHoriz) {
+ r.max.x = f->n;
+ r.max.y = f->gb.max.y + f->gb.min.y;
                 r = rectsubpt(r, Pt(0, Dy(r)/2));
         }else {
- r.max.x = f->grabbox.max.x + f->grabbox.min.x;
- r.max.y = f->xy;
+ r.max.x = f->gb.max.x + f->gb.min.x;
+ r.max.y = f->n;
                 r = rectsubpt(r, Pt(Dx(r)/2, 0));
         }
         r = rectaddpt(r, f->pt);
         
         /* Keep onscreen */
         p = ZP;
- p.x -= min(0, r.min.x);
- p.x -= max(0, r.max.x - screen->r.max.x);
- p.y -= max(0, r.max.y - screen->brect.min.y - Dy(r)/2);
+ p.x -= min(r.min.x, 0);
+ p.x -= max(r.max.x - screen->r.max.x, 0);
+ p.y -= max(r.max.y - screen->brect.min.y - Dy(r)/2, 0);
         return rectaddpt(r, p);
 }
 
 static void
-frameadjust(Framewin *f, Point pt, int orientation, int xy) {
- f->orientation = orientation;
- f->xy = xy;
+frameadjust(Framewin *f, Point pt, int or, int n) {
+ f->or = or;
+ f->n = n;
         f->pt = pt;
 }
 
 static Framewin*
-framewin(Frame *f, Point pt, int orientation, int n) {
+framewin(Frame *f, Point pt, int or, int n) {
         WinAttr wa;
         Framewin *fw;
 
@@ -76,8 +75,8 @@ framewin(Frame *f, Point pt, int orienta
         sethandler(fw->w, &handlers);
 
         fw->f = f;
- fw->grabbox = f->grabbox;
- frameadjust(fw, pt, orientation, n);
+ fw->gb = f->grabbox;
+ frameadjust(fw, pt, or, n);
         reshapewin(fw->w, framerect(fw));
 
         mapwin(fw->w);
@@ -108,8 +107,8 @@ expose_event(Window *w, XExposeEvent *e)
         r = rectsubpt(w->r, w->r.min);
         fill(buf, r, c->bg);
         border(buf, r, 1, c->border);
- border(buf, f->grabbox, 1, c->border);
- border(buf, insetrect(f->grabbox, -f->grabbox.min.x), 1, c->border);
+ border(buf, f->gb, 1, c->border);
+ border(buf, insetrect(f->gb, -f->gb.min.x), 1, c->border);
 
         copyimage(w, r, buf, ZP);
 }
@@ -120,8 +119,8 @@ static Handlers handlers = {
 
 static int
 _vsnap(Framewin *f, int y) {
- if(abs(f->xy - y) < Dy(f->w->r)) {
- f->xy = y;
+ if(abs(f->n - y) < Dy(f->w->r)) {
+ f->n = y;
                 return 1;
         }
         return 0;
@@ -147,38 +146,38 @@ vplace(Framewin *fw, Point pt) {
 
         r = fw->w->r;
         hr = Dy(r)/2;
- fw->xy = pt.y;
+ fw->n = pt.y;
 
         for(f = a->frame; f->anext; f = f->anext)
                 if(pt.y < f->r.max.y)
                         break;
 
         if(!f->collapsed) {
- fw->fprev = f;
- fw->fprev_r = f->r;
+ fw->fp = f;
+ fw->fr = fw->fp->r;
 
                 if(f == fw->f) {
- fw->fprev = f->aprev;
- fw->fprev_r.max = f->r.max;
+ fw->fp = f->aprev;
+ fw->fr.max = f->r.max;
                         if(_vsnap(fw, f->r.min.y+hr))
                                 goto done;
                 }
 
                 if(_vsnap(fw, f->r.max.y - hr)) {
- fw->fprev_r.min.y = f->r.max.y - labelh(def.font);
+ fw->fr.min.y = f->r.max.y - labelh(def.font);
                         goto done;
                 }
                 if(_vsnap(fw, f->r.min.y+Dy(r)+hr)) {
- fw->fprev_r.min.y = f->r.min.y + labelh(def.font);
+ fw->fr.min.y = f->r.min.y + labelh(def.font);
                         goto done;
                 }
                 if(f->aprev == nil || f->aprev->collapsed)
                         _vsnap(fw, f->r.min.y);
                 else if(_vsnap(fw, f->r.min.y-hr))
- fw->fprev = f->aprev;
- fw->fprev_r.min.y = pt.y - hr;
- if(fw->fprev && fw->fprev->anext == fw->f)
- fw->fprev_r.max = fw->f->r.max;
+ fw->fp = f->aprev;
+ fw->fr.min.y = pt.y - hr;
+ if(fw->fp && fw->fp->anext == fw->f)
+ fw->fr.max = fw->f->r.max;
                 goto done;
         }
 
@@ -194,7 +193,7 @@ vplace(Framewin *fw, Point pt) {
 
 done:
         pt.x = a->r.min.x;
- pt.y = fw->xy;
+ pt.y = fw->n;
         frameadjust(fw, pt, OHoriz, Dx(a->r));
         reshapewin(fw->w, framerect(fw));
 }
@@ -205,8 +204,8 @@ hplace(Framewin *fw, Point pt) {
         View *v;
         int minw;
         
+ minw = Dx(screen->r)/NCOL;
         v = screen->sel;
- minw = Dx(v->r)/NCOL;
 
         for(a = v->area->next; a->next; a = a->next)
                 if(pt.x < a->r.max.x)
@@ -234,11 +233,11 @@ do_managed_move(Client *c) {
         XEvent ev;
         Framewin *fw;
         Window *cwin;
- Frame *f, *fprev, *fnext;
+ Frame *f;
         Point pt, pt2;
         int y;
 
- focus(c, false);
+ focus(c, False);
         f = c->sel;
 
         pt = querypointer(&scr.root);
@@ -248,13 +247,13 @@ do_managed_move(Client *c) {
         fw = framewin(f, pt2, OHoriz, Dx(f->area->r));
 
         r = screen->r;
- r.min.y += fw->grabbox.min.y + Dy(fw->grabbox)/2;
+ r.min.y += fw->gb.min.y + Dy(fw->gb)/2;
         r.max.y = r.min.y + 1;
         cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
         mapwin(cwin);
 
 horiz:
- ungrabpointer();
+ XUngrabPointer(display, CurrentTime);
         if(!grabpointer(&scr.root, nil, cursor[CurIcon], MouseMask))
                 goto done;
         warppointer(pt);
@@ -276,42 +275,36 @@ horiz:
                 case ButtonRelease:
                         switch(ev.xbutton.button) {
                         case 1:
- /* TODO: Fix... Tangled, broken mess. */
- fprev = f->aprev;
- fnext = f->anext;
- column_remove(f, false);
- if(fnext
- && (!fprev || (fw->fprev != fprev)
- && (fw->fprev != fprev->aprev))) {
- fnext->r.min.y = f->r.min.y;
- frame_resize(fnext, fnext->r);
+ if((f->anext) && (!f->aprev || (fw->fp != f->aprev && fw->fp != f->aprev->aprev))) {
+ f->anext->r.min.y = f->r.min.y;
+ resize_frame(f->anext, f->anext->r);
                                 }
- else if(fprev) {
- if(fw->fprev == fprev->aprev) {
- fw->fprev = fprev->aprev;
- fprev->r = f->r;
+ else if(f->aprev) {
+ if(fw->fp == f->aprev->aprev) {
+ fw->fp = f->aprev->aprev;
+ f->aprev->r = f->r;
                                         }else
- fprev->r.max.y = f->r.max.y;
- frame_resize(fprev, fprev->r);
+ f->aprev->r.max.y = f->r.max.y;
+ resize_frame(f->aprev, f->aprev->r);
                                 }
 
- column_insert(fw->ra, f, fw->fprev);
-
- r = fw->fprev_r;
+ remove_frame(f);
+ f->area = fw->ra;
+ insert_frame(fw->fp, f);
+
                                 if(f->aprev) {
- f->aprev->r.max.y = r.min.y;
- frame_resize(f->aprev, f->aprev->r);
- }else
- r.min.y = f->area->r.min.y;
-
+ f->aprev->r.max.y = fw->fr.min.y;
+ resize_frame(f->aprev, f->aprev->r);
+ }
+ else
+ fw->fr.min.y = f->area->r.min.y;
                                 if(f->anext)
- r.max.y = f->anext->r.min.y;
+ fw->fr.max.y = f->anext->r.min.y;
                                 else
- r.max.y = f->area->r.max.y;
-
- frame_resize(f, fw->fprev_r);
-
- view_arrange(f->view);
+ fw->fr.max.y = f->area->r.max.y;
+ resize_frame(f, fw->fr);
+
+ arrange_view(f->view);
                                 goto done;
                         }
                         break;
@@ -325,7 +318,7 @@ horiz:
         }
 vert:
         y = pt.y;
- ungrabpointer();
+ XUngrabPointer(display, CurrentTime);
         if(!grabpointer(&scr.root, cwin, cursor[CurIcon], MouseMask))
                 goto done;
         hplace(fw, pt);
@@ -347,9 +340,8 @@ vert:
                         switch(ev.xbutton.button) {
                         case 1:
                                 if(fw->ra) {
- fw->ra = column_new(f->view, fw->ra, 0);
- area_moveto(fw->ra, f);
- view_arrange(f->view); /* I hate this. */
+ fw->ra = new_column(f->view, fw->ra, 0);
+ send_to_area(fw->ra, f);
                                 }
                                 goto done;
                         case 2:
@@ -360,7 +352,7 @@ vert:
                 }
         }
 done:
- ungrabpointer();
+ XUngrabPointer(display, CurrentTime);
         framedestroy(fw);
         destroywindow(cwin);
 
@@ -370,7 +362,7 @@ done:
         warppointer(pt);
 }
 
-static Window*
+static Window *
 gethsep(Rectangle r) {
         Window *w;
         WinAttr wa;
@@ -393,19 +385,19 @@ mouse_resizecolframe(Frame *f, Align ali
         Rectangle r;
         Point pt, min;
 
- assert((align&(East|West)) != (East|West));
- assert((align&(North|South)) != (North|South));
+ assert((align&(EAST|WEST)) != (EAST|WEST));
+ assert((align&(NORTH|SOUTH)) != (NORTH|SOUTH));
 
         v = screen->sel;
         for(a = v->area->next, d = divs; a; a = a->next, d = d->next)
                 if(a == f->area) break;
 
- if(align&East)
+ if(align&EAST)
                 d = d->next;
 
- min.x = Dx(v->r)/NCOL;
- min.y = /*frame_delta_h() +*/ labelh(def.font);
- if(align&North) {
+ min.x = Dx(screen->r)/NCOL;
+ min.y = frame_delta_h() + labelh(def.font);
+ if(align&NORTH) {
                 if(f->aprev) {
                         r.min.y = f->aprev->r.min.y + min.y;
                         r.max.y = f->r.max.y - min.y;
@@ -422,7 +414,7 @@ mouse_resizecolframe(Frame *f, Align ali
                         r.min.y = r.max.y - 1;
                 }
         }
- if(align&West) {
+ if(align&WEST) {
                 if(a->prev != v->area) {
                         r.min.x = a->prev->r.min.x + min.x;
                         r.max.x = a->r.max.x - min.x;
@@ -444,7 +436,7 @@ mouse_resizecolframe(Frame *f, Align ali
         mapwin(cwin);
 
         r = f->r;
- if(align&North)
+ if(align&NORTH)
                 r.min.y--;
         else
                 r.min.y = r.max.y - 1;
@@ -455,8 +447,8 @@ mouse_resizecolframe(Frame *f, Align ali
         if(!grabpointer(&scr.root, cwin, cursor[CurSizing], MouseMask))
                 goto done;
 
- pt.x = ((align&West) ? f->r.min.x : f->r.max.x);
- pt.y = ((align&North) ? f->r.min.y : f->r.max.y);
+ pt.x = ((align&WEST) ? f->r.min.x : f->r.max.x);
+ pt.y = ((align&NORTH) ? f->r.min.y : f->r.max.y);
         warppointer(pt);
 
         for(;;) {
@@ -471,34 +463,33 @@ mouse_resizecolframe(Frame *f, Align ali
                         pt.x = ev.xmotion.x_root;
                         pt.y = ev.xmotion.y_root;
 
- if(align&West)
+ if(align&WEST)
                                 r.min.x = pt.x;
                         else
                                 r.max.x = pt.x;
- r.min.y = ((align&South) ? pt.y : pt.y-1);
+ r.min.y = ((align&SOUTH) ? pt.y : pt.y-1);
                         r.max.y = r.min.y+2;
 
- div_set(d, pt.x);
+ setdiv(d, pt.x);
                         reshapewin(hwin, r);
                         break;
                 case ButtonRelease:
                         r = f->r;
- if(align&West)
+ if(align&WEST)
                                 r.min.x = pt.x;
                         else
                                 r.max.x = pt.x;
- if(align&North)
+ if(align&NORTH)
                                 r.min.y = pt.y;
                         else
                                 r.max.y = pt.y;
- column_resizeframe(f, &r);
-
- /* XXX: Magic number... */
- if(align&West)
+ resize_colframe(f, &r);
+
+ if(align&WEST)
                                 pt.x = f->r.min.x + 4;
                         else
                                 pt.x = f->r.max.x - 4;
- if(align&North)
+ if(align&NORTH)
                                 pt.y = f->r.min.y + 4;
                         else
                                 pt.y = f->r.max.y - 4;
@@ -507,7 +498,7 @@ mouse_resizecolframe(Frame *f, Align ali
                 }
         }
 done:
- ungrabpointer();
+ XUngrabPointer(display, CurrentTime);
         destroywindow(cwin);
         destroywindow(hwin);
 }
@@ -535,7 +526,7 @@ mouse_resizecol(Divide *d) {
 
         pt = querypointer(&scr.root);
 
- minw = Dx(v->r)/NCOL;
+ minw = Dx(screen->r)/NCOL;
         r.min.x = a->r.min.x + minw;
         r.max.x = a->next->r.max.x - minw;
         r.min.y = pt.y;
@@ -557,83 +548,78 @@ mouse_resizecol(Divide *d) {
                         break;
                 case MotionNotify:
                         pt.x = ev.xmotion.x_root;
- div_set(d, pt.x);
+ setdiv(d, pt.x);
                         break;
                 case ButtonRelease:
- column_resize(a, pt.x - a->r.min.x);
+ resize_column(a, pt.x - a->r.min.x);
                         goto done;
                 }
         }
 done:
- ungrabpointer();
+ XUngrabPointer(display, CurrentTime);
         destroywindow(cwin);
 }
 
 static void
-rect_morph(Rectangle *r, Point d, Align *mask) {
+rect_morph_xy(Rectangle *r, Point d, Align *mask) {
         int n;
 
- if(*mask & North)
+ if(*mask & NORTH)
                 r->min.y += d.y;
- if(*mask & West)
+ if(*mask & WEST)
                 r->min.x += d.x;
- if(*mask & South)
+ if(*mask & SOUTH)
                 r->max.y += d.y;
- if(*mask & East)
+ if(*mask & EAST)
                 r->max.x += d.x;
 
         if(r->min.x > r->max.x) {
                 n = r->min.x;
                 r->min.x = r->max.x;
                 r->max.x = n;
- *mask ^= East|West;
+ *mask ^= EAST|WEST;
         }
         if(r->min.y > r->max.y) {
                 n = r->min.y;
                 r->min.y = r->max.y;
                 r->max.y = n;
- *mask ^= North|South;
+ *mask ^= NORTH|SOUTH;
         }
 }
 
 static int
-snap_hline(Rectangle *rects, int nrect, int dy, Rectangle *r, int y) {
+snap_line(Rectangle *rects, int nrect, int d, int horiz, Rectangle *r, int x, 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;
-}
-
-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;
+ int i, tx, ty;
+
+ if(horiz) {
+ 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(d))
+ d = ty - y;
+
+ ty = rp->max.y;
+ if(abs(ty - y) <= abs(d))
+ d = ty - y;
+ }
+ }
+ }else {
+ 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(d))
+ d = tx - x;
+
+ tx = rp->max.x;
+ if(abs(tx - x) <= abs(d))
+ d = tx - x;
+ }
+ }
+ }
+ return d;
 }
 
 /* Returns a gravity for increment handling. It's normally the opposite of the mask
@@ -648,34 +634,33 @@ snap_rect(Rectangle *rects, int num, Rec
         d.x = snap+1;
         d.y = snap+1;
 
- if(*mask&North)
- d.y = snap_hline(rects, num, d.y, r, r->min.y);
- if(*mask&South)
- d.y = snap_hline(rects, num, d.y, r, r->max.y);
-
- if(*mask&East)
- d.x = snap_vline(rects, num, d.x, r, r->max.x);
- if(*mask&West)
- d.x = snap_vline(rects, num, d.x, r, r->min.x);
-
- ret = Center;
+ if(*mask&NORTH)
+ d.y = snap_line(rects, num, d.y, True, r, 0, r->min.y);
+ if(*mask&SOUTH)
+ d.y = snap_line(rects, num, d.y, True, r, 0, r->max.y);
+
+ if(*mask&EAST)
+ d.x = snap_line(rects, num, d.x, False, r, r->max.x, 0);
+ if(*mask&WEST)
+ d.x = snap_line(rects, num, d.x, False, r, r->min.x, 0);
+
+ ret = CENTER;
         if(abs(d.x) <= snap)
- ret ^= East|West;
+ ret ^= EAST|WEST;
         else
                 d.x = 0;
 
         if(abs(d.y) <= snap)
- ret ^= North|South;
+ ret ^= NORTH|SOUTH;
         else
                 d.y = 0;
 
- rect_morph(r, d, mask);
+ rect_morph_xy(r, d, mask);
         return ret ^ *mask;
 }
 
-/* Grumble... Messy... TODO: Rewrite. */
 void
-mouse_resize(Client *c, bool grabbox, Align align) {
+do_mouse_resize(Client *c, Bool opaque, Align align) {
         XEvent ev;
         Rectangle *rects;
         Rectangle frect, origin;
@@ -688,11 +673,8 @@ mouse_resize(Client *c, bool grabbox, Al
 
         f = c->sel;
 
- if(f->client->fullscreen)
- return;
-
         if(!f->area->floating) {
- if(align==Center)
+ if(align==CENTER)
                         do_managed_move(c);
                 else
                         mouse_resizecolframe(f, align);
@@ -701,10 +683,10 @@ mouse_resize(Client *c, bool grabbox, Al
 
         origin = f->r;
         frect = f->r;
- rects = view_rects(f->area->view, &num, c->frame);
-
- cur = quad_cursor(align);
- if((align==Center) && !grabbox)
+ rects = rects_of_view(f->area->view, &num, c->frame);
+
+ cur = cursor_of_quad(align);
+ if((align==CENTER) && !opaque)
                 cur = cursor[CurSizing];
 
         pt = querypointer(c->framewin);
@@ -719,17 +701,22 @@ mouse_resize(Client *c, bool grabbox, Al
         hr = subpt(frect.max, frect.min);
         hr = divpt(hr, Pt(2, 2));
 
- if(align != Center) {
+ if(align != CENTER) {
                 d = hr;
- if(align&North) d.y -= hr.y;
- if(align&South) d.y += hr.y;
- if(align&East) d.x += hr.x;
- if(align&West) d.x -= hr.x;
+
+ if(align&NORTH) d.y -= hr.y;
+ if(align&SOUTH) d.y += hr.y;
+ if(align&EAST) d.x += hr.x;
+ if(align&WEST) d.x -= hr.x;
 
                 pt = addpt(d, f->r.min);
                 warppointer(pt);
         }
- else if(!grabbox) {
+ else if(f->client->fullscreen) {
+ XUngrabPointer(display, CurrentTime);
+ return;
+ }
+ else if(!opaque) {
                 hrx = (double)(Dx(screen->r) + Dx(frect) - 2 * labelh(def.font))
                                 / Dx(screen->r);
                 hry = (double)(Dy(screen->r) + Dy(frect) - 3 * labelh(def.font))
@@ -756,7 +743,7 @@ mouse_resize(Client *c, bool grabbox, Al
                         d.x = ev.xmotion.x_root;
                         d.y = ev.xmotion.y_root;
 
- if(align == Center && !grabbox) {
+ if(align == CENTER && !opaque) {
                                 SET(hrx);
                                 SET(hry);
                                 d.x = (d.x * hrx) - pt.x;
@@ -765,7 +752,7 @@ mouse_resize(Client *c, bool grabbox, Al
                                 d = subpt(d, pt);
                         pt = addpt(pt, d);
 
- rect_morph(&origin, d, &align);
+ rect_morph_xy(&origin, d, &align);
                         origin = constrain(origin);
                         frect = origin;
 
@@ -775,12 +762,12 @@ mouse_resize(Client *c, bool grabbox, Al
                         frect = constrain(frect);
 
                         //reshapewin(c->framewin, frect);
- client_resize(c, frect);
+ resize_client(c, frect);
                         break;
                 case ButtonRelease:
- client_resize(c, frect);
-
- if(!grabbox) {
+ resize_client(c, frect);
+
+ if(!opaque) {
                                 pt = translate(c->framewin, &scr.root,
                                         Pt(Dx(frect)*rx, Dy(frect)*ry));
                                 if(pt.y > screen->brect.min.y)
@@ -789,21 +776,20 @@ mouse_resize(Client *c, bool grabbox, Al
                         }
 
                         free(rects);
- ungrabpointer();
+ XUngrabPointer(display, CurrentTime);
                         return;
                 }
         }
 }
 
-/* Doesn't belong here */
 void
 grab_button(XWindow w, uint button, ulong mod) {
         XGrabButton(display, button, mod, w, False, ButtonMask,
                         GrabModeSync, GrabModeSync, None, None);
- if((mod != AnyModifier) && (numlock_mask != 0)) {
- XGrabButton(display, button, mod | numlock_mask, w, False, ButtonMask,
+ if((mod != AnyModifier) && (num_lock_mask != 0)) {
+ XGrabButton(display, button, mod | num_lock_mask, w, False, ButtonMask,
                         GrabModeSync, GrabModeAsync, None, None);
- XGrabButton(display, button, mod | numlock_mask | LockMask, w, False,
+ XGrabButton(display, button, mod | num_lock_mask | LockMask, w, False,
                         ButtonMask, GrabModeSync, GrabModeAsync, None, None);
         }
 }
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/printevent.c
--- a/cmd/wmii/printevent.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/printevent.c Fri Jan 18 15:05:45 2008 -0500
@@ -41,6 +41,8 @@
 
 #include "dat.h"
 #include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
 #include <bio.h>
 //#include "fns.h"
 #include "printevent.h"
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/rule.c
--- a/cmd/wmii/rule.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/rule.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,10 +1,21 @@
-/* Copyright ©2006 Anselm R. Garbe <garbeam at gmail dot com>
+/*
+ * Copyright ©2006 Anselm R. Garbe <garbeam at gmail dot com>
  * See LICENSE file for license details.
  */
 
 #include "dat.h"
 #include <assert.h>
+#include <string.h>
+#include <stdlib.h>
 #include "fns.h"
+
+/* basic rule matching language /regex/ -> value
+ * regex might contain POSIX regex syntax defined in regex(3) */
+enum {
+ IGNORE,
+ REGEX,
+ VALUE
+};
 
 void
 trim(char *str, const char *chars) {
@@ -12,37 +23,22 @@ trim(char *str, const char *chars) {
         char *p, *q;
         char c;
 
- q = str;
- for(p = str; *p; p++) {
- for(cp = chars; (c = *cp); cp++)
- if(*p == c)
- goto nextchar;
- *q++ = *p;
- nextchar:
- continue;
+ for(cp = chars; (c = *cp); cp++) {
+ q = str;
+ for(p = q; *p; p++)
+ if(*p != c)
+ *q++ = *p;
+ *q = '\0';
         }
- *q = '\0';
 }
 
-/* XXX: I hate this. --KM */
 void
 update_rules(Rule **rule, const char *data) {
- /* basic rule matching language /regex/ -> value
- * regex might contain POSIX regex syntax defined in regex(3) */
- enum {
- IGNORE,
- REGEX,
- VALUE,
- COMMENT,
- };
- int state;
+ int state = IGNORE;
         Rule *rul;
         char regex[256], value[256];
- char *regex_end = regex + sizeof(regex) - 1;
- char *value_end = value + sizeof(value) - 1;
         char *r, *v;
         const char *p;
- char c;
         
         SET(r);
         SET(v);
@@ -54,56 +50,44 @@ update_rules(Rule **rule, const char *da
                 free(rul->regex);
                 free(rul);
         }
- state = IGNORE;
- for(p = data; (c = *p); p++)
+ for(p = data; *p; p++)
                 switch(state) {
- case COMMENT:
- if(c == '\n')
- state = IGNORE;
- break;
                 case IGNORE:
- if(c == '#')
- state = COMMENT;
- else if(c == '/') {
+ if(*p == '/') {
                                 r = regex;
                                 state = REGEX;
                         }
- else if(c == '>') {
+ else if(*p == '>') {
                                 value[0] = 0;
                                 v = value;
                                 state = VALUE;
                         }
                         break;
                 case REGEX:
- if(c == '\\' && p[1] == '/')
- p++;
- else if(c == '/') {
+ if(*p == '/') {
                                 *r = 0;
                                 state = IGNORE;
- break;
                         }
- if(r < regex_end)
- *r++ = c;
+ else
+ *r++ = *p;
                         break;
                 case VALUE:
- if(c == '\n' || c == '#' || c == 0) {
+ if(*p == '\n' || *p == 0) {
+ *rule = emallocz(sizeof(Rule));
                                 *v = 0;
                                 trim(value, " \t/");
- *rule = emallocz(sizeof *rule);
                                 (*rule)->regex = regcomp(regex);
                                 if((*rule)->regex) {
                                         utflcpy((*rule)->value, value, sizeof(rul->value));
                                         rule = &(*rule)->next;
- }else
- free(*rule);
+ }
+ else free(*rule);
                                 state = IGNORE;
- if(c == '#')
- state = COMMENT;
                         }
- else if(v < value_end)
- *v++ = c;
+ else
+ *v++ = *p;
                         break;
                 default: /* can't happen */
- die("invalid state");
+ assert(!"invalid state");
                 }
 }
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/utf.c
--- a/cmd/wmii/utf.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/utf.c Fri Jan 18 15:05:45 2008 -0500
@@ -2,16 +2,21 @@
 #include "dat.h"
 #include <errno.h>
 #include <iconv.h>
+#include <langinfo.h>
+#include <string.h>
 #include "fns.h"
 
 char*
-toutf8n(const char *str, size_t nstr) {
+toutf8n(char *str, size_t nstr) {
         static iconv_t cd;
         char *buf, *pos;
         size_t nbuf, bsize;
 
- if(cd == nil)
- cd = iconv_open("UTF-8", "");
+ if(cd == nil) {
+ cd = iconv_open("UTF-8", nl_langinfo(CODESET));
+ if(cd == (iconv_t)-1)
+ fatal("Can't convert from native codeset to UTF-8");
+ }
         iconv(cd, nil, nil, nil, nil);
 
         bsize = nstr * 1.25 + 4;
@@ -32,7 +37,7 @@ toutf8n(const char *str, size_t nstr) {
 }
 
 char*
-toutf8(const char *str) {
+toutf8(char *str) {
         return toutf8n(str, strlen(str));
 }
 
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/view.c
--- a/cmd/wmii/view.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/view.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,12 +1,14 @@
 /* Copyright ©2004-2006 Anselm R. Garbe <garbeam at gmail dot com>
- * Copyright ©2006-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+ * Copyright ©2006-2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #include "dat.h"
+#include <stdlib.h>
+#include <string.h>
 #include "fns.h"
 
-static bool
-empty_p(View *v) {
+static Bool
+is_empty(View *v) {
         Area *a;
         for(a=v->area; a; a=a->next)
                 if(a->frame)
@@ -14,80 +16,86 @@ empty_p(View *v) {
         return True;
 }
 
+Frame *
+view_clientframe(View *v, Client *c) {
+ Frame *f;
+
+ for(f=c->frame; f; f=f->cnext)
+ if(f->area->view == v)
+ break;
+ return f;
+}
+
 static void
-_view_select(View *v) {
+assign_sel_view(View *v) {
         if(screen->sel != v) {
                 if(screen->sel)
- event("UnfocusTag %s\n",screen->sel->name);
+ write_event("UnfocusTag %s\n",screen->sel->name);
                 screen->sel = v;
- event("FocusTag %s\n", screen->sel->name);
- ewmh_updateview();
- }
-}
-
-Client*
+ write_event("FocusTag %s\n", screen->sel->name);
+ }
+}
+
+Client *
 view_selclient(View *v) {
         return v->sel && v->sel->sel ? v->sel->sel->client : nil;
 }
 
-bool
-view_fullscreen_p(View *v) {
- Frame *f;
-
- for(f=v->area->frame; f; f=f->anext)
- if(f->client->fullscreen)
- return true;
- return false;
-}
-
-View*
-view_create(const char *name) {
+View *
+get_view(const char *name) {
+ View *v;
+ int cmp;
+
+ SET(cmp);
+ for(v = view; v; v=v->next)
+ if((cmp=strcmp(name, v->name)) >= 0)
+ break;
+ if(!v || cmp != 0)
+ v = create_view(name);
+ return v;
+}
+
+View *
+create_view(const char *name) {
         static ushort id = 1;
         View **i, *v;
 
- for(v=view; v; v=v->next)
- if(!strcmp(name, v->name))
- return v;
-
         v = emallocz(sizeof(View));
         v->id = id++;
- v->r = screen->r;
- v->r.max.y = screen->barwin->r.min.y;
 
         utflcpy(v->name, name, sizeof(v->name));
 
- event("CreateTag %s\n", v->name);
- area_create(v, nil, 0);
- column_new(v, v->area, 0);
+ write_event("CreateTag %s\n", v->name);
+ create_area(v, nil, 0);
+ new_column(v, v->area, 0);
         
- area_focus(v->area->next);
+ focus_area(v->area->next);
 
         for(i=&view; *i; i=&(*i)->next)
- if(strcmp((*i)->name, name) >= 0)
+ if(strcmp((*i)->name, name) < 0)
                         break;
         v->next = *i;
         *i = v;
 
         if(!screen->sel)
- _view_select(v);
- ewmh_updateviews();
+ assign_sel_view(v);
         return v;
 }
 
 void
-view_destroy(View *v) {
+destroy_view(View *v) {
         Area *a;
         View **i, *tv;
 
         while((a = v->area->next))
- area_destroy(a);
- area_destroy(v->area);
+ destroy_area(a);
+ destroy_area(v->area);
 
         for(i=&view; *i; i=&(*i)->next)
                 if(*i == v) break;
         *i = v->next;
 
- event("DestroyTag %s\n", v->name);
+ write_event("DestroyTag %s\n", v->name);
 
         if(v == screen->sel) {
                 for(tv=view; tv; tv=tv->next)
@@ -95,20 +103,9 @@ view_destroy(View *v) {
                 if(tv == nil)
                         tv = view;
                 if(tv)
- view_focus(screen, tv);
+ focus_view(screen, tv);
         }
         free(v);
- ewmh_updateviews();
-}
-
-Area*
-view_findarea(View *v, int idx, bool create) {
- Area *a;
-
- for(a=v->area->next; a && --idx > 0; a=a->next)
- if(create && a->next == nil)
- return area_create(v, a, 0);
- return a;
 }
 
 static void
@@ -122,141 +119,132 @@ update_frame_selectors(View *v) {
 }
 
 void
-view_focus(WMScreen *s, View *v) {
+focus_view(WMScreen *s, View *v) {
+ Frame *f;
         Client *c;
- Frame *f;
- Area *a;
- bool fscrn;
         
         USED(s);
 
         XGrabServer(display);
 
- _view_select(v);
+ assign_sel_view(v);
         update_frame_selectors(v);
- div_update_all();
- fscrn = false;
- for(a=v->area; a; a=a->next)
- for(f=a->frame; f; f=f->anext)
- if(f->client->fullscreen) {
- fscrn = true;
- if(!f->area->floating) {
- f->oldr = f->revert;
- f->oldarea = area_idx(f->area);
- area_moveto(v->area, f);
- area_setsel(v->area, f);
- }else if(f->oldarea == -1) {
- f->oldr = f->r; /* XXX: oldr */
- f->oldarea = 0;
- }
- }
+ update_divs();
         for(c=client; c; c=c->next)
                 if((f = c->sel)) {
                         if(f->view == v)
- client_resize(c, f->r);
+ resize_client(c, f->r);
                         else {
                                 unmap_frame(c);
- client_unmap(c, IconicState);
+ unmap_client(c, IconicState);
                         }
- ewmh_updatestate(c);
- ewmh_updateclient(c);
- }
-
- view_restack(v);
- if(fscrn)
- area_focus(v->area);
- else
- area_focus(v->sel);
- frame_draw_all();
-
- sync();
+ }
+
+ restack_view(v);
+ focus_area(v->sel);
+ draw_frames();
+
+ XSync(display, False);
         XUngrabServer(display);
- flushenterevents();
-}
-
-void
-view_select(const char *arg) {
+ flushevents(EnterWindowMask, False);
+}
+
+void
+select_view(const char *arg) {
         char buf[256];
 
         utflcpy(buf, arg, sizeof(buf));
         trim(buf, " \t+/");
 
- if(buf[0] == '\0')
+ if(strlen(buf) == 0)
                 return;
         if(!strcmp(buf, ".") || !strcmp(buf, ".."))
                 return;
 
- _view_select(view_create(buf));
- view_update_all(); /* performs view_focus */
-}
-
-void
-view_attach(View *v, Frame *f) {
+ assign_sel_view(get_view(buf));
+ update_views(); /* performs focus_view */
+}
+
+void
+attach_to_view(View *v, Frame *f) {
         Client *c;
- Frame *ff;
- Area *a;
         
         c = f->client;
-
- a = v->sel;
- if(client_floats_p(c))
- a = v->area;
- else if((ff = client_groupframe(c, v)))
- a = ff->area;
+ c->revert = nil;
+ if(c->trans || c->floating || c->fixedsize
+ || c->titleless || c->borderless || c->fullscreen)
+ focus_area(v->area);
         else if(starting && v->sel->floating)
- a = v->area->next;
-
- area_attach(a, f);
-}
-
-void
-view_restack(View *v) {
- static Vector_long wins;
+ focus_area(v->area->next);
+ attach_to_area(v->sel, f);
+}
+
+void
+restack_view(View *v) {
+ static XWindow *wins;
+ static uint winssz;
         Divide *d;
         Frame *f;
- Area *a;
- bool fscrn;
+ Client *c;
+ Area *a;
+ uint n, i, fscrn;
         
         if(v != screen->sel)
                 return;
 
- wins.n = 0;
- fscrn = view_fullscreen_p(v);
-
- if(!fscrn)
- vector_lpush(&wins, screen->barwin->w);
+ i = 1;
+ for(c = client; c; c = c->next)
+ i++;
+ if(i == 1)
+ return;
+
+ for(a = v->area; a; a = a->next)
+ i++;
+
+ if(i >= winssz) {
+ winssz = 2 * i;
+ wins = erealloc(wins, sizeof(Window) * winssz);
+ }
+
+ n = 0;
+ fscrn = 0;
+ wins[n++] = screen->barwin->w;
+ for(f=v->area->frame; f; f=f->anext)
+ if(f->client->fullscreen) {
+ n--;
+ fscrn++;
+ break;
+ }
 
         for(f=v->area->stack; f; f=f->snext)
- vector_lpush(&wins, f->client->framewin->w);
+ wins[n++] = f->client->framewin->w;
 
         if(fscrn)
- vector_lpush(&wins, screen->barwin->w);
+ wins[n++] = screen->barwin->w;
 
         for(d = divs; d && d->w->mapped; d = d->next)
- vector_lpush(&wins, d->w->w);
+ wins[n++] = d->w->w;
 
         for(a=v->area->next; a; a=a->next)
                 if(a->frame) {
- vector_lpush(&wins, a->sel->client->framewin->w);
+ wins[n++] = a->sel->client->framewin->w;
                         for(f=a->frame; f; f=f->anext)
                                 if(f != a->sel)
- vector_lpush(&wins, f->client->framewin->w);
- }
-
- ewmh_updatestacking();
- if(wins.n)
- XRestackWindows(display, (ulong*)wins.ary, wins.n);
-}
-
-void
-view_scale(View *v, int w) {
+ wins[n++] = f->client->framewin->w;
+ }
+ if(n)
+ XRestackWindows(display, wins, n);
+}
+
+void
+scale_view(View *v, int w) {
         uint xoff, numcol;
         uint minwidth;
         Area *a;
         float scale;
         int wdiff, dx;
 
- minwidth = Dx(v->r)/NCOL;
+ minwidth = Dx(screen->r)/NCOL;
 
         if(!v->area->next)
                 return;
@@ -299,28 +287,28 @@ view_scale(View *v, int w) {
 }
 
 void
-view_arrange(View *v) {
+arrange_view(View *v) {
         uint xoff;
         Area *a;
 
         if(!v->area->next)
                 return;
 
- view_scale(v, Dx(v->r));
+ scale_view(v, Dx(screen->r));
         xoff = 0;
         for(a=v->area->next; a; a=a->next) {
                 a->r.min.x = xoff;
                 a->r.min.y = 0;
                 a->r.max.y = screen->brect.min.y;
                 xoff = a->r.max.x;
- column_arrange(a, False);
+ arrange_column(a, False);
         }
         if(v == screen->sel)
- div_update_all();
-}
-
-Rectangle*
-view_rects(View *v, uint *num, Frame *ignore) {
+ update_divs();
+}
+
+Rectangle *
+rects_of_view(View *v, uint *num, Frame *ignore) {
         Rectangle *result;
         Frame *f;
         int i;
@@ -342,73 +330,112 @@ view_rects(View *v, uint *num, Frame *ig
         return result;
 }
 
-void
-view_update_all(void) {
- View *n, *v, *old;
-
- old = screen->sel;
- for(v=view; v; v=v->next)
- update_frame_selectors(v);
-
- for(v=view; v; v=n) {
- n=v->next;
- if(v != old && empty_p(v))
- view_destroy(v);
- }
-
- view_focus(screen, screen->sel);
-}
-
-uint
-view_newcolw(View *v, int num) {
- Rule *r;
- ulong n;
-
- for(r=def.colrules.rule; r; r=r->next)
- if(regexec(r->regex, v->name, nil, 0)) {
- char buf[sizeof r->value];
- char *toks[16];
-
- strcpy(buf, r->value);
-
- n = tokenize(toks, 16, buf, '+');
- if(num < n)
- if(getulong(toks[num], &n))
- return Dx(v->r) * (n / 100.0);
- break;
- }
- return 0;
-}
-
-char*
+uchar *
 view_index(View *v) {
         Rectangle *r;
         Frame *f;
         Area *a;
+ char *buf, *end;
         int i;
 
- bufclear();
- for((a=v->area), (i=0); a; (a=a->next), i++) {
+ buf = buffer;
+ end = buffer+sizeof(buffer)-1;
+ for((a=v->area), (i=0); a && buf < end-1; (a=a->next), i++) {
                 if(a->floating)
- bufprint("# ~ %d %d\n", Dx(a->r), Dy(a->r));
+ buf = seprint(buf, end, "# ~ %d %d\n",
+ Dx(a->r), Dy(a->r));
                 else
- bufprint("# %d %d %d\n", i, a->r.min.x, Dx(a->r));
-
- for(f=a->frame; f; f=f->anext) {
+ buf = seprint(buf, end, "# %d %d %d\n",
+ i, a->r.min.x, Dx(a->r));
+
+ for(f=a->frame; f && buf < end-1; f=f->anext) {
                         r = &f->r;
                         if(a->floating)
- bufprint("~ %C %d %d %d %d %s\n",
+ buf = seprint(buf, end, "~ %C %d %d %d %d %s\n",
                                                 f->client,
                                                 r->min.x, r->min.y,
                                                 Dx(*r), Dy(*r),
                                                 f->client->props);
                         else
- bufprint("%d %C %d %d %s\n",
+ buf = seprint(buf, end, "%d %C %d %d %s\n",
                                                 i, f->client,
                                                 r->min.y, Dy(*r),
                                                 f->client->props);
                 }
         }
- return buffer;
-}
-
+ return (uchar*)buffer;
+}
+
+uchar *
+view_ctl(View *v) {
+ Area *a;
+ char *buf, *end;
+ uint i;
+
+ buf = buffer;
+ end = buffer+sizeof(buffer)-1;
+
+ buf = seprint(buf, end, "%s\n", v->name);
+
+ /* select <area>[ <frame>] */
+ buf = seprint(buf, end, "select %s", area_name(v->sel));
+ if(v->sel->sel)
+ buf = seprint(buf, end, " %d", frame_idx(v->sel->sel));
+ buf = seprint(buf, end, "\n");
+
+ /* select client <client> */
+ if(v->sel->sel)
+ buf = seprint(buf, end, "select client %C\n", v->sel->sel->client);
+
+ for(a = v->area->next, i = 1; a && buf < end-1; a = a->next, i++) {
+ buf = seprint(buf, end, "colmode %d %s\n",
+ i, colmode2str(a->mode));
+ }
+ return (uchar*)buffer;
+}
+
+void
+update_views(void) {
+ View *n, *v, *old;
+ int found;
+
+ old = screen->sel;
+ for(v=view; v; v=v->next)
+ update_frame_selectors(v);
+
+ found = 0;
+ for(v=view; v; v=n) {
+ n=v->next;
+ if(v != old) {
+ if(is_empty(v))
+ destroy_view(v);
+ else
+ found++;
+ }
+ }
+
+ if(found && !strcmp(old->name, "nil") && is_empty(old))
+ destroy_view(old);
+ focus_view(screen, screen->sel);
+}
+
+uint
+newcolw(View *v, int num) {
+ Rule *r;
+ ulong n;
+
+ for(r=def.colrules.rule; r; r=r->next)
+ if(regexec(r->regex, v->name, nil, 0)) {
+ char buf[sizeof r->value];
+ char *toks[16];
+
+ strcpy(buf, r->value);
+
+ n = tokenize(toks, 16, buf, '+');
+ if(num < n)
+ if(getulong(toks[num], &n))
+ return Dx(screen->r) * (n / 100.0);
+ break;
+ }
+ return 0;
+}
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/x11.c
--- a/cmd/wmii/x11.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii/x11.c Fri Jan 18 15:05:45 2008 -0500
@@ -1,35 +1,23 @@
-/* Copyright ©2007-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
+/* Copyright ©2007 Kris Maglione <fbsdaemon_AT_gmail.com>
  * See LICENSE file for license details.
  */
 #define _X11_VISIBLE
-#define ZP _ZP
-#define ZR _ZR
-#define pointerwin __pointerwin
 #include "dat.h"
 #include <assert.h>
 #include <math.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <bio.h>
 #include "fns.h"
-#undef ZP /* These should be allocated in read-only memory, */
-#undef ZR /* but declaring them const causes too much trouble
- * elsewhere. */
-#undef pointerwin
-
-const Point ZP = {0, 0};
-const Rectangle ZR = {{0, 0}, {0, 0}};
-
-const Window _pointerwin = {
- .w = PointerRoot
-};
-Window *const pointerwin = (Window*)&_pointerwin;
+
+Point ZP = {0, 0};
+Rectangle ZR = {{0, 0}, {0, 0}};
 
 static Map wmap, amap;
-static MapEnt* wbucket[137];
-static MapEnt* abucket[137];
-
-
-/* Rectangles/Points */
+static MapEnt *wbucket[137];
+static MapEnt *abucket[137];
+
 XRectangle
 XRect(Rectangle r) {
         XRectangle xr;
@@ -107,20 +95,6 @@ rectsubpt(Rectangle r, Point p) {
         return r;
 }
 
-/* Formatters */
-static int
-Afmt(Fmt *f) {
- Atom a;
- char *s;
- int i;
-
- a = va_arg(f->args, Atom);
- s = XGetAtomName(display, a);
- i = fmtprint(f, "%s", s);
- free(s);
- return i;
-}
-
 static int
 Rfmt(Fmt *f) {
         Rectangle r;
@@ -169,14 +143,13 @@ initdisplay(void) {
         amap.bucket = abucket;
         amap.nhash = nelem(abucket);
 
- fmtinstall('A', Afmt);
         fmtinstall('R', Rfmt);
         fmtinstall('P', Pfmt);
         fmtinstall('W', Wfmt);
 }
 
 /* Images */
-Image*
+Image *
 allocimage(int w, int h, int depth) {
         Image *img;
 
@@ -199,7 +172,7 @@ freeimage(Image *img) {
 }
 
 /* Windows */
-Window*
+Window *
 createwindow(Window *parent, Rectangle r, int depth, uint class,
                 WinAttr *wa, int valmask)
                 {
@@ -222,15 +195,6 @@ createwindow(Window *parent, Rectangle r
         w->r = r;
         w->depth = depth;
         return w;
-}
-
-Window*
-window(XWindow w) {
- static Window win;
-
- win.type = WWindow;
- win.w = w;
- return &win;
 }
 
 void
@@ -315,9 +279,9 @@ sethandler(Window *w, Handlers *new) {
         assert((w->prev != nil && w->next != nil) || w->next == w->prev);
 
         if(new == nil)
- map_rm(&wmap, (ulong)w->w);
+ maprm(&wmap, (ulong)w->w);
         else {
- e = map_get(&wmap, (ulong)w->w, 1);
+ e = mapget(&wmap, (ulong)w->w, 1);
                 e->val = w;
         }
         old = w->handler;
@@ -329,21 +293,36 @@ findwin(XWindow w) {
 findwin(XWindow w) {
         MapEnt *e;
         
- e = map_get(&wmap, (ulong)w, 0);
+ e = mapget(&wmap, (ulong)w, 0);
         if(e)
                 return e->val;
         return nil;
 }
 
-long
+uint
 winprotocols(Window *w) {
- return ewmh_protocols(w);
+ Atom *protocols;
+ Atom actual, delete;
+ int i, n, protos;
+
+ n = getproperty(w, "WM_PROTOCOLS", "ATOM", &actual, 0L, (void*)&protocols, 20L);
+ if(n == 0)
+ return 0;
+
+ protos = 0;
+ delete = xatom("WM_DELETE_WINDOW");
+ for(i = 0; i < n; i++) {
+ if(protocols[i] == delete)
+ protos |= WM_PROTOCOL_DELWIN;
+ }
+
+ free(protocols);
+ return protos;
 }
 
 /* Shape */
 void
 setshapemask(Window *dst, Image *src, Point pt) {
- /* Assumes that we have the shape extension... */
         XShapeCombineMask (display, dst->w,
                 ShapeBounding, pt.x, pt.y, src->image, ShapeSet);
 }
@@ -417,7 +396,7 @@ drawline(Image *dst, Point p1, Point p2,
         XDrawLine(display, dst->image, dst->gc, p1.x, p1.y, p2.x, p2.y);
 }
 
-uint
+void
 drawstring(Image *dst, Font *font,
                 Rectangle r, Align align,
                 char *text, ulong col) {
@@ -454,7 +433,7 @@ drawstring(Image *dst, Font *font,
                 len += min(shortened, 3);
 
         switch (align) {
- case East:
+ case EAST:
                 x = r.max.x - (w + (font->height / 2));
                 break;
         default:
@@ -477,7 +456,6 @@ drawstring(Image *dst, Font *font,
 
 done:
         free(buf);
- return w;
 }
 
 void
@@ -490,7 +468,7 @@ copyimage(Image *dst, Rectangle r, Image
 }
 
 /* Colors */
-bool
+Bool
 namedcolor(char *name, ulong *ret) {
         XColor c, c2;
 
@@ -501,7 +479,7 @@ namedcolor(char *name, ulong *ret) {
         return 0;
 }
 
-bool
+Bool
 loadcolor(CTuple *c, char *str) {
         char buf[24];
 
@@ -515,7 +493,7 @@ loadcolor(CTuple *c, char *str) {
 }
 
 /* Fonts */
-Font*
+Font *
 loadfont(char *name) {
         Biobuf *b;
         Font *f;
@@ -594,60 +572,18 @@ xatom(char *name) {
 xatom(char *name) {
         MapEnt *e;
         
- e = hash_get(&amap, name, 1);
+ e = hashget(&amap, name, 1);
         if(e->val == nil)
                 e->val = (void*)XInternAtom(display, name, False);
         return (Atom)e->val;
 }
 
 void
-sendmessage(Window *w, char *name, char *value, long l2, long l3, long l4) {
- XClientMessageEvent e;
-
- e.type = ClientMessage;
- e.window = w->w;
- e.message_type = xatom(name);
- e.format = 32;
- e.data.l[0] = xatom(value);
- e.data.l[1] = xtime;
- e.data.l[2] = l2;
- e.data.l[3] = l3;
- e.data.l[4] = l4;
- sendevent(w, false, NoEventMask, (XEvent*)&e);
-}
-
-void
-sendevent(Window *w, bool propegate, long mask, XEvent *e) {
- XSendEvent(display, w->w, propegate, mask, e);
-}
-
-KeyCode
-keycode(char *name) {
- return XKeysymToKeycode(display, XStringToKeysym(name));
-}
-
-void
-sync(void) {
- XSync(display, False);
-}
-
-/* Properties */
-void
-delproperty(Window *w, char *prop) {
- XDeleteProperty(display, w->w, xatom(prop));
-}
-
-void
 changeproperty(Window *w, char *prop, char *type, int width, uchar data[], int n) {
         XChangeProperty(display, w->w, xatom(prop), xatom(type), width, PropModeReplace, data, n);
 }
 
 void
-changeprop_string(Window *w, char *prop, char *string) {
- changeprop_char(w, prop, "UTF8_STRING", string, strlen(string));
-}
-
-void
 changeprop_char(Window *w, char *prop, char *type, char data[], int len) {
         changeproperty(w, prop, type, 8, (uchar*)data, len);
 }
@@ -663,40 +599,21 @@ changeprop_long(Window *w, char *prop, c
 }
 
 void
-changeprop_textlist(Window *w, char *prop, char *type, char *data[]) {
- char **p, *s, *t;
- int len, n;
-
- len = 0;
- for(p=data; *p; p++)
- len += strlen(*p) + 1;
- s = emalloc(len);
- t = s;
- for(p=data; *p; p++) {
- n = strlen(*p) + 1;
- memcpy(t, *p, n);
- t += n;
- }
- changeprop_char(w, prop, type, s, len);
- free(s);
-}
-
-void
 freestringlist(char *list[]) {
         XFreeStringList(list);
 }
 
-static ulong
-getprop(Window *w, char *prop, char *type, Atom *actual, int *format, ulong offset, uchar **ret, ulong length) {
+ulong
+getproperty(Window *w, char *prop, char *type, Atom *actual, ulong offset, uchar **ret, ulong length) {
         Atom typea;
         ulong n, extra;
- int status;
+ int status, format;
 
         typea = (type ? xatom(type) : 0L);
 
         status = XGetWindowProperty(display, w->w,
                 xatom(prop), offset, length, False /* delete */,
- typea, actual, format, &n, &extra, ret);
+ typea, actual, &format, &n, &extra, ret);
 
         if(status != Success) {
                 *ret = nil;
@@ -707,29 +624,6 @@ getprop(Window *w, char *prop, char *typ
                 *ret = nil;
         }
         return n;
-}
-
-ulong
-getproperty(Window *w, char *prop, char *type, Atom *actual, ulong offset, uchar **ret, ulong length) {
- int format;
-
- return getprop(w, prop, type, actual, &format, offset, ret, length);
-}
-
-ulong
-getprop_long(Window *w, char *prop, char *type, ulong offset, long **ret, ulong length) {
- Atom actual;
- ulong n;
- int format;
-
- n = getprop(w, prop, type, &actual, &format, offset, (uchar**)ret, length);
- if(n == 0 || format == 32 && xatom(type) == actual)
- return n;
- Dprint(DGeneric, "getprop_long(%W, %s, %s) format=%d, actual=\"%A\"\n",
- w, prop, type, format, actual);
- free(*ret);
- *ret = 0;
- return 0;
 }
 
 char**
@@ -754,7 +648,7 @@ strlistdup(char *list[], int n) {
 }
 
 int
-getprop_textlist(Window *w, char *name, char **ret[]) {
+gettextlistproperty(Window *w, char *name, char **ret[]) {
         XTextProperty prop;
         char **list;
         int n;
@@ -771,14 +665,14 @@ getprop_textlist(Window *w, char *name,
         return n;
 }
 
-char*
-getprop_string(Window *w, char *name) {
+char *
+gettextproperty(Window *w, char *name) {
         char **list, *str;
         int n;
 
         str = nil;
 
- n = getprop_textlist(w, name, &list);
+ n = gettextlistproperty(w, name, &list);
         if(n > 0)
                 str = estrdup(*list);
         freestringlist(list);
@@ -794,23 +688,13 @@ setfocus(Window *w, int mode) {
 /* Mouse */
 Point
 querypointer(Window *w) {
- XWindow win;
+ XWindow dummy;
         Point pt;
         uint ui;
         int i;
         
- XQueryPointer(display, w->w, &win, &win, &i, &i, &pt.x, &pt.y, &ui);
+ XQueryPointer(display, w->w, &dummy, &dummy, &i, &i, &pt.x, &pt.y, &ui);
         return pt;
-}
-
-int
-pointerscreen(void) {
- XWindow win;
- Point pt;
- uint ui;
- int i;
-
- return XQueryPointer(display, scr.root.w, &win, &win, &i, &i, &pt.x, &pt.y, &ui);
 }
 
 void
@@ -852,7 +736,6 @@ sethints(Window *w) {
 sethints(Window *w) {
         enum { MaxInt = ((uint)(1<<(8*sizeof(int)-1))-1) };
         XSizeHints xs;
- XWMHints *wmh;
         WinHints *h;
         Point p;
         long size;
@@ -865,13 +748,6 @@ sethints(Window *w) {
 
         h->max = Pt(MaxInt, MaxInt);
         h->inc = Pt(1,1);
-
- wmh = XGetWMHints(display, w->w);
- if(wmh) {
- if(wmh->flags&WindowGroupHint)
- h->group = wmh->window_group;
- free(wmh);
- }
 
         if(!XGetWMNormalHints(display, w->w, &xs, &size))
                 return;
@@ -916,26 +792,18 @@ sethints(Window *w) {
                 xs.win_gravity = NorthWestGravity;
 
         switch (xs.win_gravity) {
- case EastGravity:
- case CenterGravity:
- case WestGravity:
+ case EastGravity: case CenterGravity: case WestGravity:
                 p.y = 1;
                 break;
- case SouthEastGravity:
- case SouthGravity:
- case SouthWestGravity:
+ case SouthEastGravity: case SouthGravity: case SouthWestGravity:
                 p.y = 2;
                 break;
         }
         switch (xs.win_gravity) {
- case NorthGravity:
- case CenterGravity:
- case SouthGravity:
+ case NorthGravity: case CenterGravity: case SouthGravity:
                 p.x = 1;
                 break;
- case NorthEastGravity:
- case EastGravity:
- case SouthEastGravity:
+ case NorthEastGravity: case EastGravity: case SouthEastGravity:
                 p.x = 2;
                 break;
         }
@@ -973,7 +841,7 @@ sizehint(WinHints *h, Rectangle r) {
         p2 = h->aspect.max;
         if(p.x * p2.y / p.y > p2.x)
                 r.max.x = h->baspect.x + p.y * p2.x / p2.y;
-
+
         return rectaddpt(r, o);
 }
 
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/x11.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/wmii/x11.h Fri Jan 18 15:05:45 2008 -0500
@@ -0,0 +1,121 @@
+#define Window XWindow
+#define Font XFont
+#define Screen XScreen
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#ifdef _X11_VISIBLE
+# include <X11/Xatom.h>
+# include <X11/extensions/shape.h>
+#endif
+#undef Window
+#undef Font
+#undef Screen
+
+typedef struct Point Point;
+typedef struct Rectangle Rectangle;
+typedef struct Screen Screen;
+typedef struct Window Window;
+typedef struct WinHints WinHints;
+typedef struct Handlers Handlers;
+typedef struct Window Image;
+typedef struct Font Font;
+typedef XSetWindowAttributes WinAttr;
+
+struct Point {
+ int x, y;
+};
+
+struct Rectangle {
+ Point min, max;
+};
+
+struct Window {
+ int type;
+ XWindow w;
+ Window *parent;
+ Drawable image;
+ GC gc;
+ Rectangle r;
+ void *aux;
+ Handlers *handler;
+ Window *next, *prev;
+ WinHints *hints;
+ Bool mapped;
+ int unmapped;
+ int depth;
+};
+
+struct WinHints {
+ Point min, max;
+ Point base, baspect;
+ Point inc;
+ Rectangle aspect;
+ Point grav;
+ Bool gravstatic;
+ Bool position;
+};
+
+struct Handlers {
+ void (*bdown)(Window*, XButtonEvent*);
+ void (*bup)(Window*, XButtonEvent*);
+ void (*kdown)(Window*, XKeyEvent*);
+ void (*kup)(Window*, XKeyEvent*);
+ void (*focusin)(Window*, XFocusChangeEvent*);
+ void (*focusout)(Window*, XFocusChangeEvent*);
+ void (*enter)(Window*, XCrossingEvent*);
+ void (*leave)(Window*, XCrossingEvent*);
+ void (*motion)(Window*, XMotionEvent*);
+ void (*destroy)(Window*, XDestroyWindowEvent*);
+ void (*configreq)(Window*, XConfigureRequestEvent*);
+ void (*map)(Window*, XMapEvent*);
+ void (*unmap)(Window*, XUnmapEvent*);
+ void (*property)(Window*, XPropertyEvent*);
+ void (*expose)(Window*, XExposeEvent*);
+};
+
+struct Screen {
+ int screen;
+ Window root;
+ Colormap colormap;
+ Visual *visual;
+ Rectangle rect;
+ GC gc;
+ int depth;
+ int fd;
+ ulong black, white;
+};
+
+enum { WWindow, WImage };
+
+struct Font {
+ XFontStruct *xfont;
+ XFontSet set;
+ int ascent;
+ int descent;
+ uint height;
+ char *name;
+};
+
+Display *display;
+Screen scr;
+
+extern Point ZP;
+extern Rectangle ZR;
+
+Rectangle insetrect(Rectangle r, int n);
+
+Point Pt(int x, int y);
+Rectangle Rect(int x0, int y0, int x1, int y1);
+Rectangle Rpt(Point min, Point max);
+
+XRectangle XRect(Rectangle r);
+
+#define Dx(r) ((r).max.x - (r).min.x)
+#define Dy(r) ((r).max.y - (r).min.y)
+#define Pt(x, y) ((Point){(x), (y)})
+#define Rpt(p, q) ((Rectangle){p, q})
+#define Rect(x0, y0, x1, y1) ((Rectangle){Pt(x0, y0), Pt(x1, y1)})
+#define changeprop(w, prop, type, data, n) \
+ changeproperty(w, prop, type, \
+ ((sizeof(*(data)) == 8 ? 4 : sizeof(*(data))) * 8), \
+ (uchar*)(data), n)
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii/xext.c
--- a/cmd/wmii/xext.c Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-/* Copyright ©2008 Kris Maglione <fbsdaemon_AT_gmail.com>
- * See LICENSE file for license details.
- */
-#define _X11_VISIBLE
-#include "dat.h"
-#include "fns.h"
-
-#if RANDR_MAJOR < 1
-# error XRandR versions less than 1.0 are not supported
-#endif
-
-static void randr_screenchange(XRRScreenChangeNotifyEvent*);
-
-bool have_RandR;
-int randr_eventbase;
-
-void
-xext_init(void) {
- randr_init();
-}
-
-void
-xext_event(XEvent *e) {
-
- if(have_RandR && (ulong)(e->type - randr_eventbase) < RRNumberEvents) {
- e->type -= randr_eventbase;
- randr_event(e);
- }
-}
-
-void
-randr_init(void) {
- int errorbase, major, minor;
-
- have_RandR = XRRQueryExtension(display, &randr_eventbase, &errorbase);
- if(have_RandR)
- if(XRRQueryVersion(display, &major, &minor) && major < 1)
- have_RandR = false;
- if(!have_RandR)
- return;
- XRRSelectInput(display, scr.root.w, RRScreenChangeNotifyMask);
-}
-
-static void
-randr_screenchange(XRRScreenChangeNotifyEvent *ev) {
- View *v;
- Point d;
-
- XRRUpdateConfiguration((XEvent*)ev);
-
- d.x = ev->width - Dx(screen->r);
- d.y = ev->height - Dy(screen->r);
- for(v=view; v; v=v->next) {
- v->r.max.x += d.x;
- v->r.max.y += d.y;
- }
- screen->r = Rect(0, 0, ev->width, ev->height);
- bar_resize(screen);
-}
-
-void
-randr_event(XEvent *e) {
-
- switch(e->type) {
- default:
- break;
- case RRScreenChangeNotify: /* Yuck. */
- randr_screenchange((XRRScreenChangeNotifyEvent*)e);
- break;
- }
-}
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmii9rc.sh
--- a/cmd/wmii9rc.sh Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmii9rc.sh Fri Jan 18 15:05:45 2008 -0500
@@ -1,7 +1,7 @@
 #!/bin/sh -f
 RC=""
 IFS=:
-for i in "$PLAN9" `echo "P9PATHS"`; do
+for i in "$PLAN9" `echo P9PATHS`; do
         if [ -d "$i" -a -x "$i/bin/rc" ]; then
                 export PLAN9="$i"
                 RC="$i/bin/rc"
@@ -9,7 +9,7 @@ for i in "$PLAN9" `echo "P9PATHS"`; do
         fi
 done
 
-if [ -z "$RC" ]; then
+if [ -n "$RC" ]; then
         exit 1
 fi
 
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmiir.c
--- a/cmd/wmiir.c Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmiir.c Fri Jan 18 15:05:45 2008 -0500
@@ -239,7 +239,7 @@ xls(int argc, char *argv[]) {
         Stat *stat;
         IxpCFid *fid;
         char *file;
- char *buf;
+ uchar *buf;
         int lflag, dflag, count, nstat, mstat, i;
 
         lflag = dflag = 0;
diff -r 3c06b49f84d1 -r 3a29c2ddccbb cmd/wmiistartrc.sh
--- a/cmd/wmiistartrc.sh Sat Jan 19 22:21:47 2008 -0500
+++ b/cmd/wmiistartrc.sh Fri Jan 18 15:05:45 2008 -0500
@@ -3,16 +3,15 @@
 
 export home="$HOME"
 lconf="$home/.wmii-CONFVERSION"
-gconf="CONFPREFIX/wmii-CONFVERSION"
+gconf="CONFPREFIX/.wmii-CONFVERSION"
 
-export WMII_CONFPATH="$lconf:$gconf"
+export WMII_CONFPATH="$conf:$gconf"
 export POSIXLY_CORRECT=gnu_hippies
 
-which="`which which`"
 if wmii9rc; then
- WMIIRC=`PATH="$WMII_CONFPATH:$PATH" $which rc.wmii`
+ WMIIRC=`PATH="$WMII_CONFPATH:$PATH" which rc.wmii`
 else
- WMIIRC=`PATH="$WMII_CONFPATH:$PATH" $which wmiirc`
+ WMIIRC=`PATH="$WMII_CONFPATH:$PATH" which wmiirc`
 fi
 
 mkdir $conf 2>/dev/null && $gconf/welcome &
diff -r 3c06b49f84d1 -r 3a29c2ddccbb config.mk
--- a/config.mk Sat Jan 19 22:21:47 2008 -0500
+++ b/config.mk Fri Jan 18 15:05:45 2008 -0500
@@ -2,25 +2,26 @@
 
 # paths
 PREFIX = /usr/local
- BIN = $(PREFIX)/bin
- MAN = $(PREFIX)/share/man
- ETC = $(PREFIX)/etc
- LIBDIR = $(PREFIX)/lib
- INCLUDE = $(PREFIX)/include
+BIN = ${PREFIX}/bin
+MAN = ${PREFIX}/share/man
+ETC = ${PREFIX}/etc
+LIBDIR = ${PREFIX}/lib
+INCLUDE = ${PREFIX}/include
 
 # Includes and libs
-INCPATH = .:$(ROOT)/include:$(INCLUDE):/usr/include
-LIBS = -L/usr/lib -lc -L$(ROOT)/lib
+INCPATH = .:${ROOT}/include:${INCLUDE}:/usr/include
+LIBS = -L/usr/lib -lc -L${ROOT}/lib
 
 # Flags
-include $(ROOT)/mk/gcc.mk
-CFLAGS += $(DEBUGCFLAGS)
-LDFLAGS += -g $(LIBS)
-SOLDFLAGS += $(LDFLAGS)
+include ${ROOT}/mk/gcc.mk
+CFLAGS += -g -O0 -DIXPlint
+LDFLAGS += -g ${LIBS}
 STATIC = -static
+MKDEP = cpp -M
 
-# Compiler, Linker. Linker should usually *not* be ld.
+# Compiler
 CC = cc -c
+# Linker (Under normal circumstances, this should *not* be 'ld')
 LD = cc
 # Archiver
 AR = ar crs
@@ -31,18 +32,15 @@ INCX11 = -I/usr/X11R6/include
 INCX11 = -I/usr/X11R6/include
 LIBX11 = -L/usr/X11R6/lib -lX11
 LIBICONV = # Leave blank if your libc includes iconv (glibc does)
-LIBIXP = $(ROOT)/libixp/libixp.a
-LIBIXP = $(LIBDIR)/libixp.a
-
-# Operating System Configurations
-
-# *BSD
-#LIBICONV = -liconv
-# +Darwin
-#STATIC = # Darwon doesn't like static linking
+LIBIXP = ${ROOT}/libixp/libixp.a
+LIBIXP = ${LIBDIR}/libixp.a
 
 # Solaris
-#CFLAGS = -fast $(INCS)
-#LDFLAGS = $(LIBS) -R$(PREFIX)/lib -lsocket -lnsl
+#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
+#LDFLAGS = ${LIBS} -R${PREFIX}/lib
+#LDFLAGS += -lsocket -lnsl
 #CFLAGS += -xtarget=ultra
 
+# Darwin
+#STATIC = # This space intentionally left blank
+#LIBICONV = -liconv
diff -r 3c06b49f84d1 -r 3a29c2ddccbb include/util.h
--- a/include/util.h Sat Jan 19 22:21:47 2008 -0500
+++ b/include/util.h Fri Jan 18 15:05:45 2008 -0500
@@ -1,6 +1,3 @@
-/* Copyright ©2007-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
- * See LICENSE file for license details.
- */
 #define nil ((void*)0)
 #define nelem(ary) (sizeof(ary) / sizeof(*ary))
 
@@ -28,7 +25,6 @@ typedef long long vlong;
 
 #define strlcat wmii_strlcat
 /* util.c */
-void _die(char*, int, char*);
 void* emalloc(uint);
 void* emallocz(uint);
 void* erealloc(void*, uint);
@@ -36,14 +32,10 @@ void fatal(const char*, ...);
 void fatal(const char*, ...);
 int max(int, int);
 int min(int, int);
+char* str_nil(char*);
 uint strlcat(char*, const char*, uint);
-char* sxprint(const char*, ...);
 uint tokenize(char **, uint, char*, char);
 int utflcpy(char*, const char*, int);
-char* vsxprint(const char*, va_list);
-
-#define die(x) \
- _die(__FILE__, __LINE__, x)
 
 char *argv0;
 #undef ARGBEGIN
diff -r 3c06b49f84d1 -r 3a29c2ddccbb include/x11.h
--- a/include/x11.h Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,239 +0,0 @@
-/* Copyright ©2007-2008 Kris Maglione <fbsdaemon_AT_gmail.com>
- * See LICENSE file for license details.
- */
-#define Window XWindow
-#define Font XFont
-#define Screen XScreen
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#ifdef _X11_VISIBLE
-# include <X11/Xatom.h>
-# include <X11/extensions/shape.h>
-# include <X11/extensions/Xrandr.h>
-#endif
-#undef Window
-#undef Font
-#undef Screen
-
-enum Align {
- North = 0x01,
- East = 0x02,
- South = 0x04,
- West = 0x08,
- NEast = North | East,
- NWest = North | West,
- SEast = South | East,
- SWest = South | West,
- Center = NEast | SWest,
-};
-
-typedef enum Align Align;
-
-typedef struct CTuple CTuple;
-typedef struct Point Point;
-typedef struct Rectangle Rectangle;
-typedef struct Screen Screen;
-typedef struct Ewmh Ewmh;
-typedef struct Window Window;
-typedef struct WinHints WinHints;
-typedef struct Handlers Handlers;
-typedef struct Window Image;
-typedef struct Font Font;
-typedef XSetWindowAttributes WinAttr;
-
-struct CTuple {
- ulong bg;
- ulong fg;
- ulong border;
- char colstr[24]; /* #RRGGBB #RRGGBB #RRGGBB */
-};
-
-struct Point {
- int x, y;
-};
-
-struct Rectangle {
- Point min, max;
-};
-
-struct Ewmh {
- long type;
- long ping;
- long timer;
-};
-
-struct Window {
- int type;
- XWindow w;
- Window *parent;
- Drawable image;
- GC gc;
- Rectangle r;
- void *aux;
- Handlers *handler;
- Window *next, *prev;
- WinHints *hints;
- Ewmh ewmh;
- bool mapped;
- int unmapped;
- int depth;
-};
-
-struct WinHints {
- Point min;
- Point max;
- Point base;
- Point baspect;
- Point inc;
- Point grav;
- Rectangle aspect;
- XWindow group;
- bool gravstatic;
- bool position;
-};
-
-struct Handlers {
- void (*bdown)(Window*, XButtonEvent*);
- void (*bup)(Window*, XButtonEvent*);
- void (*kdown)(Window*, XKeyEvent*);
- void (*kup)(Window*, XKeyEvent*);
- void (*focusin)(Window*, XFocusChangeEvent*);
- void (*focusout)(Window*, XFocusChangeEvent*);
- void (*enter)(Window*, XCrossingEvent*);
- void (*leave)(Window*, XCrossingEvent*);
- void (*motion)(Window*, XMotionEvent*);
- void (*destroy)(Window*, XDestroyWindowEvent*);
- void (*configreq)(Window*, XConfigureRequestEvent*);
- void (*map)(Window*, XMapEvent*);
- void (*unmap)(Window*, XUnmapEvent*);
- void (*property)(Window*, XPropertyEvent*);
- void (*expose)(Window*, XExposeEvent*);
-};
-
-struct Screen {
- int screen;
- Window root;
- Colormap colormap;
- Visual *visual;
- Rectangle rect;
- GC gc;
- int depth;
- int fd;
- ulong black, white;
-};
-
-enum { WWindow, WImage };
-
-struct Font {
- XFontStruct *xfont;
- XFontSet set;
- int ascent;
- int descent;
- uint height;
- char *name;
-};
-
-#ifdef VARARGCK
-# pragma varargck type "A" Atom
-# pragma varargck type "W" Window*
-# pragma varargck type "P" Point
-# pragma varargck type "R" Rectangle
-#endif
-
-Display *display;
-Screen scr;
-
-extern Point ZP;
-extern Rectangle ZR;
-extern Window* pointerwin;
-
-Rectangle insetrect(Rectangle r, int n);
-
-Point Pt(int x, int y);
-Rectangle Rect(int x0, int y0, int x1, int y1);
-Rectangle Rpt(Point min, Point max);
-
-XRectangle XRect(Rectangle r);
-
-#define Dx(r) ((r).max.x - (r).min.x)
-#define Dy(r) ((r).max.y - (r).min.y)
-#define Pt(x, y) ((Point){(x), (y)})
-#define Rpt(p, q) ((Rectangle){p, q})
-#define Rect(x0, y0, x1, y1) ((Rectangle){Pt(x0, y0), Pt(x1, y1)})
-#define changeprop(w, prop, type, data, n) \
- changeproperty(w, prop, type, \
- ((sizeof(*(data)) == 8 ? 4 : sizeof(*(data))) * 8), \
- (uchar*)(data), n)
-
-/* x11.c */
-Point addpt(Point, Point);
-Image* allocimage(int w, int h, int depth);
-void border(Image *dst, Rectangle, int w, ulong col);
-void changeprop_char(Window*, char*, char*, char[], int);
-void changeprop_long(Window*, char*, char*, long[], int);
-void changeprop_short(Window*, char*, char*, short[], int);
-void changeprop_string(Window*, char*, char*);
-void changeprop_textlist(Window*, char*, char*, char*[]);
-void changeproperty(Window*, char*, char*, int width, uchar*, int);
-void copyimage(Image*, Rectangle, Image*, Point);
-Window* createwindow(Window *parent, Rectangle, int depth, uint class, WinAttr*, int valuemask);
-void delproperty(Window*, char*);
-void destroywindow(Window*);
-Point divpt(Point, Point);
-void drawline(Image*, Point, Point, int cap, int w, ulong col);
-void drawpoly(Image*, Point*, int, int cap, int w, ulong col);
-uint drawstring(Image*, Font*, Rectangle, Align, char*, ulong col);
-int eqpt(Point, Point);
-int eqrect(Rectangle, Rectangle);
-void fill(Image*, Rectangle, ulong col);
-void fillpoly(Image*, Point*, int, ulong col);
-Window* findwin(XWindow);
-void freefont(Font*);
-void freeimage(Image *);
-void freestringlist(char**);
-ulong getprop_long(Window*, char*, char*, ulong, long**, ulong);
-char* getprop_string(Window*, char*);
-int getprop_textlist(Window *w, char *name, char **ret[]);
-ulong getproperty(Window*, char *prop, char *type, Atom *actual, ulong offset, uchar **ret, ulong length);
-int grabpointer(Window*, Window *confine, Cursor, int mask);
-void initdisplay(void);
-KeyCode keycode(char*);
-uint labelh(Font*);
-bool loadcolor(CTuple*, char*);
-Font* loadfont(char*);
-void lowerwin(Window*);
-int mapwin(Window*);
-void movewin(Window*, Point);
-Point mulpt(Point p, Point q);
-bool namedcolor(char *name, ulong*);
-int pointerscreen(void);
-Point querypointer(Window*);
-void raisewin(Window*);
-void reparentwindow(Window*, Window*, Point);
-void reshapewin(Window*, Rectangle);
-void sendevent(Window*, bool propegate, long mask, XEvent*);
-void setfocus(Window*, int mode);
-void sethints(Window*);
-void setshapemask(Window *dst, Image *src, Point);
-void setwinattr(Window*, WinAttr*, int valmask);
-char** strlistdup(char**, int);
-Point subpt(Point, Point);
-void sync(void);
-uint textwidth(Font*, char*);
-uint textwidth_l(Font*, char*, uint len);
-Point translate(Window*, Window*, Point);
-void ungrabpointer(void);
-int unmapwin(Window*);
-void warppointer(Point);
-Window* window(XWindow);
-long winprotocols(Window*);
-Atom xatom(char*);
-void sendmessage(Window*, char*, char*, long, long, long);
-XRectangle XRect(Rectangle);
-Rectangle gravitate(Rectangle dst, Rectangle src, Point grav);
-Rectangle insetrect(Rectangle, int);
-Rectangle rectaddpt(Rectangle, Point);
-Rectangle rectsubpt(Rectangle, Point);
-Handlers* sethandler(Window*, Handlers*);
-Rectangle sizehint(WinHints*, Rectangle);
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb libfmt/fmtvprint.c
--- a/libfmt/fmtvprint.c Sat Jan 19 22:21:47 2008 -0500
+++ b/libfmt/fmtvprint.c Fri Jan 18 15:05:45 2008 -0500
@@ -24,7 +24,7 @@
  * but ignore any width flags
  */
 int
-fmtvprint(Fmt *f, const char *fmt, va_list args)
+fmtvprint(Fmt *f, const char *fmt, va_list args)
 {
         va_list va;
         int n;
diff -r 3c06b49f84d1 -r 3a29c2ddccbb libregexp/Makefile
--- a/libregexp/Makefile Sat Jan 19 22:21:47 2008 -0500
+++ b/libregexp/Makefile Fri Jan 18 15:05:45 2008 -0500
@@ -11,7 +11,7 @@ OBJ=\
         regsub\
         regaux\
         rregexec\
- rregsub\
+ rregsub
 
 include ${ROOT}/mk/lib.mk
 
diff -r 3c06b49f84d1 -r 3a29c2ddccbb libwmii_hack/Makefile
--- a/libwmii_hack/Makefile Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-ROOT= ..
-include ${ROOT}/mk/hdr.mk
-
-hack.o hack.o_pic: util.c x11.c hack.h x11.h
-
-CFLAGS += $(INCX11)
-
-TARG = libwmii_hack
-OBJ = hack
-# util \
-# x11
-
-include ${ROOT}/mk/so.mk
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb libwmii_hack/hack.c
--- a/libwmii_hack/hack.c Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,144 +0,0 @@
-/* Copyright ©2008 Kris Maglione <fbsdaemon_AT_gmail.com>
- * See LICENSE file for license details.
- */
-#include "hack.h"
-#include <dlfcn.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "util.c"
-#include "x11.c"
-
-enum {
- Timeout = 10000,
-};
-
-static void* xlib;
-
-static long transient;
-static Atom types[32];
-static long ntypes;
-static char* tags[32];
-static long ntags;
-static long pid;
-static long stime;
-static char hostname[256];
-static long nmsec;
-
-typedef Window (*mapfn)(Display*, Window);
-
-static Window (*mapwindow)(Display*, Window);
-static Window (*mapraised)(Display*, Window);
-
-static long
-msec(void) {
- struct timeval tv;
-
- if(!gettimeofday(&tv, 0))
- return 0;
- return tv.tv_sec*1000 + tv.tv_usec/1000;
-}
-
-static void
-init(Display *d) { /* Hrm... assumes one display... */
- char *toks[nelem(types)];
- char *s, *p;
- long n;
- int i;
-
- xlib = dlopen("libX11.so", RTLD_GLOBAL | RTLD_LAZY);
- if(xlib == nil)
- return;
- mapwindow = (mapfn)(uintptr_t)dlsym(xlib, "XMapWindow");
- mapraised = (mapfn)(uintptr_t)dlsym(xlib, "XMapRaised");
-
- unsetenv("LD_PRELOAD");
-
- if((s = getenv("WMII_HACK_TRANSIENT"))) {
- if(getlong(s, &n))
- transient = n;
- unsetenv("WMII_HACK_TRANSIENT");
- }
- if((s = getenv("WMII_HACK_TYPE"))) {
- s = strdup(s);
- unsetenv("WMII_HACK_TYPE");
-
- n = tokenize(toks, nelem(toks), s, ',');
- for(i=0; i < n; i++) {
- for(p=toks[i]; *p; p++)
- if(*p >= 'a' && *p <= 'z')
- *p += 'A' - 'a';
- toks[i] = smprint("_NET_WM_WINDOW_TYPE_%s", toks[i]);
- }
- XInternAtoms(d, toks, n, False, types);
- ntypes = n;
- for(i=0; i < n; i++)
- free(toks[i]);
- free(s);
- }
- if((s = getenv("WMII_HACK_TAGS"))) {
- s = strdup(s);
- unsetenv("WMII_HACK_TAGS");
-
- n = tokenize(toks, nelem(toks)-1, s, '+');
- for(i=0; i < n; i++)
- tags[i] = strdup(toks[i]);
- ntags = n;
- free(s);
- }
- if((s = getenv("WMII_HACK_TIME"))) {
- getlong(s, &stime);
- unsetenv("WMII_HACK_TIME");
- }
-
- pid = getpid();
- gethostname(hostname, sizeof hostname);
-}
-
-static void
-setprops(Display *d, Window w) {
- long *l;
-
- if(!xlib)
- init(d);
-
- if(getprop_long(d, w, "_NET_WM_PID", "CARDINAL", 0L, &l, 1L))
- free(l);
- else {
- changeprop_long(d, w, "_NET_WM_PID", "CARDINAL", &pid, 1);
- changeprop_string(d, w, "WM_CLIENT_MACHINE", hostname);
- }
-
- /* Kludge. */
- if(nmsec == 0)
- nmsec = msec();
- if(msec() > nmsec + Timeout)
- return;
-
- if(transient)
- changeprop_long(d, w, "WM_TRANSIENT_FOR", "WINDOW", &transient, 1);
- if(ntypes)
- changeprop_long(d, w, "_NET_WM_WINDOW_TYPE", "ATOM", (long*)types, ntypes);
- if(ntags)
- changeprop_textlist(d, w, "_WMII_TAGS", "UTF8_STRING", tags);
- if(stime)
- changeprop_long(d, w, "_WMII_LAUNCH_TIME", "CARDINAL", &stime, 1);
-}
-
-int
-XMapWindow(Display *d, Window w) {
-
- setprops(d, w);
- return mapwindow(d, w);
-}
-
-int
-XMapRaised(Display *d, Window w) {
-
- setprops(d, w);
- return mapraised(d, w);
-}
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb libwmii_hack/hack.h
--- a/libwmii_hack/hack.h Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-
-typedef unsigned long ulong;
-typedef unsigned int uint;
-typedef unsigned char uchar;
-
-#define _XOPEN_SOURCE 600
-#define IXP_P9_STRUCTS
-#define IXP_NO_P9_
-#include <assert.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <x11.h>
-#include <X11/Xlib.h>
-
-#define strdup my_strdup
-
-static int getlong(const char*, long*);
-static uint tokenize(char*[], uint, char*, char);
-static char* smprint(const char*, ...);
-static char* vsmprint(const char*, va_list);
-static char* strdup(const char*);
-
-#define nil ((void*)0)
-#define nelem(ary) (sizeof(ary) / sizeof(*ary))
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb libwmii_hack/util.c
--- a/libwmii_hack/util.c Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,101 +0,0 @@
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-
-#define strbcmp(str, const) (strncmp((str), (const), sizeof(const)-1))
-static int
-getbase(const char **s) {
- const char *p;
-
- p = *s;
- if(!strbcmp(p, "0x")) {
- *s += 2;
- return 16;
- }
- if(isdigit(p[0])) {
- if(p[1] == 'r') {
- *s += 2;
- return p[0] - '0';
- }
- if(isdigit(p[1]) && p[2] == 'r') {
- *s += 3;
- return 10*(p[0]-'0') + (p[1]-'0');
- }
- }
- if(p[0] == '0') {
- *s += 1;
- return 8;
- }
- return 10;
-}
-
-static int
-getlong(const char *s, long *ret) {
- const char *end;
- char *rend;
- int base;
-
- end = s+strlen(s);
- base = getbase(&s);
-
- *ret = strtol(s, &rend, base);
- return (end == rend);
-}
-
-static uint
-tokenize(char *res[], uint reslen, char *str, char delim) {
- char *s;
- uint i;
-
- i = 0;
- s = str;
- while(i < reslen && *s) {
- while(*s == delim)
- *(s++) = '\0';
- if(*s)
- res[i++] = s;
- while(*s && *s != delim)
- s++;
- }
- return i;
-}
-
-static char*
-vsmprint(const char *fmt, va_list ap) {
- va_list al;
- char *buf = "";
- int n;
-
- va_copy(al, ap);
- n = vsnprintf(buf, 0, fmt, al);
- va_end(al);
-
- buf = malloc(++n);
- if(buf)
- vsnprintf(buf, n, fmt, ap);
- return buf;
-}
-
-static char*
-smprint(const char *fmt, ...) {
- va_list ap;
- char *ret;
-
- va_start(ap, fmt);
- ret = vsmprint(fmt, ap);
- va_end(ap);
- return ret;
-}
-
-static char*
-strdup(const char *s) {
- char *ret;
- int len;
-
- len = strlen(s)+1;
- ret = malloc(len);
- if(ret)
- memcpy(ret, s, len);
- return ret;
-}
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb libwmii_hack/x11.c
--- a/libwmii_hack/x11.c Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,189 +0,0 @@
-/* Copyright ©2007 Kris Maglione <fbsdaemon_AT_gmail.com>
- * See LICENSE file for license details.
- */
-#include <assert.h>
-
-/* Misc */
-static Atom
-xatom(Display *display, char *name) {
- /* Blech. I don't trust Xlib's cacheing.
- MapEnt *e;
-
- e = hash_get(&amap, name, 1);
- if(e->val == nil)
- e->val = (void*)XInternAtom(display, name, False);
- return (Atom)e->val;
- */
- return XInternAtom(display, name, False);
-}
-/* Properties */
-#if 0
-static void
-delproperty(Display *display, Window w, char *prop) {
- XDeleteProperty(display, w, xatom(display, prop));
-}
-#endif
-
-static void
-changeproperty(Display *display, Window w, char *prop, char *type, int width, uchar data[], int n) {
- XChangeProperty(display, w, xatom(display, prop), xatom(display, type), width, PropModeReplace, data, n);
-}
-
-static void
-changeprop_string(Display *display, Window w, char *prop, char *string) {
- changeprop_char(display, w, prop, "UTF8_STRING", string, strlen(string));
-}
-
-static void
-changeprop_char(Display *display, Window w, char *prop, char *type, char data[], int len) {
- changeproperty(display, w, prop, type, 8, (uchar*)data, len);
-}
-
-#if 0
-static void
-changeprop_short(Display *display, Window w, char *prop, char *type, short data[], int len) {
- changeproperty(display, w, prop, type, 16, (uchar*)data, len);
-}
-#endif
-
-static void
-changeprop_long(Display *display, Window w, char *prop, char *type, long data[], int len) {
- changeproperty(display, w, prop, type, 32, (uchar*)data, len);
-}
-
-static void
-changeprop_textlist(Display *display, Window w, char *prop, char *type, char *data[]) {
- char **p, *s, *t;
- int len, n;
-
- len = 0;
- for(p=data; *p; p++)
- len += strlen(*p) + 1;
- s = malloc(len);
- if(s == nil)
- return;
- t = s;
- for(p=data; *p; p++) {
- n = strlen(*p) + 1;
- memcpy(t, *p, n);
- t += n;
- }
- changeprop_char(display, w, prop, type, s, len);
- free(s);
-}
-
-#if 0
-static void
-freestringlist(char *list[]) {
- XFreeStringList(list);
-}
-#endif
-
-static ulong
-getprop(Display *display, Window w, char *prop, char *type, Atom *actual, int *format, ulong offset, uchar **ret, ulong length) {
- Atom typea;
- ulong n, extra;
- int status;
-
- typea = (type ? xatom(display, type) : 0L);
-
- status = XGetWindowProperty(display, w,
- xatom(display, prop), offset, length, False /* delete */,
- typea, actual, format, &n, &extra, ret);
-
- if(status != Success) {
- *ret = nil;
- return 0;
- }
- if(n == 0) {
- free(*ret);
- *ret = nil;
- }
- return n;
-}
-
-#if 0
-static ulong
-getproperty(Display *display, Window w, char *prop, char *type, Atom *actual, ulong offset, uchar **ret, ulong length) {
- int format;
-
- return getprop(display, w, prop, type, actual, &format, offset, ret, length);
-}
-#endif
-
-static ulong
-getprop_long(Display *display, Window w, char *prop, char *type, ulong offset, long **ret, ulong length) {
- Atom actual;
- ulong n;
- int format;
-
- n = getprop(display, w, prop, type, &actual, &format, offset, (uchar**)ret, length);
- if(n == 0 || format == 32 && xatom(display, type) == actual)
- return n;
- free(*ret);
- *ret = 0;
- return 0;
-}
-
-#ifdef notdef
-static char**
-strlistdup(char *list[], int n) {
- char **p, *q;
- int i, m;
-
- for(i=0, m=0; i < n; i++)
- m += strlen(list[i])+1;
-
- p = malloc((n+1)*sizeof(char*) + m);
- if(p == nil)
- return nil;
- q = (char*)&p[n+1];
-
- for(i=0; i < n; i++) {
- p[i] = q;
- m = strlen(list[i])+1;
- memcpy(q, list[i], m);
- q += m;
- }
- p[n] = nil;
- return p;
-}
-#endif
-
-#if 0
-static int
-getprop_textlist(Display *display, Window w, char *name, char **ret[]) {
- XTextProperty prop;
- char **list;
- int n;
-
- *ret = nil;
- n = 0;
-
- XGetTextProperty(display, w, &prop, xatom(display, name));
- if(prop.nitems > 0) {
- if(Xutf8TextPropertyToTextList(display, &prop, &list, &n) == Success)
- *ret = list;
- XFree(prop.value);
- }
- return n;
-}
-#endif
-
-#if 0
-static char*
-getprop_string(Display *display, Window w, char *name) {
- char **list, *str;
- int n;
-
- str = nil;
-
- n = getprop_textlist(display, w, name, &list);
- if(n > 0)
- str = strdup(*list);
- freestringlist(list);
-
- return str;
-}
-#endif
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb libwmii_hack/x11.h
--- a/libwmii_hack/x11.h Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xatom.h>
-
-static void changeprop_char(Display*, Window, char*, char*, char[], int);
-static void changeprop_long(Display*, Window, char*, char*, long[], int);
-/* static void changeprop_short(Display*, Window, char*, char*, short[], int); */
-static void changeprop_string(Display*, Window, char*, char*);
-static void changeprop_textlist(Display*, Window, char*, char*, char*[]);
-static void changeproperty(Display*, Window, char*, char*, int width, uchar*, int);
-/* static void delproperty(Display*, Window, char*); */
-/* static void freestringlist(char**); */
-static ulong getprop_long(Display*, Window, char*, char*, ulong, long**, ulong);
-/* static char* getprop_string(Display*, Window, char*); */
-/* static int getprop_textlist(Display*, Window, char*, char**[]); */
-/* static ulong getproperty(Display*, Window, char*, char*, Atom*, ulong, uchar**, ulong); */
-static Atom xatom(Display*, char*);
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb man/Makefile
--- a/man/Makefile Sat Jan 19 22:21:47 2008 -0500
+++ b/man/Makefile Fri Jan 18 15:05:45 2008 -0500
@@ -11,4 +11,3 @@ FILTER = sed "s|CONFPREFIX|${ETC}|g; \
               s|AWKPATH|${AWKPATH}|g"
 
 include ${ROOT}/mk/man.mk
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb man/wmiiloop.tex
--- a/man/wmiiloop.tex Sat Jan 19 22:21:47 2008 -0500
+++ b/man/wmiiloop.tex Fri Jan 18 15:05:45 2008 -0500
@@ -1,4 +1,4 @@
-\begin{Name}{1}{wmiiloop}{Kris Maglione}{}{wmiiloop}
+\begin{Name}{1}{wmiiloop}{Kris Maglione}{}{wmiir}
         \Prog{wmiiloop}-VERSION
 \end{Name}
 
diff -r 3c06b49f84d1 -r 3a29c2ddccbb mk/common.mk
--- a/mk/common.mk Sat Jan 19 22:21:47 2008 -0500
+++ b/mk/common.mk Fri Jan 18 15:05:45 2008 -0500
@@ -2,9 +2,9 @@ all:
 
 install: all
 
-MANDIRS=$(MAN)/man1
+MANDIRS=${MAN}/man1
 mkdirs:
- for i in $(BIN) $(ETC) $(LIBDIR) $(MANDIRS) $(INCLUDE) $(DIRS); do \
+ for i in ${BIN} ${ETC} ${LIBDIR} ${MANDIRS} ${INCLUDE} ${DIRS}; do \
                 test -d $$i || echo MKDIR $$i; \
                 mkdir -pm 0755 $$i; \
         done
@@ -15,6 +15,6 @@ cleandep:
 
 DEP:=${shell if test -f .depend;then echo .depend;else echo /dev/null; fi}
 DEP!=echo /dev/null
-include $(DEP)
+include ${DEP}
 
 .PHONY: all options clean dist install uninstall depend cleandep
diff -r 3c06b49f84d1 -r 3a29c2ddccbb mk/dir.mk
--- a/mk/dir.mk Sat Jan 19 22:21:47 2008 -0500
+++ b/mk/dir.mk Fri Jan 18 15:05:45 2008 -0500
@@ -3,21 +3,21 @@ MKSUBDIR = targ=$@; \
                 if [ ! -d $$i ]; then \
                         echo Skipping nonexistent directory: $$i 1>&2; \
                 else \
- echo MAKE $${targ\#d} $(BASE)$$i/; \
- (cd $$i && $(MAKE) BASE="$(BASE)$$i/" $${targ\#d}) || exit $?; \
+ echo MAKE $${targ\#d} ${BASE}$$i/; \
+ (cd $$i && ${MAKE} BASE="${BASE}$$i/" $${targ\#d}) || exit $?; \
                 fi; \
         done
 
 dall:
- dirs="$(DIRS)"; $(MKSUBDIR)
+ dirs="${DIRS}"; ${MKSUBDIR}
 dclean:
- dirs="$(DIRS)"; $(MKSUBDIR)
+ dirs="${DIRS}"; ${MKSUBDIR}
 dinstall:
- dirs="$(INSTDIRS)"; $(MKSUBDIR)
+ dirs="${INSTDIRS}"; ${MKSUBDIR}
 duninstall:
- dirs="$(INSTDIRS)"; $(MKSUBDIR)
+ dirs="${INSTDIRS}"; ${MKSUBDIR}
 ddepend:
- dirs="$(DIRS)"; $(MKSUBDIR)
+ dirs="${DIRS}"; ${MKSUBDIR}
 
 all: dall
 clean: dclean
@@ -25,5 +25,5 @@ uninstall: duninstall
 uninstall: duninstall
 depend: ddepend
 
-INSTDIRS = $(DIRS)
+INSTDIRS = ${DIRS}
 
diff -r 3c06b49f84d1 -r 3a29c2ddccbb mk/gcc.mk
--- a/mk/gcc.mk Sat Jan 19 22:21:47 2008 -0500
+++ b/mk/gcc.mk Fri Jan 18 15:05:45 2008 -0500
@@ -1,16 +1,7 @@ DEBUGCFLAGS = \
-DEBUGCFLAGS = \
- -g \
- -O1 \
- -fno-builtin \
- -fno-inline \
- -fno-omit-frame-pointer \
- -fno-optimize-sibling-calls \
- -fno-unroll-loops \
- -DIXPlint
 CFLAGS += \
         -std=c99 \
+ -pipe \
         -pedantic \
- -pipe \
         -Wall \
         -Wimplicit \
         -Wmissing-prototypes \
@@ -22,8 +13,4 @@ CFLAGS += \
         -Wpointer-arith \
         -Wreturn-type \
         -Wstrict-prototypes \
- -Wtrigraphs
-MKDEP = cpp -M
-SOCFLAGS += -fPIC
-SOLDFLAGS += -shared -soname $(SONAME)
-
+ -Wtrigraphs \
diff -r 3c06b49f84d1 -r 3a29c2ddccbb mk/hdr.mk
--- a/mk/hdr.mk Sat Jan 19 22:21:47 2008 -0500
+++ b/mk/hdr.mk Fri Jan 18 15:05:45 2008 -0500
@@ -1,73 +1,65 @@
 .SILENT:
-.SUFFIXES: .O .o .o_pic .c .sh .rc .so .awk .1 .depend .install .uninstall .clean
+.SUFFIXES: .O .o .c .sh .rc .awk .1 .depend .install .uninstall .clean
 all:
 
 .c.depend:
         echo MKDEP $<
- $(MKDEP) $(CFLAGS) $< >>.depend
+ ${MKDEP} ${CFLAGS} $< >>.depend
 
 .sh.depend .rc.depend .1.depend .awk.depend:
         :
 
 .c.o:
- $(COMPILE) $@ $<
-
-.c.o_pic:
- $(COMPILEPIC) $@ $<
+ ${COMPILE} $@ $<
 
 .o.O:
- $(LINK) $@ $<
+ ${LINK} $@ $<
 
 .c.O:
- ${COMPILE} ${<:.c=.o} $<
- ${LINK} $@ ${<:.c=.o}
+ ${COMPILE} $@ $<
+ ${LINK} $@ $<
 
-.sh.O:
- echo FILTER $(BASE)$<
- $(FILTER) $< >$@
- sh -n $@
- chmod 0755 $@
-.rc.O .awk.O:
- echo FILTER $(BASE)$<
- $(FILTER) $< >$@
+.rc.O .sh.O .awk.O:
+ echo FILTER ${BASE}$<
+ ${FILTER} $< >$@
         chmod 0755 $@
 
 .O.install:
- echo INSTALL $$($(CLEANNAME) $(BASE)$*)
- cp -f $< $(BIN)/$*
- chmod 0755 $(BIN)/$*
+ echo INSTALL ${BASE}$*
+ cp -f $< ${BIN}/$*
+ chmod 0755 ${BIN}/$*
 .O.uninstall:
- echo UNINSTALL $$($(CLEANNAME) $(BASE)$*)
- rm -f $(BIN)/$*
+ echo UNINSTALL ${BASE}$*
+ rm -f ${BIN}/$*
 
-.a.install .so.install:
- echo INSTALL $$($(CLEANNAME) $(BASE)$<)
- cp -f $< $(LIBDIR)/$<
- chmod 0644 $(LIBDIR)/$<
-.a.uninstall .so.uninstall:
- echo UNINSTALL $$($(CLEANNAME) $(BASE)$<)
- rm -f $(LIBDIR)/$<
+.a.install:
+ echo INSTALL ${BASE}$<
+ cp -f $< ${LIBDIR}/$<
+ chmod 0644 ${LIBDIR}/$<
+.a.uninstall:
+ echo UNINSTALL ${BASE}$<
+ rm -f ${LIBDIR}/$<
 
 .h.install:
- echo INSTALL $$($(CLEANNAME) $(BASE)$<)
- cp -f $< $(INCLUDE)/$<
- chmod 0644 $(INCLUDE)/$<
+ echo INSTALL ${BASE}$<
+ cp -f $< ${INCLUDE}/$<
+ chmod 0644 ${INCLUDE}/$<
 .h.uninstall:
- echo UNINSTALL $$($(CLEANNAME) $(BASE)$<)
- rm -f $(INCLUDE)/$<
+ echo UNINSTALL ${BASE}$<
+ rm -f ${INCLUDE}/$<
 
 .1.install:
- echo INSTALL man $$($(CLEANNAME) $*'(1)')
- $(FILTER) $< >$(MAN)/man1/$<
- chmod 0644 $(MAN)/man1/$<
+ echo INSTALL man $*'(1)'
+ ${FILTER} $< >${MAN}/man1/$<
+ chmod 0644 ${MAN}/man1/$<
 .1.uninstall:
- echo UNINSTALL man $$($(CLEANNAME) $*'(1)')
- rm -f $(MAN)/man1/$<
+ echo UNINSTALL man $*'(1)'
+ rm -f ${MAN}/man1/$<
 
 .O.clean:
         rm -f $< || true 2>/dev/null
         rm -f $*.o || true 2>/dev/null
-.o.clean .o_pic.clean:
+.o.clean:
         rm -f $< || true 2>/dev/null
 
 printinstall:
@@ -77,13 +69,9 @@ depend: cleandep
 depend: cleandep
 
 FILTER = cat
-COMPILE= CC="$(CC)" CFLAGS="$(CFLAGS)" $(ROOT)/util/compile
-COMPILEPIC= CC="$(CC)" CFLAGS="$(CFLAGS) $(SOCFLAGS)" $(ROOT)/util/compile
-LINK= LD="$(LD)" LDFLAGS="$(LDFLAGS)" $(ROOT)/util/link
-LINKSO= LD="$(LD)" LDFLAGS="$(SOLDFLAGS)" $(ROOT)/util/link
-CLEANNAME=$(ROOT)/util/cleanname
+COMPILE= CC="${CC}" CFLAGS="${CFLAGS}" ${ROOT}/util/compile
+LINK= LD="${LD}" LDFLAGS="${LDFLAGS}" ${ROOT}/util/link
 
-include $(ROOT)/config.mk
-CFLAGS += -I$$(echo $(INCPATH)|sed 's/:/ -I/g')
-include $(ROOT)/mk/common.mk
+include ${ROOT}/config.mk
+CFLAGS += -I$$(echo ${INCPATH}|sed 's/:/ -I/g')
 
diff -r 3c06b49f84d1 -r 3a29c2ddccbb mk/lib.mk
--- a/mk/lib.mk Sat Jan 19 22:21:47 2008 -0500
+++ b/mk/lib.mk Fri Jan 18 15:05:45 2008 -0500
@@ -1,30 +1,25 @@ PTARG = $(ROOT)/lib/$(TARG)
-PTARG = $(ROOT)/lib/$(TARG)
-LIB = $(PTARG).a
+LIB = ${ROOT}/lib/${TARG}.a
 OFILES = ${OBJ:=.o}
 
-all: $(HFILES) $(LIB)
+all: ${HFILES} ${LIB}
 
-install: $(PTARG).install
-uninstall: $(PTARG).uninstall
+install: ${TARG}.install
+uninstall: ${TARG}.uninstall
 clean: libclean
 depend: ${OBJ:=.depend}
 
 libclean:
- for i in $(LIB) $(OFILES); do \
+ for i in ${LIB} ${OFILES}; do \
                 rm -f $$i; \
         done 2>/dev/null || true
 
 printinstall:
         echo 'Install directories:'
- echo ' Lib: $(LIBDIR)'
+ echo ' Lib: ${LIBDIR}'
 
-$(LIB): $(OFILES)
- echo AR $$($(CLEANNAME) $(BASE)/$@)
- mkdir $(ROOT)/lib 2>/dev/null || true
- $(AR) $@ $(OFILES)
+${LIB}: ${OFILES}
+ echo AR $$($(ROOT)/util/cleanname $(BASE)/$@)
+ mkdir ${ROOT}/lib 2>/dev/null || true
+ ${AR} $@ ${OFILES}
 
-SOMKSH=case "$(MAKESO)" in 1|[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) echo $(ROOT)/mk/so.mk;; *) echo /dev/null;; esac
-SOMK:=${shell $(SOMKSH)}
-SOMK!=$(SOMKSH)
-include $(SOMK)
-
+include ${ROOT}/mk/common.mk
diff -r 3c06b49f84d1 -r 3a29c2ddccbb mk/man.mk
--- a/mk/man.mk Sat Jan 19 22:21:47 2008 -0500
+++ b/mk/man.mk Fri Jan 18 15:05:45 2008 -0500
@@ -3,5 +3,6 @@ uninstall: ${TARG:.1=.uninstall}
 
 printinstall:
         echo 'Install directories:'
- echo ' Man: $(MAN)'
+ echo ' Man: ${MAN}'
 
+include ${ROOT}/mk/common.mk
diff -r 3c06b49f84d1 -r 3a29c2ddccbb mk/many.mk
--- a/mk/many.mk Sat Jan 19 22:21:47 2008 -0500
+++ b/mk/many.mk Fri Jan 18 15:05:45 2008 -0500
@@ -1,6 +1,6 @@ PROGS = ${TARG:=.O}
 PROGS = ${TARG:=.O}
 
-all: $(OFILES) $(PROGS)
+all: ${OFILES} ${PROGS}
 
 install: ${TARG:=.install}
 uninstall: ${TARG:=.uninstall}
@@ -9,10 +9,12 @@ clean: manyclean
 
 printinstall:
         echo 'Install directories:'
- echo ' Bin: $(BIN)'
+ echo ' Bin: ${BIN}'
 
 manyclean:
- for i in ${TARG:=.o} ${TARG:=.O} $(OFILES); do \
+ for i in ${TARG:=.o} ${TARG:=.O} ${OFILES}; do \
                 rm -f $$i; \
         done 2>/dev/null || true
 
+include ${ROOT}/mk/common.mk
+
diff -r 3c06b49f84d1 -r 3a29c2ddccbb mk/one.mk
--- a/mk/one.mk Sat Jan 19 22:21:47 2008 -0500
+++ b/mk/one.mk Fri Jan 18 15:05:45 2008 -0500
@@ -1,24 +1,25 @@ PROG = $(TARG).O
-PROG = $(TARG).O
+PROG = ${TARG}.O
 OFILES = ${OBJ:=.o}
 
-all: $(PROG)
+all: ${PROG}
 
-install: $(TARG).install
-uninstall: $(TARG).uninstall
+install: ${TARG}.install
+uninstall: ${TARG}.uninstall
 clean: oneclean
 depend: ${OBJ:=.depend}
 
 printinstall:
         echo 'Install directories:'
- echo ' Bin: $(BIN)'
+ echo ' Bin: ${BIN}'
 
 oneclean:
- for i in $(PROG) $(OFILES); do \
+ for i in ${PROG} ${OFILES}; do \
                 rm -f $$i; \
         done 2>/dev/null || true
 
-$(OFILES): $(HFILES)
+${OFILES}: ${HFILES}
 
-$(PROG): $(OFILES) $(LIB)
- $(LINK) $@ $(OFILES) $(LIB)
+${PROG}: ${OFILES} ${LIB}
+ ${LINK} $@ ${OFILES} ${LIB}
 
+include ${ROOT}/mk/common.mk
diff -r 3c06b49f84d1 -r 3a29c2ddccbb mk/so.mk
--- a/mk/so.mk Sat Jan 19 22:21:47 2008 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-SOPTARG = $(ROOT)/lib/$(TARG)
-SO = $(SOPTARG).so
-SONAME = $(TARG).so
-OFILES_PIC = ${OBJ:=.o_pic}
-
-all: $(HFILES) $(SO)
-
-install: $(SOPTARG).install
-uninstall: $(SOPTARG).uninstall
-clean: soclean
-depend: ${OBJ:=.depend}
-
-soclean:
- for i in $(SO) $(OFILES_PIC); do \
- rm -f $$i; \
- done 2>/dev/null || true
-
-printsoinstall:
- echo 'Install directories:'
- echo ' Lib: $(LIBDIR)'
-
-printinstall: printsoinstall
-
-$(SO): $(OFILES_PIC)
- mkdir $(ROOT)/lib 2>/dev/null || true
- $(LINKSO) $@ $(OFILES_PIC)
-
diff -r 3c06b49f84d1 -r 3a29c2ddccbb rc/rc.wmii.rc
--- a/rc/rc.wmii.rc Sat Jan 19 22:21:47 2008 -0500
+++ b/rc/rc.wmii.rc Fri Jan 18 15:05:45 2008 -0500
@@ -1,112 +1,150 @@
 #!/usr/bin/env wmii9rc
-scriptname=$0
-oldpath=$path; path=($PLAN9/bin $path)
-. wmii.rc wmiirc # Include utility functions
-
 # WMII Configuration
 
-# Keys
+ifs='' {nl=`{echo}}
+
+confpath=`{echo $WMII_CONFPATH | sed 'y/:/ /'}
+oldpath=$path
+path=($PLAN9/bin $path)
+
+# Sanity checks
+if(echo $0 | grep -s '(^|/)rc\.wmii\.local$') {
+ echo >[1=2] Fatal: This file must not be named rc.wmii.local
+ exit badname
+}
+
+# Configurables
 MODKEY=Mod1
 UP=k
 DOWN=j
 LEFT=h
 RIGHT=l
 
-# Theme
-wmiifont='drift,-*-fixed-*-*-*-*-9-*-*-*-*-*-*-*'
-wmiifont='-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*'
-wmiinormcol=`{echo '#000000 #c1c48b #81654f'}
-wmiifocuscol=`{echo '#000000 #81654f #000000'}
-wmiibackground='#333333'
-
-# Programs
+WMII_FONT='-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*'
+WMII_NORMCOLORS=('#222222' '#5FBF77' '#2A7F3F')
+WMII_FOCUSCOLORS=('#ffffff' '#153F1F' '#2A7F3F')
+WMII_BACKGROUND='#333333'
+
 WMII_TERM=(xterm)
 
 # Column Rules
 wmiir write /colrules <<!
-/gimp/ -> 17+83+41
-/./ -> 62+38 # Golden Ratio
+/./ -> 60+40
 !
 
 # Tagging Rules
 wmiir write /tagrules <<!
-/VLC/ -> ~
 /XMMS.*/ -> ~
 /MPlayer.*/ -> ~
+/.*/ -> sel
+/.*/ -> 1
 !
 
 # Status Bar Info
-fn status {
- echo -n `{uptime | sed 's/.*://; s/,//g'} \
- '|' `{date}
-}
-
-# End Configuration
-
-ifs='' {nl=`{echo}}
-confpath=`{echo $WMII_CONFPATH | sed 'y/:/ /'}
+fn status { echo -n `{uptime | sed 's/.*://; s/,//g'} '|' `{date} }
+fn viewtitle { echo $* }
+
+# Convenience Functions
+fn wmiimenu {
+ dmenu -b -fn $WMII_FONT \
+ -nf $WMII_NORMCOLORS(1) -nb $WMII_NORMCOLORS(2) \
+ -sf $WMII_FOCUSCOLORS(1) -sb $WMII_FOCUSCOLORS(2)
+}
+
+fn 9menu {
+ wmii9menu -font $WMII_FONT \
+ -^(nf nb br)^$WMII_NORMCOLORS \
+ -^(sf sb br)^$WMII_FOCUSCOLORS $*
+}
+
+fn proglist {
+ /bin/ls -lL `{echo $* | sed 'y/:/ /'} >[2]/dev/null \
+ | awk '$1 ~ /^[^d].*x/ && NF > 2 { print $NF }' \
+ | sort | uniq
+}
+
+fn actionlist {
+ { proglist $WMII_CONFPATH
+ getfuns Action
+ } | sort | uniq
+}
+
+fn config_whatis {
+ prog = `{@{path=$confpath whatis $1} | grep -v '^fn|= ' || echo /dev/null}
+ shift; echo $prog $*
+}
+
+fn run_command { @{
+ rfork ns
+ path=$oldpath
+ eval exec $* &
+ }
+}
+
+fn getfuns {
+ env | sed -n 's/^fn#'^$1^'-([^=]+).*/\1/p'
+}
+fn initkeys {
+ getfuns Key | wmiir write /keys
+}
+fn read_tags {
+ wmiir ls /tag | sed 's,/,,; /^sel$/d'
+}
+
+fn 'fn?' {rc -c 'whatis '$1 >[2]/dev/null | grep -s '^fn ' }
 
 # Events
-fn sigexit {
- rm -f $progs_file
- wi_cleankeys
-}
-
-fn Event-CreateTag { echo $wmiinormcol $* | wmiir create /lbar/$"* }
+fn Event-Start {
+ switch($1) {
+ case wmiirc
+ rm -f $progs_file
+ exit
+ }
+}
+fn Event-Key { Key-$1 $1 }
+
+fn Event-CreateTag { echo $WMII_NORMCOLORS `{viewtitle $*} | wmiir create /lbar/$"* }
 fn Event-DestroyTag { wmiir remove /lbar/$"* }
-fn Event-FocusTag { wmiir xwrite /lbar/$"* $wmiifocuscol $* }
-fn Event-UnfocusTag { wmiir xwrite /lbar/$"* $wmiinormcol $* }
+fn Event-FocusTag { wmiir xwrite /lbar/$"* $WMII_FOCUSCOLORS `{viewtitle $*} }
+fn Event-UnfocusTag { wmiir xwrite /lbar/$"* $WMII_NORMCOLORS `{viewtitle $*} }
 fn Event-UrgentTag { shift; wmiir xwrite /lbar/$"* '*'$"* }
 fn Event-NotUrgentTag { shift; wmiir xwrite /lbar/$"* $"* }
 
-fn Event-Unresponsive {
- client = $1; shift
- @{
- msg = 'The following client is not responding. What would you like to do?'
- resp = `{wihack -transient $client \
- xmessage -nearmouse -buttons Kill,Wait -print \
- $msg $nl '' `{wmiir read /client/sel/label}}
- if(~ $resp Kill)
- wmiir xwrite /client/$client/ctl slay
- }&
-}
-
 fn Event-LeftBarClick { shift; wmiir xwrite /ctl view $* }
+
 fn Event-ClientMouseDown {
         client = $1; button = $2
         if(~ $button 3) {
- do=`{wi_9menu -initial $menulast Nop Delete Fullscreen}
+ do=`{9menu -initial $menulast Nop Delete Fullscreen}
                 switch($do) {
                 case Delete
                         wmiir xwrite /client/$client/ctl kill
                 case Fullscreen
                         wmiir xwrite /client/$client/ctl Fullscreen on
                 }
- if(! ~ $do '')
+ if(! ~ $#do 0)
                         menulast = $do;
         }
 }
 menulast = Nop
 
-# Utility
-fn 'fn?' {rc -c 'whatis '$1 >[2]/dev/null | grep -s '^fn ' }
-
-# Actions
 fn Action {
         cmd=$1 action=Action-$cmd { shift
                 if('fn?' $action)
                         $action $*
                 if not
- wi_runcmd `{wi_script $cmd} $*
+ run_command `{config_whatis $cmd} $*
         } &
 }
 
+# Actions
 fn Action-rehash {
- comm -23 <{ls $WMII_NS_DIR/proglist.* >[2]/dev/null | awk -F'\.' '{print $NF}'} \
- <{ps | awk '{print $2}'} |
- while(id=`{read})
- rm $WMII_NS_DIR/proglist.$id
- wi_proglist $PATH >$progs_file
+ if(test -d /proc/$pid)
+ for(i in $WMII_NS_DIR/proglist.*) {
+ id=`{echo $i | sed 's/.*\.(.*)/\1/'} \
+ if(! test -d /proc/$id) rm $i
+ }
+ proglist $PATH >$progs_file
 }
 fn Action-quit { wmiir xwrite /ctl quit }
 fn Action-exec { wmiir xwrite /ctl exec $* }
@@ -114,16 +152,24 @@ fn Action-status {
         flag x -; flag r -
         if(wmiir remove /rbar/status >[2]/dev/null)
                 sleep 2
- echo $wmiinormcol | wmiir create /rbar/status
+ echo $WMII_NORMCOLORS | wmiir create /rbar/status
         while(status | wmiir write /rbar/status)
                 sleep 1
 }
 
 # Source Variables, &c
-if(~ $0 rc.wmii.local */rc.wmii.local)
- wi_notice This file should not be named rc.wmii.local
-if not
- . `{wi_script rc.wmii.local} /dev/null
+local = `{config_whatis rc.wmii.local}
+. <{awk '//;
+ /^# Overrides/ {
+ print "xmessage -file - <<!"
+ print "rc.wmii: Warning:"
+ print " Your rc.wmii.local contains an ''# Overrides'' line."
+ print " This line has a deprecated special meaning. Functions"
+ print " you wish to override should be defined in a function"
+ print " called Action-overridekeys"
+ print "!"
+ exit
+ }' $local </dev/null}
 
 # Key Bindings
 fn key {
@@ -132,15 +178,12 @@ fn key {
         ~ $#key 0
 }
 
-# This is... ugly.
-
 key $MODKEY-Control-t || fn $key {
         switch(`{wmiir read /keys | wc -l}) {
         case 0 1
- wmiir xwrite /ctl $keys
+ initkeys
                 wmiir xwrite /ctl grabmod $MODKEY
         case *
- ifs=() { keys=`{wmiir read /keys} }
                 wmiir xwrite /keys $MODKEY-Control-t
                 wmiir xwrite /ctl grabmod Mod3
         }
@@ -166,36 +209,37 @@ key $MODKEY-m || fn $key { wmiir xwrite
 
 key $MODKEY-Shift-c || fn $key { wmiir xwrite /client/sel/ctl kill }
 
-key $MODKEY-a || fn $key { Action `{wi_actions | wi_menu} & }
-key $MODKEY-p || fn $key { ifs=() { wi_runcmd -t `{wi_menu <$progs_file} & } }
-key $MODKEY-Return || fn $key { wi_runcmd $WMII_TERM & }
-
-key $MODKEY-t || fn $key { wmiir xwrite /ctl view `{wi_tags | wi_menu} & }
+key $MODKEY-a || fn $key { Action `{actionlist | wmiimenu} & }
+key $MODKEY-p || fn $key { ifs=() { run_command `{wmiimenu <$progs_file} & } }
+key $MODKEY-Return || fn $key { run_command $WMII_TERM & }
+
+key $MODKEY-t || fn $key { wmiir xwrite /ctl view `{read_tags | wmiimenu} & }
 key $MODKEY-Shift-t || fn $key {
         sel = `{wmiir read /client/sel/ctl | sed 1q} \
- wmiir xwrite /client/$sel/tags `{wi_tags | wi_menu} &
-}
-
-key $MODKEY-^`{seq 0 9} || fn $key {
- wmiir xwrite /ctl view `{echo $1 | sed 's/.*-//'}
-}
+ wmiir xwrite /client/$sel/tags `{read_tags | wmiimenu} &
+}
+
+key $MODKEY-^`{seq 0 9}|| fn $key { wmiir xwrite /ctl view `{echo $1 | sed 's/.*-//'} }
 key Shift-$MODKEY-^`{seq 0 9} || fn $key {
         wmiir xwrite /client/sel/tags `{echo $1 | sed 's/.*-//'}
 }
 
 # WM Configuration
 wmiir write /ctl <<!
- view 1
         grabmod $MODKEY
         border 2
- font $wmiifont
- focuscolors $wmiifocuscol
- normcolors $wmiinormcol
-!
-xsetroot -solid $wmiibackground
+ font $WMII_FONT
+ focuscolors $WMII_FOCUSCOLORS
+ normcolors $WMII_NORMCOLORS
+!
+xsetroot -solid $WMII_BACKGROUND
 
 # Source Overrides
-Action overridekeys
+. <{awk '/^# Overrides/, 0' $local </dev/null}
+if('fn?' Action-overridekeys)
+ Action-overridekeys
+if not
+ . `{config_whatis overridekeys}
 
 # Misc Setup
 progs_file=$WMII_NS_DIR/proglist.$pid
@@ -204,15 +248,26 @@ Action rehash
 
 # Tag Bar Setup
 ifs=$nl{
- wmiir rm `{comm -23 <{wmiir ls /lbar} <{wi_tags}}
+ wmiir rm `{comm -23 <{wmiir ls /lbar} <{read_tags}}
         seltag=`{wmiir read /tag/sel/ctl | sed 1q}
- for(tag in `{wi_tags}) {
+ for(tag in `{read_tags}) {
                 if(~ $tag $seltag)
- echo $wmiifocuscol $tag | wmiir create /lbar/$tag
+ echo $WMII_FOCUSCOLORS `{viewtitle $tag} | wmiir create /lbar/$tag
                 if not
- echo $wmiinormcol $tag | wmiir create /lbar/$tag
- }
-}
-
-wi_eventloop
-
+ echo $WMII_NORMCOLORS `{viewtitle $tag} | wmiir create /lbar/$tag
+ }
+}
+
+# Keygrab Setup
+initkeys
+
+if(echo Start wmiirc | ! wmiir write /event >[2]/dev/null)
+ exit write
+
+# Event Loop
+wmiir read /event |
+ while(*=`{read}) {
+ event = $1; shift
+ Event-$event $*
+ } >[2]/dev/null </dev/null
+
diff -r 3c06b49f84d1 -r 3a29c2ddccbb rc/sh.wmii
--- a/rc/sh.wmii Sat Jan 19 22:21:47 2008 -0500
+++ b/rc/sh.wmii Fri Jan 18 15:05:45 2008 -0500
@@ -45,7 +45,8 @@ echo '
 /Firefox/ -> www
 /XMMS.*/ -> ~
 /MPlayer.*/ -> ~
-/.*/ -> sel
+/.*/ -> !
+/.*/ -> 1
 ' >/tagrules
 
 subfn seq {
@@ -138,7 +139,6 @@ Event ClientMouseDown {
         (client button) := $*
         if {~ $button 3} {
                 lastcmd = `{9menu -initial $lastcmd Nop Delete Fullscreen}
- if{~ $#lastcmd 0} {lastcmd=''}
                 cmp := {~ $lastcmd $*}
                 if {$cmp Nop} {
                 } {$cmp Delete} { echo kill >/client/$client/ctl
@@ -174,7 +174,7 @@ Key $MODKEY-Control-t {
 Key $MODKEY-Control-t {
         if { ~ `{wc -l /keys} 0 1} {
                 initkeys
- echo grabmod $MODKEY >/ctl
+ grabmod $MODKEY >/ctl
         } {
                 echo $MODKEY-Control-t >/keys
                 echo grabmod Mod3 >/ctl
diff -r 3c06b49f84d1 -r 3a29c2ddccbb rc/welcome.sh
--- a/rc/welcome.sh Sat Jan 19 22:21:47 2008 -0500
+++ b/rc/welcome.sh Fri Jan 18 15:05:45 2008 -0500
@@ -34,6 +34,7 @@ Let's go!
   window and move the cursor around.
 - Resize the xclock window: Hold $MODKEY, right-click the
   window and move the cursor around.
+- Kill the selected client (the xclock window) with: M-Shift-c
 - Open the actions menu: M-a
   Rerun wmiirc by selecting 'wmiirc'.
 - We'll now have a look at the internal filesystem used by
diff -r 3c06b49f84d1 -r 3a29c2ddccbb rc/wmiirc.sh
--- a/rc/wmiirc.sh Sat Jan 19 22:21:47 2008 -0500
+++ b/rc/wmiirc.sh Fri Jan 18 15:05:45 2008 -0500
@@ -16,8 +16,8 @@ WMII_FONT='-*-fixed-medium-r-*-*-13-*-*-
 WMII_FONT='-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*'
 
 set -- $(echo $WMII_NORMCOLORS $WMII_FOCUSCOLORS)
-WMII_MENU="dmenu -b -fn $WMII_FONT -nf $1 -nb $2 -sf $4 -sb $5"
-WMII_9MENU="wmii9menu -font $WMII_FONT -nf $1 -nb $2 -sf $4 -sb $5 -br $6"
+WMII_MENU='dmenu -b -fn "$WMII_FONT" -nf '"$1 -nb $2 -sf $4 -sb $5"
+WMII_9MENU='wmii9menu -font "$WMII_FONT" -nf '"$1 -nb $2 -sf $4 -sb $5 -br $6"
 WMII_TERM="xterm"
 
 # Column Rules
@@ -89,10 +89,12 @@ eventstuff() {
                 client=$1; button=$2
                 case "$button" in
                 3)
- do=$($WMII_9MENU -initial "${menulast:-SomeRandomName}" Nop Delete)
+ do=$(eval $WMII_9MENU -initial "${menulast:-SomeRandomName}" Nop Delete Fullscreen)
                         case "$do" in
                         Delete)
- wmiir xwrite /client/$client/ctl kill
+ wmiir xwrite /client/$client/ctl kill;;
+ Fullscreen)
+ wmiir xwrite /client/$client/ctl Fullscreen on;;
                         esac
                         menulast=${do:-"$menulast"}
                 esac
@@ -100,7 +102,7 @@ eventstuff() {
         Key $MODKEY-Control-t
                 case $(wmiir read /keys | wc -l | tr -d ' \t\n') in
                 0|1)
- echo -n \$Keys | tr ' ' '\012' | wmiir write /keys
+ echo -n $Keys | tr ' ' '\012' | wmiir write /keys
                         wmiir xwrite /ctl grabmod $MODKEY;;
                 *)
                         wmiir xwrite /keys $MODKEY-Control-t
@@ -115,15 +117,17 @@ eventstuff() {
         Key $MODKEY-m
                 wmiir xwrite /tag/sel/ctl colmode sel max
         Key $MODKEY-a
- Action $(actionlist | $WMII_MENU) &
+ Action $(actionlist | eval $WMII_MENU) &
         Key $MODKEY-p
- sh -c "$($WMII_MENU <$progsfile)" &
+ sh -c "$(eval $WMII_MENU <$progsfile)" &
         Key $MODKEY-t
                 wmiir xwrite /ctl "view $(tagsmenu)" &
         Key $MODKEY-Return
- $WMII_TERM &
+ eval $WMII_TERM &
         Key $MODKEY-Shift-space
                 wmiir xwrite /tag/sel/ctl send sel toggle
+ Key $MODKEY-f
+ wmiir xwrite /client/sel/ctl Fullscreen toggle
         Key $MODKEY-Shift-c
                 wmiir xwrite /client/sel/ctl kill
         Key $MODKEY-Shift-t
@@ -168,7 +172,6 @@ export WMII_FOCUSCOLORS WMII_SELCOLORS W
 export WMII_FOCUSCOLORS WMII_SELCOLORS WMII_NORMCOLORS
 
 # Feed events to `wmiiloop' for processing
-#echo "$(eventstuff | sed 's/^[ ]//' | { . wmiiloop; })"
 eval "$(eventstuff | sed 's/^[ ]//' | { . wmiiloop; })"
 
 echo "$Keys" | tr ' ' '\n' | wmiir write /keys
@@ -209,7 +212,7 @@ done
 
 # More functions
 tagsmenu() {
- wmiir ls /tag | sed 's|/||; /^sel$/d' | $WMII_MENU
+ wmiir ls /tag | sed 's|/||; /^sel$/d' | eval $WMII_MENU
 }
 
 actionlist() {
diff -r 3c06b49f84d1 -r 3a29c2ddccbb util/compile
--- a/util/compile Sat Jan 19 22:21:47 2008 -0500
+++ b/util/compile Fri Jan 18 15:05:45 2008 -0500
@@ -15,49 +15,10 @@ base=$(echo $BASE | sed 's/,/\\,/g')
 base=$(echo $BASE | sed 's/,/\\,/g')
 re='\([^[:space:]/]*\..:[0-9]\)'
 
-undup() { # GCC is crap.
- awk '
- function shift() {
- for(n=1; n<=3; n++)
- if(2*n <= nl)
- for(i=1; i<=n; i++) {
- if(l[i] != l[i+n])
- break;
- if(i == n) {
- for(i=1; i<=n; i++)
- print l[i]
- nl -= 2*n;
- for(i=1; i<=nl; i++)
- l[i] = l[i+2*n];
- return;
- }
- }
- if(nl == 0)
- return
- print l[1]
- for(i=1; i<nl; i++)
- l[i] = l[i+1]
- nl--
- }
- BEGIN{
- nl=0
- maxl=6
- }
- {
- if(nl == maxl)
- shift()
- l[++nl] = $0
- }
- END{
- while(nl > 0)
- shift();
- }'
-}
-
 cat $xtmp | sed "s,^$re,$base&,g; s,\([[:space:]]\)$re,\1$base\2,g" |
         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' |
- undup 1>&2
+ uniq 1>&2
 
 rm -f $xtmp
 exit $status
diff -r 3c06b49f84d1 -r 3a29c2ddccbb util/genconfig
--- a/util/genconfig Sat Jan 19 22:21:47 2008 -0500
+++ b/util/genconfig Fri Jan 18 15:05:45 2008 -0500
@@ -100,17 +100,14 @@ INCPATH="$INCPATH:/usr/local/include:/op
 
 oifs="$IFS"
 IFS=:
-findinc INCX11 X11/Xlib.h $INCPATH \
- /usr/X11R6/include /usr/x11/include /usr/x11/include /usr/X11/include \
+findinc INCX11 X11/Xlib.h $INCPATH /usr/X11R6/include /usr/x11/include /usr/x11/include /usr/X11/include \
         /usr/openwin/include /opt/x11/include /opt/X11/include
 findinc INCICONV iconv.h $INCPATH
 
-findlib LIBX11 X11 $libs \
- /usr/X11R6/lib /usr/X11/lib /usr/openwin/lib /usr/x11/lib \
- /opt/X11 /opt/x11 /usr/local/lib /opt/local/lib
+findlib LIBX11 X11 $libs /usr/X11R6/lib /usr/X11/lib /usr/openwin/lib /usr/x11/lib /opt/X11 /opt/x11 \
+ /usr/local/lib /opt/local/lib
 findlib LIBICONV iconv $libs
-findlib LIBIXP ixp "$ROOT/lib" $libs
-[ -e "$ROOT/libixp" ] && LIBIXP="$ROOT/lib/libixp.a"
+findlib LIBIXP ixp ${ROOT}/libixp $libs
 LIBIXP=$(echo "$LIBIXP"|sed 's,^-L\([^ ]*\) -l\([^ ]*\)$,\1/lib\2.a,')
 IFS="$oifs"
 
@@ -118,12 +115,6 @@ echo Library paths...
 echo Library paths...
 prompt INCX11 Compiler flags to find X11 includes
 prompt LIBX11 Linker flags to link against libX11
-# Yuck...
-if nm -D `ldd /bin/sh | awk '$1 ~ /^libc\.so/ {print $3}'` |
- awk '$2 == "T" && $3 == "iconv" {exit 0}; END {exit 1}'
-then
- echo "Your system's libc appears to contain iconv"
-fi
 prompt LIBICONV Linker flags to link agains libiconv '(may be left blank if iconv is part of your system libc)'
 prompt INCICONV Compiler flags to find iconv.h
 prompt LIBIXP Path to libixp.a
diff -r 3c06b49f84d1 -r 3a29c2ddccbb util/link
--- a/util/link Sat Jan 19 22:21:47 2008 -0500
+++ b/util/link Fri Jan 18 15:05:45 2008 -0500
@@ -9,7 +9,7 @@ for i
 for i
 do
         case "$i" in
- *.[ao]|*.o_pic)
+ *.[ao])
                 ofiles="$ofiles $i"
                 ;;
         *)
Received on Mon Jan 21 2008 - 00:31:15 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:59:03 UTC