Re: [wmii] x11-window-id for clients patch

From: Daniel Waeber <_wabu_AT_web.de>
Date: Sun, 21 Jan 2007 18:11:33 +0100

Timo Benk wrote:
> But there is a little problem:
>
> Before the patch it was possible to use the ID in /client/ID to toggle a
> client:
>
> echo -n "send ID toggle" | wmiir write /tag/xterm/ctl
>
> After the patch the same command, but with the X11 ID instead, gives me:
>
> ixpc: cannot write file: bad value
>
> Greetings,
> -timo
>

Thanks for the hint, I did not edit all lines that needed it. Heres the
new patch.

Regrads,
        wabu

diff -r f8e25d315eed client.c
--- a/client.c Tue Jan 16 23:01:53 2007 +0100
+++ b/client.c Sun Jan 21 18:00:34 2007 +0100
@@ -15,14 +15,6 @@ Client *
 Client *
 sel_client() {
         return screen->sel && screen->sel->sel->sel ? screen->sel->sel->sel->client : NULL;
-}
-
-int
-idx_of_client(Client *c) {
- Client *cl;
- int i = 0;
- for(cl=client; cl && cl != c; cl=cl->next, i++);
- return cl ? i : -1;
 }
 
 Client *
@@ -81,10 +73,7 @@ create_client(Window w, XWindowAttribute
         Client **t, *c = (Client *) ixp_emallocz(sizeof(Client));
         XSetWindowAttributes fwa;
         long msize;
- unsigned int i;
- static unsigned int id = 1;
-
- c->id = id++;
+
         c->win = w;
         c->rect.x = wa->x;
         c->rect.y = wa->y;
@@ -117,10 +106,10 @@ create_client(Window w, XWindowAttribute
                         CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa);
         c->gc = XCreateGC(blz.dpy, c->framewin, 0, 0);
         XSync(blz.dpy, False);
- for(t=&client, i=0; *t; t=&(*t)->next, i++);
+ for(t=&client; *t; t=&(*t)->next);
         c->next = *t; /* *t == NULL */
         *t = c;
- write_event("CreateClient %d\n", i);
+ write_event("CreateClient %d\n", c->win);
         return c;
 }
 
@@ -180,7 +169,7 @@ focus_client(Client *c, Bool restack) {
                 if(a_i) write_event("ColumnFocus %d\n", a_i);
                 else write_event("FocusFloating\n");
         }
- write_event("ClientFocus %d\n", idx_of_client(c));
+ write_event("ClientFocus %d\n", c->win);
 }
 
 void
@@ -375,7 +364,6 @@ destroy_client(Client *c) {
 destroy_client(Client *c) {
         char *dummy = NULL;
         Client **tc;
- uint i = idx_of_client(c);
 
         XGrabServer(blz.dpy);
         XSetErrorHandler(dummy_error_handler);
@@ -397,7 +385,7 @@ destroy_client(Client *c) {
         XSetErrorHandler(wmii_error_handler);
         XUngrabServer(blz.dpy);
         flush_masked_events(EnterWindowMask);
- write_event("DestroyClient %d\n", i);
+ write_event("DestroyClient %d\n", c->win);
 }
 
 void
diff -r f8e25d315eed config.mk
--- a/config.mk Tue Jan 16 23:01:53 2007 +0100
+++ b/config.mk Sun Jan 21 17:59:46 2007 +0100
@@ -5,7 +5,7 @@ CONFVERSION = 3.5
 # Customize below to fit your system
 
 # paths
-PREFIX = /usr/local
+PREFIX = /usr
 CONFPREFIX = ${PREFIX}/etc
 MANPREFIX = ${PREFIX}/share/man
 
diff -r f8e25d315eed event.c
--- a/event.c Tue Jan 16 23:01:53 2007 +0100
+++ b/event.c Sun Jan 21 17:59:46 2007 +0100
@@ -74,7 +74,7 @@ buttonrelease(XEvent *e) {
                         }
         }
         else if((f = frame_of_win(ev->window)))
- write_event("ClientClick %d %d\n", idx_of_client(f->client), ev->button);
+ write_event("ClientClick %d %d\n", f->client->win, ev->button);
 }
 
 static void
