This commit is contained in:
Kris Maglione 2008-02-03 15:06:26 -05:00
parent 79d7dd25a8
commit cfeed07dc4
22 changed files with 246 additions and 216 deletions

View File

@ -101,7 +101,8 @@ comm(int cols, char **toka, char **tokb) {
tokb++;
}
}
ret = strlistdup((char**)vec.ary, vec.n);
vector_ppush(&vec, nil);
ret = strlistdup((char**)vec.ary);
free(vec.ary);
return ret;
}

View File

@ -96,7 +96,7 @@ area_create(View *v, Area *pos, uint w) {
a->next->prev = a;
if(a == v->area)
a->floating = True;
a->floating = true;
if(v->sel == nil)
area_focus(a);

View File

@ -93,7 +93,7 @@ client_create(XWindow w, XWindowAttributes *wa) {
WinAttr fwa;
Point p;
c = emallocz(sizeof(Client));
c = emallocz(sizeof *c);
c->border = wa->border_width;
c->r.min = Pt(wa->x, wa->y);
@ -199,9 +199,8 @@ client_manage(Client *c) {
if(newgroup) {
if(f->area != f->view->sel)
f->view->oldsel = f->view->sel;
focus(c, false);
}
else {
frame_focus(f);
}else {
frame_restack(c->sel, c->sel->area->sel);
view_restack(c->sel->view);
}
@ -233,9 +232,9 @@ client_destroy(Client *c) {
r = client_grav(c, ZR);
hide = False;
hide = false;
if(!c->sel || c->sel->view != screen->sel)
hide = True;
hide = true;
XGrabServer(display);
@ -264,6 +263,7 @@ client_destroy(Client *c) {
event("DestroyClient %C\n", c);
flushenterevents();
flushevents(FocusChangeMask, true);
free(c->w.hints);
free(c);
}
@ -322,9 +322,12 @@ client_grav(Client *c, Rectangle rd) {
if(eqrect(rd, ZR)) {
if(c->sel) {
r = c->sel->floatr;
}else
r = frame_client2rect(c, c->r, true);
cr = frame_rect2client(c, r, true);
cr = frame_rect2client(c, r, true);
}else {
cr = c->r;
r = frame_client2rect(c, cr, true);
r = rectsetorigin(r, cr.min);
}
sp = subpt(cr.min, r.min);
r = gravitate(r, cr, h->grav);
if(!h->gravstatic)
@ -445,7 +448,7 @@ focus(Client *c, bool user) {
void
client_focus(Client *c) {
static long id;
flushevents(FocusChangeMask, True);
flushevents(FocusChangeMask, true);
Dprint(DFocus, "client_focus([%C]%s) %ld\n", c, clientname(c), id++);
@ -505,7 +508,7 @@ client_resize(Client *c, Rectangle r) {
}
sync(); /* Not ideal. */
flushenterevents();
flushevents(FocusChangeMask|ExposureMask, True);
flushevents(FocusChangeMask|ExposureMask, true);
}
void
@ -530,7 +533,7 @@ client_configure(Client *c) {
e.event = c->w.w;
e.window = c->w.w;
e.above = None;
e.override_redirect = False;
e.override_redirect = false;
e.x = r.min.x;
e.y = r.min.y;
@ -650,7 +653,7 @@ update_class(Client *c) {
strcpy(c->props, "::");
str = c->props + 1;
}
utflcpy(str+1, c->name, sizeof(c->props));
utflcpy(str+1, c->name, sizeof c->props);
}
static void
@ -663,7 +666,7 @@ client_updatename(Client *c) {
if(str == nil)
str = getprop_string(&c->w, "WM_NAME");
if(str)
utflcpy(c->name, str, sizeof(c->name));
utflcpy(c->name, str, sizeof c->name);
free(str);
update_class(c);
@ -685,12 +688,20 @@ updatemwm(Client *c) {
ulong *ret;
int n;
/* To quote Metacity, or KWin quoting Metacity:
* We support MWM hints deemed non-stupid
* Our definition of non-stupid is a bit less lenient than
* theirs, though. In fact, we don't really even support the
* idea of supporting the hints that we support, but apps
* like xmms (which noone should use) break if we don't.
*/
n = getprop_long(&c->w, "_MOTIF_WM_HINTS", "_MOTIF_WM_HINTS",
0L, (long**)&ret, 3L);
/* FIXME: Look over this. */
/* FIXME: Should somehow handle all frames. */
if(c->sel)
r = frame_rect2client(c, c->sel->r, c->sel->area->floating);
r = client_grav(c, ZR);
c->borderless = 0;
c->titleless = 0;
@ -703,7 +714,7 @@ updatemwm(Client *c) {
free(ret);
if(c->sel) {
r = frame_client2rect(c, r, c->sel->area->floating);
r = client_grav(c, r);
client_resize(c, r);
frame_draw(c->sel);
}
@ -746,7 +757,7 @@ client_prop(Client *c, Atom a) {
break;
case XA_WM_CLASS:
n = getprop_textlist(&c->w, "WM_CLASS", &class);
snprint(c->props, sizeof(c->props), "%s:%s:",
snprint(c->props, sizeof c->props, "%s:%s:",
(n > 0 ? class[0] : "<nil>"),
(n > 1 ? class[1] : "<nil>"));
freestringlist(class);

View File

@ -191,14 +191,14 @@ column_scale(Area *a) {
i++, j++;
if(f->collapsed) {
if(i < 0 && (f != a->sel)) {
f->collapsed = False;
f->collapsed = false;
area_moveto(f->view->area, f);
continue;
}
i--;
}else {
if(j < 0 && (f != a->sel))
f->collapsed = True;
f->collapsed = true;
j--;
}
/* Doesn't change if we 'continue' */
@ -287,7 +287,7 @@ column_arrange(Area *a, bool dirty) {
break;
case Colmax:
for(f=a->frame; f; f=f->anext) {
f->collapsed = False;
f->collapsed = false;
f->r = a->r;
}
goto resize;

View File

@ -360,5 +360,5 @@ EXTERN Client* kludge;
extern char* debugtab[];
#define Debug(x) if((debugflag|debugfile)&(x) && setdebug(x))
#define Dprint(x, ...) BLOCK( debug(x, __VA_ARGS__) )
#define Dprint(x, ...) BLOCK( if((debugflag|debugfile)&(x)) debug(x, __VA_ARGS__) )

View File

@ -19,7 +19,7 @@ getdiv(Divide **dp) {
d = emallocz(sizeof *d);
wa.override_redirect = True;
wa.override_redirect = true;
wa.cursor = cursor[CurDHArrow];
wa.event_mask =
ExposureMask

View File

@ -9,9 +9,10 @@ void
dispatch_event(XEvent *e) {
Debug(DEvent)
printevent(e);
if(e->type < nelem(handler) && handler[e->type])
handler[e->type](e);
else
if(e->type < nelem(handler)) {
if(handler[e->type])
handler[e->type](e);
}else
xext_event(e);
}
@ -38,12 +39,12 @@ findenter(Display *d, XEvent *e, XPointer v) {
USED(d);
l = (long*)v;
if(*l)
return False;
return false;
if(e->type == EnterNotify)
return True;
return true;
if(e->type == MotionNotify)
(*l)++;
return False;
return false;
}
/* This isn't perfect. If there were motion events in the queue
@ -147,7 +148,7 @@ enternotify(XEvent *e) {
if((w = findwin(ev->window)))
handle(w, enter, ev);
else if(ev->window == scr.root.w) {
sel_screen = True;
sel_screen = true;
frame_draw_all();
}
}
@ -159,7 +160,7 @@ leavenotify(XEvent *e) {
ev = &e->xcrossing;
xtime = ev->time;
if((ev->window == scr.root.w) && !ev->same_screen) {
sel_screen = True;
sel_screen = true;
frame_draw_all();
}
}

View File

@ -83,8 +83,10 @@ float_placeframe(Frame *f) {
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;

View File

@ -30,7 +30,7 @@ frame_create(Client *c, View *v) {
f->floatr = c->sel->floatr;
f->r = c->sel->r;
}else{
f->r = frame_client2rect(c, client_grav(c, ZR), true);
f->r = client_grav(c, ZR);
f->floatr = f->r;
c->sel = f;
}
@ -545,7 +545,7 @@ frame_focus(Frame *f) {
client_focus(f->client);
if(!a->floating && ((a->mode == Colstack) || (a->mode == Colmax)))
column_arrange(a, False);
column_arrange(a, false);
}
int

View File

@ -184,7 +184,7 @@ get_file(void) {
FileId *temp;
if(!free_fileid) {
uint i = 15;
temp = emallocz(sizeof(FileId) * i);
temp = emallocz(i * sizeof *temp);
for(; i; i--) {
temp->next = free_fileid;
free_fileid = temp++;
@ -414,7 +414,7 @@ event(const char *format, ...) {
va_list ap;
va_start(ap, format);
vsnprint(buffer, sizeof(buffer), format, ap);
vsnprint(buffer, sizeof buffer, format, ap);
va_end(ap);
pending_write(&events, buffer, strlen(buffer));
@ -435,11 +435,15 @@ vdebug(int flag, const char *fmt, va_list ap) {
if(flag == 0)
flag = dflags;
if(!((debugflag|debugfile) & flag))
return;
s = vsmprint(fmt, ap);
len = strlen(s);
if(debugflag&flag)
print("%s", s);
if(debugfile&flag)
for(i=0; i < nelem(pdebug); i++)
if(flag & (1<<i))
@ -1102,7 +1106,7 @@ fs_clunk(Ixp9Req *r) {
*q-- = '\0';
q = f->p.bar->text;
utflcpy(q, (char*)m.pos, sizeof(((Bar*)0)->text));
utflcpy(q, (char*)m.pos, sizeof ((Bar*)0)->text);
free(p);

View File

@ -56,12 +56,12 @@ str2modmask(const char *val) {
static void
grabkey(Key *k) {
XGrabKey(display, k->key, k->mod, scr.root.w,
True, GrabModeAsync, GrabModeAsync);
true, GrabModeAsync, GrabModeAsync);
if(numlock_mask) {
XGrabKey(display, k->key, k->mod | numlock_mask, scr.root.w,
True, GrabModeAsync, GrabModeAsync);
true, GrabModeAsync, GrabModeAsync);
XGrabKey(display, k->key, k->mod | numlock_mask | LockMask, scr.root.w,
True, GrabModeAsync, GrabModeAsync);
true, GrabModeAsync, GrabModeAsync);
}
sync();
}
@ -81,7 +81,7 @@ name2key(const char *name) {
Key *k;
for(k=key; k; k=k->lnext)
if(!strncmp(k->name, name, sizeof(k->name)))
if(!strncmp(k->name, name, sizeof k->name))
return k;
return nil;
}
@ -101,16 +101,16 @@ getkey(const char *name) {
ungrabkey(k);
return k;
}
utflcpy(buf, name, sizeof(buf));
utflcpy(buf, name, sizeof buf);
toks = tokenize(seq, 8, buf, ',');
for(i = 0; i < toks; i++) {
if(!k)
r = k = emallocz(sizeof(Key));
r = k = emallocz(sizeof *k);
else {
k->next = emallocz(sizeof(Key));
k->next = emallocz(sizeof *k);
k = k->next;
}
utflcpy(k->name, name, sizeof(k->name));
utflcpy(k->name, name, sizeof k->name);
kstr = strrchr(seq[i], '-');
if(kstr)
kstr++;
@ -189,7 +189,7 @@ kpress_seq(XWindow w, Key *done) {
Key *found;
next_keystroke(&mod, &key);
found = match_keys(done, mod, key, True);
found = match_keys(done, mod, key, true);
if((done->mod == mod) && (done->key == key))
fake_keypress(mod, key); /* double key */
else {
@ -208,14 +208,14 @@ kpress(XWindow w, ulong mod, KeyCode keycode) {
for(k=key; k; k=k->lnext)
k->tnext=k->lnext;
found = match_keys(key, mod, keycode, False);
found = match_keys(key, mod, keycode, false);
if(!found) /* grabbed but not found */
XBell(display, 0);
else if(!found->tnext && !found->next)
event("Key %s\n", found->name);
else {
XGrabKeyboard(display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime);
flushevents(FocusChangeMask, True);
XGrabKeyboard(display, w, true, GrabModeAsync, GrabModeAsync, CurrentTime);
flushevents(FocusChangeMask, true);
kpress_seq(w, found);
XUngrabKeyboard(display, CurrentTime);
sync();

View File

@ -20,11 +20,15 @@ static const char
version[] = "wmii-"VERSION", ©2007 Kris Maglione\n";
static int (*xlib_errorhandler) (Display*, XErrorEvent*);
static char *address, *ns_path;
static int check_other_wm;
static struct sigaction sa;
static struct passwd *passwd;
static int sleeperfd, sock, exitsignal;
static char* address;
static char* ns_path;
static bool check_other_wm;
static int sleeperfd;
static int sock;
static int exitsignal;
static struct sigaction sa;
static struct passwd* passwd;
static void
usage(void) {
@ -67,49 +71,8 @@ scan_wins(void) {
XFree(wins);
}
static char*
ns_display(void) {
char *s, *disp;
disp = getenv("DISPLAY");
if(disp == nil)
fatal("DISPLAY is unset");
disp = estrdup(disp);
s = &disp[strlen(disp) - 2];
if(strcmp(s, ".0") == 0)
*s = '\0';
s = emalloc(strlen(disp) + strlen(user) + strlen("/tmp/ns..") + 1);
sprint(s, "/tmp/ns.%s.%s", user, disp);
free(disp);
return s;
}
static void
rmkdir(char *path, int mode) {
char *p;
int ret;
char c;
for(p = path+1; ; p++) {
c = *p;
if((c == '/') || (c == '\0')) {
*p = '\0';
ret = mkdir(path, mode);
if((ret == -1) && (errno != EEXIST))
fatal("Can't create path '%s': %r", path);
*p = c;
}
if(c == '\0')
break;
}
}
static void
init_ns(void) {
struct stat st;
char *s;
if(address && strncmp(address, "unix!", 5) == 0) {
@ -117,35 +80,24 @@ init_ns(void) {
s = strrchr(ns_path, '/');
if(s != nil)
*s = '\0';
}
else if((s = getenv("NAMESPACE")))
ns_path = s;
else
ns_path = ns_display();
if(ns_path[0] != '/' || ns_path[0] == '\0')
fatal("address \"%s\" is not an absolute path", address);
setenv("NAMESPACE", ns_path, true);
}else
ns_path = ixp_namespace();
if(ns_path[0] != '/' || ns_path[0] == '\0')
fatal("Bad ns_path");
rmkdir(ns_path, 0700);
if(stat(ns_path, &st))
fatal("Can't stat ns_path '%s': %r", ns_path);
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);
if(ns_path == nil)
fatal("Bad namespace path: %r\n");
}
static void
init_environment(void) {
init_ns();
if(address == nil)
if(address)
setenv("WMII_ADDRESS", address, true);
else
address = smprint("unix!%s/wmii", ns_path);
setenv("WMII_NS_DIR", ns_path, True);
setenv("WMII_ADDRESS", address, True);
}
static void
@ -249,7 +201,7 @@ cleanup_handler(int signal) {
sa.sa_handler = SIG_DFL;
sigaction(signal, &sa, nil);
srv.running = False;
srv.running = false;
switch(signal) {
default:
@ -395,7 +347,7 @@ main(int argc, char *argv[]) {
usage();
setlocale(LC_CTYPE, "");
starting = True;
starting = true;
initdisplay();
@ -449,7 +401,7 @@ main(int argc, char *argv[]) {
sel_screen = pointerscreen();
num_screens = 1;
screens = emallocz(num_screens * sizeof(*screens));
screens = emallocz(num_screens * sizeof *screens);
screen = &screens[0];
for(i = 0; i < num_screens; i++) {
s = &screens[i];

View File

@ -382,7 +382,7 @@ message_root(void *p, IxpMsg *m) {
if((n & (Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) == 0)
return Ebadvalue;
utflcpy(def.grabmod, s, sizeof(def.grabmod));
utflcpy(def.grabmod, s, sizeof def.grabmod);
def.mod = n;
break;
case LNORMCOLORS:
@ -462,7 +462,7 @@ message_view(View *v, IxpMsg *m) {
return Ebadvalue;
a->mode = i;
column_arrange(a, True);
column_arrange(a, true);
view_restack(v);
if(v == screen->sel)

View File

@ -91,7 +91,7 @@ update_rules(Rule **rule, const char *data) {
*rule = emallocz(sizeof **rule);
(*rule)->regex = regcomp(regex);
if((*rule)->regex) {
utflcpy((*rule)->value, value, sizeof(rul->value));
utflcpy((*rule)->value, value, sizeof rul->value);
rule = &(*rule)->next;
}else
free(*rule);

View File

@ -73,7 +73,7 @@ view_create(const char *name) {
v->r = screen->r;
v->r.max.y = screen->barwin->r.min.y;
utflcpy(v->name, name, sizeof(v->name));
utflcpy(v->name, name, sizeof v->name);
event("CreateTag %s\n", v->name);
area_create(v, nil, 0);
@ -265,7 +265,7 @@ void
view_select(const char *arg) {
char buf[256];
utflcpy(buf, arg, sizeof(buf));
utflcpy(buf, arg, sizeof buf);
trim(buf, " \t+/");
if(buf[0] == '\0')
@ -301,10 +301,16 @@ view_attach(View *v, Frame *f) {
void
view_detach(Frame *f) {
Client *c;
View *v;
v = f->view;
c = f->client;
area_detach(f);
if(c->sel == f)
c->sel = f->cnext;
if(v != screen->sel && empty_p(v))
view_destroy(v);
}
@ -449,7 +455,7 @@ view_rects(View *v, uint *num, Frame *ignore) {
for(f=v->area->frame; f; f=f->anext)
i++;
result = emallocz(i * sizeof(Rectangle));
result = emallocz(i * sizeof *result);
i = 0;
for(f=v->area->frame; f; f=f->anext)

View File

@ -411,7 +411,7 @@ convpts(Point *pt, int np) {
XPoint *rp;
int i;
rp = emalloc(np * sizeof(*rp));
rp = emalloc(np * sizeof *rp);
for(i = 0; i < np; i++) {
rp[i].x = pt[i].x;
rp[i].y = pt[i].y;
@ -628,7 +628,7 @@ xatom(char *name) {
e = hash_get(&atommap, name, 1);
if(e->val == nil)
e->val = (void*)XInternAtom(display, name, False);
e->val = (void*)XInternAtom(display, name, false);
return (Atom)e->val;
}
@ -660,7 +660,7 @@ keycode(char *name) {
void
sync(void) {
XSync(display, False);
XSync(display, false);
}
/* Properties */
@ -732,7 +732,7 @@ getprop(Window *w, char *prop, char *type, Atom *actual, int *format, ulong offs
typea = (type ? xatom(type) : 0L);
status = XGetWindowProperty(display, w->w,
xatom(prop), offset, length, False /* delete */,
xatom(prop), offset, length, false /* delete */,
typea, actual, format, &n, &extra, ret);
if(status != Success) {
@ -762,8 +762,6 @@ getprop_long(Window *w, char *prop, char *type, ulong offset, long **ret, ulong
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;
@ -775,19 +773,21 @@ getprop_ulong(Window *w, char *prop, char *type, ulong offset, ulong **ret, ulon
}
char**
strlistdup(char *list[], int n) {
strlistdup(char *list[]) {
char **p, *q;
int i, m;
int i, m, n;
for(i=0, m=0; i < n; i++)
m += strlen(list[i])+1;
n = 0;
m = 0;
for(p=list; *p; p++, n++)
m += strlen(*p) + 1;
p = malloc((n+1)*sizeof(char*) + m);
p = malloc((n+1) * sizeof(*p) + m);
q = (char*)&p[n+1];
for(i=0; i < n; i++) {
p[i] = q;
m = strlen(list[i])+1;
m = strlen(list[i]) + 1;
memcpy(q, list[i], m);
q += m;
}
@ -879,7 +879,7 @@ grabpointer(Window *w, Window *confine, Cursor cur, int mask) {
cw = None;
if(confine)
cw = confine->w;
return XGrabPointer(display, w->w, False /* owner events */, mask,
return XGrabPointer(display, w->w, false /* owner events */, mask,
GrabModeAsync, GrabModeAsync, cw, cur, CurrentTime
) == GrabSuccess;
}

View File

@ -169,8 +169,8 @@ main(int argc, char **argv)
numitems = argc;
labels = emalloc(numitems * sizeof(*labels));
commands = emalloc(numitems * sizeof(*labels));
labels = emalloc(numitems * sizeof *labels);
commands = emalloc(numitems * sizeof *labels);
for(i = 0; i < numitems; i++) {
labels[i] = argv[i];

View File

@ -1,4 +1,4 @@
/* Copyright ©2007 Kris Maglione <fbsdaemon@gmail.com>
/* Copyight ©2007-2008 Kris Maglione <fbsdaemon@gmail.com>
* See LICENSE file for license details.
*/
#define IXP_NO_P9_
@ -35,12 +35,13 @@ write_data(IxpCFid *fid, char *name) {
int len;
buf = emalloc(fid->iounit);;
do {
for(;;) {
len = read(0, buf, fid->iounit);
if(len > 0 && ixp_write(fid, buf, len) != len)
if(len <= 0)
break;
if(ixp_write(fid, buf, len) != len)
fatal("cannot write file '%s': %r\n", name);
} while(len > 0);
}
free(buf);
}
@ -88,16 +89,24 @@ timestr(uint val) {
}
static void
print_stat(Stat *s, int lflag) {
print_stat(Stat *s, int lflag, char *file, int pflag) {
char *slash;
slash = "";
if(pflag)
slash = "/";
else
file = "";
if(lflag)
print("%s %s %s %5llud %s %s\n",
print("%s %s %s %5llud %s %s%s%s\n",
modestr(s->mode), s->uid, s->gid, s->length,
timestr(s->mtime), s->name);
timestr(s->mtime), file, slash, s->name);
else {
if((s->mode&P9_DMDIR) && strcmp(s->name, "/"))
print("%s/\n", s->name);
print("%s%s%s/\n", file, slash, s->name);
else
print("%s\n", s->name);
print("%s%s%s\n", file, slash, s->name);
}
}
@ -125,8 +134,8 @@ xwrite(int argc, char *argv[]) {
static int
xawrite(int argc, char *argv[]) {
IxpCFid *fid;
char *file, *buf, *arg;
int nbuf, mbuf, len;
char *file, *buf;
int nbuf, i;
ARGBEGIN{
default:
@ -139,19 +148,14 @@ xawrite(int argc, char *argv[]) {
fatal("Can't open file '%s': %r\n", file);
nbuf = 0;
mbuf = 128;
buf = emalloc(mbuf);
for(i=0; i < argc; i++)
nbuf += strlen(argv[i]) + 1;
buf = emalloc(nbuf);
buf[0] = '\0';
while(argc) {
arg = ARGF();
len = strlen(arg);
if(nbuf + len + 1 > mbuf) {
mbuf <<= 1;
buf = erealloc(buf, mbuf);
}
memcpy(buf+nbuf, arg, len);
nbuf += len;
strcat(buf, ARGF());
if(argc)
buf[nbuf++] = ' ';
strcat(buf, " ");
}
if(ixp_write(fid, buf, nbuf) == -1)
@ -237,9 +241,10 @@ xls(int argc, char *argv[]) {
IxpCFid *fid;
char *file;
char *buf;
int lflag, dflag, count, nstat, mstat, i;
int lflag, dflag, pflag;
int count, nstat, mstat, i;
lflag = dflag = 0;
lflag = dflag = pflag = 0;
ARGBEGIN{
case 'l':
@ -248,55 +253,81 @@ xls(int argc, char *argv[]) {
case 'd':
dflag++;
break;
case 'p':
pflag++;
break;
default:
usage();
}ARGEND;
file = EARGF(usage());
do {
stat = ixp_stat(client, file);
if(stat == nil)
fatal("cannot stat file '%s': %r\n", file);
stat = ixp_stat(client, file);
if(stat == nil)
fatal("cannot stat file '%s': %r\n", file);
if(dflag || (stat->mode&P9_DMDIR) == 0) {
print_stat(stat, lflag);
ixp_freestat(stat);
return 0;
}
ixp_freestat(stat);
fid = ixp_open(client, file, P9_OREAD);
if(fid == nil)
fatal("Can't open file '%s': %r\n", file);
nstat = 0;
mstat = 16;
stat = emalloc(sizeof(*stat) * mstat);
buf = emalloc(fid->iounit);
while((count = ixp_read(fid, buf, fid->iounit)) > 0) {
m = ixp_message(buf, count, MsgUnpack);
while(m.pos < m.end) {
if(nstat == mstat) {
mstat <<= 1;
stat = erealloc(stat, sizeof(*stat) * mstat);
}
ixp_pstat(&m, &stat[nstat++]);
i = strlen(file);
if(file[i-1] == '/') {
file[i-1] = '\0';
if(!(stat->mode&P9_DMDIR))
fatal("%s: not a directory", file);
}
}
ixp_close(fid);
if(dflag || (stat->mode&P9_DMDIR) == 0) {
print_stat(stat, lflag, file, pflag);
ixp_freestat(stat);
continue;
}
ixp_freestat(stat);
qsort(stat, nstat, sizeof(*stat), comp_stat);
for(i = 0; i < nstat; i++) {
print_stat(&stat[i], lflag);
ixp_freestat(&stat[i]);
}
free(stat);
fid = ixp_open(client, file, P9_OREAD);
if(fid == nil)
fatal("Can't open file '%s': %r\n", file);
nstat = 0;
mstat = 16;
stat = emalloc(mstat * sizeof *stat);
buf = emalloc(fid->iounit);
while((count = ixp_read(fid, buf, fid->iounit)) > 0) {
m = ixp_message(buf, count, MsgUnpack);
while(m.pos < m.end) {
if(nstat == mstat) {
mstat <<= 1;
stat = erealloc(stat, mstat * sizeof *stat);
}
ixp_pstat(&m, &stat[nstat++]);
}
}
ixp_close(fid);
qsort(stat, nstat, sizeof *stat, comp_stat);
for(i = 0; i < nstat; i++) {
print_stat(&stat[i], lflag, file, pflag);
ixp_freestat(&stat[i]);
}
free(stat);
} while((file = ARGF()));
if(count == -1)
fatal("cannot read directory '%s': %r\n", file);
return 0;
}
static int
xnamespace(int argc, char *argv[]) {
char *path;
ARGBEGIN{
default:
usage();
}ARGEND;
path = ixp_namespace();
if(path == nil)
fatal("can't find namespace: %r\n");
print("%s\n", path);
return 0;
}
static int
xsetsid(int argc, char *argv[]) {
char *av0;
@ -322,17 +353,20 @@ typedef struct exectab exectab;
struct exectab {
char *cmd;
int (*fn)(int, char**);
} etab[] = {
} fstab[] = {
{"cat", xread},
{"create", xcreate},
{"ls", xls},
{"read", xread},
{"remove", xremove},
{"rm", xremove},
{"setsid", xsetsid},
{"write", xwrite},
{"xwrite", xawrite},
{0, 0}
{0, }
}, utiltab[] = {
{"namespace", xnamespace},
{"setsid", xsetsid},
{0, }
};
int
@ -347,7 +381,7 @@ main(int argc, char *argv[]) {
ARGBEGIN{
case 'v':
print("%s-" VERSION ", ©2007 Kris Maglione\n", argv0);
print("%s-" VERSION ", ©2008 Kris Maglione\n", argv0);
exit(0);
case 'a':
address = EARGF(usage());
@ -356,14 +390,18 @@ main(int argc, char *argv[]) {
usage();
}ARGEND;
if(!address)
fatal("$WMII_ADDRESS not set\n");
for(tab=utiltab; tab->cmd; tab++)
if(!strcmp(*argv, tab->cmd))
return tab->fn(argc, argv);
client = ixp_mount(address);
if(address && *address)
client = ixp_mount(address);
else
client = ixp_nsmount("wmii");
if(client == nil)
fatal("can't mount: %r\n");
for(tab = etab; tab->cmd; tab++)
for(tab=fstab; tab->cmd; tab++)
if(strcmp(*argv, tab->cmd) == 0) break;
if(tab->cmd == 0)
usage();
@ -373,3 +411,4 @@ main(int argc, char *argv[]) {
ixp_unmount(client);
return ret;
}

View File

@ -8,7 +8,22 @@ iconwidth = 32
iconscale = `{*=$epsbox; hoc -e $iconwidth/'('$3-' '$1')'}
iconheight = `{*=$epsbox; hoc -e '('$4-' '$2')*'$iconscale}
icon.png: $eps
%.png: %.eps
* = `{hoc -e'-('$epsbox')'}
x = $1
y = $2
gs -q -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile=$target -g$iconwidth'x'$iconheight - <<!
$iconscale $iconscale scale
$x $y translate
($eps) run
showpage
quit
!
%-small.png: %.eps
iconwidth = 16
iconscale = `{*=$epsbox; hoc -e $iconwidth/'('$3-' '$1')'}
iconheight = `{*=$epsbox; hoc -e '('$4-' '$2')*'$iconscale}
* = `{hoc -e'-('$epsbox')'}
x = $1
y = $2

View File

@ -226,7 +226,7 @@ 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);
char** strlistdup(char**);
Point subpt(Point, Point);
void sync(void);
uint textwidth(Font*, char*);

View File

@ -123,10 +123,10 @@ fn Event-LeftBarMouseDown {
# Actions
fn Action-rehash {
comm -23 <{ls $WMII_NS_DIR/proglist.* >[2]/dev/null | awk -F'\.' '{print $NF}'} \
comm -23 <{ls `{namespace}/proglist.* >[2]/dev/null | awk -F'\.' '{print $NF}'} \
<{ps | awk '{print $2}'} |
while(id=`{read})
rm $WMII_NS_DIR/proglist.$id
rm `{namespace}/proglist.$id
wi_proglist $PATH >$progs_file}
fn Action-quit {
wmiir xwrite /ctl quit}
@ -221,7 +221,6 @@ key Shift-$MODKEY-^`{seq 0 9} || fn $key {
#` WM Configuration
wmiir write /ctl <<!
view 1
grabmod $MODKEY
border 2
font $wmiifont
@ -234,7 +233,7 @@ xsetroot -solid $wmiibackground
Action overridekeys
# Misc Setup
progs_file=$WMII_NS_DIR/proglist.$pid
progs_file=`{namespace}/proglist.$pid
Action status
Action rehash

View File

@ -185,7 +185,7 @@ export WMII_MENU WMII_9MENU WMII_FONT WMII_TERM
export WMII_FOCUSCOLORS WMII_SELCOLORS WMII_NORMCOLORS
# Misc
progsfile="$WMII_NS_DIR/.proglist"
progsfile="$(wmiir namespace)/.proglist"
Action status &
wi_proglist $PATH >$progsfile &