[hackers] [wmii] Try a bit harder to get the right tags in wmii_hack. Use time in seconds to prevent wraparound; check the tags of the last window.

From: Kris Maglione <jg_AT_suckless.org>
Date: Mon Feb 04 01:12:04 2008

changeset: 2278:f0f54438fdab
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sun Feb 03 19:10:13 2008 -0500
summary: Try a bit harder to get the right tags in wmii_hack. Use time in seconds to prevent wraparound; check the tags of the last window.

diff -r d30dd7887635 -r f0f54438fdab cmd/wmii/client.c
--- a/cmd/wmii/client.c Sun Feb 03 17:45:28 2008 -0500
+++ b/cmd/wmii/client.c Sun Feb 03 19:10:13 2008 -0500
@@ -173,7 +173,7 @@ client_manage(Client *c) {
         if(trans == nil && c->group)
                 trans = group_leader(c->group);
 
- if(tags)
+ if(tags && (!trans || starting))
                 utflcpy(c->tags, tags, sizeof c->tags);
         else if(trans)
                 utflcpy(c->tags, trans->tags, sizeof c->tags);
diff -r d30dd7887635 -r f0f54438fdab libwmii_hack/hack.c
--- a/libwmii_hack/hack.c Sun Feb 03 17:45:28 2008 -0500
+++ b/libwmii_hack/hack.c Sun Feb 03 19:10:13 2008 -0500
@@ -13,34 +13,27 @@
 #include "x11.c"
 
 enum {
- Timeout = 10000,
+ Timeout = 10,
 };
 
 static void* xlib;
 
+static Window lastwin;
 static long transient;
 static Atom types[32];
 static long ntypes;
-static char* tags[32];
-static long ntags;
+static char** tags;
 static long pid;
 static long stime;
 static char hostname[256];
-static long nmsec;
+static long nsec;
 
 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 Window (*unmapwindow)(Display*, Window);
+static Window (*destroywindow)(Display*, Window);
 
 static void
 init(Display *d) { /* Hrm... assumes one display... */
@@ -54,6 +47,8 @@ init(Display *d) { /* Hrm... assumes one
                 return;
         mapwindow = (mapfn)(uintptr_t)dlsym(xlib, "XMapWindow");
         mapraised = (mapfn)(uintptr_t)dlsym(xlib, "XMapRaised");
+ unmapwindow = (mapfn)(uintptr_t)dlsym(xlib, "XUnmapWindow");
+ destroywindow = (mapfn)(uintptr_t)dlsym(xlib, "XDestroyWindow");
 
         unsetenv("LD_PRELOAD");
 
@@ -84,9 +79,8 @@ init(Display *d) { /* Hrm... assumes one
                 unsetenv("WMII_HACK_TAGS");
 
                 n = tokenize(toks, nelem(toks)-1, s, '+');
- for(i=0; i < n; i++)
- tags[i] = strdup(toks[i]);
- ntags = n;
+ toks[n] = 0;
+ tags = strlistdup(toks);
                 free(s);
         }
         if((s = getenv("WMII_HACK_TIME"))) {
@@ -113,16 +107,22 @@ setprops(Display *d, Window w) {
         }
 
         /* Kludge. */
- if(nmsec == 0)
- nmsec = msec();
- if(msec() > nmsec + Timeout)
+ if(nsec == 0)
+ nsec = time(0);
+ else if(time(0) > nsec + Timeout)
                 return;
+
+ if(lastwin) {
+ free(tags);
+ getprop_textlist(d, lastwin, "_WMII_TAGS", &tags);
+ }
+ lastwin = w;
 
         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)
+ if(tags)
                 changeprop_textlist(d, w, "_WMII_TAGS", "UTF8_STRING", tags);
         if(stime)
                 changeprop_long(d, w, "_WMII_LAUNCH_TIME", "CARDINAL", &stime, 1);
@@ -142,3 +142,20 @@ XMapRaised(Display *d, Window w) {
         return mapraised(d, w);
 }
 
+/* These are not perfect. */
+int
+XUnmapWindow(Display *d, Window w) {
+
+ if(lastwin == w)
+ lastwin = 0;
+ return unmapwindow(d, w);
+}
+
+int
+XDestroyWindow(Display *d, Window w) {
+
+ if(lastwin == w)
+ lastwin = 0;
+ return destroywindow(d, w);
+}
+
diff -r d30dd7887635 -r f0f54438fdab libwmii_hack/x11.c
--- a/libwmii_hack/x11.c Sun Feb 03 17:45:28 2008 -0500
+++ b/libwmii_hack/x11.c Sun Feb 03 19:10:13 2008 -0500
@@ -150,25 +150,47 @@ strlistdup(char *list[], int n) {
 }
 #endif
 
-#if 0
+static char**
+strlistdup(char *list[]) {
+ char **p, *q;
+ int i, m, n;
+
+ n = 0;
+ m = 0;
+ for(p=list; *p; p++, n++)
+ m += strlen(*p) + 1;
+
+ 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;
+ memcpy(q, list[i], m);
+ q += m;
+ }
+ p[n] = nil;
+ return p;
+}
+
 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;
+ if(Xutf8TextPropertyToTextList(display, &prop, &list, &n) == Success) {
+ *ret = strlistdup(list);
+ XFreeStringList(list);
+ }
                 XFree(prop.value);
         }
         return n;
 }
-#endif
 
 #if 0
 static char*
diff -r d30dd7887635 -r f0f54438fdab libwmii_hack/x11.h
--- a/libwmii_hack/x11.h Sun Feb 03 17:45:28 2008 -0500
+++ b/libwmii_hack/x11.h Sun Feb 03 19:10:13 2008 -0500
@@ -12,7 +12,7 @@ static void changeproperty(Display*, Win
 /* 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 int getprop_textlist(Display*, Window, char*, char**[]);
 /* static ulong getproperty(Display*, Window, char*, char*, Atom*, ulong, uchar**, ulong); */
 static Atom xatom(Display*, char*);
 
Received on Mon Feb 04 2008 - 01:12:04 UTC

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