[hackers] [wmii] Fixes, cleanup. Pass strings around instead of Atoms.

From: Kris Maglione <jg_AT_suckless.org>
Date: Fri, 01 Jun 2007 01:09:44 -0000

changeset: 2101:1e153d8472c6
user: Kris Maglione <jg_AT_suckless.org>
date: Fri Apr 20 15:24:49 2007 -0400
summary: Fixes, cleanup. Pass strings around instead of Atoms.

diff -r 732ec36f108f -r 1e153d8472c6 cmd/Makefile
--- a/cmd/Makefile Fri Apr 20 13:02:30 2007 -0400
+++ b/cmd/Makefile Fri Apr 20 15:24:49 2007 -0400
@@ -16,6 +16,7 @@ FILTER = sed "s|CONFPREFIX|${ETC}|g; \
               s|CONFVERSION|${CONFVERSION}|g; \
               s|P9PATHS|${P9PATHS}|g; \
               s|AWKPATH|${AWKPATH}|g"
+EXCFLAGS = -DVERSION=\"${VERSION}\"
 
 include ${ROOT}/mk/many.mk
 include ${ROOT}/mk/dir.mk
diff -r 732ec36f108f -r 1e153d8472c6 cmd/wmii/Makefile
--- a/cmd/wmii/Makefile Fri Apr 20 13:02:30 2007 -0400
+++ b/cmd/wmii/Makefile Fri Apr 20 15:24:49 2007 -0400
@@ -5,27 +5,28 @@ main.c: ${ROOT}/mk/wmii.mk
 main.c: ${ROOT}/mk/wmii.mk
 
 TARG = wmii
-HFILES= dat.h fns.h
+HFILES= dat.h fns.h utf.h x11.h
 
 LIB = ${LIBIXP}
 EXLDFLAGS = -lm ${LIBX11} -lXext ${LIBICONV}
-EXCFLAGS = ${INCX11} ${INCICONV}
+EXCFLAGS = ${INCX11} ${INCICONV} -DVERSION=\"${VERSION}\"
 OBJ = area \
         bar \
         client \
         column \
         event \
         frame \
- fs \
+ fs \
         geom \
- key \
- main \
+ key \
+ main \
+ map \
         mouse \
- rule \
+ rule \
         printevent\
- utf \
- view \
- x11 \
+ utf \
+ view \
+ x11 \
         ../util
 
 include ${ROOT}/mk/one.mk
