wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 13f235b076f845d81dfe4b2b2afeee8b9c77b828
parent 75abe3f7a5fa57fd5ce4a792c4413a06151f0e13
Author: Kris Maglione <jg@suckless.org>
Date:   Thu, 21 May 2009 15:57:04 -0400

Minor pygmi efficiency fixed.

Diffstat:
alternative_wmiircs/python/pygmi/fs.py | 35++++++++++++++++++++++++-----------
alternative_wmiircs/python/pyxp/asyncclient.py | 13+++++++------
alternative_wmiircs/python/pyxp/client.py | 13+++++++------
cmd/wmii/bar.c | 24++++++++++++++++++++++++
cmd/wmii/fns.h | 1+
cmd/wmii/fs.c | 22+---------------------
6 files changed, 64 insertions(+), 44 deletions(-)

diff --git a/alternative_wmiircs/python/pygmi/fs.py b/alternative_wmiircs/python/pygmi/fs.py @@ -337,28 +337,41 @@ class Button(object): self.name = name self.base_path = self.sides[side] self.path = '%s/%s' % (self.base_path, self.name) - self.create(colors, label) + self.file = None + if colors or label: + self.create(colors, label) def create(self, colors=None, label=None): - with client.create(self.path, OWRITE) as f: - f.write(self.getval(colors, label)) + if not self.file: + self.file = client.create(self.path, ORDWR) + if colors: + self.file.awrite(self.getval(colors, label), offset=0) + elif label: + self.file.awrite(label, offset=24) def remove(self): - client.aremove(self.path) + if self.file: + self.file.aremove() + self.file = None def getval(self, colors=None, label=None): - if colors is None: - colors = self.colors if label is None: label = self.label + if colors is None and re.match( + r'#[0-9a-f]{6} #[0-9a-f]{6} #[0-9a-f]{6}', label, re.I): + colors = self.colors + if not colors: + return str(label) return ' '.join([Color(c).hex for c in colors] + [str(label)]) colors = property( - lambda self: tuple(map(Color, client.read(self.path).split(' ')[:3])), - lambda self, val: client.awrite(self.path, self.getval(colors=val))) + lambda self: self.file and + tuple(map(Color, self.file.read(offset=0).split(' ')[:3])) + or (), + lambda self, val: self.create(colors=val)) label = property( - lambda self: client.read(self.path).split(' ', 3)[3], - lambda self, val: client.write(self.path, self.getval(label=val))) + lambda self: self.file and self.file.read(offset=0).split(' ', 3)[3] or '', + lambda self, val: self.create(label=val)) @classmethod def all(cls, side): @@ -516,7 +529,7 @@ class Tags(object): self.add(t.id) for b in wmii.lbuttons: if b.name not in self.tags: - b.aremove() + b.remove() self.focus(Tag('sel').id) self.mru = [self.sel.id] diff --git a/alternative_wmiircs/python/pyxp/asyncclient.py b/alternative_wmiircs/python/pyxp/asyncclient.py @@ -41,7 +41,7 @@ class Client(client.Client): next) next() - def _open(self, path, mode, open): + def _open(self, path, mode, open, origpath=None): resp = None with self.walk(path) as nfid: @@ -50,18 +50,18 @@ class Client(client.Client): def cleanup(): self.aclunk(fid) - file = File(self, '/'.join(path), resp, fid, mode, cleanup) + file = File(self, origpath or '/'.join(path), resp, fid, mode, cleanup) self.files[fid] = file return file - def _aopen(self, path, mode, open, callback): + def _aopen(self, path, mode, open, callback, origpath=None): resp = None def next(fid, exc, tb): def next(resp, exc, tb): def cleanup(): self.clunk(fid) - file = File(self, '/'.join(path), resp, fid, mode, cleanup) + file = File(self, origpath or '/'.join(path), resp, fid, mode, cleanup) self.files[fid] = file self.respond(callback, file) self.dorpc(open(fid), next, callback) @@ -83,7 +83,8 @@ class Client(client.Client): def callback(resp, exc, tb): if resp: resp.close() - return self._aopen(path, mode, open, async) + return self._aopen(path, mode, open, async, + origpath='/'.join(path + [name])) def aremove(self, path, callback=True): path = self.splitpath(path) @@ -177,7 +178,7 @@ class File(client.File): callback(None) self.aread(next) - def awrite(self, data, callback, offset=None): + def awrite(self, data, callback=True, offset=None): ctxt = dict(offset=self.offset, off=0) if offset is not None: ctxt['offset'] = offset diff --git a/alternative_wmiircs/python/pyxp/client.py b/alternative_wmiircs/python/pyxp/client.py @@ -164,7 +164,7 @@ class Client(object): self.clunk(fid) return Res - def _open(self, path, mode, open): + def _open(self, path, mode, open, origpath=None): resp = None with self.walk(path) as nfid: @@ -173,7 +173,7 @@ class Client(object): def cleanup(): self.aclunk(fid) - file = File(self, '/'.join(path), resp, fid, mode, cleanup) + file = File(self, origpath or '/'.join(path), resp, fid, mode, cleanup) self.files[fid] = file return file @@ -191,7 +191,7 @@ class Client(object): def open(fid): return fcall.Tcreate(fid=fid, mode=mode, name=name, perm=perm) - return self._open(path, mode, open) + return self._open(path, mode, open, origpath='/'.join(path + [name])) def remove(self, path): path = self.splitpath(path) @@ -245,6 +245,9 @@ class File(object): self.closed = False self.offset = 0 + def __del__(self): + if not self.closed: + self.cleanup() def dorpc(self, fcall, async=None, error=None): if hasattr(fcall, 'fid'): @@ -277,9 +280,7 @@ class File(object): break if offset is None: self.offset = offs - res = ''.join(res) - if len(res) > 0: - return res + return ''.join(res) def readlines(self): last = None while True: diff --git a/cmd/wmii/bar.c b/cmd/wmii/bar.c @@ -184,6 +184,30 @@ bar_draw(WMScreen *s) { copyimage(s->barwin, r, disp.ibuf, ZP); } +void +bar_load(Bar *b) { + IxpMsg m; + char *p, *q; + + p = b->buf; + m = ixp_message(p, strlen(p), 0); + msg_parsecolors(&m, &b->col); + + q = (char*)m.end-1; + while(q >= (char*)m.pos && *q == '\n') + *q-- = '\0'; + + q = b->text; + utflcpy(q, (char*)m.pos, sizeof b->text); + + p[0] = '\0'; + strlcat(p, b->col.colstr, sizeof b->buf); + strlcat(p, " ", sizeof b->buf); + strlcat(p, b->text, sizeof b->buf); + + bar_draw(b->screen); +} + Bar* bar_find(Bar *bp, const char *name) { Bar *b; diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h @@ -61,6 +61,7 @@ void bar_destroy(Bar**, Bar*); void bar_draw(WMScreen*); Bar* bar_find(Bar*, const char*); void bar_init(WMScreen*); +void bar_load(Bar*); void bar_resize(WMScreen*); void bar_sety(WMScreen*, int); void bar_setbounds(WMScreen*, int, int); diff --git a/cmd/wmii/fs.c b/cmd/wmii/fs.c @@ -545,6 +545,7 @@ fs_write(Ixp9Req *r) { i = strlen(f->p.bar->buf); p = f->p.bar->buf; ixp_srv_writebuf(r, &p, &i, 279); + bar_load(f->p.bar); r->ofcall.io.count = i - r->ifcall.io.offset; respond(r, nil); return; @@ -664,8 +665,6 @@ fs_remove(Ixp9Req *r) { void fs_clunk(Ixp9Req *r) { IxpFileId *f; - char *p, *q; - IxpMsg m; f = r->fid->aux; if(!ixp_srv_verifyfile(f, lookup_file)) { @@ -697,25 +696,6 @@ fs_clunk(Ixp9Req *r) { case FsFKeys: update_keys(); break; - case FsFBar: - p = f->p.bar->buf; - m = ixp_message(p, strlen(p), 0); - msg_parsecolors(&m, &f->p.bar->col); - - q = (char*)m.end-1; - while(q >= (char*)m.pos && *q == '\n') - *q-- = '\0'; - - q = f->p.bar->text; - utflcpy(q, (char*)m.pos, sizeof ((Bar*)0)->text); - - p[0] = '\0'; - strlcat(p, f->p.bar->col.colstr, sizeof(f->p.bar->buf)); - strlcat(p, " ", sizeof(f->p.bar->buf)); - strlcat(p, f->p.bar->text, sizeof(f->p.bar->buf)); - - bar_draw(f->p.bar->screen); - break; } respond(r, nil); }