diff -r f8e25d315eed fs.c
--- a/fs.c Tue Jan 16 23:01:53 2007 +0100
+++ b/fs.c Sun Jan 21 18:00:02 2007 +0100
@@ -365,7 +365,7 @@ lookup_file(FileId *parent, char *name)
         Client *c;
         View *v;
         Bar *b;
- unsigned int i, id;
+ unsigned int id;
 
         if(!(parent->tab.perm & P9DMDIR))
                 return NULL;
@@ -383,8 +383,8 @@ lookup_file(FileId *parent, char *name)
                                                 *last = file;
                                                 last = &file->next;
                                                 file->content.client = c;
- file->id = c->id;
- file->index = idx_of_client(c);
+ file->id = c->win;
+ file->index = c->win;
                                                 file->tab = *dir;
                                                 file->tab.name = ixp_estrdup("sel");
                                         }if(name) goto LastItem;
@@ -393,17 +393,16 @@ lookup_file(FileId *parent, char *name)
                                         id = (unsigned int)strtol(name, &name, 10);
                                         if(*name) goto NextItem;
                                 }
- i=0;
- for(c=client; c; c=c->next, i++) {
- if(!name || i == id) {
+ for(c=client; c; c=c->next) {
+ if(!name || c->win == id) {
                                                 file = get_file();
                                                 *last = file;
                                                 last = &file->next;
                                                 file->content.client = c;
- file->id = c->id;
+ file->id = c->win;
                                                 file->tab = *dir;
                                                 file->tab.name = ixp_emallocz(16);
- snprintf(file->tab.name, 16, "%d", i);
+ snprintf(file->tab.name, 16, "%d", c->win);
                                                 if(name) goto LastItem;
                                         }
                                 }
diff -r f8e25d315eed view.c
--- a/view.c Tue Jan 16 23:01:53 2007 +0100
+++ b/view.c Sun Jan 21 17:59:46 2007 +0100
@@ -287,12 +287,12 @@ view_index(View *v) {
                         XRectangle *r = &f->rect;
                         if(a->floating)
                                 n = snprintf(&buffer[buf_i], len, "~ %d %d %d %d %d %s\n",
- idx_of_client(f->client),
+ f->client->win,
                                                 r->x, r->y, r->width, r->height,
                                                 f->client->props);
                         else
                                 n = snprintf(&buffer[buf_i], len, "%d %d %d %d %s\n",
- a_i, idx_of_client(f->client), r->y,
+ a_i, f->client->win, r->y,
                                                 r->height, f->client->props);
                         if(len - n < 0)
                                 return (unsigned char *)buffer;
@@ -305,16 +305,16 @@ view_index(View *v) {
 
 Client *
 client_of_message(View *v, char *message, unsigned int *next) {
- unsigned int i;
+ unsigned int id;
         Client *c;
 
         if(!strncmp(message, "sel ", 4)) {
                 *next = 4;
                 return sel_client_of_view(v);
         }
- if((1 != sscanf(message, "%d %n", &i, next)))
+ if((1 != sscanf(message, "%d %n", &id, next)))
                 return NULL;
- for(c=client; i && c; c=c->next, i--);
+ for(c=client; c && c->win!=id; c=c->next);
         return c;
 }
 
diff -r f8e25d315eed wmii.h
--- a/wmii.h Tue Jan 16 23:01:53 2007 +0100
+++ b/wmii.h Sun Jan 21 17:59:46 2007 +0100
@@ -135,7 +135,6 @@ struct Client {
         char name[256];
         char tags[256];
         char props[512];
- unsigned short id;
         unsigned int border;
         int proto;
         Bool floating;
@@ -280,7 +279,6 @@ extern Client *sel_client();
 extern Client *sel_client();
 extern Frame *frame_of_win(Window w);
 extern Client *client_of_win(Window w);
-extern int idx_of_client(Client *c);
 extern void update_client_grab(Client *c, Bool is_sel);
 extern void apply_rules(Client *c);
 extern void apply_tags(Client *c, const char *tags);

Received on Sun Jan 21 2007 - 18:12:50 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 16:19:34 UTC