diff -r 732ec36f108f -r 1e153d8472c6 cmd/wmii/client.c
--- a/cmd/wmii/client.c Fri Apr 20 13:02:30 2007 -0400
+++ b/cmd/wmii/client.c Fri Apr 20 15:24:49 2007 -0400
@@ -44,10 +44,10 @@ create_client(XWindow w, XWindowAttribut
         c->w.r = c->r;
 
         c->proto = winprotocols(&c->w);
- prop_client(c, XA_WM_TRANSIENT_FOR);
- prop_client(c, XA_WM_NORMAL_HINTS);
- prop_client(c, XA_WM_HINTS);
- prop_client(c, XA_WM_NAME);
+ 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_NAME"));
 
         XSetWindowBorderWidth(display, w, 0);
         XAddToSaveSet(display, w);
@@ -164,16 +164,17 @@ destroy_client(Client *c) {
 
 void
 manage_client(Client *c) {
- XTextProperty tags = { 0 };
         Client *trans;
-
- XGetTextProperty(display, c->w.w, &tags, atom[TagsAtom]);
+ char *tags;
+
+ tags = gettextproperty(&c->w, "_WIN_TAGS");
 
         if((trans = win2client(c->trans)))
                 strncpy(c->tags, trans->tags, sizeof(c->tags));
- else if(tags.nitems)
- strncpy(c->tags, (char *)tags.value, sizeof(c->tags));
- XFree(tags.value);
+ else if(tags)
+ strncpy(c->tags, tags, sizeof(c->tags));
+
+ free(tags);
 
         gravclient(c, c->w.r);
         reparent_client(c, c->framewin, Pt(def.border, labelh(def.font)));
@@ -355,35 +356,46 @@ win2client(XWindow w) {
         return c;
 }
 
+uint
+clientwin(Client *c) {
+ if(c)
+ return (uint)c->w.w;
+ return 0;
+}
+
+char *
+clientname(Client *c) {
+ if(c)
+ return c->name;
+ return "<nil>";
+}
+
 static void
 update_client_name(Client *c) {
- XClassHint ch = {0};
- char *str;
-
- c->name[0] = '0';
-
- str = gettextproperty(&c->w, atom[NetWMName]);
+ char *str, **class;
+ int n;
+
+ c->name[0] = '\0';
+
+ str = gettextproperty(&c->w, "_NET_WM_NAME)");
         if(str == nil)
- str = gettextproperty(&c->w, XA_WM_NAME);
+ str = gettextproperty(&c->w, "WM_NAME");
         if(str)
                 utfecpy(c->name, c->name+sizeof(c->name), str);
         free(str);
 
- XGetClassHint(display, c->w.w, &ch);
+ n = gettextlistproperty(&c->w, "WM_CLASS", &class);
         snprintf(c->props, sizeof(c->props), "%s:%s:%s",
- str_nil(ch.res_class),
- str_nil(ch.res_name),
+ (n > 0 ? class[0] : "<nil>"),
+ (n > 1 ? class[1] : "<nil>"),
                         c->name);
- if(ch.res_class)
- XFree(ch.res_class);
- if(ch.res_name)
- XFree(ch.res_name);
+ freestringlist(class);
 }
 
 void
 set_client_state(Client * c, int state) {
         long data[] = { state, None };
- changeproperty(&c->w, atom[WMState], atom[WMState], 32, (uchar*)data, nelem(data));
+ changeprop(&c->w, "WM_STATE", "WM_STATE", data, nelem(data));
 }
 
 void
@@ -455,23 +467,23 @@ configure_client(Client *c) {
 }
 
 static void
-send_client_message(XWindow w, Atom a, long value) {
+send_client_message(Client *c, char *name, char *value) {
         XEvent e;
 
         e.type = ClientMessage;
- e.xclient.window = w;
- e.xclient.message_type = a;
+ e.xclient.window = c->w.w;
+ e.xclient.message_type = xatom(name);
         e.xclient.format = 32;
- e.xclient.data.l[0] = value;
+ e.xclient.data.l[0] = xatom(value);
         e.xclient.data.l[1] = CurrentTime;
- XSendEvent(display, w, False, NoEventMask, &e);
+ 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->w.w, atom[WMProtocols], atom[WMDelete]);
+ send_client_message(c, "WM_PROTOCOLS", "WM_DELETE_WINDOW");
         else
                 XKillClient(display, c->w.w);
 }
@@ -483,37 +495,32 @@ set_urgent(Client *c, Bool urgent, Bool
         Frame *f, *ff;
         Area *a;
 
- cwrite = "Client";
- if(write)
- cwrite = "Manager";
- cnot = "Not";
- if(urgent)
- cnot = "";
+ cwrite = (write ? "Manager" : "Client");
+ cnot = (urgent ? "" : "Not");
 
         if(urgent != c->urgent) {
- write_event("%sUrgent 0x%x %s\n", cnot, c->w, cwrite);
+ write_event("%sUrgent 0x%x %s\n", cnot, clientwin(c), cwrite);
                 c->urgent = urgent;
                 if(c->sel) {
                         if(c->sel->view == screen->sel)
                                 draw_frame(c->sel);
- if(!urgent || c->sel->view != screen->sel)
- for(f=c->frame; f; f=f->cnext) {
+ for(f=c->frame; f; f=f->cnext) {
+ if(!urgent)
                                         for(a=f->view->area; a; a=a->next)
                                                 for(ff=a->frame; ff; ff=ff->anext)
                                                         if(ff->client->urgent) break;
- if(!ff)
- write_event("%sUrgentTag %s %s\n", cnot, cwrite, f->view->name);
- }
+ if(urgent || ff == nil)
+ write_event("%sUrgentTag %s %s\n", cnot, cwrite, f->view->name);
+ }
                 }
         }
 
         if(write) {
                 wmh = XGetWMHints(display, c->w.w);
                 if(wmh) {
+ wmh->flags &= ~XUrgencyHint;
                         if(urgent)
                                 wmh->flags |= XUrgencyHint;
- else
- wmh->flags &= ~XUrgencyHint;
                         XSetWMHints(display, c->w.w, wmh);
                         XFree(wmh);
                 }
@@ -524,14 +531,10 @@ prop_client(Client *c, Atom a) {
 prop_client(Client *c, Atom a) {
         XWMHints *wmh;
 
- if(a == atom[WMProtocols])
+ if(a == xatom("WM_PROTOCOLS"))
                 c->proto = winprotocols(&c->w);
- else if(a== atom[NetWMName]) {
-wmname:
- update_client_name(c);
- if(c->frame)
- draw_frame(c->sel);
- }
+ else if(a == xatom("_NET_WM_NAME"))
+ goto wmname;
         else switch (a) {
         case XA_WM_TRANSIENT_FOR:
                 XGetTransientForHint(display, c->w.w, &c->trans);
@@ -549,7 +552,11 @@ wmname:
                 }
                 break;
         case XA_WM_NAME:
- goto wmname;
+wmname:
+ update_client_name(c);
+ if(c->frame)
+ draw_frame(c->sel);
+ break;
         }
 }
 
@@ -605,18 +612,16 @@ focus_client(Client *c) {
         flushevents(FocusChangeMask, True);
 
         if(verbose)
- fprintf(stderr, "focus_client(%p[%x]) => %s\n", c,
- (c ? (uint)c->w.w : 0), (c ? c->name : nil));
+ fprintf(stderr, "focus_client(%p[%x]) => %s\n", c, clientwin(c), clientname(c));
 
         if(screen->focus != c) {
                 if(verbose)
                         fprintf(stderr, "\t%s => %s\n",
- (screen->focus ? screen->focus->name : "<nil>"),
- (c ? c->name : "<nil>"));
+ clientname(screen->focus), clientname(c));
                 if(c)
- XSetInputFocus(display, c->w.w, RevertToParent, CurrentTime);
+ setfocus(&c->w, RevertToParent);
                 else
- XSetInputFocus(display, screen->barwin->w, RevertToParent, CurrentTime);
+ setfocus(screen->barwin, RevertToParent);
                 XSync(display, False);
         }
 
@@ -901,7 +906,7 @@ apply_tags(Client *c, const char *tags)
 
         update_client_views(c, toks);
 
- changeproperty(&c->w, atom[TagsAtom], atom[Utf8String], 8, (uchar*)c->tags, strlen(c->tags));
+ changeprop(&c->w, "_WIN_TAGS", "UTF8_STRING", c->tags, strlen(c->tags));
 }
 
 void
diff -r 732ec36f108f -r 1e153d8472c6 cmd/wmii/dat.h
--- a/cmd/wmii/dat.h Fri Apr 20 13:02:30 2007 -0400
+++ b/cmd/wmii/dat.h Fri Apr 20 15:24:49 2007 -0400
@@ -32,14 +32,6 @@ struct CTuple {
         ulong fg;
         ulong border;
         char colstr[24]; /* #RRGGBB #RRGGBB #RRGGBB */
-};
-
-enum {
- WMState, WMProtocols, WMDelete,
- NetSupported, NetWMName,
- Utf8String,
- TagsAtom,
- AtomLast
 };
 
 enum {
@@ -70,6 +62,20 @@ typedef struct Rule Rule;
 typedef struct Rule Rule;
 typedef struct Ruleset Ruleset;
 typedef struct WMScreen WMScreen;
+typedef struct Map Map;
+typedef struct MapEnt MapEnt;
+
+struct Map {
+ MapEnt **bucket;
+ uint nhash;
+};
+
+struct MapEnt {
+ ulong hash;
+ char *key;
+ void *val;
+ MapEnt *next;
+};
 
 struct View {
         View *next;
@@ -227,7 +233,6 @@ Bool sel_screen;
 
 Image xor;
 
-Atom atom[AtomLast];
 Cursor cursor[CurLast];
 void (*handler[LASTEvent]) (XEvent *);
 
diff -r 732ec36f108f -r 1e153d8472c6 cmd/wmii/event.c
--- a/cmd/wmii/event.c Fri Apr 20 13:02:30 2007 -0400
+++ b/cmd/wmii/event.c Fri Apr 20 15:24:49 2007 -0400
@@ -132,11 +132,8 @@ print_focus(Client *c, char *to) {
 print_focus(Client *c, char *to) {
                 if(verbose) {
                         fprintf(stderr, "screen->focus: %p[%x] => %p[%x]\n",
- screen->focus, (uint)(screen->focus ? screen->focus->w.w : 0),
- c, (uint)(c ? c->w.w : 0));
- fprintf(stderr, "\t%s => %s\n",
- (screen->focus ? screen->focus->name : "<nil>"),
- to);
+ screen->focus, clientwin(screen->focus), c, clientwin(c));
+ fprintf(stderr, "\t%s => %s\n", clientname(screen->focus), to);
                 }
 }
 
@@ -152,7 +149,7 @@ focusin(XEvent *e) {
         if(ev->detail == NotifyDetailNone) {
                 print_focus(&c_magic, "<magic[none]>");
                 screen->focus = &c_magic;
- XSetInputFocus(display, screen->barwin->w, RevertToParent, CurrentTime);
+ setfocus(screen->barwin, RevertToParent);
                 return;
         }
 
diff -r 732ec36f108f -r 1e153d8472c6 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Fri Apr 20 13:02:30 2007 -0400
+++ b/cmd/wmii/fns.h Fri Apr 20 15:24:49 2007 -0400
@@ -49,6 +49,8 @@ void size_client(Client*, char *arg);
 void size_client(Client*, char *arg);
 Client *selclient();
 Client *win2client(XWindow);
+uint clientwin(Client *c);
+char *clientname(Client*);
 void apply_rules(Client*);
 void apply_tags(Client*, const char*);
 
@@ -112,13 +114,18 @@ void init_lock_keys();
 void init_lock_keys();
 ulong mod_key_of_str(char*);
 
+/* map.c */
+MapEnt* mapget(Map*, ulong, int create);
+MapEnt* hashget(Map*, char*, int create);
+void* maprm(Map*, ulong);
+void* hashrm(Map*, char*);
+
 /* mouse.c */
 void mouse_resizecol(Divide*);
 void do_mouse_resize(Client*, Bool opaque, Align);
 void grab_mouse(XWindow, ulong mod, ulong button);
 void ungrab_mouse(XWindow, ulong mod, uint button);
-Align snap_rect(Rectangle *rects, int num, Rectangle *current,
- Align *mask, int snapw);
+Align snap_rect(Rectangle *rects, int num, Rectangle *current, Align *mask, int snapw);
 void grab_button(XWindow, uint button, ulong mod);
 
 /* rule.c */
@@ -189,8 +196,11 @@ uint textwidth(Font*, char*);
 uint textwidth(Font*, char*);
 uint labelh(Font*);
 Atom xatom(char*);
-char *gettextproperty(Window*, Atom);
-void changeproperty(Window*, Atom prop, Atom type, int width, uchar *data, int n);
+void freestringlist(char**);
+char *gettextproperty(Window*, char*);
+int gettextlistproperty(Window *w, char *name, char **ret[]);
+void changeproperty(Window*, char *prop, char *type, int width, uchar *data, int n);
+void setfocus(Window*, int mode);
 Point querypointer(Window*);
 void warppointer(Point);
 Point translate(Window*, Window*, Point);
diff -r 732ec36f108f -r 1e153d8472c6 cmd/wmii/main.c
--- a/cmd/wmii/main.c Fri Apr 20 13:02:30 2007 -0400
+++ b/cmd/wmii/main.c Fri Apr 20 15:24:49 2007 -0400
@@ -145,16 +145,9 @@ init_environment() {
 
 static void
 init_atoms() {
- atom[WMState] = xatom("WM_STATE");
- atom[WMProtocols] = xatom("WM_PROTOCOLS");
- atom[WMDelete] = xatom("WM_DELETE_WINDOW");
- atom[NetSupported] = xatom("_NET_SUPPORTED");
- atom[NetWMName] = xatom("_NET_WM_NAME");
- atom[Utf8String] = xatom("UTF8_STRING");
- atom[TagsAtom] = xatom("_WIN_TAGS");
-
- XChangeProperty(display, scr.root.w, atom[NetSupported], XA_ATOM, 32,
- PropModeReplace, (uchar *)&atom[NetSupported], 2);
+ Atom net[] = { xatom("_NET_SUPPORTED"), xatom("_NET_WM_NAME")};
+
+ changeprop(&scr.root, "_NET_SUPPORTED", "ATOM", net, nelem(net));
 }
 
 static void
@@ -485,7 +478,7 @@ main(int argc, char *argv[]) {
         }
 
         screen->focus = nil;
- XSetInputFocus(display, screen->barwin->w, RevertToParent, CurrentTime);
+ setfocus(screen->barwin, RevertToParent);
 
         scan_wins();
         starting = False;
diff -r 732ec36f108f -r 1e153d8472c6 cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Fri Apr 20 13:02:30 2007 -0400
+++ b/cmd/wmii/mouse.c Fri Apr 20 15:24:49 2007 -0400
@@ -52,8 +52,7 @@ framerect(Framewin *f) {
         p = ZP;
         p.x -= min(r.min.x, 0);
         p.x -= max(r.max.x - screen->r.max.x, 0);
- p.y -= min(r.min.y, 0);
- p.y -= max(r.max.y - screen->brect.min.y, 0);
+ p.y -= max(r.max.y - screen->brect.min.y - Dy(r)/2, 0);
         return rectaddpt(r, p);
 }
 
@@ -117,6 +116,15 @@ static Handlers handlers = {
         .expose = expose_event,
 };
 
+static int
+_vsnap(Framewin *f, int y) {
+ if(abs(f->n - y) < Dy(f->w->r)) {
+ f->n = y;
+ return 1;
+ }
+ return 0;
+}
+
 static void
 vplace(Framewin *fw, Point pt) {
         Rectangle r;
@@ -128,7 +136,9 @@ vplace(Framewin *fw, Point pt) {
         v = screen->sel;
         r = fw->w->r;
         hr = Dy(r)/2;
-
+
+ fw->n = pt.y;
+
         for(a = v->area->next; a->next; a = a->next)
                 if(pt.x < a->r.max.x)
                         break;
@@ -137,32 +147,35 @@ vplace(Framewin *fw, Point pt) {
                 if(pt.y < f->r.max.y)
                         break;
 
-#if 0
         if(!f->collapsed) {
- if(pt.y + Dy(r) + hr > f->r.max)
- pt.y = f->r.max - hr
- else if(f == fw->r && abs(pt.y - f->r.min + hr) < Dy(r))
- pt.y = f->r.min + hr;
- else if(
- }
-#endif
-
- if(abs(pt.y - f->r.min.y) < labelh(def.font)) {
- pt.y = f->r.min.y;
- if(f == fw->f)
- pt.y += Dy(fw->w->r)/2;
- else if(f->aprev == fw->f)
- pt.y += labelh(def.font);
- }
- else if(abs(pt.y - f->r.max.y) < labelh(def.font)) {
- if(f != fw->f) {
- pt.y = f->r.max.y;
- if(f->anext == fw->f)
- pt.y += Dy(fw->w->r)/2;
- }
- }
-
+ if(_vsnap(fw, f->r.max.y - hr))
+ goto done;
+ if(f == fw->f) {
+ _vsnap(fw, f->r.min.y+hr);
+ goto done;
+ }
+ if(_vsnap(fw, f->r.min.y+Dy(r)+hr))
+ goto done;
+ if(f->aprev == nil || f->aprev->collapsed)
+ _vsnap(fw, f->r.min.y);
+ else
+ _vsnap(fw, f->r.min.y-hr);
+ goto done;
+ }
+
+ if(pt.y < f->r.min.y + hr) {
+ fw->n = f->r.min.y;
+ if(f->aprev && !f->aprev->collapsed)
+ fw->n -= hr;
+ }else {
+ fw->n = f->r.max.y;
+ if(f->anext == fw->f)
+ fw->n += hr;
+ }
+
+done:
         pt.x = a->r.min.x;
+ pt.y = fw->n;
         frameadjust(fw, pt, OHoriz, Dx(a->r));
 }
 
diff -r 732ec36f108f -r 1e153d8472c6 cmd/wmii/x11.c
--- a/cmd/wmii/x11.c Fri Apr 20 13:02:30 2007 -0400
+++ b/cmd/wmii/x11.c Fri Apr 20 15:24:49 2007 -0400
@@ -13,7 +13,9 @@ Point ZP = {0, 0};
 Point ZP = {0, 0};
 Rectangle ZR = {{0, 0}, {0, 0}};
 
-Window wlist;
+Map wmap, amap;
+MapEnt *wbucket[137];
+MapEnt *abucket[137];
 
 XRectangle
 XRect(Rectangle r) {
@@ -111,7 +113,10 @@ initdisplay() {
         
         scr.root.parent = &scr.root;
 
- wlist.next = wlist.prev = &wlist;
+ wmap.bucket = wbucket;
+ wmap.nhash = nelem(wbucket);
+ amap.bucket = abucket;
+ amap.nhash = nelem(abucket);
 }
 
 /* Images */
@@ -121,8 +126,7 @@ allocimage(int w, int h, int depth) {
 
         img = emallocz(sizeof *img);
         img->type = WImage;
- img->image = XCreatePixmap(display, scr.root.w,
- w, h, depth);
+ img->image = XCreatePixmap(display, scr.root.w, w, h, depth);
         img->gc = XCreateGC(display, img->image, 0, nil);
         img->depth = depth;
         img->r = Rect(0, 0, w, h);
@@ -236,54 +240,43 @@ Handlers*
 Handlers*
 sethandler(Window *w, Handlers *new) {
         Handlers *old;
- Window *wp;
+ MapEnt *e;
 
         assert(w->type == WWindow);
         assert((w->prev != nil && w->next != nil) || w->next == w->prev);
 
+ if(new == nil)
+ maprm(&wmap, (ulong)w->w);
+ else {
+ e = mapget(&wmap, (ulong)w->w, 1);
+ e->val = w;
+ }
         old = w->handler;
- if(new == nil) {
- if(w->prev) {
- w->prev->next = w->next;
- w->next->prev = w->prev;
- w->next = w->prev = nil;
- }
- }else {
- for(wp = wlist.next; wp != &wlist; wp = wp->next)
- if(w->w <= wp->w) break;
- if(wp->w != w->w) {
- w->next = wp;
- w->prev = wp->prev;
- wp->prev = w;
- w->prev->next = w;
- }
- }
         w->handler = new;
         return old;
 }
 
 Window*
 findwin(XWindow w) {
- Window *wp;
-
- for(wp = wlist.next; wp != &wlist; wp=wp->next)
- if(wp->w >= w) break;
- if(wp->w == w)
- return wp;
+ MapEnt *e;
+
+ e = mapget(&wmap, (ulong)w, 0);
+ if(e)
+ return e->val;
         return nil;
 }
 
 uint
 winprotocols(Window *w) {
         Atom *protocols;
- Atom real;
+ Atom real, delete;
         ulong nitems, extra;
         int i, format, status, protos;
 
         status = XGetWindowProperty(
- display, w->w, atom[WMProtocols],
+ display, w->w, xatom("_WM_PROTOCOLS"),
                 /* offset, length, delete, req_type */
- 0L, 20L, False, XA_ATOM,
+ 0L, 20L, False, xatom("ATOM"),
                 /* type, format, nitems, extra bytes returns */
                 &real, &format, &nitems, &extra,
                 /* property return */
@@ -292,14 +285,10 @@ winprotocols(Window *w) {
         if(status != Success || protocols == nil)
                 return 0;
 
- if(nitems == 0) {
- XFree(protocols);
- return 0;
- }
-
         protos = 0;
+ delete = xatom("WM_DELETE_WINDOW");
         for(i = 0; i < nitems; i++) {
- if(protocols[i] == atom[WMDelete])
+ if(protocols[i] == delete)
                         protos |= WM_PROTOCOL_DELWIN;
         }
 
@@ -490,7 +479,7 @@ loadfont(char *name) {
                 for(i = 0; i < n; i++)
                          fprintf(stderr, "%s %s", (i ? ",":""), missing[i]);
                 fprintf(stderr, "\n");
- XFreeStringList(missing);
+ freestringlist(missing);
         }
 
         if(f->set) {
@@ -550,35 +539,60 @@ labelh(Font *font) {
 /* Misc */
 Atom
 xatom(char *name) {
- return XInternAtom(display, name, False);
-}
-
-void
-changeproperty(Window *w, Atom prop, Atom type, int width, uchar *data, int n) {
- XChangeProperty(display, w->w, prop, type, width, PropModeReplace, data, n);
+ MapEnt *e;
+
+ e = hashget(&amap, name, 1);
+ if(e->val == nil)
+ e->val = (void*)XInternAtom(display, name, False);
+ return (Atom)e->val;
+}
+
+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
+freestringlist(char *list[]) {
+ XFreeStringList(list);
+}
+
+int
+gettextlistproperty(Window *w, char *name, char **ret[]) {
+ XTextProperty prop;
+ char **list;
+ int n;
+
+ *ret = nil;
+ n = 0;
+
+ XGetTextProperty(display, w->w, &prop, xatom(name));
+ if(prop.nitems > 0) {
+ if(Xutf8TextPropertyToTextList(display, &prop, &list, &n) == Success)
+ *ret = list;
+ XFree(prop.value);
+ }
+ return n;
 }
 
 char *
-gettextproperty(Window *w, Atom name) {
- XTextProperty prop;
+gettextproperty(Window *w, char *name) {
         char **list, *str;
         int n;
 
         str = nil;
 
- XGetTextProperty(display, w->w, &prop, name);
- if(prop.nitems > 0) {
- if(Xutf8TextPropertyToTextList(display, &prop, &list, &n) == Success) {
- if(n > 0) {
- n = strlen(*list)+1;
- str = emalloc(n);
- memcpy(str, *list, n);
- }
- XFreeStringList(list);
- }
- XFree(prop.value);
- }
+ n = gettextlistproperty(w, name, &list);
+ if(n > 0)
+ str = estrdup(*list);
+ freestringlist(list);
+
         return str;
+}
+
+void
+setfocus(Window *w, int mode) {
+ XSetInputFocus(display, w->w, mode, CurrentTime);
 }
 
 /* Mouse */
diff -r 732ec36f108f -r 1e153d8472c6 cmd/wmii/x11.h
--- a/cmd/wmii/x11.h Fri Apr 20 13:02:30 2007 -0400
+++ b/cmd/wmii/x11.h Fri Apr 20 15:24:49 2007 -0400
@@ -112,3 +112,5 @@ XRectangle XRect(Rectangle r);
 #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), \
+ (uchar*)(data), n)
diff -r 732ec36f108f -r 1e153d8472c6 config.mk
--- a/config.mk Fri Apr 20 13:02:30 2007 -0400
+++ b/config.mk Fri Apr 20 15:24:49 2007 -0400
@@ -13,7 +13,7 @@ LIBS = -L/usr/lib -lc
 LIBS = -L/usr/lib -lc
 
 # Flags
-CFLAGS = -g -Wall -DVERSION=\"${VERSION}\"
+CFLAGS = -g -Wall
 LDFLAGS = -g ${LIBS}
 STATIC = -static
 
Received on Fri Jun 01 2007 - 03:09:44 UTC

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